From 0b07749fbac8b933f8ea7b25a34b350b8ac47ba1 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 26 Jul 2017 11:34:07 +0300 Subject: [PATCH] mdbx: major fix - madvise(MADV_REMOVE) only for exclusive mode. Change-Id: I6799df7b85eaf32a1c46f251ca64a4df4ff092b2 --- src/mdbx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index dde2f598..7668e608 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -4205,9 +4205,10 @@ static int __cold mdbx_env_map(MDBX_env *env, size_t usedsize) { #endif #ifdef MADV_REMOVE - if (env->me_flags & MDBX_WRITEMAP) + if (usedsize && (env->me_flags & MDBX_WRITEMAP)) { (void)madvise(env->me_map + usedsize, env->me_mapsize - usedsize, MADV_REMOVE); + } #else (void)usedsize; #endif @@ -4619,8 +4620,10 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, int lck_rc) { } } - err = mdbx_env_map(env, expected_bytes); - if (err) + err = mdbx_env_map(env, (lck_rc != /* lck exclusive */ MDBX_RESULT_TRUE) + ? 0 + : expected_bytes); + if (err != MDBX_SUCCESS) return err; const unsigned meta_clash_mask = mdbx_meta_eq_mask(env);