Skip to content

Commit f80a8b4

Browse files
Jannik2099jwakely
authored andcommitted
libstdc++: Also use sendfile for big files
We were previously only using sendfile for files smaller than 2GB, as sendfile needs to be called repeatedly for files bigger than that. Some quick numbers, copying a 16GB file, average of 10 repetitions: old: real: 13.4s user: 0.14s sys : 7.43s new: real: 8.90s user: 0.00s sys : 3.68s libstdc++-v3/ChangeLog: * acinclude.m4 (_GLIBCXX_HAVE_LSEEK): Define. * config.h.in: Regenerate. * configure: Regenerate. * src/filesystem/ops-common.h (copy_file_sendfile): Define new function for sendfile logic. Loop to support large files. Skip zero-length files. (do_copy_file): Use it. Signed-off-by: Jannik Glückert <[email protected]>
1 parent c4deccd commit f80a8b4

File tree

4 files changed

+170
-84
lines changed

4 files changed

+170
-84
lines changed

libstdc++-v3/acinclude.m4

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4956,6 +4956,7 @@ dnl _GLIBCXX_USE_FCHMOD
49564956
dnl _GLIBCXX_USE_FCHMODAT
49574957
dnl _GLIBCXX_USE_SENDFILE
49584958
dnl HAVE_LINK
4959+
dnl HAVE_LSEEK
49594960
dnl HAVE_READLINK
49604961
dnl HAVE_SYMLINK
49614962
dnl
@@ -5091,25 +5092,6 @@ dnl
50915092
if test $glibcxx_cv_fchmodat = yes; then
50925093
AC_DEFINE(_GLIBCXX_USE_FCHMODAT, 1, [Define if fchmodat is available in <sys/stat.h>.])
50935094
fi
5094-
dnl
5095-
AC_CACHE_CHECK([for sendfile that can copy files],
5096-
glibcxx_cv_sendfile, [dnl
5097-
case "${target_os}" in
5098-
gnu* | linux* | solaris* | uclinux*)
5099-
GCC_TRY_COMPILE_OR_LINK(
5100-
[#include <sys/sendfile.h>],
5101-
[sendfile(1, 2, (off_t*)0, sizeof 1);],
5102-
[glibcxx_cv_sendfile=yes],
5103-
[glibcxx_cv_sendfile=no])
5104-
;;
5105-
*)
5106-
glibcxx_cv_sendfile=no
5107-
;;
5108-
esac
5109-
])
5110-
if test $glibcxx_cv_sendfile = yes; then
5111-
AC_DEFINE(_GLIBCXX_USE_SENDFILE, 1, [Define if sendfile is available in <sys/sendfile.h>.])
5112-
fi
51135095
dnl
51145096
AC_CACHE_CHECK([for link],
51155097
glibcxx_cv_link, [dnl
@@ -5122,6 +5104,18 @@ dnl
51225104
if test $glibcxx_cv_link = yes; then
51235105
AC_DEFINE(HAVE_LINK, 1, [Define if link is available in <unistd.h>.])
51245106
fi
5107+
dnl
5108+
AC_CACHE_CHECK([for lseek],
5109+
glibcxx_cv_lseek, [dnl
5110+
GCC_TRY_COMPILE_OR_LINK(
5111+
[#include <unistd.h>],
5112+
[lseek(1, 0, SEEK_SET);],
5113+
[glibcxx_cv_lseek=yes],
5114+
[glibcxx_cv_lseek=no])
5115+
])
5116+
if test $glibcxx_cv_lseek = yes; then
5117+
AC_DEFINE(HAVE_LSEEK, 1, [Define if lseek is available in <unistd.h>.])
5118+
fi
51255119
dnl
51265120
AC_CACHE_CHECK([for readlink],
51275121
glibcxx_cv_readlink, [dnl
@@ -5158,6 +5152,25 @@ dnl
51585152
if test $glibcxx_cv_truncate = yes; then
51595153
AC_DEFINE(HAVE_TRUNCATE, 1, [Define if truncate is available in <unistd.h>.])
51605154
fi
5155+
dnl
5156+
AC_CACHE_CHECK([for sendfile that can copy files],
5157+
glibcxx_cv_sendfile, [dnl
5158+
case "${target_os}" in
5159+
gnu* | linux* | solaris* | uclinux*)
5160+
GCC_TRY_COMPILE_OR_LINK(
5161+
[#include <sys/sendfile.h>],
5162+
[sendfile(1, 2, (off_t*)0, sizeof 1);],
5163+
[glibcxx_cv_sendfile=yes],
5164+
[glibcxx_cv_sendfile=no])
5165+
;;
5166+
*)
5167+
glibcxx_cv_sendfile=no
5168+
;;
5169+
esac
5170+
])
5171+
if test $glibcxx_cv_sendfile = yes && test $glibcxx_cv_lseek = yes; then
5172+
AC_DEFINE(_GLIBCXX_USE_SENDFILE, 1, [Define if sendfile is available in <sys/sendfile.h>.])
5173+
fi
51615174
dnl
51625175
AC_CACHE_CHECK([for fdopendir],
51635176
glibcxx_cv_fdopendir, [dnl

libstdc++-v3/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@
254254
/* Define to 1 if you have the `logl' function. */
255255
#undef HAVE_LOGL
256256

257+
/* Define if lseek is available in <unistd.h>. */
258+
#undef HAVE_LSEEK
259+
257260
/* Define to 1 if you have the <machine/endian.h> header file. */
258261
#undef HAVE_MACHINE_ENDIAN_H
259262

libstdc++-v3/configure

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71005,29 +71005,27 @@ $as_echo "$glibcxx_cv_fchmodat" >&6; }
7100571005
$as_echo "#define _GLIBCXX_USE_FCHMODAT 1" >>confdefs.h
7100671006

7100771007
fi
71008-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendfile that can copy files" >&5
71009-
$as_echo_n "checking for sendfile that can copy files... " >&6; }
71010-
if ${glibcxx_cv_sendfile+:} false; then :
71008+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for link" >&5
71009+
$as_echo_n "checking for link... " >&6; }
71010+
if ${glibcxx_cv_link+:} false; then :
7101171011
$as_echo_n "(cached) " >&6
7101271012
else
71013-
case "${target_os}" in
71014-
gnu* | linux* | solaris* | uclinux*)
71015-
if test x$gcc_no_link = xyes; then
71013+
if test x$gcc_no_link = xyes; then
7101671014
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7101771015
/* end confdefs.h. */
71018-
#include <sys/sendfile.h>
71016+
#include <unistd.h>
7101971017
int
7102071018
main ()
7102171019
{
71022-
sendfile(1, 2, (off_t*)0, sizeof 1);
71020+
link("", "");
7102371021
;
7102471022
return 0;
7102571023
}
7102671024
_ACEOF
7102771025
if ac_fn_cxx_try_compile "$LINENO"; then :
71028-
glibcxx_cv_sendfile=yes
71026+
glibcxx_cv_link=yes
7102971027
else
71030-
glibcxx_cv_sendfile=no
71028+
glibcxx_cv_link=no
7103171029
fi
7103271030
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7103371031
else
@@ -71036,40 +71034,35 @@ else
7103671034
fi
7103771035
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7103871036
/* end confdefs.h. */
71039-
#include <sys/sendfile.h>
71037+
#include <unistd.h>
7104071038
int
7104171039
main ()
7104271040
{
71043-
sendfile(1, 2, (off_t*)0, sizeof 1);
71041+
link("", "");
7104471042
;
7104571043
return 0;
7104671044
}
7104771045
_ACEOF
7104871046
if ac_fn_cxx_try_link "$LINENO"; then :
71049-
glibcxx_cv_sendfile=yes
71047+
glibcxx_cv_link=yes
7105071048
else
71051-
glibcxx_cv_sendfile=no
71049+
glibcxx_cv_link=no
7105271050
fi
7105371051
rm -f core conftest.err conftest.$ac_objext \
7105471052
conftest$ac_exeext conftest.$ac_ext
7105571053
fi
71056-
;;
71057-
*)
71058-
glibcxx_cv_sendfile=no
71059-
;;
71060-
esac
7106171054

7106271055
fi
71063-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_sendfile" >&5
71064-
$as_echo "$glibcxx_cv_sendfile" >&6; }
71065-
if test $glibcxx_cv_sendfile = yes; then
71056+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_link" >&5
71057+
$as_echo "$glibcxx_cv_link" >&6; }
71058+
if test $glibcxx_cv_link = yes; then
7106671059

