Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3761fe3

Browse files
committed
Simplify LWLock tranche machinery by removing array_base/array_stride.
array_base and array_stride were added so that we could identify theoffset of an LWLock within a tranche, but this facility is only verymarginally used apart from the main tranche. So, give every lock inthe 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 theLWLock using %p instead of the offset. This is arguably more useful,and certainly a lot cheaper. Drop the offset-within-tranche fromthe information reported to dtrace and from one can't-happen messageinside lwlock.c.The main user-visible impact of this change is that pg_stat_activitywill now report all waits for LWLocks as "LWLock" rather thanreporting some as "LWLockTranche" and others as "LWLockNamed".The main motivation for this change is that the need to specify anarray_base and an array_stride is awkward for parallel query. Thereis only a very limited supply of tranche IDs so we can't just keepallocating new ones, and if we try to use the same tranche IDs everytime then we run into trouble when multiple parallel contexts areuse simultaneously. So if we didn't get rid of this mechanism we'dhave to make it even more complicated. By simplifying it in thisway, we instead reduce the size of the generated code for lwlock.cby about 5%.Discussion:http://postgr.es/m/CA+TgmoYsFn6NUW1x0AZtupJGUAs1UDY4dJtCN47_Q6D0sP80PA@mail.gmail.com
1 parent4e344c2 commit3761fe3

File tree

14 files changed

+112
-261
lines changed

14 files changed

+112
-261
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -646,18 +646,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
646646
<itemizedlist>
647647
<listitem>
648648
<para>
649-
<literal>LWLockNamed</>: The backend is waiting for a specific named
650-
lightweight lock. Each such lock protects a particular data
651-
structure in shared memory. <literal>wait_event</> will contain
652-
the name of the lightweight lock.
653-
</para>
654-
</listitem>
655-
<listitem>
656-
<para>
657-
<literal>LWLockTranche</>: The backend is waiting for one of a
658-
group of related lightweight locks. All locks in the group perform
659-
a similar function; <literal>wait_event</> will identify the general
660-
purpose of locks in that group.
649+
<literal>LWLock</>: The backend is waiting for a lightweight lock.
650+
Each such lock protects a particular data structure in shared memory.
651+
<literal>wait_event</> will contain a name identifying the purpose
652+
of the lightweight lock. (Some locks have specific names; others
653+
are part of a group of locks each with a similar purpose.)
661654
</para>
662655
</listitem>
663656
<listitem>
@@ -825,7 +818,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
825818

