Use single LWLock for lock statistics in pgstats
Michael Paquier <michael@paquier.xyz>
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 <tomas@vondra.me> Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/1af63e6d-16d5-4d5b-9b03-11472ef1adf9@vondra.me
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/utils/activity/pgstat_lock.c | modified | +29 −57 |
| src/include/utils/pgstat_internal.h | modified | +2 −5 |
Discussion
- Adding locks statistics 61 messages · 2025-08-01 → 2026-04-07