tree ed58cfc7e6e31bd08ec7129d310c41575d0453df
parent 378bac820be6a0ec95df8151524de73ad2b2d2ac
author Karsten Wiese <[EMAIL PROTECTED]> Wed, 07 Sep 2005 05:17:12 -0700
committer Linus Torvalds <[EMAIL PROTECTED]> Thu, 08 Sep 2005 06:57:26 -0700

[PATCH] Speedup FAT filesystem directory reads

      OGAWA Hirofumi <[EMAIL PROTECTED]>

This speeds up directory reads for large FAT partitions, if the buffercache
has to be filled from the drive. Following values were taken from:

        $ time find path_to_freshly_mounted_fat > /dev/null

on an otherwise idle system.

FAT with 16KB Clusters on IDE attached drive:   Factor  2
FAT with 32KB Clusters on USB2 attached drive:  Factor 10 (!)
Its less than 1/10 slower, if the buffercache is uptodate.

The patch introduces the new function fat_dir_readahead().

fat_dir_readahead() calls sb_breadahead() to readahead a whole cluster,
if the requested sector is the first one in a cluster.
It is usefull to do this, because on FAT directories occupy whole
clusters, with the exception of FAT12/FAT16 root dirs.

Readahead is only done, if the cluster's first sector is not uptodate
to avoid overhead, when the buffer cache is already uptodate.
Note that under memory pressure, the maximal byte count wasted
(read: has to be red from disk twice) is 1 cluster's size.  Thats 64KB.

fat_dir_readahead() is called from fat__get_entry().

There is also an unrelated cleanup at one spot:

        if (bh)
                brelse(bh);

is replaced with:

        brelse(bh);

brelse() can handle NULL pointer arguments by itself.

Signed-off-by: Karsten Wiese <[EMAIL PROTECTED]>
Signed-off-by: OGAWA Hirofumi <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 fs/fat/dir.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -30,6 +30,29 @@ static inline loff_t fat_make_i_pos(stru
                | (de - (struct msdos_dir_entry *)bh->b_data);
 }
 
+static inline void fat_dir_readahead(struct inode *dir, sector_t iblock,
+                                    sector_t phys)
+{
+       struct super_block *sb = dir->i_sb;
+       struct msdos_sb_info *sbi = MSDOS_SB(sb);
+       struct buffer_head *bh;
+       int sec;
+
+       /* This is not a first sector of cluster, or sec_per_clus == 1 */
+       if ((iblock & (sbi->sec_per_clus - 1)) || sbi->sec_per_clus == 1)
+               return;
+       /* root dir of FAT12/FAT16 */
+       if ((sbi->fat_bits != 32) && (dir->i_ino == MSDOS_ROOT_INO))
+               return;
+
+       bh = sb_getblk(sb, phys);
+       if (bh && !buffer_uptodate(bh)) {
+               for (sec = 0; sec < sbi->sec_per_clus; sec++)
+                       sb_breadahead(sb, phys + sec);
+       }
+       brelse(bh);
+}
+
 /* Returns the inode number of the directory entry at offset pos. If bh is
    non-NULL, it is brelse'd before. Pos is incremented. The buffer header is
    returned in bh.
@@ -58,6 +81,8 @@ next:
        if (err || !phys)
                return -1;      /* beyond EOF or error */
 
+       fat_dir_readahead(dir, iblock, phys);
+
        *bh = sb_bread(sb, phys);
        if (*bh == NULL) {
                printk(KERN_ERR "FAT: Directory bread(block %llu) failed\n",
@@ -635,8 +660,7 @@ RecEnd:
 EODir:
        filp->f_pos = cpos;
 FillFailed:
-       if (bh)
-               brelse(bh);
+       brelse(bh);
        if (unicode)
                free_page((unsigned long)unicode);
 out:
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to