diff --git a/src/elements/core.c b/src/elements/core.c index 9142cf32..ef606fc5 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -8047,7 +8047,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) { } err = mdbx_mmap(env->me_flags, &env->me_dxb_mmap, env->me_dbgeo.now, - env->me_dbgeo.upper, lck_rc); + env->me_dbgeo.upper, lck_rc ? MMAP_OPTION_TRUNCATE : 0); if (unlikely(err != MDBX_SUCCESS)) return err; @@ -8379,7 +8379,8 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, env->me_maxreaders = (unsigned)maxreaders; err = mdbx_mmap(MDBX_WRITEMAP, &env->me_lck_mmap, (size_t)size, (size_t)size, - lck_seize_rc); + lck_seize_rc ? MMAP_OPTION_TRUNCATE | MMAP_OPTION_SEMAPHORE + : MMAP_OPTION_SEMAPHORE); if (unlikely(err != MDBX_SUCCESS)) goto bailout; diff --git a/src/elements/osal.c b/src/elements/osal.c index 797ecef3..c1014c6a 100644 --- a/src/elements/osal.c +++ b/src/elements/osal.c @@ -1166,7 +1166,7 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) { MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, const size_t size, const size_t limit, - const bool truncate) { + const unsigned options) { assert(size <= limit); map->limit = 0; map->current = 0; @@ -1180,7 +1180,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, if (unlikely(err != MDBX_SUCCESS)) return err; - if ((flags & MDBX_RDONLY) == 0 && truncate) { + if ((flags & MDBX_RDONLY) == 0 && (options & MMAP_OPTION_TRUNCATE) != 0) { err = mdbx_ftruncate(map->fd, size); if (err != MDBX_SUCCESS) return err; @@ -1243,7 +1243,18 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, map->address = mmap( NULL, limit, (flags & MDBX_WRITEMAP) ? PROT_READ | PROT_WRITE : PROT_READ, - MAP_SHARED, map->fd, 0); + MAP_SHARED | MAP_FILE +#ifdef MAP_NOSYNC + | (((options & MMAP_OPTION_SEMAPHORE) != 0 || + F_ISSET(flags, MDBX_UTTERLY_NOSYNC)) + ? MAP_NOSYNC + : 0) +#endif +#ifdef MAP_HASSEMAPHORE + | ((options & MMAP_OPTION_SEMAPHORE) ? MAP_HASSEMAPHORE : 0) +#endif + , + map->fd, 0); if (unlikely(map->address == MAP_FAILED)) { map->limit = 0; diff --git a/src/elements/osal.h b/src/elements/osal.h index 04af577d..957d2d8a 100644 --- a/src/elements/osal.h +++ b/src/elements/osal.h @@ -649,9 +649,11 @@ typedef struct mdbx_mmap_param { #endif } mdbx_mmap_t; +#define MMAP_OPTION_TRUNCATE 1 +#define MMAP_OPTION_SEMAPHORE 2 MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, const size_t must, const size_t limit, - const bool truncate); + const unsigned options); MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map); MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t current, size_t wanna);