Re: MAX_BACKENDS size (comment accuracy)
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Jacob Brazeal <jacob.brazeal@gmail.com>
Cc: pgsql-hackers@postgresql.org
Date: 2025-02-21T18:27:40Z
Lists: pgsql-hackers
Attachments
- v2-0001-Move-MAX_BACKENDS-to-procnumber.h.patch (text/x-diff)
Hi, On 2025-01-26 12:55:15 -0800, Jacob Brazeal wrote: > The patch series looks good. Thanks for reviewing! And sorry for not getting back to you about your review comments earlier. > > StaticAssertDecl((MAX_BACKENDS & LW_FLAG_MASK) == 0, > > "MAX_BACKENDS and LW_FLAG_MASK overlap"); > > Should this check that MAX_BACKENDS & LW_LOCK_MASK == 0? To also ensure the > LW_VAL_EXCLUSIVE bit does not overlap. Yes, I think you're right. On 2025-01-26 12:57:50 -0800, Jacob Brazeal wrote: > Looking at v1-0003-WIP-Base-LWLock-limits-directly-on-MAX_BACKENDS.patch, > I'm curious about the following assert; > > > #define LW_VAL_EXCLUSIVE (MAX_BACKENDS + 1) > ... > > StaticAssertDecl(MAX_BACKENDS < LW_VAL_EXCLUSIVE, > "MAX_BACKENDS too big for lwlock.c"); > > Since LW_VAL_EXCLUSIVE is already defined as MAX_BACKENDS + 1, is this > basically just checking for an integer overflow? You're right, it's redundant. I think I added that in an earlier version and then didn't remove it. Updated patches attached. I didn't really like moving MAX_BACKENDS to pg_config_manual.h, there are too many constraints on it. I moved it to procnumber.h. That's maybe not perfect, but seems a bit better? I also introduced MAX_BACKENDS_BITS, so that it's easier to check against when asserting restrictions on bit space. I also added a patch from a different thread, to remove a bunch of the magic constants in buf_internals.h, as it felt awkward to assert the refcount bits alone were compatible with MAX_BACKENDS, when a 'standalone' 18 was used in a bunch of other places. As Heikki had already reviewed that quite a while ago, I'll push that soon. I chose to not directly base BUF_REFCOUNT_BITS directly on MAX_BACKEND_BITS, as it's ok to lower MAX_BACKEND_BITS without adjusting BUF_REFCOUNT_BITS. But I went back and forth on that one. Greetings, Andres Freund
Commits
-
Fix comment for MAX_BACKENDS.
- c56e8af75e08 18.0 landed
-
Add static asserts for MAX_BACKENDS limiting factors
- 5ee75e32fa73 18.0 landed
-
Base LWLock limits directly on MAX_BACKENDS
- cd3ccf88aacb 18.0 landed
-
Move MAX_BACKENDS to procnumber.h
- 6394a3a61c0d 18.0 landed
-
bufmgr: Make it easier to change number of buffer state bits
- 418451bfe161 18.0 landed
-
Remove check hooks for GUCs that contribute to MaxBackends.
- 0b1fe1413ea8 18.0 cited
-
Allow Pin/UnpinBuffer to operate in a lockfree manner.
- 48354581a49c 9.6.0 cited