From c100340729b66dc46d4f9d68a794957bf2c468d8 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 26 Jan 2026 10:52:02 +0900 Subject: [PATCH] Remove PG_MMAP_FLAGS from mem.h Based on name of the macro, it was implied that it could be used for all mmap() calls on portability grounds. However, its use is limited to sysv_shmem.c, for CreateAnonymousSegment(). This commit removes the declaration, reducing the confusion around it as a portability tweak, being limited to SysV-style shared memory. This macro has been introduced in b0fc0df9364d for sysv_shmem.c, originally. It has been moved to mem.h in 0ac5e5a7e152 a bit later. Suggested by: Peter Eisentraut Author: Ashutosh Bapat Discussion: https://postgr.es/m/CAExHW5vTWABxuM5fbQcFkGuTLwaxuZDEE2vtx2WuMUWk6JnF4g@mail.gmail.com Discussion: https://postgr.es/m/12add41a-7625-4639-a394-a5563e349322@eisentraut.org --- src/backend/port/sysv_shmem.c | 9 +++++---- src/include/portability/mem.h | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 5239b6acbbc..3cd3544fa2b 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -602,6 +602,7 @@ 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 */ @@ -613,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 = add_size(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", @@ -645,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)