Skip to content

Commit 967288e

Browse files
Chi Zhilingnamjaejeon
authored andcommitted
exfat: add cache option for __exfat_ent_get
When multiple entries are obtained consecutively, these entries are mostly stored adjacent to each other. this patch introduces a "last" parameter to cache the last opened buffer head, and reuse it when possible, which reduces the number of sb_bread() calls. When the passed parameter "last" is NULL, it means cache option is disabled, the behavior unchanged as it was. Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn> Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 0914882 commit 967288e

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

fs/exfat/fatent.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,32 @@ static int exfat_mirror_bh(struct super_block *sb, sector_t sec,
3636
}
3737

3838
static int __exfat_ent_get(struct super_block *sb, unsigned int loc,
39-
unsigned int *content)
39+
unsigned int *content, struct buffer_head **last)
4040
{
4141
unsigned int off;
4242
sector_t sec;
43-
struct buffer_head *bh;
43+
struct buffer_head *bh = last ? *last : NULL;
4444

4545
sec = FAT_ENT_OFFSET_SECTOR(sb, loc);
4646
off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc);
4747

48-
bh = sb_bread(sb, sec);
49-
if (!bh)
50-
return -EIO;
48+
if (!bh || bh->b_blocknr != sec || !buffer_uptodate(bh)) {
49+
brelse(bh);
50+
bh = sb_bread(sb, sec);
51+
if (last)
52+
*last = bh;
53+
if (unlikely(!bh))
54+
return -EIO;
55+
}
5156

5257
*content = le32_to_cpu(*(__le32 *)(&bh->b_data[off]));
5358

5459
/* remap reserved clusters to simplify code */
5560
if (*content > EXFAT_BAD_CLUSTER)
5661
*content = EXFAT_EOF_CLUSTER;
5762

58-
brelse(bh);
63+
if (!last)
64+
brelse(bh);
5965
return 0;
6066
}
6167

@@ -95,7 +101,7 @@ int exfat_ent_get(struct super_block *sb, unsigned int loc,
95101
return -EIO;
96102
}
97103

98-
err = __exfat_ent_get(sb, loc, content);
104+
err = __exfat_ent_get(sb, loc, content, NULL);
99105
if (err) {
100106
exfat_fs_error_ratelimit(sb,
101107
"failed to access to FAT (entry 0x%08x, err:%d)",

0 commit comments

Comments
 (0)