hpfs: implement prefetch to improve performance
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / hpfs / buffer.c
index f49d149..4d0a1af 100644 (file)
@@ -7,8 +7,37 @@
  */
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/blkdev.h>
 #include "hpfs_fn.h"
 
+void hpfs_prefetch_sectors(struct super_block *s, unsigned secno, int n)
+{
+       struct buffer_head *bh;
+       struct blk_plug plug;
+
+       if (n <= 0 || unlikely(secno >= hpfs_sb(s)->sb_fs_size))
+               return;
+
+       bh = sb_find_get_block(s, secno);
+       if (bh) {
+               if (buffer_uptodate(bh)) {
+                       brelse(bh);
+                       return;
+               }
+               brelse(bh);
+       };
+
+       blk_start_plug(&plug);
+       while (n > 0) {
+               if (unlikely(secno >= hpfs_sb(s)->sb_fs_size))
+                       break;
+               sb_breadahead(s, secno);
+               secno++;
+               n--;
+       }
+       blk_finish_plug(&plug);
+}
+
 /* Map a sector into a buffer and return pointers to it and to the buffer. */
 
 void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
@@ -18,6 +47,8 @@ void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head
 
        hpfs_lock_assert(s);
 
+       hpfs_prefetch_sectors(s, secno, ahead);
+
        cond_resched();
 
        *bhp = bh = sb_bread(s, secno);
@@ -67,6 +98,8 @@ void *hpfs_map_4sectors(struct super_block *s, unsigned secno, struct quad_buffe
                return NULL;
        }
 
+       hpfs_prefetch_sectors(s, secno, 4 + ahead);
+
        qbh->data = data = kmalloc(2048, GFP_NOFS);
        if (!data) {
                printk("HPFS: hpfs_map_4sectors: out of memory\n");