From 957c99d86fead8a7a65916a413a322a53ef9972c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Mon, 12 Dec 2022 15:23:47 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20`MDBX=5Fopt=5Fprefault=5Fwrite=5Fena?= =?UTF-8?q?ble`=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20`MDBX=5FENABLE=5F?= =?UTF-8?q?PREFAULT`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mdbx.h | 5 +++++ src/core.c | 19 ++++++++++++++++--- src/options.h | 12 ------------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/mdbx.h b/mdbx.h index cb14bf33..1b3dcfd8 100644 --- a/mdbx.h +++ b/mdbx.h @@ -2254,6 +2254,11 @@ enum MDBX_option_t { * On Windows a write-through is used always but \ref MDBX_NOMETASYNC could * be used for switching to write-and-flush. */ MDBX_opt_writethrough_threshold, + + /** \brief Controls prevention of page-faults of reclaimed and allocated pages + * in the \ref MDBX_WRITEMAP mode by clearing ones through file handle before + * touching. */ + MDBX_opt_prefault_write_enable, }; #ifndef __cplusplus /** \ingroup c_settings */ diff --git a/src/core.c b/src/core.c index 74922f9d..544e5934 100644 --- a/src/core.c +++ b/src/core.c @@ -7043,7 +7043,6 @@ static __inline pgr_t page_alloc_finalize(MDBX_env *const env, MDBX_ASAN_UNPOISON_MEMORY_REGION(ret.page, pgno2bytes(env, num)); VALGRIND_MAKE_MEM_UNDEFINED(ret.page, pgno2bytes(env, num)); -#if MDBX_ENABLE_PREFAULT /* Содержимое выделенной страницы не нужно, но если страница отсутствует * в ОЗУ (что весьма вероятно), то любое обращение к ней приведет * к page-fault: @@ -7107,7 +7106,6 @@ static __inline pgr_t page_alloc_finalize(MDBX_env *const env, need_clean = false; } } -#endif /* MDBX_ENABLE_PREFAULT */ } else { ret.page = page_malloc(txn, num); if (unlikely(!ret.page)) { @@ -24553,6 +24551,18 @@ __cold int mdbx_env_set_option(MDBX_env *env, const MDBX_option_t option, #endif break; + case MDBX_opt_prefault_write_enable: + if (value == /* default */ UINT64_MAX) { + env->me_options.prefault_write = default_prefault_write(env); + env->me_options.flags.non_auto.prefault_write = false; + } else if (value > 1) + err = MDBX_EINVAL; + else { + env->me_options.prefault_write = value != 0; + env->me_options.flags.non_auto.prefault_write = true; + } + break; + default: return MDBX_EINVAL; } @@ -24634,6 +24644,10 @@ __cold int mdbx_env_get_option(const MDBX_env *env, const MDBX_option_t option, #endif break; + case MDBX_opt_prefault_write_enable: + *pvalue = env->me_options.prefault_write; + break; + default: return MDBX_EINVAL; } @@ -25120,7 +25134,6 @@ __dll_export " MDBX_AVOID_MSYNC=" MDBX_STRINGIFY(MDBX_AVOID_MSYNC) " MDBX_ENABLE_REFUND=" MDBX_STRINGIFY(MDBX_ENABLE_REFUND) " MDBX_ENABLE_MADVISE=" MDBX_STRINGIFY(MDBX_ENABLE_MADVISE) - " MDBX_ENABLE_PREFAULT=" MDBX_STRINGIFY(MDBX_ENABLE_PREFAULT) " MDBX_ENABLE_MINCORE=" MDBX_STRINGIFY(MDBX_ENABLE_MINCORE) " MDBX_ENABLE_PGOP_STAT=" MDBX_STRINGIFY(MDBX_ENABLE_PGOP_STAT) " MDBX_ENABLE_PROFGC=" MDBX_STRINGIFY(MDBX_ENABLE_PROFGC) diff --git a/src/options.h b/src/options.h index 3e9c9243..92b0f56e 100644 --- a/src/options.h +++ b/src/options.h @@ -87,18 +87,6 @@ #error MDBX_ENABLE_PGOP_STAT must be defined as 0 or 1 #endif /* MDBX_ENABLE_PGOP_STAT */ -/** Controls prevention of page-faults of reclaimed and allocated pages in the - * MDBX_WRITEMAP mode by clearing ones through file handle before touching. */ -#ifndef MDBX_ENABLE_PREFAULT -#if MDBX_MMAP_INCOHERENT_FILE_WRITE -#define MDBX_ENABLE_PREFAULT 0 -#else -#define MDBX_ENABLE_PREFAULT 1 -#endif -#elif !(MDBX_ENABLE_PREFAULT == 0 || MDBX_ENABLE_PREFAULT == 1) -#error MDBX_ENABLE_PREFAULT must be defined as 0 or 1 -#endif /* MDBX_ENABLE_PREFAULT */ - /** Controls using Unix' mincore() to determine whether DB-pages * are resident in memory. */ #ifndef MDBX_ENABLE_MINCORE