From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: make LWLockCounter a global variable |
Date: | 2025-08-28 21:56:07 |
Message-ID: | 1943925.1756418167@sss.pgh.pa.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Nathan Bossart <nathandbossart(at)gmail(dot)com> writes:
> In lwlock.c, uses of LWLockCounter must first calculate its address in
> shared memory with something like this:
> LWLockCounter = (int *) ((char *) MainLWLockArray - sizeof(int));
> This appears to have been started by commit 82e861f in order to fix
> EXEC_BACKEND builds, but it could also be fixed by adding it to the
> BackendParameters struct. I find the current approach somewhat difficult
> to read and understand, so I'd like to switch to the latter approach. This
> is admittedly just nitpicking...
No objection here. As a small improvement, perhaps you could swap
around the code in LWLockShmemSize so that the order in which it
considers size contributions matches the physical layout, more
or less like
/* Calculate total number of locks needed in the main array. */
numLocks += NumLWLocksForNamedTranches();
+ /* Space for dynamic allocation counter, plus room for alignment. */
+ size = sizeof(int) + LWLOCK_PADDED_SIZE;
+
/* Space for the LWLock array. */
- size = mul_size(numLocks, sizeof(LWLockPadded));
+ size = add_size(size, mul_size(numLocks, sizeof(LWLockPadded)));
- /* Space for dynamic allocation counter, plus room for alignment. */
- size = add_size(size, sizeof(int) + LWLOCK_PADDED_SIZE);
-
/* space for named tranches. */
size = add_size(size, mul_size(NamedLWLockTrancheRequests, sizeof(NamedLWLockTranche)));
I find it a little confusing that that code doesn't line up
exactly with what CreateLWLocks does.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Matheus Alcantara | 2025-08-28 22:31:35 | Re: LISTEN/NOTIFY bug: VACUUM sets frozenxid past a xid in async queue |
Previous Message | Thomas Munro | 2025-08-28 21:50:57 | Re: index prefetching |