From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.audio.sox.devel Subject: [PATCH] use posix_fadvise to increase readahead Date: Mon, 7 Sep 2015 01:10:17 +0000 Message-ID: <20150907011017.GA9788@dcvr.yhbt.net> Reply-To: sox-devel@lists.sourceforge.net NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1441588246 18618 80.91.229.3 (7 Sep 2015 01:10:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Sep 2015 01:10:46 +0000 (UTC) To: sox-devel@lists.sourceforge.net Original-X-From: sox-devel-bounces@lists.sourceforge.net Mon Sep 07 03:10:37 2015 Return-path: Envelope-to: gcasd-sox-devel@m.gmane.org X-ACL-Warn: Content-Disposition: inline X-Spam-Score: -1.0 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1ZYkwx-0001Eq-KC X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: sox-devel-bounces@lists.sourceforge.net Xref: news.gmane.org gmane.comp.audio.sox.devel:419 Archived-At: Received: from lists.sourceforge.net ([216.34.181.88]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZYkxA-0005WW-G7 for gcasd-sox-devel@m.gmane.org; Mon, 07 Sep 2015 03:10:36 +0200 Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZYkx1-0005mR-87; Mon, 07 Sep 2015 01:10:27 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZYkwz-0005mM-NS for sox-devel@lists.sourceforge.net; Mon, 07 Sep 2015 01:10:25 +0000 Received: from dcvr.yhbt.net ([64.71.152.64]) by sog-mx-4.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1ZYkwx-0001Eq-KC for sox-devel@lists.sourceforge.net; Mon, 07 Sep 2015 01:10:25 +0000 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 20D1863386A; Mon, 7 Sep 2015 01:10:18 +0000 (UTC) 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 #include #include -- EW ------------------------------------------------------------------------------