diff --git a/CMakeLists.txt b/CMakeLists.txt index 8855de26..6367a60d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -700,6 +700,8 @@ mark_as_advanced(MDBX_ENABLE_PROFGC) add_option(MDBX ENABLE_DBI_SPARSE "Support for sparse sets of DBI handles to reduce overhead when starting and processing transactions" ON) add_option(MDBX ENABLE_DBI_LOCKFREE "Support for deferred releasing and a lockfree path to quickly open DBI handles" ON) +add_option(MDBX USE_FALLOCATE "Using posix_fallocate() or fcntl(F_PREALLOCATE) on OSX" AUTO) +mark_as_advanced(MDBX_USE_FALLOCATE) if(NOT MDBX_AMALGAMATED_SOURCE) if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE_UPPERCASE STREQUAL "DEBUG") diff --git a/conanfile.py b/conanfile.py index b36e7b44..c7a850f8 100644 --- a/conanfile.py +++ b/conanfile.py @@ -82,6 +82,7 @@ class libmdbx(ConanFile): 'mdbx.use_mincore': ['Auto', True, False], 'mdbx.use_ofdlocks': ['Auto', True, False], 'mdbx.use_sendfile': ['Auto', True, False], + 'mdbx.use_fallocate': ['Auto', True, False], 'mdbx.without_msvc_crt': ['Default', True, False], 'shared': [True, False], } @@ -113,6 +114,7 @@ class libmdbx(ConanFile): 'mdbx.use_mincore': 'Auto', 'mdbx.use_ofdlocks': 'Auto', 'mdbx.use_sendfile': 'Auto', + 'mdbx.use_fallocate': 'Auto', 'mdbx.without_msvc_crt': 'Default', 'shared': True, } @@ -143,7 +145,8 @@ class libmdbx(ConanFile): 'mdbx.use_copyfilerange': 'Advanced: Use `copy_file_range()` syscall. ', 'mdbx.use_mincore': "Use Unix' `mincore()` to determine whether database pages are resident in memory. ", 'mdbx.use_ofdlocks': 'Advanced: Use POSIX OFD-locks. ', - 'mdbx.use_sendfile': 'Advancedc: Use `sendfile()` syscall. ', + 'mdbx.use_sendfile': 'Advanced: Use `sendfile()` syscall. ', + 'mdbx.use_fallocate': 'Advanced: Use posix_fallocate() or fcntl(F_PREALLOCATE) on OSX. ', 'mdbx.without_msvc_crt': 'Avoid dependence from MSVC CRT and use ntdll.dll instead. ', } @@ -160,6 +163,7 @@ class libmdbx(ConanFile): self.options.rm_safe('mdbx.mmap_incoherent_file_write') self.options.rm_safe('mdbx.use_mincore') self.options.rm_safe('mdbx.use_ofdlocks') + self.options.rm_safe('mdbx.use_fallocate') else: self.options.rm_safe('mdbx.without_msvc_crt') if is_apple_os(self): diff --git a/src/config.h.in b/src/config.h.in index 5d53860c..447c699d 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -63,6 +63,11 @@ #cmakedefine01 MDBX_USE_MINCORE +#cmakedefine MDBX_USE_FALLOCATE_AUTO +#ifndef MDBX_USE_FALLOCATE_AUTO +#cmakedefine01 MDBX_USE_FALLOCATE +#endif /* MDBX_USE_FALLOCATE */ + /* Build Info */ #ifndef MDBX_BUILD_TIMESTAMP #cmakedefine MDBX_BUILD_TIMESTAMP "@MDBX_BUILD_TIMESTAMP@" diff --git a/src/global.c b/src/global.c index e3435f72..36e9eaaf 100644 --- a/src/global.c +++ b/src/global.c @@ -379,6 +379,7 @@ __dll_export #else /* Windows */ " MDBX_LOCKING=" MDBX_LOCKING_CONFIG " MDBX_USE_OFDLOCKS=" MDBX_USE_OFDLOCKS_CONFIG + " MDBX_USE_FALLOCATE=" MDBX_USE_FALLOCATE_CONFIG #endif /* !Windows */ " MDBX_CACHELINE_SIZE=" MDBX_STRINGIFY(MDBX_CACHELINE_SIZE) " MDBX_CPU_WRITEBACK_INCOHERENT=" MDBX_STRINGIFY(MDBX_CPU_WRITEBACK_INCOHERENT) diff --git a/src/options.h b/src/options.h index 732cdeab..9e6e8c9b 100644 --- a/src/options.h +++ b/src/options.h @@ -350,7 +350,7 @@ #error MDBX_USE_COPYFILERANGE must be defined as 0 or 1 #endif /* MDBX_USE_COPYFILERANGE */ -/** Advanced: Using posix_fallocate() or fcntl(F_PREALLOCATE) (autodetection by default). */ +/** Advanced: Using posix_fallocate() or fcntl(F_PREALLOCATE) on OSX (autodetection by default). */ #ifndef MDBX_USE_FALLOCATE #if defined(__APPLE__) #define MDBX_USE_FALLOCATE 0 /* Too slow and unclean, but not required to prevent SIGBUS */ @@ -359,8 +359,11 @@ #else #define MDBX_USE_FALLOCATE 0 #endif +#define MDBX_USE_FALLOCATE_CONFIG "AUTO=" MDBX_STRINGIFY(MDBX_USE_FALLOCATE) #elif !(MDBX_USE_FALLOCATE == 0 || MDBX_USE_FALLOCATE == 1) #error MDBX_USE_FALLOCATE must be defined as 0 or 1 +#else +#define MDBX_USE_FALLOCATE_CONFIG MDBX_STRINGIFY(MDBX_USE_FALLOCATE) #endif /* MDBX_USE_FALLOCATE */ //------------------------------------------------------------------------------