All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fengguang Wu <wfg@mail.ustc.edu.cn>
To: Andrew Morton <akpm@osdl.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nick Piggin <npiggin@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/9] readahead: auto detection of sequential mmap reads
Date: Sat, 22 Dec 2007 09:31:50 +0800	[thread overview]
Message-ID: <398287205.95879@ustc.edu.cn> (raw)
Message-ID: <20071222013314.837299924@mail.ustc.edu.cn> (raw)
In-Reply-To: 20071222013147.897522982@mail.ustc.edu.cn

[-- Attachment #1: readahead-auto-detect-mmap-sequential-reads.patch --]
[-- Type: text/plain, Size: 2138 bytes --]

Auto-detect sequential mmap reads and do sync/async readahead for them.

The sequential mmap readahead will be triggered when
- sync readahead: it's a major fault and (prev_offset==offset-1);
- async readahead: minor fault on PG_readahead page with valid readahead state.

It's a bit conservative to require valid readahead state for async readahead,
which means we don't do readahead for interleaved reads for now, but let's make
it safe for this initial try.

======
The benefits of doing readahead instead of read-around:
- less I/O wait thanks to async readahead
- double real I/O size and no more cache hits

Some numbers on 100,000 sequential mmap reads:

                                    user       system    cpu        total
(1-1)  plain -mm, 128KB readaround: 3.224      2.554     48.40%     11.838
(1-2)  plain -mm, 256KB readaround: 3.170      2.392     46.20%     11.976
(2)  patched -mm, 128KB readahead:  3.117      2.448     47.33%     11.607

The patched (2) has smallest total time. It has no cache hit overheads
and less I/O block time(thanks to async readahead). Here the I/O size
makes no much difference, since there's only one single stream.

Note that (1-1)'s real I/O size is 64KB and (1-2)'s real I/O size is
128KB, since the half of the read-around pages will be cache hits.

Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn>
---

---
 mm/filemap.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- linux-2.6.24-rc5-mm1.orig/mm/filemap.c
+++ linux-2.6.24-rc5-mm1/mm/filemap.c
@@ -1318,7 +1318,8 @@ static void do_sync_mmap_readahead(struc
 	if (VM_RandomReadHint(vma))
 		return;
 
-	if (VM_SequentialReadHint(vma)) {
+	if (VM_SequentialReadHint(vma) ||
+			offset - 1 == (ra->prev_pos >> PAGE_CACHE_SHIFT)) {
 		page_cache_sync_readahead(mapping, ra, file, offset, 1);
 		return;
 	}
@@ -1360,7 +1361,8 @@ static void do_async_mmap_readahead(stru
 		return;
 	if (ra->mmap_miss > 0)
 		ra->mmap_miss--;
-	if (PageReadahead(page))
+	if (PageReadahead(page) &&
+			offset == ra->start + ra->size - ra->async_size)
 		page_cache_async_readahead(mapping, ra, file, page, offset, 1);
 }
 

-- 

  parent reply	other threads:[~2007-12-22  1:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-22  1:31 [PATCH 0/9] mmap read-around and readahead take 2 Fengguang Wu
2007-12-22  1:31 ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 1/9] readahead: simplify readahead call scheme Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 2/9] readahead: clean up and simplify the code for filemap page fault readahead Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` Fengguang Wu [this message]
2007-12-22  1:31   ` [PATCH 3/9] readahead: auto detection of sequential mmap reads Fengguang Wu
2007-12-22  1:31 ` [PATCH 4/9] readahead: quick startup on sequential mmap readahead Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 5/9] readahead: make ra_submit() non-static Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 6/9] readahead: save mmap read-around states in file_ra_state Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 7/9] readahead: remove unused do_page_cache_readahead() Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 8/9] readahead: move max_sane_readahead() calls into force_page_cache_readahead() Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
2007-12-22  1:31 ` [PATCH 9/9] readahead: call max_sane_readahead() in ondemand_readahead() Fengguang Wu
2007-12-22  1:31   ` Fengguang Wu
  -- strict thread matches above, loose matches on Subject: below --
2007-12-16 11:59 [PATCH 0/9] mmap read-around and readahead Fengguang Wu
2007-12-16 11:59 ` [PATCH 3/9] readahead: auto detection of sequential mmap reads Fengguang Wu
2007-12-16 11:59   ` Fengguang Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=398287205.95879@ustc.edu.cn \
    --to=wfg@mail.ustc.edu.cn \
    --cc=akpm@osdl.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.