From: Eric Wong <normalperson@yhbt.net>
To: "Måns Rullgård" <mans@mansr.com>
Cc: sox-devel@lists.sourceforge.net
Subject: Re: [PATCH] use posix_fadvise to increase readahead
Date: Wed, 12 Aug 2020 06:28:48 +0000 [thread overview]
Message-ID: <20200812062848.GA27511@dcvr> (raw)
In-Reply-To: <20150907011017.GA9788@dcvr.yhbt.net>
Eric Wong <normalperson@yhbt.net> wrote:
> 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.
Btw, I've been running this for a few years, too; but pretty
much all on FLAC.
I don't know if there's audio formats we support which aren't
sequential. Maybe there's some wacky audio format which
requires random read all over the place...
> ---
> 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
Nowadays moved to:
https://yhbt.net/sox.git ew/fadvise
The commit SHA-1 remains unchanged
> 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.
Still true as of Linux 5.8 :<
> + */
> + (void)posix_fadvise(fd, (off_t)0, st.st_size, POSIX_FADV_SEQUENTIAL);
Also, Linux has always ignored offset and size for
POSIX_FADV_SEQUENTIAL, so this won't do anything strange when
using the trim-as-first-effect to force seeking.
> + }
> +#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
> +
I think _DEFAULT_SOURCE is needed, too, nowadays.
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel
next prev parent reply other threads:[~2020-08-12 6:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 1:10 [PATCH] use posix_fadvise to increase readahead Eric Wong
2020-08-12 6:28 ` Eric Wong [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.sourceforge.net/lists/listinfo/sox-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200812062848.GA27511@dcvr \
--to=sox-devel@lists.sourceforge.net \
--cc=mans@mansr.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).