]> granicus.if.org Git - postgresql/commitdiff
Use mmap MAP_NOSYNC option to limit shared memory writes
authorBruce Momjian <bruce@momjian.us>
Sun, 22 Mar 2015 02:06:19 +0000 (22:06 -0400)
committerBruce Momjian <bruce@momjian.us>
Sun, 22 Mar 2015 02:06:19 +0000 (22:06 -0400)
mmap() is rarely used for shared memory, but when it is, this option is
useful, particularly on the BSDs.

Patch by Sean Chittenden

src/backend/storage/ipc/dsm_impl.c
src/include/portability/mem.h

index cf7938cb44d2a3a7fe24661abe342eaf395818c0..0859fbfc930b70fd4d02da01636d0245332d26dc 100644 (file)
@@ -368,7 +368,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
 
        /* Map it. */
        address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
-                                  MAP_SHARED | MAP_HASSEMAPHORE, fd, 0);
+                                  MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
        if (address == MAP_FAILED)
        {
                int                     save_errno;
@@ -960,7 +960,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
 
        /* Map it. */
        address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
-                                  MAP_SHARED | MAP_HASSEMAPHORE, fd, 0);
+                                  MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
        if (address == MAP_FAILED)
        {
                int                     save_errno;
index 7c77dbd1284d0bbe8045b1246326b1c10a1e7409..a4b01fecaed3a4d66f9ce44c7cc3f8d0d49ab9c8 100644 (file)
 #define MAP_HASSEMAPHORE               0
 #endif
 
+/*
+ * BSD-derived systems use the MAP_NOSYNC flag to prevent dirty mmap(2)
+ * pages from being gratuitously flushed to disk.
+ */
+#ifndef MAP_NOSYNC
+#define MAP_NOSYNC                     0
+#endif
+
 #define PG_MMAP_FLAGS                  (MAP_SHARED|MAP_ANONYMOUS|MAP_HASSEMAPHORE)
 
 /* Some really old systems don't define MAP_FAILED. */