826819
<tbody>
827820
<row>
828-
<entry morerows="41"><literal>LWLockNamed</></entry>
821+
<entry morerows="57"><literal>LWLock</></entry>
829822
<entry><literal>ShmemIndexLock</></entry>
830823
<entry>Waiting to find or allocate space in shared memory.</entry>
831824
</row>
@@ -1011,7 +1004,6 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
10111004
<entry>Waiting to read or update old snapshot control information.</entry>
10121005
</row>
10131006
<row>
1014-
<entry morerows="15"><literal>LWLockTranche</></entry>
10151007
<entry><literal>clog</></entry>
10161008
<entry>Waiting for I/O on a clog (transaction status) buffer.</entry>
10171009
</row>
@@ -1279,7 +1271,7 @@ SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event i
12791271
pid | wait_event_type | wait_event
12801272
------+-----------------+---------------
12811273
2540 | Lock | relation
1282-
6644 |LWLockNamed | ProcArrayLock
1274+
6644 |LWLock | ProcArrayLock
12831275
(2 rows)
12841276
</programlisting>
12851277
</para>
@@ -3347,55 +3339,49 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
33473339
</row>
33483340
<row>
33493341
<entry><literal>lwlock-acquire</literal></entry>
3350-
<entry><literal>(char *,int,LWLockMode)</literal></entry>
3342+
<entry><literal>(char *, LWLockMode)</literal></entry>
33513343
<entry>Probe that fires when an LWLock has been acquired.
33523344
arg0 is the LWLock's tranche.
3353-
arg1 is the LWLock's offset within its tranche.
3354-
arg2 is the requested lock mode, either exclusive or shared.</entry>
3345+
arg1 is the requested lock mode, either exclusive or shared.</entry>
33553346
</row>
33563347
<row>
33573348
<entry><literal>lwlock-release</literal></entry>
3358-
<entry><literal>(char *, int)</literal></entry>
3349+
<entry><literal>(char *)</literal></entry>
33593350
<entry>Probe that fires when an LWLock has been released (but note
33603351
that any released waiters have not yet been awakened).
3361-
arg0 is the LWLock's tranche.
3362-
arg1 is the LWLock's offset within its tranche.</entry>
3352+
arg0 is the LWLock's tranche.</entry>
33633353
</row>
33643354
<row>
33653355
<entry><literal>lwlock-wait-start</literal></entry>
3366-
<entry><literal>(char *,int,LWLockMode)</literal></entry>
3356+
<entry><literal>(char *, LWLockMode)</literal></entry>
33673357
<entry>Probe that fires when an LWLock was not immediately available and
33683358
a server process has begun to wait for the lock to become available.
33693359
arg0 is the LWLock's tranche.
3370-
arg1 is the LWLock's offset within its tranche.
3371-
arg2 is the requested lock mode, either exclusive or shared.</entry>
3360+
arg1 is the requested lock mode, either exclusive or shared.</entry>
33723361
</row>
33733362
<row>
33743363
<entry><literal>lwlock-wait-done</literal></entry>
3375-
<entry><literal>(char *,int,LWLockMode)</literal></entry>
3364+
<entry><literal>(char *, LWLockMode)</literal></entry>
33763365
<entry>Probe that fires when a server process has been released from its
33773366
wait for an LWLock (it does not actually have the lock yet).
33783367
arg0 is the LWLock's tranche.
3379-
arg1 is the LWLock's offset within its tranche.
3380-
arg2 is the requested lock mode, either exclusive or shared.</entry>
3368+
arg1 is the requested lock mode, either exclusive or shared.</entry>
33813369
</row>
33823370
<row>
33833371
<entry><literal>lwlock-condacquire</literal></entry>
3384-
<entry><literal>(char *,int,LWLockMode)</literal></entry>
3372+
<entry><literal>(char *, LWLockMode)</literal></entry>
33853373
<entry>Probe that fires when an LWLock was successfully acquired when the
33863374
caller specified no waiting.
33873375
arg0 is the LWLock's tranche.
3388-
arg1 is the LWLock's offset within its tranche.
3389-
arg2 is the requested lock mode, either exclusive or shared.</entry>
3376+
arg1 is the requested lock mode, either exclusive or shared.</entry>
33903377
</row>
33913378
<row>
33923379
<entry><literal>lwlock-condacquire-fail</literal></entry>
3393-
<entry><literal>(char *,int,LWLockMode)</literal></entry>
3380+
<entry><literal>(char *, LWLockMode)</literal></entry>
33943381
<entry>Probe that fires when an LWLock was not successfully acquired when
33953382
the caller specified no waiting.
33963383
arg0 is the LWLock's tranche.
3397-
arg1 is the LWLock's offset within its tranche.
3398-
arg2 is the requested lock mode, either exclusive or shared.</entry>
3384+
arg1 is the requested lock mode, either exclusive or shared.</entry>
33993385
</row>
34003386
<row>
34013387
<entry><literal>lock-wait-start</literal></entry>

‎src/backend/access/transam/slru.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
216216
Assert(strlen(name)+1<SLRU_MAX_NAME_LENGTH);
217217
strlcpy(shared->lwlock_tranche_name,name,SLRU_MAX_NAME_LENGTH);
218218
shared->lwlock_tranche_id=tranche_id;
219-
shared->lwlock_tranche.name=shared->lwlock_tranche_name;
220-
shared->lwlock_tranche.array_base=shared->buffer_locks;
221-
shared->lwlock_tranche.array_stride=sizeof(LWLockPadded);
222219

223220
ptr+=BUFFERALIGN(offset);
224221
for (slotno=0;slotno<nslots;slotno++)
@@ -237,7 +234,8 @@ SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
237234
Assert(found);
238235

239236
/* Register SLRU tranche in the main tranches array */
240-
LWLockRegisterTranche(shared->lwlock_tranche_id,&shared->lwlock_tranche);
237+
LWLockRegisterTranche(shared->lwlock_tranche_id,
238+
shared->lwlock_tranche_name);
241239

