sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* [PATCH] use posix_fadvise to increase readahead
@ 2015-09-07  1:10 Eric Wong
  2020-08-12  6:28 ` Eric Wong
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Wong @ 2015-09-07  1:10 UTC (permalink / raw)
  To: sox-devel

All relevant audio file formats store data sequentially, so
give a hint to the kernel to perform more readahead.  In current
Linux, the readahead hint doubles readahead pages and can help
with playback on slow devices.
---
  If you prefer "git pull" instead of "git am":

  The following changes since commit 7e74b254b2a7c963be0bfce751fc5911fe681c12:

    Remove hepler script. It's mostly unmaintained, I don't know if anyone but me ever used it. In any case, those who want a custom Debian package should be capable of updating the debian/changelog entry on their own. (2015-02-26 22:48:40 -0500)

  are available in the git repository at:

    git://bogomips.org/sox fadvise

  for you to fetch changes up to 1c47376a04218838447e7bd49fb42156e9cb13b6:

    use posix_fadvise to increase readahead (2015-09-07 00:39:24 +0000)

  ----------------------------------------------------------------
  Eric Wong (1):
        use posix_fadvise to increase readahead

   configure.ac  |  1 +
   src/formats.c | 18 ++++++++++++++++--
   src/sox_i.h   |  4 ++++
   3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 23138a9..d9ae1ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -208,6 +208,7 @@ AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h sys/stat.h sys/time.h sys/timeb.h s
 
 dnl Checks for library functions.
 AC_CHECK_FUNCS(strcasecmp strdup popen vsnprintf gettimeofday mkstemp fmemopen)
+AC_CHECK_FUNCS(posix_fadvise)
 
 dnl Check if math library is needed.
 AC_SEARCH_LIBS([pow], [m])
diff --git a/src/formats.c b/src/formats.c
index 724a4cd..340b867 100644
--- a/src/formats.c
+++ b/src/formats.c
@@ -329,12 +329,26 @@ static void set_endiannesses(sox_format_t * ft)
 static sox_bool is_seekable(sox_format_t const * ft)
 {
   struct stat st;
+  int fd, seekable;
 
   assert(ft);
   if (!ft->fp)
     return sox_false;
-  fstat(fileno((FILE*)ft->fp), &st);
-  return ((st.st_mode & S_IFMT) == S_IFREG);
+  fd = fileno((FILE*)ft->fp);
+  if (fd < 0)
+     return 0;
+  fstat(fd, &st);
+  seekable = ((st.st_mode & S_IFMT) == S_IFREG);
+#if defined HAVE_POSIX_FADVISE
+  if (seekable) {
+    /*
+     * POSIX_FADV_NOREUSE can potentially be beneficial, too,
+     * but is a no-op as of Linux 4.2.  Not sure about other kernels.
+     */
+    (void)posix_fadvise(fd, (off_t)0, st.st_size, POSIX_FADV_SEQUENTIAL);
+  }
+#endif
+  return seekable;
 }
 
 /* check that all settings have been given */
diff --git a/src/sox_i.h b/src/sox_i.h
index 04bbe8c..2eec9d3 100644
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -20,6 +20,10 @@
 #define _GNU_SOURCE
 #endif
 
+#if defined HAVE_POSIX_FADVISE
+#define _XOPEN_SOURCE 600
+#endif
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-- 
EW


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-13 11:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-07  1:10 [PATCH] use posix_fadvise to increase readahead Eric Wong
2020-08-12  6:28 ` Eric Wong
2020-08-12  9:39   ` Måns Rullgård
2020-08-13  3:53     ` Eric Wong
2020-08-13 11:32       ` Måns Rullgård

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).