Use single LWLock for lock statistics in pgstats Previously, one LWLock was used for each lock type, adding complexity without an observable performance benefit as data is gathered only for paths involving lock waits, at least currently. This commit replaces the per-type set of LWLocks with a single LWLock protecting the stats data of all the lock types, like the stats kinds for SLRU or WAL. A good chunk of the callbacks get simpler thanks to this change.
The previous approach also had one bug in the flush callback when nowait was called with "true": a backend iterating over all entries could successfully flush some entries while skipping others due to contention, then unconditionally reset the pending data. This would cause some stats data loss. Oversight in 4019f725f5d4. Reported-by: Tomas Vondra <[email protected]> Author: Bertrand Drouvot <[email protected]> Discussion: https://postgr.es/m/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/404a17c155ac6e80d990fb0625569a3854f7090d Modified Files -------------- src/backend/utils/activity/pgstat_lock.c | 86 +++++++++++--------------------- src/include/utils/pgstat_internal.h | 7 +-- 2 files changed, 31 insertions(+), 62 deletions(-)