71067-
$as_echo "#define _GLIBCXX_USE_SENDFILE 1" >>confdefs.h
71060+
$as_echo "#define HAVE_LINK 1" >>confdefs.h
7106871061

7106971062
fi
71070-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for link" >&5
71071-
$as_echo_n "checking for link... " >&6; }
71072-
if ${glibcxx_cv_link+:} false; then :
71063+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lseek" >&5
71064+
$as_echo_n "checking for lseek... " >&6; }
71065+
if ${glibcxx_cv_lseek+:} false; then :
7107371066
$as_echo_n "(cached) " >&6
7107471067
else
7107571068
if test x$gcc_no_link = xyes; then
@@ -71079,15 +71072,15 @@ else
7107971072
int
7108071073
main ()
7108171074
{
71082-
link("", "");
71075+
lseek(1, 0, SEEK_SET);
7108371076
;
7108471077
return 0;
7108571078
}
7108671079
_ACEOF
7108771080
if ac_fn_cxx_try_compile "$LINENO"; then :
71088-
glibcxx_cv_link=yes
71081+
glibcxx_cv_lseek=yes
7108971082
else
71090-
glibcxx_cv_link=no
71083+
glibcxx_cv_lseek=no
7109171084
fi
7109271085
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
7109371086
else
@@ -71100,26 +71093,26 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7110071093
int
7110171094
main ()
7110271095
{
71103-
link("", "");
71096+
lseek(1, 0, SEEK_SET);
7110471097
;
7110571098
return 0;
7110671099
}
7110771100
_ACEOF
7110871101
if ac_fn_cxx_try_link "$LINENO"; then :
71109-
glibcxx_cv_link=yes
71102+
glibcxx_cv_lseek=yes
7111071103
else
71111-
glibcxx_cv_link=no
71104+
glibcxx_cv_lseek=no
7111271105
fi
7111371106
rm -f core conftest.err conftest.$ac_objext \
7111471107
conftest$ac_exeext conftest.$ac_ext
7111571108
fi
7111671109

