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: add block readahead in exfat_chain_cont_cluster

When a file cannot allocate contiguous clusters, exfat converts the file
from NO_FAT_CHAIN to FAT_CHAIN format. For large files, this conversion
process can take a significant amount of time.

Add simple readahead to read all the FAT blocks in advance, as these
blocks are consecutive, significantly improving the conversion performance.

Test in an empty exfat filesystem:
dd if=/dev/zero of=/mnt/file bs=1M count=30k
dd if=/dev/zero of=/mnt/file2 bs=1M count=1
time cat /mnt/file2 >> /mnt/file

| cluster size | before patch | after patch |
| ------------ | ------------ | ----------- |
| 512 | 47.667s | 4.316s |
| 4k | 6.436s | 0.541s |
| 32k | 0.758s | 0.071s |
| 256k | 0.117s | 0.011s |

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
6ed88c94 bf179796

+46 -2
+9 -2
fs/exfat/exfat_fs.h
··· 10 10 #include <linux/ratelimit.h> 11 11 #include <linux/nls.h> 12 12 #include <linux/blkdev.h> 13 + #include <linux/backing-dev.h> 13 14 #include <uapi/linux/exfat.h> 14 15 15 16 #define EXFAT_ROOT_INO 1 ··· 80 79 #define EXFAT_HINT_NONE -1 81 80 #define EXFAT_MIN_SUBDIR 2 82 81 82 + #define EXFAT_BLK_RA_SIZE(sb) \ 83 + (min_t(blkcnt_t, (sb)->s_bdi->ra_pages, (sb)->s_bdi->io_pages) \ 84 + << (PAGE_SHIFT - (sb)->s_blocksize_bits)) 85 + 83 86 /* 84 87 * helpers for cluster size to byte conversion. 85 88 */ ··· 122 117 #define FAT_ENT_SIZE (4) 123 118 #define FAT_ENT_SIZE_BITS (2) 124 119 #define FAT_ENT_OFFSET_SECTOR(sb, loc) (EXFAT_SB(sb)->FAT1_start_sector + \ 125 - (((u64)loc << FAT_ENT_SIZE_BITS) >> sb->s_blocksize_bits)) 120 + (((u64)(loc) << FAT_ENT_SIZE_BITS) >> sb->s_blocksize_bits)) 126 121 #define FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc) \ 127 - ((loc << FAT_ENT_SIZE_BITS) & (sb->s_blocksize - 1)) 122 + (((loc) << FAT_ENT_SIZE_BITS) & (sb->s_blocksize - 1)) 128 123 129 124 /* 130 125 * helpers for bitmap. ··· 453 448 unsigned int *ret_clu); 454 449 int exfat_count_num_clusters(struct super_block *sb, 455 450 struct exfat_chain *p_chain, unsigned int *ret_count); 451 + int exfat_blk_readahead(struct super_block *sb, sector_t sec, 452 + sector_t *ra, blkcnt_t *ra_cnt, sector_t end); 456 453 457 454 /* balloc.c */ 458 455 int exfat_load_bitmap(struct super_block *sb);
+37
fs/exfat/fatent.c
··· 142 142 return -EIO; 143 143 } 144 144 145 + int exfat_blk_readahead(struct super_block *sb, sector_t sec, 146 + sector_t *ra, blkcnt_t *ra_cnt, sector_t end) 147 + { 148 + struct blk_plug plug; 149 + 150 + if (sec < *ra) 151 + return 0; 152 + 153 + *ra += *ra_cnt; 154 + 155 + /* No blocks left (or only the last block), skip readahead. */ 156 + if (*ra >= end) 157 + return 0; 158 + 159 + *ra_cnt = min(end - *ra + 1, EXFAT_BLK_RA_SIZE(sb)); 160 + if (*ra_cnt == 0) { 161 + /* Move 'ra' to the end to disable readahead. */ 162 + *ra = end; 163 + return 0; 164 + } 165 + 166 + blk_start_plug(&plug); 167 + for (unsigned int i = 0; i < *ra_cnt; i++) 168 + sb_breadahead(sb, *ra + i); 169 + blk_finish_plug(&plug); 170 + return 0; 171 + } 172 + 145 173 int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, 146 174 unsigned int len) 147 175 { 176 + sector_t sec, end, ra; 177 + blkcnt_t ra_cnt = 0; 178 + 148 179 if (!len) 149 180 return 0; 150 181 182 + ra = FAT_ENT_OFFSET_SECTOR(sb, chain); 183 + end = FAT_ENT_OFFSET_SECTOR(sb, chain + len - 1); 184 + 151 185 while (len > 1) { 186 + sec = FAT_ENT_OFFSET_SECTOR(sb, chain); 187 + exfat_blk_readahead(sb, sec, &ra, &ra_cnt, end); 188 + 152 189 if (exfat_ent_set(sb, chain, chain + 1)) 153 190 return -EIO; 154 191 chain++;