Commit 34afbba8 authored by Bruce Momjian's avatar Bruce Momjian

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
parent 9d61b995
...@@ -368,7 +368,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size, ...@@ -368,7 +368,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
/* Map it. */ /* Map it. */
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE, 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) if (address == MAP_FAILED)
{ {
int save_errno; int save_errno;
...@@ -960,7 +960,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size, ...@@ -960,7 +960,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
/* Map it. */ /* Map it. */
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE, 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) if (address == MAP_FAILED)
{ {
int save_errno; int save_errno;
......
...@@ -30,6 +30,14 @@ ...@@ -30,6 +30,14 @@
#define MAP_HASSEMAPHORE 0 #define MAP_HASSEMAPHORE 0
#endif #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) #define PG_MMAP_FLAGS (MAP_SHARED|MAP_ANONYMOUS|MAP_HASSEMAPHORE)
/* Some really old systems don't define MAP_FAILED. */ /* Some really old systems don't define MAP_FAILED. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment