mdbx: переименование и доработка опций сборки.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2024-12-02 18:11:36 +03:00
parent 35177611d2
commit 44865dadc7
9 changed files with 88 additions and 145 deletions

View File

@ -690,7 +690,7 @@ add_mdbx_option(MDBX_INSTALL_STATIC
add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY add_mdbx_option(MDBX_BUILD_SHARED_LIBRARY
"Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS}) "Build libmdbx as shared library (DLL)" ${BUILD_SHARED_LIBS})
add_mdbx_option( add_mdbx_option(
MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy)" MDBX_BUILD_TOOLS "Build MDBX tools (mdbx_chk/stat/dump/load/copy/drop)"
${MDBX_BUILD_TOOLS_DEFAULT}) ${MDBX_BUILD_TOOLS_DEFAULT})
cmake_dependent_option( cmake_dependent_option(
MDBX_INSTALL_MANPAGES MDBX_INSTALL_MANPAGES
@ -699,8 +699,10 @@ cmake_dependent_option(
add_mdbx_option( add_mdbx_option(
MDBX_TXN_CHECKOWNER MDBX_TXN_CHECKOWNER
"Checking transaction matches the calling thread inside libmdbx's API" ON) "Checking transaction matches the calling thread inside libmdbx's API" ON)
add_mdbx_option(MDBX_ENV_CHECKPID "Paranoid checking PID inside libmdbx's API" add_mdbx_option(
AUTO) MDBX_ENV_CHECKPID
"Checking PID inside libmdbx's API against reuse DB environment after the fork()"
AUTO)
mark_as_advanced(MDBX_ENV_CHECKPID) mark_as_advanced(MDBX_ENV_CHECKPID)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions" add_mdbx_option(MDBX_DISABLE_GNU_SOURCE "Don't use GNU/Linux libc extensions"
@ -708,9 +710,9 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
mark_as_advanced(MDBX_DISABLE_GNU_SOURCE) mark_as_advanced(MDBX_DISABLE_GNU_SOURCE)
endif() endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS) if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR IOS)
add_mdbx_option(MDBX_OSX_SPEED_INSTEADOF_DURABILITY add_mdbx_option(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY
"Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF) "Disable use fcntl(F_FULLFSYNC) in favor of speed" OFF)
mark_as_advanced(MDBX_OSX_SPEED_INSTEADOF_DURABILITY) mark_as_advanced(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY)
endif() endif()
if(WIN32) if(WIN32)
if(MDBX_NTDLL_EXTRA_IMPLIB) if(MDBX_NTDLL_EXTRA_IMPLIB)
@ -724,15 +726,25 @@ else()
MDBX_USE_OFDLOCKS MDBX_USE_OFDLOCKS
"Use Open file description locks (aka OFD locks, non-POSIX)" AUTO) "Use Open file description locks (aka OFD locks, non-POSIX)" AUTO)
mark_as_advanced(MDBX_USE_OFDLOCKS) mark_as_advanced(MDBX_USE_OFDLOCKS)
add_mdbx_option(
MDBX_USE_MINCORE
"Use Unix' mincore() to determine whether DB-pages are resident in memory"
ON)
mark_as_advanced(MDBX_USE_MINCORE)
set(MDBX_AVOID_MSYNC_DEFAULT OFF) set(MDBX_AVOID_MSYNC_DEFAULT OFF)
endif() endif()
add_mdbx_option( add_mdbx_option(
MDBX_AVOID_MSYNC MDBX_AVOID_MSYNC
"Controls dirty pages tracking, spilling and persisting in MDBX_WRITEMAP mode" "Disable in-memory database updating with consequent flush-to-disk/msync syscall in `MDBX_WRITEMAP` mode"
${MDBX_AVOID_MSYNC_DEFAULT}) ${MDBX_AVOID_MSYNC_DEFAULT})
add_mdbx_option(
MDBX_MMAP_NEEDS_JOLT
"Assume system needs explicit syscall to sync/flush/write modified mapped memory"
AUTO)
mark_as_advanced(MDBX_MMAP_NEEDS_JOLT)
add_mdbx_option( add_mdbx_option(
MDBX_LOCKING MDBX_LOCKING
"Locking method (Windows=-1, SysV=5, POSIX=1988, POSIX=2001, POSIX=2008, Futexes=1995)" "Locking method (Windows=-1, SystemV=5, POSIX=1988, POSIX=2001, POSIX=2008)"
AUTO) AUTO)
mark_as_advanced(MDBX_LOCKING) mark_as_advanced(MDBX_LOCKING)
add_mdbx_option( add_mdbx_option(
@ -747,23 +759,22 @@ add_mdbx_option(
mark_as_advanced(MDBX_DISABLE_VALIDATION) mark_as_advanced(MDBX_DISABLE_VALIDATION)
add_mdbx_option(MDBX_ENABLE_REFUND add_mdbx_option(MDBX_ENABLE_REFUND
"Zerocost auto-compactification during write-transactions" ON) "Zerocost auto-compactification during write-transactions" ON)
add_mdbx_option(MDBX_ENABLE_MADVISE
"Using POSIX' madvise() and/or similar hints" ON)
if(CMAKE_TARGET_BITNESS GREATER 32)
set(MDBX_BIGFOOT_DEFAULT ON)
else()
set(MDBX_BIGFOOT_DEFAULT OFF)
endif()
add_mdbx_option( add_mdbx_option(
MDBX_ENABLE_BIGFOOT MDBX_ENABLE_BIGFOOT
"Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages" "Chunking long list of retired pages during huge transactions commit to avoid use sequences of pages"
${MDBX_BIGFOOT_DEFAULT}) ON)
add_mdbx_option(MDBX_ENABLE_PGOP_STAT add_mdbx_option(MDBX_ENABLE_PGOP_STAT
"Gathering statistics for page operations" ON) "Gathering statistics for page operations" ON)
add_mdbx_option(MDBX_ENABLE_PROFGC "Profiling of GC search and updates" OFF) add_mdbx_option(MDBX_ENABLE_PROFGC "Profiling of GC search and updates" OFF)
mark_as_advanced(MDBX_ENABLE_PROFGC) mark_as_advanced(MDBX_ENABLE_PROFGC)
add_mdbx_option(MDBX_ENABLE_DBI_SPARSE "FIXME" ON) add_mdbx_option(
add_mdbx_option(MDBX_ENABLE_DBI_LOCKFREE "FIXME" ON) MDBX_ENABLE_DBI_SPARSE
"Support for sparse sets of DBI handles to reduce overhead when starting and processing transactions"
ON)
add_mdbx_option(
MDBX_ENABLE_DBI_LOCKFREE
"Support for deferred releasing and a lockfree path to quickly open DBI handles"
ON)
if(NOT MDBX_AMALGAMATED_SOURCE) if(NOT MDBX_AMALGAMATED_SOURCE)
if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG") if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG")

View File

@ -382,49 +382,7 @@ __cold int mdbx_env_warmup(const MDBX_env *env, const MDBX_txn *txn,
#endif /* MLOCK_ONFAULT */ #endif /* MLOCK_ONFAULT */
int err = MDBX_ENOSYS; int err = MDBX_ENOSYS;
#if MDBX_ENABLE_MADVISE
err = dxb_set_readahead(env, used_pgno, true, true); err = dxb_set_readahead(env, used_pgno, true, true);
#else
#if defined(_WIN32) || defined(_WIN64)
if (imports.PrefetchVirtualMemory) {
WIN32_MEMORY_RANGE_ENTRY hint;
hint.VirtualAddress = env->dxb_mmap.base;
hint.NumberOfBytes = used_range;
if (imports.PrefetchVirtualMemory(GetCurrentProcess(), 1, &hint, 0))
err = MDBX_SUCCESS;
else {
err = (int)GetLastError();
ERROR("%s(%zu) error %d", "PrefetchVirtualMemory", used_range, err);
}
}
#endif /* Windows */
#if defined(POSIX_MADV_WILLNEED)
err = posix_madvise(env->dxb_mmap.base, used_range, POSIX_MADV_WILLNEED)
? ignore_enosys(errno)
: MDBX_SUCCESS;
#elif defined(MADV_WILLNEED)
err = madvise(env->dxb_mmap.base, used_range, MADV_WILLNEED)
? ignore_enosys(errno)
: MDBX_SUCCESS;
#endif
#if defined(F_RDADVISE)
if (err) {
fcntl(env->lazy_fd, F_RDAHEAD, true);
struct radvisory hint;
hint.ra_offset = 0;
hint.ra_count = unlikely(used_range > INT_MAX &&
sizeof(used_range) > sizeof(hint.ra_count))
? INT_MAX
: (int)used_range;
err = fcntl(env->lazy_fd, F_RDADVISE, &hint) ? ignore_enosys(errno)
: MDBX_SUCCESS;
if (err == ENOTTY)
err = MDBX_SUCCESS /* Ignore ENOTTY for DB on the ram-disk */;
}
#endif /* F_RDADVISE */
#endif /* MDBX_ENABLE_MADVISE */
if (err != MDBX_SUCCESS && rc == MDBX_SUCCESS) if (err != MDBX_SUCCESS && rc == MDBX_SUCCESS)
rc = err; rc = err;

View File

@ -32,7 +32,6 @@
#cmakedefine01 MDBX_DISABLE_VALIDATION #cmakedefine01 MDBX_DISABLE_VALIDATION
#cmakedefine01 MDBX_AVOID_MSYNC #cmakedefine01 MDBX_AVOID_MSYNC
#cmakedefine01 MDBX_ENABLE_REFUND #cmakedefine01 MDBX_ENABLE_REFUND
#cmakedefine01 MDBX_ENABLE_MADVISE
#cmakedefine01 MDBX_ENABLE_BIGFOOT #cmakedefine01 MDBX_ENABLE_BIGFOOT
#cmakedefine01 MDBX_ENABLE_PGOP_STAT #cmakedefine01 MDBX_ENABLE_PGOP_STAT
#cmakedefine01 MDBX_ENABLE_PROFGC #cmakedefine01 MDBX_ENABLE_PROFGC
@ -40,19 +39,29 @@
#cmakedefine01 MDBX_ENABLE_DBI_LOCKFREE #cmakedefine01 MDBX_ENABLE_DBI_LOCKFREE
/* Windows */ /* Windows */
#if !defined(MDBX_BUILD_TEST) && !defined(MDBX_WITHOUT_MSVC_CRT) #if defined(MDBX_BUILD_TEST) || !defined(MDBX_BUILD_CXX) || MDBX_BUILD_CXX
#define MDBX_WITHOUT_MSVC_CRT 0
#else
#cmakedefine01 MDBX_WITHOUT_MSVC_CRT #cmakedefine01 MDBX_WITHOUT_MSVC_CRT
#endif #endif /* MDBX_WITHOUT_MSVC_CRT */
/* MacOS & iOS */ /* MacOS & iOS */
#cmakedefine01 MDBX_OSX_SPEED_INSTEADOF_DURABILITY #cmakedefine01 MDBX_APPLE_SPEED_INSTEADOF_DURABILITY
/* POSIX */ /* POSIX */
#cmakedefine01 MDBX_DISABLE_GNU_SOURCE #cmakedefine01 MDBX_DISABLE_GNU_SOURCE
#cmakedefine MDBX_USE_OFDLOCKS_AUTO #cmakedefine MDBX_USE_OFDLOCKS_AUTO
#ifndef MDBX_USE_OFDLOCKS_AUTO #ifndef MDBX_USE_OFDLOCKS_AUTO
#cmakedefine01 MDBX_USE_OFDLOCKS #cmakedefine01 MDBX_USE_OFDLOCKS
#endif #endif /* MDBX_USE_OFDLOCKS */
#cmakedefine MDBX_MMAP_NEEDS_JOLT_AUTO
#ifndef MDBX_MMAP_NEEDS_JOLT_AUTO
#cmakedefine01 MDBX_MMAP_NEEDS_JOLT
#endif /* MDBX_MMAP_NEEDS_JOLT */
#cmakedefine01 MDBX_USE_MINCORE
/* Build Info */ /* Build Info */
#ifndef MDBX_BUILD_TIMESTAMP #ifndef MDBX_BUILD_TIMESTAMP

View File

@ -153,9 +153,7 @@ __cold int dxb_resize(MDBX_env *const env, const pgno_t used_pgno,
} }
const size_t limit_bytes = pgno_align2os_bytes(env, limit_pgno); const size_t limit_bytes = pgno_align2os_bytes(env, limit_pgno);
const size_t size_bytes = pgno_align2os_bytes(env, size_pgno); const size_t size_bytes = pgno_align2os_bytes(env, size_pgno);
#if MDBX_ENABLE_MADVISE || defined(ENABLE_MEMCHECK)
const void *const prev_map = env->dxb_mmap.base; const void *const prev_map = env->dxb_mmap.base;
#endif /* MDBX_ENABLE_MADVISE || ENABLE_MEMCHECK */
VERBOSE("resize(env-flags 0x%x, mode %d) datafile/mapping: " VERBOSE("resize(env-flags 0x%x, mode %d) datafile/mapping: "
"present %" PRIuPTR " -> %" PRIuPTR ", " "present %" PRIuPTR " -> %" PRIuPTR ", "
@ -252,7 +250,6 @@ __cold int dxb_resize(MDBX_env *const env, const pgno_t used_pgno,
} }
munlock_after(env, aligned_munlock_pgno, size_bytes); munlock_after(env, aligned_munlock_pgno, size_bytes);
#if MDBX_ENABLE_MADVISE
if (size_bytes < prev_size && mode > implicit_grow) { if (size_bytes < prev_size && mode > implicit_grow) {
NOTICE("resize-MADV_%s %u..%u", NOTICE("resize-MADV_%s %u..%u",
(env->flags & MDBX_WRITEMAP) ? "REMOVE" : "DONTNEED", size_pgno, (env->flags & MDBX_WRITEMAP) ? "REMOVE" : "DONTNEED", size_pgno,
@ -304,12 +301,10 @@ __cold int dxb_resize(MDBX_env *const env, const pgno_t used_pgno,
} else } else
env->lck->discarded_tail.weak = size_pgno; env->lck->discarded_tail.weak = size_pgno;
} }
#endif /* MDBX_ENABLE_MADVISE */
rc = osal_mresize(mresize_flags, &env->dxb_mmap, size_bytes, limit_bytes); rc = osal_mresize(mresize_flags, &env->dxb_mmap, size_bytes, limit_bytes);
eASSERT(env, env->dxb_mmap.limit >= env->dxb_mmap.current); eASSERT(env, env->dxb_mmap.limit >= env->dxb_mmap.current);
#if MDBX_ENABLE_MADVISE
if (rc == MDBX_SUCCESS) { if (rc == MDBX_SUCCESS) {
eASSERT(env, limit_bytes == env->dxb_mmap.limit); eASSERT(env, limit_bytes == env->dxb_mmap.limit);
eASSERT(env, size_bytes <= env->dxb_mmap.filesize); eASSERT(env, size_bytes <= env->dxb_mmap.filesize);
@ -329,7 +324,6 @@ __cold int dxb_resize(MDBX_env *const env, const pgno_t used_pgno,
; ;
rc = dxb_set_readahead(env, size_pgno, readahead, force); rc = dxb_set_readahead(env, size_pgno, readahead, force);
} }
#endif /* MDBX_ENABLE_MADVISE */
bailout: bailout:
if (rc == MDBX_SUCCESS) { if (rc == MDBX_SUCCESS) {
@ -448,7 +442,6 @@ void dxb_sanitize_tail(MDBX_env *env, MDBX_txn *txn) {
} }
#endif /* ENABLE_MEMCHECK || __SANITIZE_ADDRESS__ */ #endif /* ENABLE_MEMCHECK || __SANITIZE_ADDRESS__ */
#if MDBX_ENABLE_MADVISE
/* Turn on/off readahead. It's harmful when the DB is larger than RAM. */ /* Turn on/off readahead. It's harmful when the DB is larger than RAM. */
__cold int dxb_set_readahead(const MDBX_env *env, const pgno_t edge, __cold int dxb_set_readahead(const MDBX_env *env, const pgno_t edge,
const bool enable, const bool force_whole) { const bool enable, const bool force_whole) {
@ -570,7 +563,6 @@ __cold int dxb_set_readahead(const MDBX_env *env, const pgno_t edge,
err = MDBX_SUCCESS; err = MDBX_SUCCESS;
return err; return err;
} }
#endif /* MDBX_ENABLE_MADVISE */
__cold int dxb_setup(MDBX_env *env, const int lck_rc, __cold int dxb_setup(MDBX_env *env, const int lck_rc,
const mdbx_mode_t mode_bits) { const mdbx_mode_t mode_bits) {
@ -776,12 +768,10 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc,
globals.bootid.x, globals.bootid.y, globals.bootid.x, globals.bootid.y,
(globals.bootid.x | globals.bootid.y) ? "" : "not-"); (globals.bootid.x | globals.bootid.y) ? "" : "not-");
#if MDBX_ENABLE_MADVISE
/* calculate readahead hint before mmap with zero redundant pages */ /* calculate readahead hint before mmap with zero redundant pages */
const bool readahead = const bool readahead =
!(env->flags & MDBX_NORDAHEAD) && !(env->flags & MDBX_NORDAHEAD) &&
mdbx_is_readahead_reasonable(used_bytes, 0) == MDBX_RESULT_TRUE; mdbx_is_readahead_reasonable(used_bytes, 0) == MDBX_RESULT_TRUE;
#endif /* MDBX_ENABLE_MADVISE */
err = osal_mmap(env->flags, &env->dxb_mmap, env->geo_in_bytes.now, err = osal_mmap(env->flags, &env->dxb_mmap, env->geo_in_bytes.now,
env->geo_in_bytes.upper, env->geo_in_bytes.upper,
@ -789,7 +779,6 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc,
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
return err; return err;
#if MDBX_ENABLE_MADVISE
#if defined(MADV_DONTDUMP) #if defined(MADV_DONTDUMP)
err = madvise(env->dxb_mmap.base, env->dxb_mmap.limit, MADV_DONTDUMP) err = madvise(env->dxb_mmap.base, env->dxb_mmap.limit, MADV_DONTDUMP)
? ignore_enosys(errno) ? ignore_enosys(errno)
@ -807,7 +796,6 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc,
return err; return err;
} }
#endif /* MADV_DODUMP */ #endif /* MADV_DODUMP */
#endif /* MDBX_ENABLE_MADVISE */
#ifdef ENABLE_MEMCHECK #ifdef ENABLE_MEMCHECK
env->valgrind_handle = env->valgrind_handle =
@ -1082,7 +1070,6 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc,
} /* lck exclusive, lck_rc == MDBX_RESULT_TRUE */ } /* lck exclusive, lck_rc == MDBX_RESULT_TRUE */
//---------------------------------------------------- setup madvise/readahead //---------------------------------------------------- setup madvise/readahead
#if MDBX_ENABLE_MADVISE
if (used_aligned2os_bytes < env->dxb_mmap.current) { if (used_aligned2os_bytes < env->dxb_mmap.current) {
#if defined(MADV_REMOVE) #if defined(MADV_REMOVE)
if (lck_rc && (env->flags & MDBX_WRITEMAP) != 0 && if (lck_rc && (env->flags & MDBX_WRITEMAP) != 0 &&
@ -1125,7 +1112,6 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc,
err = dxb_set_readahead(env, bytes2pgno(env, used_bytes), readahead, true); err = dxb_set_readahead(env, bytes2pgno(env, used_bytes), readahead, true);
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
return err; return err;
#endif /* MDBX_ENABLE_MADVISE */
return rc; return rc;
} }
@ -1192,8 +1178,7 @@ int dxb_sync_locked(MDBX_env *env, unsigned flags, meta_t *const pending,
} }
#endif /* ENABLE_MEMCHECK || __SANITIZE_ADDRESS__ */ #endif /* ENABLE_MEMCHECK || __SANITIZE_ADDRESS__ */
#if MDBX_ENABLE_MADVISE && \ #if defined(MADV_DONTNEED) || defined(POSIX_MADV_DONTNEED)
(defined(MADV_DONTNEED) || defined(POSIX_MADV_DONTNEED))
const size_t discard_edge_pgno = pgno_align2os_pgno(env, largest_pgno); const size_t discard_edge_pgno = pgno_align2os_pgno(env, largest_pgno);
if (prev_discarded_pgno >= discard_edge_pgno + env->madv_threshold) { if (prev_discarded_pgno >= discard_edge_pgno + env->madv_threshold) {
const size_t prev_discarded_bytes = const size_t prev_discarded_bytes =
@ -1249,7 +1234,7 @@ int dxb_sync_locked(MDBX_env *env, unsigned flags, meta_t *const pending,
env->lck->discarded_tail.weak = discard_edge_pgno; env->lck->discarded_tail.weak = discard_edge_pgno;
} }
} }
#endif /* MDBX_ENABLE_MADVISE && (MADV_DONTNEED || POSIX_MADV_DONTNEED) */ #endif /* MADV_DONTNEED || POSIX_MADV_DONTNEED */
/* LY: check conditions to shrink datafile */ /* LY: check conditions to shrink datafile */
const pgno_t backlog_gap = 3 + pending->trees.gc.height * 3; const pgno_t backlog_gap = 3 + pending->trees.gc.height * 3;

View File

@ -3,7 +3,7 @@
#include "internals.h" #include "internals.h"
#if MDBX_ENABLE_MINCORE #if MDBX_USE_MINCORE
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Проверка размещения/расположения отображенных страниц БД в ОЗУ (mem-in-core), * Проверка размещения/расположения отображенных страниц БД в ОЗУ (mem-in-core),
* с кешированием этой информации. */ * с кешированием этой информации. */
@ -77,11 +77,11 @@ static bool mincore_fetch(MDBX_env *const env, const size_t unit_begin) {
lck->mincore_cache.mask[0] = ~mask; lck->mincore_cache.mask[0] = ~mask;
return bit_tas(lck->mincore_cache.mask, 0); return bit_tas(lck->mincore_cache.mask, 0);
} }
#endif /* MDBX_ENABLE_MINCORE */ #endif /* MDBX_USE_MINCORE */
MDBX_MAYBE_UNUSED static inline bool mincore_probe(MDBX_env *const env, MDBX_MAYBE_UNUSED static inline bool mincore_probe(MDBX_env *const env,
const pgno_t pgno) { const pgno_t pgno) {
#if MDBX_ENABLE_MINCORE #if MDBX_USE_MINCORE
const size_t offset_aligned = const size_t offset_aligned =
floor_powerof2(pgno2bytes(env, pgno), globals.sys_pagesize); floor_powerof2(pgno2bytes(env, pgno), globals.sys_pagesize);
const unsigned unit_log2 = (env->ps2ln > globals.sys_pagesize_ln2) const unsigned unit_log2 = (env->ps2ln > globals.sys_pagesize_ln2)
@ -97,7 +97,7 @@ MDBX_MAYBE_UNUSED static inline bool mincore_probe(MDBX_env *const env,
(void)env; (void)env;
(void)pgno; (void)pgno;
return false; return false;
#endif /* MDBX_ENABLE_MINCORE */ #endif /* MDBX_USE_MINCORE */
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@ -351,8 +351,7 @@ __dll_export
" MDBX_TRUST_RTC=" MDBX_TRUST_RTC_CONFIG " MDBX_TRUST_RTC=" MDBX_TRUST_RTC_CONFIG
" MDBX_AVOID_MSYNC=" MDBX_STRINGIFY(MDBX_AVOID_MSYNC) " MDBX_AVOID_MSYNC=" MDBX_STRINGIFY(MDBX_AVOID_MSYNC)
" MDBX_ENABLE_REFUND=" MDBX_STRINGIFY(MDBX_ENABLE_REFUND) " MDBX_ENABLE_REFUND=" MDBX_STRINGIFY(MDBX_ENABLE_REFUND)
" MDBX_ENABLE_MADVISE=" MDBX_STRINGIFY(MDBX_ENABLE_MADVISE) " MDBX_USE_MINCORE=" MDBX_STRINGIFY(MDBX_USE_MINCORE)
" MDBX_ENABLE_MINCORE=" MDBX_STRINGIFY(MDBX_ENABLE_MINCORE)
" MDBX_ENABLE_PGOP_STAT=" MDBX_STRINGIFY(MDBX_ENABLE_PGOP_STAT) " MDBX_ENABLE_PGOP_STAT=" MDBX_STRINGIFY(MDBX_ENABLE_PGOP_STAT)
" MDBX_ENABLE_PROFGC=" MDBX_STRINGIFY(MDBX_ENABLE_PROFGC) " MDBX_ENABLE_PROFGC=" MDBX_STRINGIFY(MDBX_ENABLE_PROFGC)
#if MDBX_DISABLE_VALIDATION #if MDBX_DISABLE_VALIDATION
@ -373,7 +372,7 @@ __dll_export
" _GNU_SOURCE=NO" " _GNU_SOURCE=NO"
#endif /* _GNU_SOURCE */ #endif /* _GNU_SOURCE */
#ifdef __APPLE__ #ifdef __APPLE__
" MDBX_OSX_SPEED_INSTEADOF_DURABILITY=" MDBX_STRINGIFY(MDBX_OSX_SPEED_INSTEADOF_DURABILITY) " MDBX_APPLE_SPEED_INSTEADOF_DURABILITY=" MDBX_STRINGIFY(MDBX_APPLE_SPEED_INSTEADOF_DURABILITY)
#endif /* MacOS */ #endif /* MacOS */
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
" MDBX_WITHOUT_MSVC_CRT=" MDBX_STRINGIFY(MDBX_WITHOUT_MSVC_CRT) " MDBX_WITHOUT_MSVC_CRT=" MDBX_STRINGIFY(MDBX_WITHOUT_MSVC_CRT)

View File

@ -78,7 +78,6 @@ __cold static int lck_setup_locked(MDBX_env *env) {
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
return err; return err;
#if MDBX_ENABLE_MADVISE
#ifdef MADV_DODUMP #ifdef MADV_DODUMP
err = madvise(env->lck_mmap.lck, size, MADV_DODUMP) ? ignore_enosys(errno) err = madvise(env->lck_mmap.lck, size, MADV_DODUMP) ? ignore_enosys(errno)
: MDBX_SUCCESS; : MDBX_SUCCESS;
@ -97,7 +96,6 @@ __cold static int lck_setup_locked(MDBX_env *env) {
if (unlikely(MDBX_IS_ERROR(err))) if (unlikely(MDBX_IS_ERROR(err)))
return err; return err;
#endif /* MADV_WILLNEED */ #endif /* MADV_WILLNEED */
#endif /* MDBX_ENABLE_MADVISE */
lck_t *lck = env->lck_mmap.lck; lck_t *lck = env->lck_mmap.lck;
if (lck_seize_rc == MDBX_RESULT_TRUE) { if (lck_seize_rc == MDBX_RESULT_TRUE) {

View File

@ -29,23 +29,15 @@
/** Using fsync() with chance of data lost on power failure */ /** Using fsync() with chance of data lost on power failure */
#define MDBX_OSX_WANNA_SPEED 1 #define MDBX_OSX_WANNA_SPEED 1
#ifndef MDBX_OSX_SPEED_INSTEADOF_DURABILITY #ifndef MDBX_APPLE_SPEED_INSTEADOF_DURABILITY
/** Choices \ref MDBX_OSX_WANNA_DURABILITY or \ref MDBX_OSX_WANNA_SPEED /** Choices \ref MDBX_OSX_WANNA_DURABILITY or \ref MDBX_OSX_WANNA_SPEED
* for OSX & iOS */ * for OSX & iOS */
#define MDBX_OSX_SPEED_INSTEADOF_DURABILITY MDBX_OSX_WANNA_DURABILITY #define MDBX_APPLE_SPEED_INSTEADOF_DURABILITY MDBX_OSX_WANNA_DURABILITY
#endif /* MDBX_OSX_SPEED_INSTEADOF_DURABILITY */ #endif /* MDBX_APPLE_SPEED_INSTEADOF_DURABILITY */
/** Controls using of POSIX' madvise() and/or similar hints. */
#ifndef MDBX_ENABLE_MADVISE
#define MDBX_ENABLE_MADVISE 1
#elif !(MDBX_ENABLE_MADVISE == 0 || MDBX_ENABLE_MADVISE == 1)
#error MDBX_ENABLE_MADVISE must be defined as 0 or 1
#endif /* MDBX_ENABLE_MADVISE */
/** Controls checking PID against reuse DB environment after the fork() */ /** Controls checking PID against reuse DB environment after the fork() */
#ifndef MDBX_ENV_CHECKPID #ifndef MDBX_ENV_CHECKPID
#if (defined(MADV_DONTFORK) && MDBX_ENABLE_MADVISE) || defined(_WIN32) || \ #if defined(MADV_DONTFORK) || defined(_WIN32) || defined(_WIN64)
defined(_WIN64)
/* PID check could be omitted: /* PID check could be omitted:
* - on Linux when madvise(MADV_DONTFORK) is available, i.e. after the fork() * - on Linux when madvise(MADV_DONTFORK) is available, i.e. after the fork()
* mapped pages will not be available for child process. * mapped pages will not be available for child process.
@ -110,15 +102,16 @@
/** Controls using Unix' mincore() to determine whether DB-pages /** Controls using Unix' mincore() to determine whether DB-pages
* are resident in memory. */ * are resident in memory. */
#ifndef MDBX_ENABLE_MINCORE #ifndef MDBX_USE_MINCORE
#if defined(MINCORE_INCORE) || !(defined(_WIN32) || defined(_WIN64)) #if defined(MINCORE_INCORE) || !(defined(_WIN32) || defined(_WIN64))
#define MDBX_ENABLE_MINCORE 1 #define MDBX_USE_MINCORE 1
#else #else
#define MDBX_ENABLE_MINCORE 0 #define MDBX_USE_MINCORE 0
#endif #endif
#elif !(MDBX_ENABLE_MINCORE == 0 || MDBX_ENABLE_MINCORE == 1) #define MDBX_USE_MINCORE_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_USE_MINCORE)
#error MDBX_ENABLE_MINCORE must be defined as 0 or 1 #elif !(MDBX_USE_MINCORE == 0 || MDBX_USE_MINCORE == 1)
#endif /* MDBX_ENABLE_MINCORE */ #error MDBX_USE_MINCORE must be defined as 0 or 1
#endif /* MDBX_USE_MINCORE */
/** Enables chunking long list of retired pages during huge transactions commit /** Enables chunking long list of retired pages during huge transactions commit
* to avoid use sequences of pages. */ * to avoid use sequences of pages. */
@ -151,12 +144,16 @@
#endif /* MDBX_DPL_PREALLOC_FOR_RADIXSORT */ #endif /* MDBX_DPL_PREALLOC_FOR_RADIXSORT */
/** Controls dirty pages tracking, spilling and persisting in `MDBX_WRITEMAP` /** Controls dirty pages tracking, spilling and persisting in `MDBX_WRITEMAP`
* mode. 0/OFF = Don't track dirty pages at all, don't spill ones, and use * mode, i.e. disables in-memory database updating with consequent
* msync() to persist data. This is by-default on Linux and other systems where * flush-to-disk/msync syscall.
* kernel provides properly LRU tracking and effective flushing on-demand. 1/ON *
* = Tracking of dirty pages but with LRU labels for spilling and explicit * 0/OFF = Don't track dirty pages at all, don't spill ones, and use msync() to
* persist ones by write(). This may be reasonable for systems which low * persist data. This is by-default on Linux and other systems where kernel
* performance of msync() and/or LRU tracking. */ * provides properly LRU tracking and effective flushing on-demand.
*
* 1/ON = Tracking of dirty pages but with LRU labels for spilling and explicit
* persist ones by write(). This may be reasonable for goofy systems (Windows)
* which low performance of msync() and/or zany LRU tracking. */
#ifndef MDBX_AVOID_MSYNC #ifndef MDBX_AVOID_MSYNC
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#define MDBX_AVOID_MSYNC 1 #define MDBX_AVOID_MSYNC 1
@ -212,7 +209,7 @@
#error MDBX_ENVCOPY_WRITEBUF must be defined in range 65536..1073741824 and be multiple of 65536 #error MDBX_ENVCOPY_WRITEBUF must be defined in range 65536..1073741824 and be multiple of 65536
#endif /* MDBX_ENVCOPY_WRITEBUF */ #endif /* MDBX_ENVCOPY_WRITEBUF */
/** Forces assertion checking */ /** Forces assertion checking. */
#ifndef MDBX_FORCE_ASSERTIONS #ifndef MDBX_FORCE_ASSERTIONS
#define MDBX_FORCE_ASSERTIONS 0 #define MDBX_FORCE_ASSERTIONS 0
#elif !(MDBX_FORCE_ASSERTIONS == 0 || MDBX_FORCE_ASSERTIONS == 1) #elif !(MDBX_FORCE_ASSERTIONS == 0 || MDBX_FORCE_ASSERTIONS == 1)
@ -284,9 +281,6 @@
/** POSIX-2008 Robust Mutexes for \ref MDBX_LOCKING */ /** POSIX-2008 Robust Mutexes for \ref MDBX_LOCKING */
#define MDBX_LOCKING_POSIX2008 2008 #define MDBX_LOCKING_POSIX2008 2008
/** BeOS Benaphores, aka Futexes for \ref MDBX_LOCKING */
#define MDBX_LOCKING_BENAPHORE 1995
/** Advanced: Choices the locking implementation (autodetection by default). */ /** Advanced: Choices the locking implementation (autodetection by default). */
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#define MDBX_LOCKING MDBX_LOCKING_WIN32FILES #define MDBX_LOCKING MDBX_LOCKING_WIN32FILES
@ -363,19 +357,6 @@
#error MDBX_USE_COPYFILERANGE must be defined as 0 or 1 #error MDBX_USE_COPYFILERANGE must be defined as 0 or 1
#endif /* MDBX_USE_COPYFILERANGE */ #endif /* MDBX_USE_COPYFILERANGE */
/** Advanced: Using sync_file_range() syscall (autodetection by default). */
#ifndef MDBX_USE_SYNCFILERANGE
#if ((defined(__linux__) || defined(__gnu_linux__)) && \
defined(SYNC_FILE_RANGE_WRITE) && !defined(__ANDROID_API__)) || \
(defined(__ANDROID_API__) && __ANDROID_API__ >= 26)
#define MDBX_USE_SYNCFILERANGE 1
#else
#define MDBX_USE_SYNCFILERANGE 0
#endif
#elif !(MDBX_USE_SYNCFILERANGE == 0 || MDBX_USE_SYNCFILERANGE == 1)
#error MDBX_USE_SYNCFILERANGE must be defined as 0 or 1
#endif /* MDBX_USE_SYNCFILERANGE */
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef MDBX_CPU_WRITEBACK_INCOHERENT #ifndef MDBX_CPU_WRITEBACK_INCOHERENT
@ -416,15 +397,19 @@
#error MDBX_MMAP_INCOHERENT_CPU_CACHE must be defined as 0 or 1 #error MDBX_MMAP_INCOHERENT_CPU_CACHE must be defined as 0 or 1
#endif /* MDBX_MMAP_INCOHERENT_CPU_CACHE */ #endif /* MDBX_MMAP_INCOHERENT_CPU_CACHE */
#ifndef MDBX_MMAP_USE_MS_ASYNC /** Assume system needs explicit syscall to sync/flush/write modified mapped
#if MDBX_MMAP_INCOHERENT_FILE_WRITE || MDBX_MMAP_INCOHERENT_CPU_CACHE * memory. */
#define MDBX_MMAP_USE_MS_ASYNC 1 #ifndef MDBX_MMAP_NEEDS_JOLT
#if MDBX_MMAP_INCOHERENT_FILE_WRITE || MDBX_MMAP_INCOHERENT_CPU_CACHE || \
!(defined(__linux__) || defined(__gnu_linux__))
#define MDBX_MMAP_NEEDS_JOLT 1
#else #else
#define MDBX_MMAP_USE_MS_ASYNC 0 #define MDBX_MMAP_NEEDS_JOLT 0
#endif #endif
#elif !(MDBX_MMAP_USE_MS_ASYNC == 0 || MDBX_MMAP_USE_MS_ASYNC == 1) #define MDBX_MMAP_NEEDS_JOLT_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_MMAP_NEEDS_JOLT)
#error MDBX_MMAP_USE_MS_ASYNC must be defined as 0 or 1 #elif !(MDBX_MMAP_NEEDS_JOLT == 0 || MDBX_MMAP_NEEDS_JOLT == 1)
#endif /* MDBX_MMAP_USE_MS_ASYNC */ #error MDBX_MMAP_NEEDS_JOLT must be defined as 0 or 1
#endif /* MDBX_MMAP_NEEDS_JOLT */
#ifndef MDBX_64BIT_ATOMIC #ifndef MDBX_64BIT_ATOMIC
#if MDBX_WORDBITS >= 64 || defined(DOXYGEN) #if MDBX_WORDBITS >= 64 || defined(DOXYGEN)
@ -507,7 +492,9 @@
#endif /* MDBX_CACHELINE_SIZE */ #endif /* MDBX_CACHELINE_SIZE */
/* Max length of iov-vector passed to writev() call, used for auxilary writes */ /* Max length of iov-vector passed to writev() call, used for auxilary writes */
#ifndef MDBX_AUXILARY_IOV_MAX
#define MDBX_AUXILARY_IOV_MAX 64 #define MDBX_AUXILARY_IOV_MAX 64
#endif
#if defined(IOV_MAX) && IOV_MAX < MDBX_AUXILARY_IOV_MAX #if defined(IOV_MAX) && IOV_MAX < MDBX_AUXILARY_IOV_MAX
#undef MDBX_AUXILARY_IOV_MAX #undef MDBX_AUXILARY_IOV_MAX
#define MDBX_AUXILARY_IOV_MAX IOV_MAX #define MDBX_AUXILARY_IOV_MAX IOV_MAX

View File

@ -1623,7 +1623,7 @@ MDBX_INTERNAL int osal_fsync(mdbx_filehandle_t fd,
#else #else
#if defined(__APPLE__) && \ #if defined(__APPLE__) && \
MDBX_OSX_SPEED_INSTEADOF_DURABILITY == MDBX_OSX_WANNA_DURABILITY MDBX_APPLE_SPEED_INSTEADOF_DURABILITY == MDBX_OSX_WANNA_DURABILITY
if (mode_bits & MDBX_SYNC_IODQ) if (mode_bits & MDBX_SYNC_IODQ)
return likely(fcntl(fd, F_FULLFSYNC) != -1) ? MDBX_SUCCESS : errno; return likely(fcntl(fd, F_FULLFSYNC) != -1) ? MDBX_SUCCESS : errno;
#endif /* MacOS */ #endif /* MacOS */
@ -1776,7 +1776,7 @@ MDBX_INTERNAL int osal_thread_join(osal_thread_t thread) {
MDBX_INTERNAL int osal_msync(const osal_mmap_t *map, size_t offset, MDBX_INTERNAL int osal_msync(const osal_mmap_t *map, size_t offset,
size_t length, enum osal_syncmode_bits mode_bits) { size_t length, enum osal_syncmode_bits mode_bits) {
if (!MDBX_MMAP_USE_MS_ASYNC && mode_bits == MDBX_SYNC_NONE) if (!MDBX_MMAP_NEEDS_JOLT && mode_bits == MDBX_SYNC_NONE)
return MDBX_SUCCESS; return MDBX_SUCCESS;
void *ptr = ptr_disp(map->base, offset); void *ptr = ptr_disp(map->base, offset);
@ -1793,7 +1793,7 @@ MDBX_INTERNAL int osal_msync(const osal_mmap_t *map, size_t offset,
// //
// However, this behavior may be changed in custom kernels, // However, this behavior may be changed in custom kernels,
// so just leave such optimization to the libc discretion. // so just leave such optimization to the libc discretion.
// NOTE: The MDBX_MMAP_USE_MS_ASYNC must be defined to 1 for such cases. // NOTE: The MDBX_MMAP_NEEDS_JOLT must be defined to 1 for such cases.
// //
// assert(mdbx.linux_kernel_version > 0x02061300); // assert(mdbx.linux_kernel_version > 0x02061300);
// if (mode_bits <= MDBX_SYNC_KICK) // if (mode_bits <= MDBX_SYNC_KICK)
@ -2314,7 +2314,6 @@ MDBX_INTERNAL int osal_mmap(const int flags, osal_mmap_t *map, size_t size,
} }
map->limit = limit; map->limit = limit;
#if MDBX_ENABLE_MADVISE
#ifdef MADV_DONTFORK #ifdef MADV_DONTFORK
if (unlikely(madvise(map->base, map->limit, MADV_DONTFORK) != 0)) if (unlikely(madvise(map->base, map->limit, MADV_DONTFORK) != 0))
return errno; return errno;
@ -2322,7 +2321,6 @@ MDBX_INTERNAL int osal_mmap(const int flags, osal_mmap_t *map, size_t size,
#ifdef MADV_NOHUGEPAGE #ifdef MADV_NOHUGEPAGE
(void)madvise(map->base, map->limit, MADV_NOHUGEPAGE); (void)madvise(map->base, map->limit, MADV_NOHUGEPAGE);
#endif /* MADV_NOHUGEPAGE */ #endif /* MADV_NOHUGEPAGE */
#endif /* MDBX_ENABLE_MADVISE */
#endif /* ! Windows */ #endif /* ! Windows */
@ -2735,7 +2733,6 @@ retry_mapview:;
map->limit = limit; map->limit = limit;
map->current = size; map->current = size;
#if MDBX_ENABLE_MADVISE
#ifdef MADV_DONTFORK #ifdef MADV_DONTFORK
if (unlikely(madvise(map->base, map->limit, MADV_DONTFORK) != 0)) { if (unlikely(madvise(map->base, map->limit, MADV_DONTFORK) != 0)) {
assert(errno != 0); assert(errno != 0);
@ -2745,7 +2742,6 @@ retry_mapview:;
#ifdef MADV_NOHUGEPAGE #ifdef MADV_NOHUGEPAGE
(void)madvise(map->base, map->limit, MADV_NOHUGEPAGE); (void)madvise(map->base, map->limit, MADV_NOHUGEPAGE);
#endif /* MADV_NOHUGEPAGE */ #endif /* MADV_NOHUGEPAGE */
#endif /* MDBX_ENABLE_MADVISE */
#endif /* POSIX / Windows */ #endif /* POSIX / Windows */