Weird usages of sentinel_ok()
Weird usages of sentinel_ok()
In [1], Matthias is proposing to introduce a new system memory context type that basically ties palloc directly to malloc. While reviewing that patch, I noticed it copied a usage of sentinel_ok() that deviates from the norm. Technically it's fine, as sentinel_ok()'s first parameter is a void pointer, so passing the MemoryChunk rather than what palloc() would return is fine, provided you add on the byte difference to the MemoryChunk. I felt the need to mention the weirdness during the review, and since people clearly copy a load of code from an existing context type when adding new ones, it means that pattern is going to be copied again when the next person adds a new allocator. I thought it might be good to adjust this at the source to prevent that. Anyone disagree? Patch attached. David [1] https://postgr.es/m/CAApHDvp_-zh5cdR_aNaUCXGHeddWC0b1a5kiJpC1cKdG0vx6DA@mail.gmail.com
Re: Weird usages of sentinel_ok()
От:
shihao zhong <zhong950419@gmail.com>
Дата:
Hi David,
The patch looks right to me. All three CHUNKHDRSZ macros are
sizeof(MemoryChunk), so the checked byte is the same.
While looking at the other callers I noticed bump.c sets the sentinel
and requested_size in BumpAllocLarge() and BumpAllocChunkFromBlock(),
but nothing ever reads them. Bump has no pfree, so BumpCheck() is the
only place that could check it, and it doesn't. Is that on purpose, or
should BumpCheck() call sentinel_ok() like the others do?
sizeof(MemoryChunk), so the checked byte is the same.
While looking at the other callers I noticed bump.c sets the sentinel
and requested_size in BumpAllocLarge() and BumpAllocChunkFromBlock(),
but nothing ever reads them. Bump has no pfree, so BumpCheck() is the
only place that could check it, and it doesn't. Is that on purpose, or
should BumpCheck() call sentinel_ok() like the others do?
Thanks,
Shihao
Re: Weird usages of sentinel_ok()
От:
David Rowley <dgrowleyml@gmail.com>
Дата:
On Fri, 16 Oct 2026 at 16:00, shihao zhong wrote: > The patch looks right to me. All three CHUNKHDRSZ macros are > sizeof(MemoryChunk), so the checked byte is the same. Thanks for checking. > While looking at the other callers I noticed bump.c sets the sentinel > and requested_size in BumpAllocLarge() and BumpAllocChunkFromBlock(), > but nothing ever reads them. Bump has no pfree, so BumpCheck() is the > only place that could check it, and it doesn't. Is that on purpose, or > should BumpCheck() call sentinel_ok() like the others do? It should be checked. It's quite a bad oversight. I've pushed a fix back to v17 to resolve that. David
Re: Weird usages of sentinel_ok()
От:
David Rowley <dgrowleyml@gmail.com>
Дата:
On Fri, 16 Oct 2026 at 16:00, shihao zhong wrote: > The patch looks right to me. All three CHUNKHDRSZ macros are > sizeof(MemoryChunk), so the checked byte is the same. I've now pushed the patch to adjust the 3 sentinel_ok() checks. David