2006-11-15 07:57:16

by Wu Fengguang

[permalink] [raw]
Subject: [PATCH 24/28] readahead: loop case

Disable look-ahead for loop file.

Loopback files normally contain filesystems, in which case there are already
proper look-aheads in the upper layer, more look-aheads on the loopback file
only ruins the read-ahead hit rate.

Signed-off-by: Wu Fengguang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
--- linux-2.6.19-rc5-mm2.orig/drivers/block/loop.c
+++ linux-2.6.19-rc5-mm2/drivers/block/loop.c
@@ -755,6 +755,12 @@ static int loop_set_fd(struct loop_devic
mapping = file->f_mapping;
inode = mapping->host;

+ /* Instruct the readahead code to skip look-ahead on loop file.
+ * The upper layer should already do proper look-ahead,
+ * one more look-ahead here only ruins the cache hit rate.
+ */
+ file->f_ra.flags |= RA_FLAG_LOOP;
+
if (!(file->f_mode & FMODE_WRITE))
lo_flags |= LO_FLAGS_READ_ONLY;

--- linux-2.6.19-rc5-mm2.orig/include/linux/fs.h
+++ linux-2.6.19-rc5-mm2/include/linux/fs.h
@@ -741,6 +741,7 @@ struct file_ra_state {
#define RA_FLAG_MISS (1UL<<31) /* a cache miss occured against this file */
#define RA_FLAG_INCACHE (1UL<<30) /* file is already in cache */
#define RA_FLAG_MMAP (1UL<<29) /* mmap page access */
+#define RA_FLAG_LOOP (1UL<<28) /* loopback file */

struct file {
/*
--- linux-2.6.19-rc5-mm2.orig/mm/readahead.c
+++ linux-2.6.19-rc5-mm2/mm/readahead.c
@@ -985,6 +985,10 @@ static int ra_submit(struct file_ra_stat
ra->lookahead_index = eof;
}

+ /* Disable look-ahead for loopback file. */
+ if (ra->flags & RA_FLAG_LOOP)
+ ra->lookahead_index = ra->readahead_index;
+
/* Take down the current read-ahead aging value. */
ra->age = nr_scanned_pages_node(numa_node_id());


--