242240
/*
243241
* Initialize the unshared control struct, including directory path. We

‎src/backend/access/transam/xlog.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ typedef struct XLogCtlInsert
517517
* WAL insertion locks.
518518
*/
519519
WALInsertLockPadded*WALInsertLocks;
520-
LWLockTrancheWALInsertLockTranche;
521520
}XLogCtlInsert;
522521

523522
/*
@@ -4688,7 +4687,7 @@ XLOGShmemInit(void)
46884687
/* Initialize local copy of WALInsertLocks and register the tranche */
46894688
WALInsertLocks=XLogCtl->Insert.WALInsertLocks;
46904689
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,
4691-
&XLogCtl->Insert.WALInsertLockTranche);
4690+
"wal_insert");
46924691
return;
46934692
}
46944693
memset(XLogCtl,0,sizeof(XLogCtlData));
@@ -4711,11 +4710,7 @@ XLOGShmemInit(void)
47114710
(WALInsertLockPadded*)allocptr;
47124711
allocptr+=sizeof(WALInsertLockPadded)*NUM_XLOGINSERT_LOCKS;
47134712

4714-
XLogCtl->Insert.WALInsertLockTranche.name="wal_insert";
4715-
XLogCtl->Insert.WALInsertLockTranche.array_base=WALInsertLocks;
4716-
XLogCtl->Insert.WALInsertLockTranche.array_stride=sizeof(WALInsertLockPadded);
4717-
4718-
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,&XLogCtl->Insert.WALInsertLockTranche);
4713+
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,"wal_insert");
47194714
for (i=0;i<NUM_XLOGINSERT_LOCKS;i++)
47204715
{
47214716
LWLockInitialize(&WALInsertLocks[i].l.lock,LWTRANCHE_WAL_INSERT);

‎src/backend/postmaster/pgstat.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,11 +3152,8 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
31523152

31533153
switch (classId)
31543154
{
3155-
casePG_WAIT_LWLOCK_NAMED:
3156-
event_type="LWLockNamed";
3157-
break;
3158-
casePG_WAIT_LWLOCK_TRANCHE:
3159-
event_type="LWLockTranche";
3155+
casePG_WAIT_LWLOCK:
3156+
event_type="LWLock";
31603157
break;
31613158
casePG_WAIT_LOCK:
31623159
event_type="Lock";
@@ -3209,8 +3206,7 @@ pgstat_get_wait_event(uint32 wait_event_info)
32093206

32103207
switch (classId)
32113208
{
3212-
casePG_WAIT_LWLOCK_NAMED:
3213-
casePG_WAIT_LWLOCK_TRANCHE:
3209+
casePG_WAIT_LWLOCK:
32143210
event_name=GetLWLockIdentifier(classId,eventId);
32153211
break;
32163212
casePG_WAIT_LOCK:

‎src/backend/replication/logical/origin.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ typedef struct ReplicationStateOnDisk
143143
typedefstructReplicationStateCtl
144144
{
145145
inttranche_id;
146-
LWLockTranchetranche;
147146
ReplicationStatestates[FLEXIBLE_ARRAY_MEMBER];
148147
}ReplicationStateCtl;
149148

@@ -474,11 +473,6 @@ ReplicationOriginShmemInit(void)
474473
inti;
475474

476475
replication_states_ctl->tranche_id=LWTRANCHE_REPLICATION_ORIGIN;
477-
replication_states_ctl->tranche.name="replication_origin";
478-
replication_states_ctl->tranche.array_base=
479-
&replication_states[0].lock;
480-
replication_states_ctl->tranche.array_stride=
481-
sizeof(ReplicationState);
482476

483477
MemSet(replication_states,0,ReplicationOriginShmemSize());
484478

@@ -488,7 +482,7 @@ ReplicationOriginShmemInit(void)
488482
}
489483

490484
LWLockRegisterTranche(replication_states_ctl->tranche_id,
491-
&replication_states_ctl->tranche);
485+
"replication_origin");
492486
}
493487

