From f55c30f2863b107d1118111eb18e537fb6514a33 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 26 Jul 2017 13:14:19 +0300 Subject: [PATCH] mdbx: backport - don't madvise(MADV_REMOVE). Avoid lost changes and corruption in case a collision between mdbx_env_open() in one process and write-txn with next-pgno updates in an another process. Change-Id: I890db9251edbd77ac0ace10bed10a24517d709ec --- mdb.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/mdb.c b/mdb.c index 482873a3..6f8d3da2 100644 --- a/mdb.c +++ b/mdb.c @@ -4341,7 +4341,7 @@ mdb_env_create(MDB_env **env) } static int __cold -mdb_env_map(MDB_env *env, void *addr, size_t usedsize) +mdb_env_map(MDB_env *env, void *addr) { unsigned flags = env->me_flags; @@ -4381,12 +4381,6 @@ mdb_env_map(MDB_env *env, void *addr, size_t usedsize) } #endif -#ifdef MADV_REMOVE - if (flags & MDB_WRITEMAP) { - (void) madvise(env->me_map + usedsize, env->me_mapsize - usedsize, MADV_REMOVE); - } -#endif - /* Turn on/off readahead. It's harmful when the DB is larger than RAM. */ if (madvise(env->me_map, env->me_mapsize, (flags & MDB_NORDAHEAD) ? MADV_RANDOM : MADV_WILLNEED)) return errno; @@ -4439,7 +4433,7 @@ mdb_env_set_mapsize(MDB_env *env, size_t size) #endif env->me_mapsize = size; old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL; - rc = mdb_env_map(env, old, usedsize); + rc = mdb_env_map(env, old); if (rc) return rc; } @@ -4557,8 +4551,7 @@ mdb_env_open2(MDB_env *env, MDB_meta *meta) newenv = 0; } - const size_t usedsize = (meta->mm_last_pg + 1) * env->me_psize; - rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta->mm_address : NULL, usedsize); + rc = mdb_env_map(env, (flags & MDB_FIXEDMAP) ? meta->mm_address : NULL); if (rc) return rc;