diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-06-06 21:18:11 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-06-07 00:44:45 -0700 |
commit | 486a81f387bb59b2fbbc6aff7b41adbe1621394e (patch) | |
tree | 7b61ed0a44666f10e4da54ef3e0905974c861944 /m4 | |
parent | 111408a0e9eb3a9492c4057ac7d6ddbb8b365aa9 (diff) | |
download | emacs-486a81f387bb59b2fbbc6aff7b41adbe1621394e.tar.gz |
Use copy_file_range to copy files
The copy_file_range syscall (introduced in Linux kernel
version 4.5) can copy files more efficiently via server-side
copy etc.
* admin/merge-gnulib (GNULIB_MODULES): Add copy-file-range.
* lib/copy-file-range.c, m4/copy-file-range.m4:
New files, copied from Gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* src/fileio.c (Fcopy_file): Try copy_file_range first,
falling back on read+write only if copy_file_range failed or
if the input is empty and so could be a /proc file.
Diffstat (limited to 'm4')
-rw-r--r-- | m4/copy-file-range.m4 | 36 | ||||
-rw-r--r-- | m4/gnulib-comp.m4 | 8 |
2 files changed, 44 insertions, 0 deletions
diff --git a/m4/copy-file-range.m4 b/m4/copy-file-range.m4 new file mode 100644 index 00000000000..20fd05697fe --- /dev/null +++ b/m4/copy-file-range.m4 @@ -0,0 +1,36 @@ +# copy-file-range.m4 +dnl Copyright 2019 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_COPY_FILE_RANGE], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc <unistd.h> to declare copy_file_range. + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + dnl Use AC_LINK_IFELSE, rather than AC_CHECK_FUNCS or a variant, + dnl since we don't want AC_CHECK_FUNCS's checks for glibc stubs. + dnl Programs that use copy_file_range must fall back on read+write + dnl anyway, and there's little point to substituting the Gnulib stub + dnl for a glibc stub. + AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <unistd.h> + ]], + [[ssize_t (*func) (int, off_t *, int, off_t, size_t, unsigned) + = copy_file_range; + return func (0, 0, 0, 0, 0, 0) & 127; + ]]) + ], + [gl_cv_func_copy_file_range=yes], + [gl_cv_func_copy_file_range=no]) + ]) + + if test "$gl_cv_func_copy_file_range" != yes; then + HAVE_COPY_FILE_RANGE=0 + fi +]) diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 0a7a30e5ae2..4627575bf63 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -56,6 +56,7 @@ AC_DEFUN([gl_EARLY], # Code from module clock-time: # Code from module cloexec: # Code from module close-stream: + # Code from module copy-file-range: # Code from module count-leading-zeros: # Code from module count-one-bits: # Code from module count-trailing-zeros: @@ -201,6 +202,11 @@ AC_DEFUN([gl_INIT], AC_CHECK_FUNCS_ONCE([readlinkat]) gl_CLOCK_TIME gl_MODULE_INDICATOR([close-stream]) + gl_FUNC_COPY_FILE_RANGE + if test $HAVE_COPY_FILE_RANGE = 0; then + AC_LIBOBJ([copy-file-range]) + fi + gl_UNISTD_MODULE_INDICATOR([copy-file-range]) gl_COUNT_LEADING_ZEROS gl_COUNT_ONE_BITS gl_COUNT_TRAILING_ZEROS @@ -846,6 +852,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/cloexec.h lib/close-stream.c lib/close-stream.h + lib/copy-file-range.c lib/count-leading-zeros.c lib/count-leading-zeros.h lib/count-one-bits.c @@ -995,6 +1002,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/builtin-expect.m4 m4/byteswap.m4 m4/clock_time.m4 + m4/copy-file-range.m4 m4/count-leading-zeros.m4 m4/count-one-bits.m4 m4/count-trailing-zeros.m4 |