mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:04:12 +08:00
mdbx: conditionally use cacheflush() for linux < 2.6.11
Change-Id: Id34c67797e14f709f767bf1b687319cd2dfef874
This commit is contained in:
parent
a6bad26e1d
commit
663f3f3c58
@ -19,6 +19,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "./bits.h"
|
#include "./bits.h"
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
/* Some platforms define the EOWNERDEAD error code
|
/* Some platforms define the EOWNERDEAD error code
|
||||||
* even though they don't support Robust Mutexes.
|
* even though they don't support Robust Mutexes.
|
||||||
@ -36,10 +37,31 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif /* MDBX_USE_ROBUST */
|
#endif /* MDBX_USE_ROBUST */
|
||||||
|
|
||||||
|
uint32_t linux_kernel_version;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/* rthc */
|
/* rthc */
|
||||||
|
|
||||||
static __cold __attribute__((constructor)) void mdbx_global_constructor(void) {
|
static __cold __attribute__((constructor)) void mdbx_global_constructor(void) {
|
||||||
|
struct utsname buffer;
|
||||||
|
if (uname(&buffer) == 0) {
|
||||||
|
int i = 0;
|
||||||
|
char *p = buffer.release;
|
||||||
|
while (*p && i < 4) {
|
||||||
|
if (*p >= '0' && *p <= '9') {
|
||||||
|
long number = strtol(p, &p, 10);
|
||||||
|
if (number > 0) {
|
||||||
|
if (number > 255)
|
||||||
|
number = 255;
|
||||||
|
linux_kernel_version += number << (24 - i * 8);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
} else {
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mdbx_rthc_global_init();
|
mdbx_rthc_global_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/mdbx.c
19
src/mdbx.c
@ -4639,9 +4639,17 @@ static int mdbx_page_flush(MDBX_txn *txn, pgno_t keep) {
|
|||||||
mdbx_debug("Write error: %s", mdbx_strerror(rc));
|
mdbx_debug("Write error: %s", mdbx_strerror(rc));
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
#if MDBX_CPU_CACHE_MMAP_NONCOHERENT == 1
|
|
||||||
|
#if MDBX_CPU_CACHE_MMAP_NONCOHERENT
|
||||||
|
#if defined(__linux__) || defined(__gnu_linux__)
|
||||||
|
if (linux_kernel_version >= 0x02060b00)
|
||||||
|
/* Linux kernels older than version 2.6.11 ignore the addr and nbytes
|
||||||
|
* arguments, making this function fairly expensive. Therefore, the
|
||||||
|
* whole cache is always flushed. */
|
||||||
|
#endif /* Linux */
|
||||||
mdbx_invalidate_mmap_noncoherent_cache(env->me_map + wpos, wsize);
|
mdbx_invalidate_mmap_noncoherent_cache(env->me_map + wpos, wsize);
|
||||||
#endif
|
#endif /* MDBX_CPU_CACHE_MMAP_NONCOHERENT */
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
if (i > pagecount)
|
if (i > pagecount)
|
||||||
@ -4657,13 +4665,16 @@ static int mdbx_page_flush(MDBX_txn *txn, pgno_t keep) {
|
|||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MDBX_CPU_CACHE_MMAP_NONCOHERENT > 1
|
#if MDBX_CPU_CACHE_MMAP_NONCOHERENT && \
|
||||||
|
(defined(__linux__) || defined(__gnu_linux__))
|
||||||
|
if (linux_kernel_version < 0x02060b00) {
|
||||||
/* Linux kernels older than version 2.6.11 ignore the addr and nbytes
|
/* Linux kernels older than version 2.6.11 ignore the addr and nbytes
|
||||||
* arguments, making this function fairly expensive. Therefore, the whole
|
* arguments, making this function fairly expensive. Therefore, the whole
|
||||||
* cache is always flushed. */
|
* cache is always flushed. */
|
||||||
mdbx_invalidate_mmap_noncoherent_cache(env->me_map,
|
mdbx_invalidate_mmap_noncoherent_cache(env->me_map,
|
||||||
pgno2bytes(env, txn->mt_next_pgno));
|
pgno2bytes(env, txn->mt_next_pgno));
|
||||||
#endif
|
}
|
||||||
|
#endif /* MDBX_CPU_CACHE_MMAP_NONCOHERENT && Linux */
|
||||||
|
|
||||||
for (i = keep; ++i <= pagecount;) {
|
for (i = keep; ++i <= pagecount;) {
|
||||||
dp = dl[i].ptr;
|
dp = dl[i].ptr;
|
||||||
|
@ -462,6 +462,10 @@ int mdbx_vasprintf(char **strp, const char *fmt, va_list ap);
|
|||||||
/* max bytes to write in one call */
|
/* max bytes to write in one call */
|
||||||
#define MAX_WRITE UINT32_C(0x3fff0000)
|
#define MAX_WRITE UINT32_C(0x3fff0000)
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined(__gnu_linux__)
|
||||||
|
extern uint32_t linux_kernel_version;
|
||||||
|
#endif /* Linux */
|
||||||
|
|
||||||
/* Get the size of a memory page for the system.
|
/* Get the size of a memory page for the system.
|
||||||
* This is the basic size that the platform's memory manager uses, and is
|
* This is the basic size that the platform's memory manager uses, and is
|
||||||
* fundamental to the use of memory-mapped files. */
|
* fundamental to the use of memory-mapped files. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user