]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove PG_MMAP_FLAGS from mem.h
authorMichael Paquier <michael@paquier.xyz>
Mon, 26 Jan 2026 01:52:02 +0000 (10:52 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 26 Jan 2026 01:52:02 +0000 (10:52 +0900)
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 <peter@eisentraut.org>
Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
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
src/include/portability/mem.h

index 5239b6acbbc9f90a05b9d395fadfaa65783121a4..3cd3544fa2bb1254601d59f6984ebc1d2fb80d78 100644 (file)
@@ -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;
        }
 
index 091328f680da5fa3bed98e975bb3c6da193aea92..c048e8836c514d67cd1c3c308c6f835d585f8c75 100644 (file)
@@ -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)