Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 34afbba

Browse files
committed
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
1 parent 9d61b99 commit 34afbba

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/backend/storage/ipc/dsm_impl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ dsm_impl_posix(dsm_op op, dsm_handle handle, Size request_size,
368368

369369
/* Map it. */
370370
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
371-
MAP_SHARED | MAP_HASSEMAPHORE, fd, 0);
371+
MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
372372
if (address == MAP_FAILED)
373373
{
374374
int save_errno;
@@ -960,7 +960,7 @@ dsm_impl_mmap(dsm_op op, dsm_handle handle, Size request_size,
960960

961961
/* Map it. */
962962
address = mmap(NULL, request_size, PROT_READ | PROT_WRITE,
963-
MAP_SHARED | MAP_HASSEMAPHORE, fd, 0);
963+
MAP_SHARED | MAP_HASSEMAPHORE | MAP_NOSYNC, fd, 0);
964964
if (address == MAP_FAILED)
965965
{
966966
int save_errno;

src/include/portability/mem.h

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#define MAP_HASSEMAPHORE 0
3131
#endif
3232

33+
/*
34+
* BSD-derived systems use the MAP_NOSYNC flag to prevent dirty mmap(2)
35+
* pages from being gratuitously flushed to disk.
36+
*/
37+
#ifndef MAP_NOSYNC
38+
#define MAP_NOSYNC 0
39+
#endif
40+
3341
#define PG_MMAP_FLAGS (MAP_SHARED|MAP_ANONYMOUS|MAP_HASSEMAPHORE)
3442

3543
/* Some really old systems don't define MAP_FAILED. */

0 commit comments

Comments
 (0)