summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2013-05-13 09:01:43 -0400
committerKeith Bostic <keith@wiredtiger.com>2013-05-13 09:01:43 -0400
commit014499da26d35f8c72279f3c37b3c467dfc910aa (patch)
treeee2b91a68e555c04fd3e2e97e386203347d6143d
parentaa7a01c558c093094ec6f3ee2ac01c4ffbc85408 (diff)
parent808d3eff2fde7b55918f570a8a375f12116d5b1b (diff)
downloadmongo-014499da26d35f8c72279f3c37b3c467dfc910aa.tar.gz
Merge branch 'develop' into file-extend
-rw-r--r--src/os_posix/os_map.c19
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)