From f183cef7d770dedb68f999cb135d6c39c76b90b7 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Thu, 22 Nov 2018 14:19:49 +0300 Subject: [PATCH] mdbx-windows: backport - always susppend local threads while resize DB (workaround for Windows kernel bug). We should not concern about performance on Windows platform, it just unreasonable. Therefore just always suspend the local threads to avoid this issue. This resolves https://github.com/leo-yuriev/libmdbx/issues/48 Change-Id: I6e652692794b8c4c0d41625be62f2051b63c033a --- src/mdbx.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index e6907a8c..b2124fe9 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -1983,19 +1983,21 @@ static int mdbx_mapresize(MDBX_env *env, const pgno_t size_pgno, env->me_dxb_mmap.current == env->me_dxb_mmap.filesize) goto bailout; - if ((env->me_flags & MDBX_RDONLY) || limit_bytes != env->me_dxb_mmap.length || - size_bytes < env->me_dxb_mmap.current) { - /* Windows allows only extending a read-write section, but not a - * corresponing mapped view. Therefore in other cases we must suspend - * the local threads for safe remap. */ - array_onstack.limit = ARRAY_LENGTH(array_onstack.handles); - array_onstack.count = 0; - suspended = &array_onstack; - rc = mdbx_suspend_threads_before_remap(env, &suspended); - if (rc != MDBX_SUCCESS) { - mdbx_error("failed suspend-for-remap: errcode %d", rc); - goto bailout; - } + /* 1) Windows allows only extending a read-write section, but not a + * corresponing mapped view. Therefore in other cases we must suspend + * the local threads for safe remap. + * 2) At least on Windows 10 1803 the entire mapped section is unavailable + * for short time during NtExtendSection() or VirtualAlloc() execution. + * + * THEREFORE LOCAL THREADS SUSPENDING IS ALWAYS REQUIRED! + */ + array_onstack.limit = ARRAY_LENGTH(array_onstack.handles); + array_onstack.count = 0; + suspended = &array_onstack; + rc = mdbx_suspend_threads_before_remap(env, &suspended); + if (rc != MDBX_SUCCESS) { + mdbx_error("failed suspend-for-remap: errcode %d", rc); + goto bailout; } #else /* Acquire guard to avoid collision between read and write txns