diff options
| author | Nathan Bossart <nathan@postgresql.org> | 2026-01-23 10:46:49 -0600 |
|---|---|---|
| committer | Nathan Bossart <nathan@postgresql.org> | 2026-01-23 10:46:49 -0600 |
| commit | 8eef2df1898cc34dfaa69ff200f5112d7eeb7c67 (patch) | |
| tree | 4a334920d9ed212e66565961f57d26bb3ae7d442 /src | |
| parent | a36164e7465fd1e10e94569e9c1c07656e38a9de (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/port/sysv_shmem.c | 2 | ||||
| -rw-r--r-- | src/backend/storage/ipc/ipci.c | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index de491897118..53f7a64fa45 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -617,7 +617,7 @@ CreateAnonymousSegment(Size *size) GetHugePageSize(&hugepagesize, &mmap_flags); if (allocsize % hugepagesize != 0) - allocsize += hugepagesize - (allocsize % hugepagesize); + allocsize = add_size(allocsize, hugepagesize - (allocsize % hugepagesize)); ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE, PG_MMAP_FLAGS | mmap_flags, -1, 0); diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 85c67b2c183..2a3dfedf7e9 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -363,7 +363,9 @@ InitializeShmemGUCs(void) { Size hp_required; - hp_required = add_size(size_b / hp_size, 1); + hp_required = size_b / hp_size; + if (size_b % hp_size != 0) + hp_required = add_size(hp_required, 1); sprintf(buf, "%zu", hp_required); SetConfigOption("shared_memory_size_in_huge_pages", buf, PGC_INTERNAL, PGC_S_DYNAMIC_DEFAULT); |
