From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wu Fengguang Subject: [PATCH 11/15] readahead: dont do start-of-file readahead after lseek() Date: Wed, 24 Feb 2010 11:10:12 +0800 Message-ID: <20100224031055.164120692@intel.com> References: <20100224031001.026464755@intel.com> Return-path: Received: from kanga.kvack.org ([205.233.56.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Nk7gf-0006am-NG for glkm-linux-mm-2@m.gmane.org; Wed, 24 Feb 2010 04:13:22 +0100 Received: from mail202.messagelabs.com (mail202.messagelabs.com [216.82.254.227]) by kanga.kvack.org (Postfix) with SMTP id A4B736B0089 for ; Tue, 23 Feb 2010 22:13:09 -0500 (EST) Content-Disposition: inline; filename=readahead-lseek.patch Sender: owner-linux-mm@kvack.org To: Andrew Morton Cc: Jens Axboe , Linus Torvalds , Wu Fengguang , Chris Mason , Peter Zijlstra , Clemens Ladisch , Olivier Galibert , Vivek Goyal , Christian Ehrhardt , Matt Mackall , Nick Piggin , Linux Memory Management List , linux-fsdevel@vger.kernel.org, LKML List-Id: linux-mm.kvack.org Some applications (eg. blkid, id3tool etc.) seek around the file to get information. For example, blkid does seek to 0 read 1024 seek to 1536 read 16384 The start-of-file readahead heuristic is wrong for them, whose access pattern can be identified by lseek() calls. So test-and-set a READAHEAD_LSEEK flag on lseek() and don't do start-of-file readahead on seeing it. Proposed by Linus. Acked-by: Linus Torvalds Signed-off-by: Wu Fengguang --- fs/read_write.c | 3 +++ include/linux/fs.h | 1 + mm/readahead.c | 5 +++++ 3 files changed, 9 insertions(+) --- linux.orig/mm/readahead.c 2010-02-24 10:44:47.000000000 +0800 +++ linux/mm/readahead.c 2010-02-24 10:44:48.000000000 +0800 @@ -672,6 +672,11 @@ ondemand_readahead(struct address_space if (!offset) { ra_set_pattern(ra, RA_PATTERN_INITIAL); ra->start = offset; + if ((ra->ra_flags & READAHEAD_LSEEK) && req_size <= max) { + ra->size = req_size; + ra->async_size = 0; + goto readit; + } ra->size = get_init_ra_size(req_size, max); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; --- linux.orig/fs/read_write.c 2010-02-24 10:44:30.000000000 +0800 +++ linux/fs/read_write.c 2010-02-24 10:44:48.000000000 +0800 @@ -71,6 +71,9 @@ generic_file_llseek_unlocked(struct file file->f_version = 0; } + if (!(file->f_ra.ra_flags & READAHEAD_LSEEK)) + file->f_ra.ra_flags |= READAHEAD_LSEEK; + return offset; } EXPORT_SYMBOL(generic_file_llseek_unlocked); --- linux.orig/include/linux/fs.h 2010-02-24 10:44:45.000000000 +0800 +++ linux/include/linux/fs.h 2010-02-24 10:44:48.000000000 +0800 @@ -899,6 +899,7 @@ struct file_ra_state { #define READAHEAD_MMAP_MISS 0x00000fff /* cache misses for mmap access */ #define READAHEAD_THRASHED 0x10000000 #define READAHEAD_MMAP 0x20000000 +#define READAHEAD_LSEEK 0x40000000 /* be conservative after lseek() */ /* * Which policy makes decision to do the current read-ahead IO? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org