mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:34:14 +08:00
mdbx: добавление опции MDBX_MMAP_USE_MS_ASYNC
.
Суть в избавлении от лишнего вызова msync(MS_ASYNC) в режимах MDBX_WRITEMAP+MDBX_SAFE_NOSYNC и т.п. Гипотетически могут быть системы/платформы, на которых изменения в разделяемой памяти не видны другим процессам до вызова msync(MS_ASYNC) и/или до этого вызова не будет инициироваться вытеснение/запись таких страниц на диск. Поэтому использование msync(MS_ASYNC) вынесено под опцию MDBX_MMAP_USE_MS_ASYNC, которая по-умолчанию включена только на системах с MDBX_MMAP_INCOHERENT_FILE_WRITE или MDBX_MMAP_INCOHERENT_CPU_CACHE.
This commit is contained in:
parent
23fedf6bba
commit
07f2ccb752
@ -389,6 +389,16 @@
|
|||||||
#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
|
||||||
|
#if MDBX_MMAP_INCOHERENT_FILE_WRITE || MDBX_MMAP_INCOHERENT_CPU_CACHE
|
||||||
|
#define MDBX_MMAP_USE_MS_ASYNC 1
|
||||||
|
#else
|
||||||
|
#define MDBX_MMAP_USE_MS_ASYNC 0
|
||||||
|
#endif
|
||||||
|
#elif !(MDBX_MMAP_USE_MS_ASYNC == 0 || MDBX_MMAP_USE_MS_ASYNC == 1)
|
||||||
|
#error MDBX_MMAP_USE_MS_ASYNC must be defined as 0 or 1
|
||||||
|
#endif /* MDBX_MMAP_USE_MS_ASYNC */
|
||||||
|
|
||||||
#ifndef MDBX_64BIT_ATOMIC
|
#ifndef MDBX_64BIT_ATOMIC
|
||||||
#if MDBX_WORDBITS >= 64 || defined(DOXYGEN)
|
#if MDBX_WORDBITS >= 64 || defined(DOXYGEN)
|
||||||
#define MDBX_64BIT_ATOMIC 1
|
#define MDBX_64BIT_ATOMIC 1
|
||||||
|
12
src/osal.c
12
src/osal.c
@ -1707,10 +1707,16 @@ MDBX_INTERNAL_FUNC int osal_thread_join(osal_thread_t thread) {
|
|||||||
MDBX_INTERNAL_FUNC int osal_msync(const osal_mmap_t *map, size_t offset,
|
MDBX_INTERNAL_FUNC int osal_msync(const osal_mmap_t *map, size_t offset,
|
||||||
size_t length,
|
size_t length,
|
||||||
enum osal_syncmode_bits mode_bits) {
|
enum osal_syncmode_bits mode_bits) {
|
||||||
|
if (!MDBX_MMAP_USE_MS_ASYNC && mode_bits == MDBX_SYNC_KICK)
|
||||||
|
return MDBX_SUCCESS;
|
||||||
|
|
||||||
void *ptr = ptr_disp(map->base, offset);
|
void *ptr = ptr_disp(map->base, offset);
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
if (!FlushViewOfFile(ptr, length))
|
if (!FlushViewOfFile(ptr, length))
|
||||||
return (int)GetLastError();
|
return (int)GetLastError();
|
||||||
|
if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) &&
|
||||||
|
!FlushFileBuffers(map->fd))
|
||||||
|
return (int)GetLastError();
|
||||||
#else
|
#else
|
||||||
#if defined(__linux__) || defined(__gnu_linux__)
|
#if defined(__linux__) || defined(__gnu_linux__)
|
||||||
/* Since Linux 2.6.19, MS_ASYNC is in fact a no-op. The kernel properly
|
/* Since Linux 2.6.19, MS_ASYNC is in fact a no-op. The kernel properly
|
||||||
@ -1718,6 +1724,7 @@ MDBX_INTERNAL_FUNC 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.
|
||||||
//
|
//
|
||||||
// assert(linux_kernel_version > 0x02061300);
|
// assert(linux_kernel_version > 0x02061300);
|
||||||
// if (mode_bits == MDBX_SYNC_KICK)
|
// if (mode_bits == MDBX_SYNC_KICK)
|
||||||
@ -1725,9 +1732,10 @@ MDBX_INTERNAL_FUNC int osal_msync(const osal_mmap_t *map, size_t offset,
|
|||||||
#endif /* Linux */
|
#endif /* Linux */
|
||||||
if (msync(ptr, length, (mode_bits & MDBX_SYNC_DATA) ? MS_SYNC : MS_ASYNC))
|
if (msync(ptr, length, (mode_bits & MDBX_SYNC_DATA) ? MS_SYNC : MS_ASYNC))
|
||||||
return errno;
|
return errno;
|
||||||
mode_bits &= ~MDBX_SYNC_DATA;
|
if ((mode_bits & MDBX_SYNC_SIZE) && fsync(map->fd))
|
||||||
|
return errno;
|
||||||
#endif
|
#endif
|
||||||
return osal_fsync(map->fd, mode_bits);
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDBX_INTERNAL_FUNC int osal_check_fs_rdonly(mdbx_filehandle_t handle,
|
MDBX_INTERNAL_FUNC int osal_check_fs_rdonly(mdbx_filehandle_t handle,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user