public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] avoid unnnecessary mtd read when read can be satisfied by write buffer
@ 2006-05-31 21:50 Kevin Vigor
  2006-06-01 14:32 ` Jörn Engel
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Vigor @ 2006-05-31 21:50 UTC (permalink / raw)
  To: linux-mtd

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) ) {

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-06-01 19:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <85257180.00537972.00@pine.cspi.com>
2006-06-01 16:10 ` [PATCH] avoid unnnecessary mtd read when read can be satisfied by write buffer Kevin Vigor
2006-05-31 21:50 Kevin Vigor
2006-06-01 14:32 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox