[PATCH 1/9] readahead: simplify readahead call scheme

Fengguang Wu
2007-12-16T12:07:47Z

[-- Attachment #1: readahead-merge-sync-async.patch --]
[-- Type: text/plain, Size: 1668 bytes --]

It is insane and error-prone to insist on the call sites to check for async
readahead after doing any sync one. I.e. whenever someone do a sync readahead:

if (!page)
page_cache_sync_readahead(...);

He must try async readahead, too:

page = find_get_page(...);
if (PageReadahead(page))
page_cache_async_readahead(...);

The tricky point is that PG_readahead could be set by a sync readahead for the
_current_ newly faulted in page, and the readahead code simply expects one more
callback to handle it. If the caller fails to do so, it will miss the
PG_readahead bits and never able to start an async readahead.

Avoid it by piggy-backing the async part _inside_ the readahead code.

Now if an async readahead should be started immediately after a sync one,
the readahead logic itself will do it. So the following code becomes valid:

if (!page)
page_cache_sync_readahead(...);
else if (PageReadahead(page))
page_cache_async_readahead(...);

Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn>
---
mm/readahead.c | 8 ++++++++
1 file changed, 8 insertions(+)

--- linux-2.6.24-rc4-mm1.orig/mm/readahead.c
+++ linux-2.6.24-rc4-mm1/mm/readahead.c
@@ -402,6 +402,14 @@ ondemand_readahead(struct address_space
ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size;

readit:
+ /*
+ * An async readahead should be triggered immediately.
+ * Instead of demanding all call sites to check for async readahead
+ * immediate after a sync one, start the async part now and here.
+ */
+ if (!hit_readahead_marker && ra->size == ra->async_size)
+ ra->size *= 2;
+
return ra_submit(ra, mapping, filp);
}

--