7111771110
fi
71118-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_link" >&5
71119-
$as_echo "$glibcxx_cv_link" >&6; }
71120-
if test $glibcxx_cv_link = yes; then
71111+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_lseek" >&5
71112+
$as_echo "$glibcxx_cv_lseek" >&6; }
71113+
if test $glibcxx_cv_lseek = yes; then
7112171114

71122-
$as_echo "#define HAVE_LINK 1" >>confdefs.h
71115+
$as_echo "#define HAVE_LSEEK 1" >>confdefs.h
7112371116

7112471117
fi
7112571118
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for readlink" >&5
@@ -71286,6 +71279,68 @@ $as_echo "$glibcxx_cv_truncate" >&6; }
7128671279

7128771280
$as_echo "#define HAVE_TRUNCATE 1" >>confdefs.h
7128871281

71282+
fi
71283+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendfile that can copy files" >&5
71284+
$as_echo_n "checking for sendfile that can copy files... " >&6; }
71285+
if ${glibcxx_cv_sendfile+:} false; then :
71286+
$as_echo_n "(cached) " >&6
71287+
else
71288+
case "${target_os}" in
71289+
gnu* | linux* | solaris* | uclinux*)
71290+
if test x$gcc_no_link = xyes; then
71291+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71292+
/* end confdefs.h. */
71293+
#include <sys/sendfile.h>
71294+
int
71295+
main ()
71296+
{
71297+
sendfile(1, 2, (off_t*)0, sizeof 1);
71298+
;
71299+
return 0;
71300+
}
71301+
_ACEOF
71302+
if ac_fn_cxx_try_compile "$LINENO"; then :
71303+
glibcxx_cv_sendfile=yes
71304+
else
71305+
glibcxx_cv_sendfile=no
71306+
fi
71307+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
71308+
else
71309+
if test x$gcc_no_link = xyes; then
71310+
as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
71311+
fi
71312+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71313+
/* end confdefs.h. */
71314+
#include <sys/sendfile.h>
71315+
int
71316+
main ()
71317+
{
71318+
sendfile(1, 2, (off_t*)0, sizeof 1);
71319+
;
71320+
return 0;
71321+
}
71322+
_ACEOF
71323+
if ac_fn_cxx_try_link "$LINENO"; then :
71324+
glibcxx_cv_sendfile=yes
71325+
else
71326+
glibcxx_cv_sendfile=no
71327+
fi
71328+
rm -f core conftest.err conftest.$ac_objext \
71329+
conftest$ac_exeext conftest.$ac_ext
71330+
fi
71331+
;;
71332+
*)
71333+
glibcxx_cv_sendfile=no
71334+
;;
71335+
esac
71336+
71337+
fi
71338+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_sendfile" >&5
71339+
$as_echo "$glibcxx_cv_sendfile" >&6; }
71340+
if test $glibcxx_cv_sendfile = yes && test $glibcxx_cv_lseek = yes; then
71341+
71342+
$as_echo "#define _GLIBCXX_USE_SENDFILE 1" >>confdefs.h
71343+
7128971344
fi
7129071345
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fdopendir" >&5
7129171346
$as_echo_n "checking for fdopendir... " >&6; }

0 commit comments

Comments
 (0)