Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

exfat: optimize exfat_chain_cont_cluster with cached buffer heads

When converting files from NO_FAT_CHAIN to FAT_CHAIN format, profiling
reveals significant time spent in mark_buffer_dirty() and exfat_mirror_bh()
operations. This overhead occurs because each FAT entry modification
triggers a full block dirty marking and mirroring operation.

For consecutive clusters that reside in the same block, optimize by caching
the buffer head and performing dirty marking only once at the end of the
block's modifications.

Performance improvements for converting a 30GB file:

| Cluster Size | Before Patch | After Patch | Speedup |
|--------------|--------------|-------------|---------|
| 512 bytes | 4.243s | 1.866s | 2.27x |
| 4KB | 0.863s | 0.236s | 3.66x |
| 32KB | 0.069s | 0.034s | 2.03x |
| 256KB | 0.012s | 0.006s | 2.00x |

Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

authored by

Chi Zhiling and committed by
Namjae Jeon
636bd622 63193eb4

+37 -12
+37 -12
fs/exfat/fatent.c
··· 32 32 return err; 33 33 } 34 34 35 + static int exfat_end_bh(struct super_block *sb, struct buffer_head *bh) 36 + { 37 + int err; 38 + 39 + exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); 40 + err = exfat_mirror_bh(sb, bh); 41 + brelse(bh); 42 + 43 + return err; 44 + } 45 + 35 46 static int __exfat_ent_get(struct super_block *sb, unsigned int loc, 36 47 unsigned int *content, struct buffer_head **last) 37 48 { ··· 73 62 return 0; 74 63 } 75 64 76 - int exfat_ent_set(struct super_block *sb, unsigned int loc, 77 - unsigned int content) 65 + static int __exfat_ent_set(struct super_block *sb, unsigned int loc, 66 + unsigned int content, struct buffer_head **cache) 78 67 { 79 - unsigned int off; 80 68 sector_t sec; 81 69 __le32 *fat_entry; 82 - struct buffer_head *bh; 70 + struct buffer_head *bh = cache ? *cache : NULL; 71 + unsigned int off; 83 72 84 73 sec = FAT_ENT_OFFSET_SECTOR(sb, loc); 85 74 off = FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); 86 75 87 - bh = sb_bread(sb, sec); 88 - if (!bh) 89 - return -EIO; 76 + if (!bh || bh->b_blocknr != sec || !buffer_uptodate(bh)) { 77 + if (bh) 78 + exfat_end_bh(sb, bh); 79 + bh = sb_bread(sb, sec); 80 + if (cache) 81 + *cache = bh; 82 + if (unlikely(!bh)) 83 + return -EIO; 84 + } 90 85 91 86 fat_entry = (__le32 *)&(bh->b_data[off]); 92 87 *fat_entry = cpu_to_le32(content); 93 - exfat_update_bh(bh, sb->s_flags & SB_SYNCHRONOUS); 94 - exfat_mirror_bh(sb, bh); 95 - brelse(bh); 88 + if (!cache) 89 + exfat_end_bh(sb, bh); 96 90 return 0; 91 + } 92 + 93 + int exfat_ent_set(struct super_block *sb, unsigned int loc, 94 + unsigned int content) 95 + { 96 + return __exfat_ent_set(sb, loc, content, NULL); 97 97 } 98 98 99 99 /* ··· 192 170 int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, 193 171 unsigned int len) 194 172 { 173 + struct buffer_head *bh = NULL; 195 174 sector_t sec, end, ra; 196 175 blkcnt_t ra_cnt = 0; 197 176 ··· 206 183 sec = FAT_ENT_OFFSET_SECTOR(sb, chain); 207 184 exfat_blk_readahead(sb, sec, &ra, &ra_cnt, end); 208 185 209 - if (exfat_ent_set(sb, chain, chain + 1)) 186 + if (__exfat_ent_set(sb, chain, chain + 1, &bh)) 210 187 return -EIO; 211 188 chain++; 212 189 len--; 213 190 } 214 191 215 - if (exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER)) 192 + if (__exfat_ent_set(sb, chain, EXFAT_EOF_CLUSTER, &bh)) 216 193 return -EIO; 194 + 195 + exfat_end_bh(sb, bh); 217 196 return 0; 218 197 } 219 198