diff options
author | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-05-13 22:38:49 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@wiredtiger.com> | 2013-05-13 22:38:49 +1000 |
commit | 808d3eff2fde7b55918f570a8a375f12116d5b1b (patch) | |
tree | f6a621e31c4ea4714cdc52faa15bd0a750d7c58d | |
parent | a7a8135990cea26a1d94a4cec9e858e9520cdec7 (diff) | |
download | mongo-808d3eff2fde7b55918f570a8a375f12116d5b1b.tar.gz |
imported patch madvise-alignment
-rw-r--r-- | src/os_posix/os_map.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/os_posix/os_map.c b/src/os_posix/os_map.c index eda86c131fb..0a3cc2e4dea 100644 --- a/src/os_posix/os_map.c +++ b/src/os_posix/os_map.c @@ -36,6 +36,8 @@ __wt_mmap(WT_SESSION_IMPL *session, WT_FH *fh, void *mapp, size_t *lenp) return (0); } +#define WT_VM_PAGESIZE 4096 + /* * __wt_mmap_preload -- * Cause a section of a memory map to be faulted in. @@ -44,10 +46,10 @@ int __wt_mmap_preload(WT_SESSION_IMPL *session, void *p, size_t size) { #ifdef HAVE_POSIX_MADVISE - /* Linux requires the address be aligned to 4096 bytes */ + /* Linux requires the address be aligned to a 4KB boundary. */ WT_BM *bm = S2BT(session)->bm; WT_DECL_RET; - void *blk = (void *)((uintptr_t)p & ~(uintptr_t)4095); + void *blk = (void *)((uintptr_t)p & ~(uintptr_t)(WT_VM_PAGESIZE - 1)); size += WT_PTRDIFF(p, blk); /* XXX proxy for "am I doing a scan?" -- manual read-ahead */ @@ -60,7 +62,14 @@ __wt_mmap_preload(WT_SESSION_IMPL *session, void *p, size_t size) WT_PTRDIFF((uint8_t *)bm->map + bm->maplen, blk)); } - if ((ret = posix_madvise(blk, size, POSIX_MADV_WILLNEED)) != 0) + /* + * Manual pages aren't clear on whether alignment is required for the + * size, so we will be conservative. + */ + size &= ~(size_t)(WT_VM_PAGESIZE - 1); + + if (size > WT_VM_PAGESIZE && + (ret = posix_madvise(blk, size, POSIX_MADV_WILLNEED)) != 0) WT_RET_MSG(session, ret, "posix_madvise will need"); #else WT_UNUSED(session); @@ -79,9 +88,9 @@ int __wt_mmap_discard(WT_SESSION_IMPL *session, void *p, size_t size) { #ifdef HAVE_POSIX_MADVISE - /* Linux requires the address be aligned to 4096 bytes */ + /* Linux requires the address be aligned to a 4KB boundary. */ WT_DECL_RET; - void *blk = (void *)((uintptr_t)p & ~(uintptr_t)4095); + void *blk = (void *)((uintptr_t)p & ~(uintptr_t)(WT_VM_PAGESIZE - 1)); size += WT_PTRDIFF(p, blk); if ((ret = posix_madvise(blk, size, POSIX_MADV_DONTNEED)) != 0) |