1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Simplify LWLock tranche machinery by removing array_base/array_stride.

array_base and array_stride were added so that we could identify the
offset of an LWLock within a tranche, but this facility is only very
marginally used apart from the main tranche.  So, give every lock in
the main tranche its own tranche ID and get rid of array_base,
array_stride, and all that's attached.  For debugging facilities
(Trace_lwlocks and LWLOCK_STATS) print the pointer address of the
LWLock using %p instead of the offset.  This is arguably more useful,
and certainly a lot cheaper.  Drop the offset-within-tranche from
the information reported to dtrace and from one can't-happen message
inside lwlock.c.

The main user-visible impact of this change is that pg_stat_activity
will now report all waits for LWLocks as "LWLock" rather than
reporting some as "LWLockTranche" and others as "LWLockNamed".

The main motivation for this change is that the need to specify an
array_base and an array_stride is awkward for parallel query.  There
is only a very limited supply of tranche IDs so we can't just keep
allocating new ones, and if we try to use the same tranche IDs every
time then we run into trouble when multiple parallel contexts are
use simultaneously.  So if we didn't get rid of this mechanism we'd
have to make it even more complicated.  By simplifying it in this
way, we instead reduce the size of the generated code for lwlock.c
by about 5%.

Discussion: http://postgr.es/m/CA+TgmoYsFn6NUW1x0AZtupJGUAs1UDY4dJtCN47_Q6D0sP80PA@mail.gmail.com
This commit is contained in:
Robert Haas
2016-12-16 11:29:23 -05:00
parent 4e344c2cf4
commit 3761fe3c20
14 changed files with 111 additions and 260 deletions

View File

@ -646,18 +646,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<itemizedlist>
<listitem>
<para>
<literal>LWLockNamed</>: The backend is waiting for a specific named
lightweight lock. Each such lock protects a particular data
structure in shared memory. <literal>wait_event</> will contain
the name of the lightweight lock.
</para>
</listitem>
<listitem>
<para>
<literal>LWLockTranche</>: The backend is waiting for one of a
group of related lightweight locks. All locks in the group perform
a similar function; <literal>wait_event</> will identify the general
purpose of locks in that group.
<literal>LWLock</>: The backend is waiting for a lightweight lock.
Each such lock protects a particular data structure in shared memory.
<literal>wait_event</> will contain a name identifying the purpose
of the lightweight lock. (Some locks have specific names; others
are part of a group of locks each with a similar purpose.)
</para>
</listitem>
<listitem>
@ -825,7 +818,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<tbody>
<row>
<entry morerows="41"><literal>LWLockNamed</></entry>
<entry morerows="57"><literal>LWLock</></entry>
<entry><literal>ShmemIndexLock</></entry>
<entry>Waiting to find or allocate space in shared memory.</entry>
</row>
@ -1011,7 +1004,6 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<entry>Waiting to read or update old snapshot control information.</entry>
</row>
<row>
<entry morerows="15"><literal>LWLockTranche</></entry>
<entry><literal>clog</></entry>
<entry>Waiting for I/O on a clog (transaction status) buffer.</entry>
</row>
@ -1279,7 +1271,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
pid | wait_event_type | wait_event
------+-----------------+---------------
2540 | Lock | relation
6644 | LWLockNamed | ProcArrayLock
6644 | LWLock | ProcArrayLock
(2 rows)
</programlisting>
</para>
@ -3347,55 +3339,49 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
</row>
<row>
<entry><literal>lwlock-acquire</literal></entry>
<entry><literal>(char *, int, LWLockMode)</literal></entry>
<entry><literal>(char *, LWLockMode)</literal></entry>
<entry>Probe that fires when an LWLock has been acquired.
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.
arg2 is the requested lock mode, either exclusive or shared.</entry>
arg1 is the requested lock mode, either exclusive or shared.</entry>
</row>
<row>
<entry><literal>lwlock-release</literal></entry>
<entry><literal>(char *, int)</literal></entry>
<entry><literal>(char *)</literal></entry>
<entry>Probe that fires when an LWLock has been released (but note
that any released waiters have not yet been awakened).
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.</entry>
arg0 is the LWLock's tranche.</entry>
</row>
<row>
<entry><literal>lwlock-wait-start</literal></entry>
<entry><literal>(char *, int, LWLockMode)</literal></entry>
<entry><literal>(char *, LWLockMode)</literal></entry>
<entry>Probe that fires when an LWLock was not immediately available and
a server process has begun to wait for the lock to become available.
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.
arg2 is the requested lock mode, either exclusive or shared.</entry>
arg1 is the requested lock mode, either exclusive or shared.</entry>
</row>
<row>
<entry><literal>lwlock-wait-done</literal></entry>
<entry><literal>(char *, int, LWLockMode)</literal></entry>
<entry><literal>(char *, LWLockMode)</literal></entry>
<entry>Probe that fires when a server process has been released from its
wait for an LWLock (it does not actually have the lock yet).
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.
arg2 is the requested lock mode, either exclusive or shared.</entry>
arg1 is the requested lock mode, either exclusive or shared.</entry>
</row>
<row>
<entry><literal>lwlock-condacquire</literal></entry>
<entry><literal>(char *, int, LWLockMode)</literal></entry>
<entry><literal>(char *, LWLockMode)</literal></entry>
<entry>Probe that fires when an LWLock was successfully acquired when the
caller specified no waiting.
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.
arg2 is the requested lock mode, either exclusive or shared.</entry>
arg1 is the requested lock mode, either exclusive or shared.</entry>
</row>
<row>
<entry><literal>lwlock-condacquire-fail</literal></entry>
<entry><literal>(char *, int, LWLockMode)</literal></entry>
<entry><literal>(char *, LWLockMode)</literal></entry>
<entry>Probe that fires when an LWLock was not successfully acquired when
the caller specified no waiting.
arg0 is the LWLock's tranche.
arg1 is the LWLock's offset within its tranche.
arg2 is the requested lock mode, either exclusive or shared.</entry>
arg1 is the requested lock mode, either exclusive or shared.</entry>
</row>
<row>
<entry><literal>lock-wait-start</literal></entry>