From 34afbba84e8fd12bbf905d68d1112f51ed584df9 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 21 Mar 2015 22:06:19 -0400 Subject: [PATCH] Use mmap MAP_NOSYNC option to limit shared memory writes 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 | 4 ++-- src/include/portability/mem.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c index cf7938cb44..0859fbfc93 100644 --- a/src/backend/storage/ipc/dsm_impl.c +++ b/src/backend/storage/ipc/dsm_impl.c @@ -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; diff --git a/src/include/portability/mem.h b/src/include/portability/mem.h index 7c77dbd128..a4b01fecae 100644 --- a/src/include/portability/mem.h +++ b/src/include/portability/mem.h @@ -30,6 +30,14 @@ #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. */ -- 2.40.0