494488
/* ---------------------------------------------------------------------------

‎src/backend/replication/slot.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ ReplicationSlot *MyReplicationSlot = NULL;
9898
intmax_replication_slots=0;/* the maximum number of replication
9999
* slots */
100100

101-
staticLWLockTrancheReplSlotIOLWLockTranche;
102-
103101
staticvoidReplicationSlotDropAcquired(void);
104102
staticvoidReplicationSlotDropPtr(ReplicationSlot*slot);
105103

@@ -141,12 +139,8 @@ ReplicationSlotsShmemInit(void)
141139
ShmemInitStruct("ReplicationSlot Ctl",ReplicationSlotsShmemSize(),
142140
&found);
143141

144-
ReplSlotIOLWLockTranche.name="replication_slot_io";
145-
ReplSlotIOLWLockTranche.array_base=
146-
((char*)ReplicationSlotCtl)+ offsetof(ReplicationSlotCtlData,replication_slots)+offsetof(ReplicationSlot,io_in_progress_lock);
147-
ReplSlotIOLWLockTranche.array_stride=sizeof(ReplicationSlot);
148142
LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS,
149-
&ReplSlotIOLWLockTranche);
143+
"replication_slot_io");
150144

151145
if (!found)
152146
{

‎src/backend/storage/buffer/buf_init.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
BufferDescPadded*BufferDescriptors;
2222
char*BufferBlocks;
2323
LWLockMinimallyPadded*BufferIOLWLockArray=NULL;
24-
LWLockTrancheBufferIOLWLockTranche;
25-
LWLockTrancheBufferContentLWLockTranche;
2624
WritebackContextBackendWritebackContext;
2725
CkptSortItem*CkptBufferIds;
2826

@@ -90,18 +88,8 @@ InitBufferPool(void)
9088
NBuffers* (Size)sizeof(LWLockMinimallyPadded),
9189
&foundIOLocks);
9290

93-
BufferIOLWLockTranche.name="buffer_io";
94-
BufferIOLWLockTranche.array_base=BufferIOLWLockArray;
95-
BufferIOLWLockTranche.array_stride=sizeof(LWLockMinimallyPadded);
96-
LWLockRegisterTranche(LWTRANCHE_BUFFER_IO_IN_PROGRESS,
97-
&BufferIOLWLockTranche);
98-
99-
BufferContentLWLockTranche.name="buffer_content";
100-
BufferContentLWLockTranche.array_base=
101-
((char*)BufferDescriptors)+ offsetof(BufferDesc,content_lock);
102-
BufferContentLWLockTranche.array_stride=sizeof(BufferDescPadded);
103-
LWLockRegisterTranche(LWTRANCHE_BUFFER_CONTENT,
104-
&BufferContentLWLockTranche);
91+
LWLockRegisterTranche(LWTRANCHE_BUFFER_IO_IN_PROGRESS,"buffer_io");
92+
LWLockRegisterTranche(LWTRANCHE_BUFFER_CONTENT,"buffer_content");
10593

10694
/*
10795
* The array used to sort to-be-checkpointed buffer ids is located in

‎src/backend/storage/ipc/procarray.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ static TransactionId *KnownAssignedXids;
106106
staticbool*KnownAssignedXidsValid;
107107
staticTransactionIdlatestObservedXid=InvalidTransactionId;
108108

109-
/* LWLock tranche for backend locks */
110-
staticLWLockTrancheProcLWLockTranche;
111-
112109
/*
113110
* If we're in STANDBY_SNAPSHOT_PENDING state, standbySnapshotPendingXmin is
114111
* the highest xid that might still be running that we don't have in
@@ -266,11 +263,7 @@ CreateSharedProcArray(void)
266263
}
267264

268265
/* Register and initialize fields of ProcLWLockTranche */
269-
ProcLWLockTranche.name="proc";
270-
ProcLWLockTranche.array_base= (char*) (ProcGlobal->allProcs)+
271-
offsetof(PGPROC,backendLock);
272-
ProcLWLockTranche.array_stride=sizeof(PGPROC);
273-
LWLockRegisterTranche(LWTRANCHE_PROC,&ProcLWLockTranche);
266+
LWLockRegisterTranche(LWTRANCHE_PROC,"proc");
274267
}
275268

276269
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp