On Fri, Jan 23, 2026 at 10:12 AM Michael Paquier <[email protected]> wrote: > > On Fri, Jan 23, 2026 at 08:04:18AM +0530, Ashutosh Bapat wrote: > > As Peter mentioned in the shared buffers resizing thread [1] it's > > placement and name in mem.h led us to think that it affects all mmap > > calls or that all mmap calls should use those flags. Neither of which > > is true. We have different mmap calls using different set of flags. > > Attached patch proposes changes similar (not exact) as you suggest > > above. Please take a look. > > > > [1] > > https://www.postgresql.org/message-id/[email protected] > > Okay, point taken. I can live with your patch suggestion based on > what you have attached.
Thanks. I revised the patch a bit. The macro had parenthesis around the macro definition which are not required in the assignment. Removed them. Also revised the commit message a bit. -- Best Wishes, Ashutosh Bapat
From 5299c2f228f1ff2110511faca661aa2f63adca26 Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat <[email protected]> Date: Thu, 22 Jan 2026 20:48:36 +0530 Subject: [PATCH v20260123] Remove PG_MMAP_FLAGS Based on the file and name of the macro, it seems that the macro was meant to be used for all mmap() calls. But it is actually used only in CreateAnonymousSegment(). Each of the other calls to mmap() use flags according to the requirement of the caller. The macro was introduced in commit b0fc0df9364d2d2d17c0162cf3b8b59f6cb09f67, but was never used for portability. Remove it and use the flags directly in CreateAnonymousSegment(). Author: Ashutosh Bapat <[email protected]> Suggested by: Peter Eisentraut <[email protected]> Discussion: https://www.postgresql.org/message-id/[email protected] --- src/backend/port/sysv_shmem.c | 10 ++++++---- src/include/portability/mem.h | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index de491897118..eaa28c9c1e6 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -601,6 +601,8 @@ CreateAnonymousSegment(Size *size) Size allocsize = *size; void *ptr = MAP_FAILED; int mmap_errno = 0; + int mmap_flags = MAP_SHARED | MAP_ANONYMOUS | MAP_HASSEMAPHORE; + #ifndef MAP_HUGETLB /* PGSharedMemoryCreate should have dealt with this case */ @@ -612,15 +614,15 @@ CreateAnonymousSegment(Size *size) * Round up the request size to a suitable large value. */ Size hugepagesize; - int mmap_flags; + int huge_mmap_flags; - GetHugePageSize(&hugepagesize, &mmap_flags); + GetHugePageSize(&hugepagesize, &huge_mmap_flags); if (allocsize % hugepagesize != 0) allocsize += hugepagesize - (allocsize % hugepagesize); ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE, - PG_MMAP_FLAGS | mmap_flags, -1, 0); + mmap_flags | huge_mmap_flags, -1, 0); mmap_errno = errno; if (huge_pages == HUGE_PAGES_TRY && ptr == MAP_FAILED) elog(DEBUG1, "mmap(%zu) with MAP_HUGETLB failed, huge pages disabled: %m", @@ -644,7 +646,7 @@ CreateAnonymousSegment(Size *size) */ allocsize = *size; ptr = mmap(NULL, allocsize, PROT_READ | PROT_WRITE, - PG_MMAP_FLAGS, -1, 0); + mmap_flags, -1, 0); mmap_errno = errno; } diff --git a/src/include/portability/mem.h b/src/include/portability/mem.h index 091328f680d..c048e8836c5 100644 --- a/src/include/portability/mem.h +++ b/src/include/portability/mem.h @@ -38,8 +38,6 @@ #define MAP_NOSYNC 0 #endif -#define PG_MMAP_FLAGS (MAP_SHARED|MAP_ANONYMOUS|MAP_HASSEMAPHORE) - /* Some really old systems don't define MAP_FAILED. */ #ifndef MAP_FAILED #define MAP_FAILED ((void *) -1) base-commit: a36164e7465fd1e10e94569e9c1c07656e38a9de -- 2.34.1
