From 40112ebd621d1e8d31c9c3913ece5e51e5bac5ab Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 30 Jun 2019 16:11:05 +0300 Subject: [PATCH] mdbx: engage copy_file_range() for env_copy_as_is. Change-Id: I7ea17914d80500ffa70451b80920d726f0e9c2f8 --- src/mdbx.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mdbx.c b/src/mdbx.c index 8f193b6c..ec00390f 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -11647,6 +11647,17 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn, /* Copy the data */ const size_t data_bytes = pgno2bytes(env, read_txn->mt_next_pgno); +#if __GLIBC_PREREQ(2, 27) + for (off_t in_offset = meta_bytes; in_offset < (off_t)data_bytes;) { + off_t out_offset = in_offset; + ssize_t bytes_copied = copy_file_range( + env->me_fd, &in_offset, fd, &out_offset, data_bytes - in_offset, 0); + if (bytes_copied < 0) { + rc = errno; + break; + } + } +#else uint8_t *data_buffer = buffer + meta_bytes; for (size_t offset = meta_bytes; likely(rc == MDBX_SUCCESS) && offset < data_bytes;) { @@ -11656,8 +11667,9 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn, rc = mdbx_pwrite(fd, data_buffer, chunk, offset); offset += chunk; } +#endif - if (likely(rc == MDBX_SUCCESS)) + if (likely(rc == MDBX_SUCCESS) && whole_size != data_bytes) rc = mdbx_ftruncate(fd, whole_size); return rc;