On Thu, Mar 07, 2019 at 11:25:10AM +0900, Michael Paquier wrote:
> On Wed, Mar 06, 2019 at 11:08:12AM -0800, Jeremy Schneider wrote:
>> If anything, I think we might just want to add comments to
>> RegisterLWLockTranches() and lwlocknames.txt with links to the doc file
>> that needs to be updated whenever a new tranche is added.
> 
> Yes, that would surely help.
> 
>> Not sure the best place for a comment on SLRUs (is SimpleLruInit a good
>> place?)... but I'm kindof hopeful that we're not adding many more new
>> SLRUs anyway and that people would bias toward leveraging the buffer
>> cache when possible.
> 
> A reference at the top of SimpleLruInit() sounds good to me.

Thinking more about that, a comment at the top of SimpleLruInit() and
RegisterLWLockTranches() are both good things.

So please find attached a patch which does the following things to
address this thread:
- Reorder the list of events in the Lock section in alphabetical order
(not LWLock!).
- Add the missing event entries, which is what Thomas has provided.
- Add more documentation to mention the doc updates.

Thoughts?
--
Michael
diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index 0e73cdcdda..feff6d4d60 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -861,7 +861,7 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
 
       <tbody>
        <row>
-        <entry morerows="63"><literal>LWLock</literal></entry>
+        <entry morerows="67"><literal>LWLock</literal></entry>
         <entry><literal>ShmemIndexLock</literal></entry>
         <entry>Waiting to find or allocate space in shared memory.</entry>
        </row>
@@ -1139,44 +1139,27 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
          <entry>Waiting to allocate or exchange a chunk of memory or update
          counters during Parallel Hash plan execution.</entry>
         </row>
+        <row>
+         <entry><literal>session_dsa</literal></entry>
+         <entry>Waiting for per-session dynamic shared memory allocation
+         lock.</entry>
+        </row>
+        <row>
+         <entry><literal>session_record_table</literal></entry>
+         <entry>Waiting to access a shared record type cache by
+         structure.</entry>
+        </row>
+        <row>
+         <entry><literal>session_typmod_table</literal></entry>
+         <entry>Waiting to access a shared record type cache by
+         typmod.</entry>
+        </row>
+        <row>
+         <entry><literal>shared_tuplestore</literal></entry>
+         <entry>Waiting to access a shared tuplestore.</entry>
+        </row>
         <row>
          <entry morerows="9"><literal>Lock</literal></entry>
-         <entry><literal>relation</literal></entry>
-         <entry>Waiting to acquire a lock on a relation.</entry>
-        </row>
-        <row>
-         <entry><literal>extend</literal></entry>
-         <entry>Waiting to extend a relation.</entry>
-        </row>
-        <row>
-         <entry><literal>page</literal></entry>
-         <entry>Waiting to acquire a lock on page of a relation.</entry>
-        </row>
-        <row>
-         <entry><literal>tuple</literal></entry>
-         <entry>Waiting to acquire a lock on a tuple.</entry>
-        </row>
-        <row>
-         <entry><literal>transactionid</literal></entry>
-         <entry>Waiting for a transaction to finish.</entry>
-        </row>
-        <row>
-         <entry><literal>virtualxid</literal></entry>
-         <entry>Waiting to acquire a virtual xid lock.</entry>
-        </row>
-        <row>
-         <entry><literal>speculative token</literal></entry>
-         <entry>Waiting to acquire a speculative insertion lock.</entry>
-        </row>
-        <row>
-         <entry><literal>object</literal></entry>
-         <entry>Waiting to acquire a lock on a non-relation database object.</entry>
-        </row>
-        <row>
-         <entry><literal>userlock</literal></entry>
-         <entry>Waiting to acquire a user lock.</entry>
-        </row>
-        <row>
          <entry><literal>advisory</literal></entry>
          <entry>Waiting to acquire an advisory user lock.</entry>
         </row>
@@ -1185,6 +1168,42 @@ postgres   27093  0.0  0.0  30096  2752 ?        Ss   11:34   0:00 postgres: ser
          <entry><literal>BufferPin</literal></entry>
          <entry>Waiting to acquire a pin on a buffer.</entry>
         </row>
+        <row>
+         <entry><literal>extend</literal></entry>
+         <entry>Waiting to extend a relation.</entry>
+        </row>
+        <row>
+         <entry><literal>object</literal></entry>
+         <entry>Waiting to acquire a lock on a non-relation database object.</entry>
+        </row>
+        <row>
+         <entry><literal>page</literal></entry>
+         <entry>Waiting to acquire a lock on page of a relation.</entry>
+        </row>
+        <row>
+         <entry><literal>relation</literal></entry>
+         <entry>Waiting to acquire a lock on a relation.</entry>
+        </row>
+        <row>
+         <entry><literal>speculative token</literal></entry>
+         <entry>Waiting to acquire a speculative insertion lock.</entry>
+        </row>
+        <row>
+         <entry><literal>transactionid</literal></entry>
+         <entry>Waiting for a transaction to finish.</entry>
+        </row>
+        <row>
+         <entry><literal>tuple</literal></entry>
+         <entry>Waiting to acquire a lock on a tuple.</entry>
+        </row>
+        <row>
+         <entry><literal>userlock</literal></entry>
+         <entry>Waiting to acquire a user lock.</entry>
+        </row>
+        <row>
+         <entry><literal>virtualxid</literal></entry>
+         <entry>Waiting to acquire a virtual xid lock.</entry>
+        </row>
         <row>
          <entry morerows="13"><literal>Activity</literal></entry>
          <entry><literal>ArchiverMain</literal></entry>
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c
index 3623352b9c..42ddc61121 100644
--- a/src/backend/access/transam/slru.c
+++ b/src/backend/access/transam/slru.c
@@ -161,6 +161,12 @@ SimpleLruShmemSize(int nslots, int nlsns)
 	return BUFFERALIGN(sz) + BLCKSZ * nslots;
 }
 
+/*
+ * Initialize new SLRU tranche in shared memory
+ *
+ * Note that the tranche name is registered as a wait event, hence the
+ * related documentation for pg_stat_activity should be kept in sync.
+ */
 void
 SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
 			  LWLock *ctllock, const char *subdir, int tranche_id)
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 81dac45ae5..beeca0011d 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -597,6 +597,9 @@ LWLockNewTrancheId(void)
  * routine will save a pointer to the tranche name passed as an argument,
  * so the name should be allocated in a backend-lifetime context
  * (TopMemoryContext, static variable, or similar).
+ *
+ * Note that the tranche name is registered as a wait event, hence the related
+ * documentation for pg_stat_activity should be kept in sync.
  */
 void
 LWLockRegisterTranche(int tranche_id, const char *tranche_name)
diff --git a/src/backend/storage/lmgr/lwlocknames.txt b/src/backend/storage/lmgr/lwlocknames.txt
index db47843229..7c87529382 100644
--- a/src/backend/storage/lmgr/lwlocknames.txt
+++ b/src/backend/storage/lmgr/lwlocknames.txt
@@ -2,7 +2,8 @@
 # these are defined here.  If you add a lock, add it to the end to avoid
 # renumbering the existing locks; if you remove a lock, consider leaving a gap
 # in the numbering sequence for the benefit of DTrace and other external
-# debugging scripts.
+# debugging scripts.  Each lock has an associated wait event, hence the
+# documentation for pg_stat_activity should be kept in sync with this data.
 
 # 0 is available; was formerly BufFreelistLock
 ShmemIndexLock						1

Attachment: signature.asc
Description: PGP signature

Reply via email to