From a67bb3bff5dc51400294fdfb4c77c0827afd5d14 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 19 Jan 2010 00:09:21 +0100 Subject: [PATCH] libblkid: disable read-ahead when probing device files Read-ahead doesn't work very well on device probing, and can hurt a lot when we do essentially random accesses on very slow devices. So disable it if possible. [kzak@redhat.com: - add posix_fadvise() configure test] Signed-off-by: Linus Torvalds Signed-off-by: Karel Zak --- configure.ac | 1 + shlibs/blkid/src/probe.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/configure.ac b/configure.ac index 5ddeaa5d..1fef9444 100644 --- a/configure.ac +++ b/configure.ac @@ -163,6 +163,7 @@ AC_CHECK_FUNCS( setresuid \ inotify_init \ prctl \ + posix_fadvise \ getmntinfo \ __secure_getenv \ rpmatch]) diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 2d3cafec..b2c96a6b 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -640,6 +640,10 @@ int blkid_probe_set_device(blkid_probe pr, int fd, pr->mode = 0; pr->blkssz = 0; +#if defined(POSIX_FADV_RANDOM) && defined(HAVE_POSIX_FADVISE) + /* Disable read-ahead */ + posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); +#endif if (size) pr->size = size; else { -- 2.39.5