pgsql: Use single LWLock for lock statistics in pgstats - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Use single LWLock for lock statistics in pgstats
Date
Msg-id E1w9c7Q-003BZI-1q@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

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(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Improve more stability of worker_spi termination test
Next
From: Michael Paquier
Date:
Subject: Re: pgsql: Convert all remaining subsystems to use the new shmem allocation