mdbx: minor refine madvise order.

Change-Id: Ia6b78cad2aae68f5cb4c8475fbd27f9a9cb44cf2
This commit is contained in:
Leo Yuriev 2016-04-17 23:44:55 +03:00
parent 80e660317f
commit 026a566fc6

34
mdb.c
View File

@ -4336,18 +4336,19 @@ mdb_env_map(MDB_env *env, void *addr)
return errno; return errno;
} }
if (flags & MDB_NORDAHEAD) { /* Can happen because the address argument to mmap() is just a
/* Turn off readahead. It's harmful when the DB is larger than RAM. */ * hint. mmap() can pick another, e.g. if the range is in use.
if (madvise(env->me_map, env->me_mapsize, MADV_RANDOM) < 0) * The MAP_FIXED flag would prevent that, but then mmap could
return errno; * instead unmap existing pages to make room for the new map.
*/
if (addr && env->me_map != addr) {
errno = 0; /* LY: clean errno as a hit for this case */
return EBUSY; /* TODO: Make a new MDB_* error code? */
} }
if (madvise(env->me_map, env->me_mapsize, MADV_DONTFORK) < 0) if (madvise(env->me_map, env->me_mapsize, MADV_DONTFORK) < 0)
return errno; return errno;
if (madvise(env->me_map, env->me_mapsize, MADV_WILLNEED) < 0)
return errno;
#ifdef MADV_NOHUGEPAGE #ifdef MADV_NOHUGEPAGE
(void) madvise(env->me_map, env->me_mapsize, MADV_NOHUGEPAGE); (void) madvise(env->me_map, env->me_mapsize, MADV_NOHUGEPAGE);
#endif #endif
@ -4358,14 +4359,13 @@ mdb_env_map(MDB_env *env, void *addr)
} }
#endif #endif
/* Can happen because the address argument to mmap() is just a if (madvise(env->me_map, env->me_mapsize, MADV_WILLNEED) < 0)
* hint. mmap() can pick another, e.g. if the range is in use. return errno;
* The MAP_FIXED flag would prevent that, but then mmap could
* instead unmap existing pages to make room for the new map. if (flags & MDB_NORDAHEAD) {
*/ /* Turn off readahead. It's harmful when the DB is larger than RAM. */
if (addr && env->me_map != addr) { if (madvise(env->me_map, env->me_mapsize, MADV_RANDOM) < 0)
errno = 0; /* LY: clean errno as a hit for this case */ return errno;
return EBUSY; /* TODO: Make a new MDB_* error code? */
} }
/* Lock meta pages to avoid unexpected write, /* Lock meta pages to avoid unexpected write,
@ -4374,8 +4374,8 @@ mdb_env_map(MDB_env *env, void *addr)
return errno; return errno;
#ifdef USE_VALGRIND #ifdef USE_VALGRIND
env->me_valgrind_handle = VALGRIND_CREATE_BLOCK( env->me_valgrind_handle =
env->me_map, env->me_mapsize, "lmdb"); VALGRIND_CREATE_BLOCK(env->me_map, env->me_mapsize, "lmdb");
#endif #endif
return MDB_SUCCESS; return MDB_SUCCESS;