2007-05-16 22:51:08

by Wu Fengguang

[permalink] [raw]
Subject: [PATCH 8/9] readahead: convert ext3/ext4 invocations

Convert ext3/ext4 dir reads to use on-demand readahead.

Readahead for dirs operates _not_ on file level, but on blockdev level.
This makes a difference when the data blocks are not continuous.
And the read routine is somehow opaque: there's no handy info about the status
of current page. So a simplified call scheme is employed: to call into
readahead whenever the current page falls out of readahead windows.

Signed-off-by: Fengguang Wu <[email protected]>
---
fs/ext3/dir.c | 14 ++++++++------
fs/ext4/dir.c | 14 ++++++++------
2 files changed, 16 insertions(+), 12 deletions(-)

--- linux-2.6.22-rc1-mm1.orig/fs/ext3/dir.c
+++ linux-2.6.22-rc1-mm1/fs/ext3/dir.c
@@ -136,12 +136,14 @@ static int ext3_readdir(struct file * fi
err = ext3_get_blocks_handle(NULL, inode, blk, 1,
&map_bh, 0, 0);
if (err > 0) {
- page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
- &filp->f_ra,
- filp,
- map_bh.b_blocknr >>
- (PAGE_CACHE_SHIFT - inode->i_blkbits),
- 1);
+ pgoff_t index = map_bh.b_blocknr >>
+ (PAGE_CACHE_SHIFT - inode->i_blkbits);
+ if (!ra_has_index(&filp->f_ra, index))
+ page_cache_readahead_ondemand(
+ sb->s_bdev->bd_inode->i_mapping,
+ &filp->f_ra, filp,
+ NULL, index, 1);
+ filp->f_ra.prev_index = index;
bh = ext3_bread(NULL, inode, blk, 0, &err);
}

--- linux-2.6.22-rc1-mm1.orig/fs/ext4/dir.c
+++ linux-2.6.22-rc1-mm1/fs/ext4/dir.c
@@ -135,12 +135,14 @@ static int ext4_readdir(struct file * fi
map_bh.b_state = 0;
err = ext4_get_blocks_wrap(NULL, inode, blk, 1, &map_bh, 0, 0);
if (err > 0) {
- page_cache_readahead(sb->s_bdev->bd_inode->i_mapping,
- &filp->f_ra,
- filp,
- map_bh.b_blocknr >>
- (PAGE_CACHE_SHIFT - inode->i_blkbits),
- 1);
+ pgoff_t index = map_bh.b_blocknr >>
+ (PAGE_CACHE_SHIFT - inode->i_blkbits);
+ if (!ra_has_index(&filp->f_ra, index))
+ page_cache_readahead_ondemand(
+ sb->s_bdev->bd_inode->i_mapping,
+ &filp->f_ra, filp,
+ NULL, index, 1);
+ filp->f_ra.prev_index = index;
bh = ext4_bread(NULL, inode, blk, 0, &err);
}


--


2007-05-19 12:20:09

by Andi Kleen

[permalink] [raw]
Subject: Re: [PATCH 8/9] readahead: convert ext3/ext4 invocations

On Thu, May 17, 2007 at 06:48:00AM +0800, Fengguang Wu wrote:
> Convert ext3/ext4 dir reads to use on-demand readahead.
>
> Readahead for dirs operates _not_ on file level, but on blockdev level.
> This makes a difference when the data blocks are not continuous.
> And the read routine is somehow opaque: there's no handy info about the status
> of current page. So a simplified call scheme is employed: to call into
> readahead whenever the current page falls out of readahead windows.

ext2 too would be nice. Also when it goes in it might be worth
contacting linux-fsdevel with a quick pointer to this so that other
file systems can possibly benefit too.
-Andi