Fix some rounding code for shared memory.
authorNathan Bossart <nathan@postgresql.org>
Fri, 23 Jan 2026 16:46:49 +0000 (10:46 -0600)
committerNathan Bossart <nathan@postgresql.org>
Fri, 23 Jan 2026 16:46:49 +0000 (10:46 -0600)
commit8eef2df1898cc34dfaa69ff200f5112d7eeb7c67
tree4a334920d9ed212e66565961f57d26bb3ae7d442
parenta36164e7465fd1e10e94569e9c1c07656e38a9de
Fix some rounding code for shared memory.

InitializeShmemGUCs() always added 1 to the value calculated for
shared_memory_size_in_huge_pages, which is unnecessary if the
shared memory size is divisible by the huge page size.

CreateAnonymousSegment() neglected to check for overflow when
rounding up to a multiple of the huge page size.

These are arguably bugs, but they seem extremely unlikely to be
causing problems in practice, so no back-patch.

Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAO6_Xqq2vZbva0R9eQSY0p2kfksX2aP4r%3D%2BZ_q1HBYNU%3Dm8bBg%40mail.gmail.com
src/backend/port/sysv_shmem.c
src/backend/storage/ipc/ipci.c