diff options
| author | Paul Eggert | 2019-06-06 21:18:11 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-06-07 00:44:45 -0700 |
| commit | 486a81f387bb59b2fbbc6aff7b41adbe1621394e (patch) | |
| tree | 7b61ed0a44666f10e4da54ef3e0905974c861944 /m4 | |
| parent | 111408a0e9eb3a9492c4057ac7d6ddbb8b365aa9 (diff) | |
| download | emacs-486a81f387bb59b2fbbc6aff7b41adbe1621394e.tar.gz emacs-486a81f387bb59b2fbbc6aff7b41adbe1621394e.zip | |
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 @@ | |||
| 1 | # copy-file-range.m4 | ||
| 2 | dnl Copyright 2019 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | AC_DEFUN([gl_FUNC_COPY_FILE_RANGE], | ||
| 8 | [ | ||
| 9 | AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) | ||
| 10 | |||
| 11 | dnl Persuade glibc <unistd.h> to declare copy_file_range. | ||
| 12 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) | ||
| 13 | |||
| 14 | dnl Use AC_LINK_IFELSE, rather than AC_CHECK_FUNCS or a variant, | ||
| 15 | dnl since we don't want AC_CHECK_FUNCS's checks for glibc stubs. | ||
| 16 | dnl Programs that use copy_file_range must fall back on read+write | ||
| 17 | dnl anyway, and there's little point to substituting the Gnulib stub | ||
| 18 | dnl for a glibc stub. | ||
| 19 | AC_CACHE_CHECK([for copy_file_range], [gl_cv_func_copy_file_range], | ||
| 20 | [AC_LINK_IFELSE( | ||
| 21 | [AC_LANG_PROGRAM( | ||
| 22 | [[#include <unistd.h> | ||
| 23 | ]], | ||
| 24 | [[ssize_t (*func) (int, off_t *, int, off_t, size_t, unsigned) | ||
| 25 | = copy_file_range; | ||
| 26 | return func (0, 0, 0, 0, 0, 0) & 127; | ||
| 27 | ]]) | ||
| 28 | ], | ||
| 29 | [gl_cv_func_copy_file_range=yes], | ||
| 30 | [gl_cv_func_copy_file_range=no]) | ||
| 31 | ]) | ||
| 32 | |||
| 33 | if test "$gl_cv_func_copy_file_range" != yes; then | ||
| 34 | HAVE_COPY_FILE_RANGE=0 | ||
| 35 | fi | ||
| 36 | ]) | ||
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], | |||
| 56 | # Code from module clock-time: | 56 | # Code from module clock-time: |
| 57 | # Code from module cloexec: | 57 | # Code from module cloexec: |
| 58 | # Code from module close-stream: | 58 | # Code from module close-stream: |
| 59 | # Code from module copy-file-range: | ||
| 59 | # Code from module count-leading-zeros: | 60 | # Code from module count-leading-zeros: |
| 60 | # Code from module count-one-bits: | 61 | # Code from module count-one-bits: |
| 61 | # Code from module count-trailing-zeros: | 62 | # Code from module count-trailing-zeros: |
| @@ -201,6 +202,11 @@ AC_DEFUN([gl_INIT], | |||
| 201 | AC_CHECK_FUNCS_ONCE([readlinkat]) | 202 | AC_CHECK_FUNCS_ONCE([readlinkat]) |
| 202 | gl_CLOCK_TIME | 203 | gl_CLOCK_TIME |
| 203 | gl_MODULE_INDICATOR([close-stream]) | 204 | gl_MODULE_INDICATOR([close-stream]) |
| 205 | gl_FUNC_COPY_FILE_RANGE | ||
| 206 | if test $HAVE_COPY_FILE_RANGE = 0; then | ||
| 207 | AC_LIBOBJ([copy-file-range]) | ||
| 208 | fi | ||
| 209 | gl_UNISTD_MODULE_INDICATOR([copy-file-range]) | ||
| 204 | gl_COUNT_LEADING_ZEROS | 210 | gl_COUNT_LEADING_ZEROS |
| 205 | gl_COUNT_ONE_BITS | 211 | gl_COUNT_ONE_BITS |
| 206 | gl_COUNT_TRAILING_ZEROS | 212 | gl_COUNT_TRAILING_ZEROS |
| @@ -846,6 +852,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 846 | lib/cloexec.h | 852 | lib/cloexec.h |
| 847 | lib/close-stream.c | 853 | lib/close-stream.c |
| 848 | lib/close-stream.h | 854 | lib/close-stream.h |
| 855 | lib/copy-file-range.c | ||
| 849 | lib/count-leading-zeros.c | 856 | lib/count-leading-zeros.c |
| 850 | lib/count-leading-zeros.h | 857 | lib/count-leading-zeros.h |
| 851 | lib/count-one-bits.c | 858 | lib/count-one-bits.c |
| @@ -995,6 +1002,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 995 | m4/builtin-expect.m4 | 1002 | m4/builtin-expect.m4 |
| 996 | m4/byteswap.m4 | 1003 | m4/byteswap.m4 |
| 997 | m4/clock_time.m4 | 1004 | m4/clock_time.m4 |
| 1005 | m4/copy-file-range.m4 | ||
| 998 | m4/count-leading-zeros.m4 | 1006 | m4/count-leading-zeros.m4 |
| 999 | m4/count-one-bits.m4 | 1007 | m4/count-one-bits.m4 |
| 1000 | m4/count-trailing-zeros.m4 | 1008 | m4/count-trailing-zeros.m4 |