From 5299c2f228f1ff2110511faca661aa2f63adca26 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
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 <ashutosh.bapat.oss@gmail.com>
Suggested by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/12add41a-7625-4639-a394-a5563e349322@eisentraut.org
---
 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

