public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Kevin Vigor <kevin@realmsys.com>
To: linux-mtd@lists.infradead.org
Subject: [PATCH] avoid unnnecessary mtd read when read can be satisfied by write buffer
Date: Wed, 31 May 2006 15:50:28 -0600	[thread overview]
Message-ID: <447E0FA4.7010201@realmsys.com> (raw)

The following small patch modifies wbuf.c::jffs2_flash_read to avoid a 
call to the mtd read layer in the case where all data returned by the 
read would be replaced by data from the write buffer anyway. This 
condition occurs relatively infrequently, but the cost of the test is 
low and the benefit of avoiding the mtd read is high.

Signed-off-by: Kevin Vigor <kevin@realmsys.com>


diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index a7f153f..01ef266 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -907,6 +907,20 @@ int jffs2_flash_read(struct jffs2_sb_inf

    /* Read flash */
    down_read(&c->wbuf_sem);
+
+    /* Check if the read can be completely satisfied from the write buffer;
+     * if so, we can avoid the mtd call entirely.
+     */
+    if (c->wbuf_pagesize &&
+        (SECTOR_ADDR(ofs) == SECTOR_ADDR(c->wbuf_ofs)) &&
+        (ofs >= c->wbuf_ofs) &&
+        (ofs + len) <= (c->wbuf_ofs + c->wbuf_len)) {
+        memcpy(buf, c->wbuf + (ofs - c->wbuf_ofs), len);
+        *retlen = len;
+        ret = 0;
+        goto exit;
+    }
+
    ret = c->mtd->read(c->mtd, ofs, len, retlen, buf);

    if ( (ret == -EBADMSG || ret == -EUCLEAN) && (*retlen == len) ) {

             reply	other threads:[~2006-05-31 21:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-31 21:50 Kevin Vigor [this message]
2006-06-01 14:32 ` [PATCH] avoid unnnecessary mtd read when read can be satisfied by write buffer Jörn Engel
2006-06-01 14:39   ` David Woodhouse
2006-06-01 14:49     ` Jörn Engel
2006-06-01 15:05       ` David Woodhouse
2006-06-01 15:27         ` Jörn Engel
     [not found] <85257180.00537972.00@pine.cspi.com>
2006-06-01 16:10 ` Kevin Vigor

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=447E0FA4.7010201@realmsys.com \
    --to=kevin@realmsys.com \
    --cc=linux-mtd@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox