diff --git a/Makefile.am b/Makefile.am index 2ea3852..fd95255 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,4 +102,4 @@ analyse: $(pv_SOURCES:.c=.e) FORCE FORCE: clean-local: - rm -f $(pv_SOURCES:.c=.e) + rm -f src/*/*.e diff --git a/configure.ac b/configure.ac index 79a07d9..2201a15 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ AC_CHECK_FUNCS([getopt_long]) AC_CHECK_HEADERS([getopt.h]) AC_CHECK_FUNCS([memcpy basename vsnprintf strlcat]) AC_CHECK_FUNCS([fdatasync]) -AC_CHECK_FUNCS([fpathconf sysconf posix_memalign]) +AC_CHECK_FUNCS([fpathconf sysconf posix_memalign posix_fadvise]) AC_CHECK_HEADERS([limits.h]) AC_CHECK_HEADERS([wctype.h]) AC_CHECK_HEADERS([termios.h]) diff --git a/doc/NEWS.md b/doc/NEWS.md index 979a5e1..679abd8 100644 --- a/doc/NEWS.md +++ b/doc/NEWS.md @@ -1,6 +1,7 @@ 0.0.20230828-UNRELEASED * feature: new "`--enable-static`" option to "`configure`" for static builds ([#75](https://codeberg.org/a-j-wood/pv/pull/75)) + * feature: now uses `posix_fadvise()` like `cat`(1) does, to improve efficiency ([#39](https://codeberg.org/a-j-wood/pv/issues/39)) * security: with "`--pidfile`", write to a temporary file and rename it into place, to improve security * security: keep self-contained copies of name and format string in PV internal state for memory safety * cleanup: switched the build system to GNU Automake diff --git a/doc/TODO.md b/doc/TODO.md index 469ea77..471f502 100644 --- a/doc/TODO.md +++ b/doc/TODO.md @@ -27,7 +27,6 @@ Feature requests * ([#36](https://codeberg.org/a-j-wood/pv/issues/36)) Ignore *SIGWINCH* (window size change) if "`-w`" / "`-H`" provided * ([#37](https://codeberg.org/a-j-wood/pv/issues/37)) Allow "`-E`" to take a block size argument so errors cause a skip to the next block (Anthony DeRobertis - Oct 2016) * ([#38](https://codeberg.org/a-j-wood/pv/issues/38)) Reset ETA on *SIGUSR1* (Jacek Wielemborek - Jan 2019) - * ([#39](https://codeberg.org/a-j-wood/pv/issues/39)) Use `posix_fadvise()` like `cat`(1) does (Jacek Wielemborek - Oct 2015) * ([#40](https://codeberg.org/a-j-wood/pv/issues/40)) Permit "`-c`" with "`-d PID:FD`", reject "`-N`" with "`-d PID`" (Norman Rasmussen - Nov 2020) * ([#41](https://codeberg.org/a-j-wood/pv/issues/41)) Improve how backwards-moving reads are shown in "`--watchfd`" (Ryan Cooley - Dec 2017) * ([#42](https://codeberg.org/a-j-wood/pv/issues/42)) Option to discard stdin so nothing is written to stdout (André Stapf - Apr 2017) diff --git a/src/include/config.h.in b/src/include/config.h.in index 37dd4d7..d7b8f2c 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -61,6 +61,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MINIX_CONFIG_H +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + /* Define to 1 if you have the `posix_memalign' function. */ #undef HAVE_POSIX_MEMALIGN diff --git a/src/pv/file.c b/src/pv/file.c index eb5c040..d8d18d4 100644 --- a/src/pv/file.c +++ b/src/pv/file.c @@ -165,6 +165,11 @@ unsigned long long pv_calc_total_size(pvstate_t state) return total; } +#if HAVE_POSIX_FADVISE + /* Advise the OS that we will only be reading sequentially. */ + (void) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + while (1) { unsigned char scanbuf[1024]; int numread, j; @@ -275,6 +280,7 @@ int pv_next_file(pvstate_t state, int filenum, int oldfd) if (0 == strcmp(state->input_files[filenum], "-")) { state->current_file = "(stdin)"; } + #ifdef O_DIRECT /* * Set or clear O_DIRECT on the file descriptor. diff --git a/src/pv/loop.c b/src/pv/loop.c index 7823601..e56146e 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -114,6 +114,12 @@ int pv_main_loop(pvstate_t state) pv_crs_fini(state); return state->exit_status; } + +#if HAVE_POSIX_FADVISE + /* Advise the OS that we will only be reading sequentially. */ + (void) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + #ifdef O_DIRECT /* * Set or clear O_DIRECT on the output.