mdbx: provide MDBX_USE_SENDFILE and MDBX_USE_SENDFILE options.

Change-Id: Icd9a6487ae6e398276a9e720926ff24de5897c1a
This commit is contained in:
Leonid Yuriev 2020-09-20 20:16:26 +03:00
parent 6db7b13266
commit 25e3968199
2 changed files with 27 additions and 7 deletions

View File

@ -16314,10 +16314,8 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn,
uint8_t *const data_buffer =
buffer + ceil_powerof2(meta_bytes, env->me_os_psize);
for (size_t offset = meta_bytes; rc == MDBX_SUCCESS && offset < used_size;) {
#if MDBX_USE_SENDFILE
if (dest_is_pipe) {
#if (defined(__linux__) || defined(__gnu_linux__)) && \
(!defined(__ANDROID_API__) || __ANDROID_API__ >= 21) && \
!defined(MDBX_SAFE4QEMU)
off_t in_offset = offset;
const intptr_t written =
sendfile(fd, env->me_lazy_fd, &in_offset, used_size - offset);
@ -16327,9 +16325,11 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn,
}
offset = in_offset;
continue;
#endif
} else {
#if __GLIBC_PREREQ(2, 27) && defined(_GNU_SOURCE) && !defined(MDBX_SAFE4QEMU)
}
#endif /* MDBX_USE_SENDFILE */
#if MDBX_USE_COPYFILERANGE
if (!dest_is_pipe) {
off_t in_offset = offset, out_offset = offset;
ssize_t bytes_copied = copy_file_range(
env->me_lazy_fd, &in_offset, fd, &out_offset, used_size - offset, 0);
@ -16339,8 +16339,8 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn,
}
offset = in_offset;
continue;
#endif
}
#endif /* MDBX_USE_COPYFILERANGE */
/* fallback to portable */
const size_t chunk =

View File

@ -162,6 +162,26 @@
#define MDBX_USE_OFDLOCKS_CONFIG STRINGIFY(MDBX_USE_OFDLOCKS)
#endif /* MDBX_USE_OFDLOCKS */
/** Advanced: Using sendfile() syscall (autodetection by default). */
#ifndef MDBX_USE_SENDFILE
#if (defined(__linux__) || defined(__gnu_linux__)) && \
(!defined(__ANDROID_API__) || __ANDROID_API__ >= 21) && \
!defined(MDBX_SAFE4QEMU)
#define MDBX_USE_SENDFILE 1
#else
#define MDBX_USE_SENDFILE 0
#endif
#endif /* MDBX_USE_SENDFILE */
/** Advanced: Using copy_file_range() syscall (autodetection by default). */
#ifndef MDBX_USE_COPYFILERANGE
#if __GLIBC_PREREQ(2, 27) && defined(_GNU_SOURCE) && !defined(MDBX_SAFE4QEMU)
#define MDBX_USE_COPYFILERANGE 1
#else
#define MDBX_USE_COPYFILERANGE 0
#endif
#endif /* MDBX_USE_COPYFILERANGE */
//------------------------------------------------------------------------------
#ifndef MDBX_CPU_WRITEBACK_INCOHERENT