1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-22 02:52:08 +03:00

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
This commit is contained in:
Bruce Momjian
2015-03-21 22:06:19 -04:00
parent 9d61b9953c
commit 34afbba84e
2 changed files with 10 additions and 2 deletions

View 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;

View File

@ -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. */