exfat: optimize performance of deleting a file
Subsystems (2)
RFC PATCH 1/1 exfat: optimize performance of deleting a file
When a large file is deleted, it's cluster bitmap is cleared.
After a bit is cleared, the buffer_head is synced.
A buffer_head can be synced many times repeatedly.
We can clear all bits first and then sync all buffer_heads.
So each buffer_head is synced only once, which significantly improves performance.
In my test, It takes about 2 minitues to delete a 5GB file without the patch. After applying the patch, the file is deleted in almost less than 1s.
--- fs/exfat/balloc.c | 28 ++++++++++++++++++++++++++-- fs/exfat/exfat_fs.h | 2 ++ fs/exfat/fatent.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 6 deletions(-)
fs/exfat/balloc.c +26 -2
@@ -164,7 +164,6 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu)unsigned int ent_idx;struct super_block *sb = inode->i_sb;struct exfat_sb_info *sbi =EXFAT_SB (sb); -struct exfat_mount_options *opts = &sbi->options;WARN_ON (clu <EXFAT_FIRST_CLUSTER ); ent_idx =CLUSTER_TO_BITMAP_ENT (clu);
@@ -172,7 +171,32 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu) b =BITMAP_OFFSET_BIT_IN_SECTOR (sb, ent_idx);clear_bit_le (b, sbi->vol_amap[i]->b_data); -exfat_update_bh (sbi->vol_amap[i],IS_DIRSYNC (inode)); +set_buffer_uptodate (sbi->vol_amap[i]); +mark_buffer_dirty (sbi->vol_amap[i]); +} + +void exfat_wait_bitmap (struct inode *inode,unsigned int clu) +{ +int i; +unsigned int ent_idx; +struct super_block *sb = inode->i_sb; +struct exfat_sb_info *sbi =EXFAT_SB (sb); + +WARN_ON (clu <EXFAT_FIRST_CLUSTER ); + ent_idx =CLUSTER_TO_BITMAP_ENT (clu); + i =BITMAP_OFFSET_SECTOR_INDEX (sb, ent_idx); + +if (IS_DIRSYNC (inode)) +sync_dirty_buffer (sbi->vol_amap[i]); +} + +void exfat_discard_cluster (struct inode *inode,unsigned int clu) +{ +struct super_block *sb = inode->i_sb; +struct exfat_sb_info *sbi =EXFAT_SB (sb); +struct exfat_mount_options *opts = &sbi->options; + +WARN_ON (clu <EXFAT_FIRST_CLUSTER );if (opts->discard) {int ret_discard;
fs/exfat/exfat_fs.h +2 -0
@@ -409,6 +409,8 @@ int exfat_load_bitmap(struct super_block *sb);void exfat_free_bitmap (struct exfat_sb_info *sbi);int exfat_set_bitmap (struct inode *inode,unsigned int clu);void exfat_clear_bitmap (struct inode *inode,unsigned int clu); +void exfat_wait_bitmap (struct inode *inode,unsigned int clu); +void exfat_discard_cluster (struct inode *inode,unsigned int clu);unsigned int exfat_find_free_bitmap (struct super_block *sb,unsigned int clu);int exfat_count_used_clusters (struct super_block *sb,unsigned int *ret_count);
fs/exfat/fatent.c +41 -4
60 lines not on this page · raw message
Signature · 1 line
2.36.1
Sungjong Seo
maintainerHello, Jun,
Perhaps you are looking at an old version of the exfat code. The performance of exfat_free_cluster has been improved in the latest version. I think the below commit could help you.
f728760aa923 ("exfat: improve performance of exfat_free_cluster when using dirsync mount option")
Thanks.
Quoted 147 lines
When a large file is deleted, it's cluster bitmap is cleared. After a bit is cleared, the
buffer_headis synced.
Abuffer_headcan be synced many times repeatedly.
We can clear all bits first and then sync allbuffer_heads. So eachbuffer_headis synced only once, which significantly improves performance.In my test, It takes about 2 minitues to delete a 5GB file without the patch.
After applying the patch, the file is deleted in almost less than 1s.Signed-off-by Jun <[email protected]>Change-Id I7637032db04042b8ad1ca73fe7db09d43a253255--- fs/exfat/balloc.c | 28 ++++++++++++++++++++++++++-- fs/exfat/exfat_fs.h | 2 ++ fs/exfat/fatent.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 6 deletions(-)fs/exfat/balloc.c index renamed from fs/exfat/balloc.c +0
-0
579c10f57c2b..58bdfb58bf1d100644fs/exfat/balloc.c +0
-1@@ -164,7 +164,6 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu)unsigned int ent_idx;struct super_block *sb = inode->i_sb;struct exfat_sb_info *sbi =EXFAT_SB (sb); -struct exfat_mount_options *opts = &sbi->options;WARN_ON (clu <EXFAT_FIRST_CLUSTER );fs/exfat/balloc.c +24
-1ent_idx =CLUSTER_TO_BITMAP_ENT (clu);@@ -172,7 +171,32 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu) b =BITMAP_OFFSET_BIT_IN_SECTOR (sb, ent_idx);clear_bit_le (b, sbi->vol_amap[i]->b_data); -exfat_update_bh (sbi->vol_amap[i],IS_DIRSYNC (inode)); +set_buffer_uptodate (sbi->vol_amap[i]); +mark_buffer_dirty (sbi->vol_amap[i]); +} + +void exfat_wait_bitmap (struct inode *inode,unsigned int clu) { +int i; +unsigned int ent_idx; +struct super_block *sb = inode->i_sb; +struct exfat_sb_info *sbi =EXFAT_SB (sb); + +WARN_ON (clu <EXFAT_FIRST_CLUSTER ); + ent_idx =CLUSTER_TO_BITMAP_ENT (clu); + i =BITMAP_OFFSET_SECTOR_INDEX (sb, ent_idx); + +if (IS_DIRSYNC (inode)) +sync_dirty_buffer (sbi->vol_amap[i]); +} + +void exfat_discard_cluster (struct inode *inode,unsigned int clu) { +struct super_block *sb = inode->i_sb; +struct exfat_sb_info *sbi =EXFAT_SB (sb); +struct exfat_mount_options *opts = &sbi->options; + +WARN_ON (clu <EXFAT_FIRST_CLUSTER );if (opts->discard) {int ret_discard;fs/exfat/exfat_fs.h index renamed from fs/exfat/exfat_fs.h +0
-0
b8f0e829ecbd..1ecd2379022d100644fs/exfat/exfat_fs.h +0
-0@@ -409,6 +409,8 @@ int exfat_load_bitmap(struct super_block *sb); void
exfat_free_bitmap(struct exfat_sb_info *sbi); intexfat_set_bitmap(struct inode *inode, unsigned int clu); voidexfat_clear_bitmap(struct inode *inode, unsigned int clu);fs/exfat/exfat_fs.h +2
-0+void exfat_wait_bitmap (struct inode *inode,unsigned int clu);void +exfat_discard_cluster (struct inode *inode,unsigned int clu); unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned intclu); int
exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);fs/exfat/fatent.c index renamed from fs/exfat/fatent.c +0
-0
c3c9afee7418..f39a912a7da7100644fs/exfat/fatent.c +41
-5@@ -183,19 +183,56 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain) num_clusters++; }while (num_clusters < p_chain->size); + sbi->used_clusters -= num_clusters; + + clu = p_chain->dir; + num_clusters =0 ; +do { +exfat_wait_bitmap (inode, clu); + clu++; + + num_clusters++; + }while (num_clusters < p_chain->size); + + clu = p_chain->dir; + num_clusters =0 ; +do { +exfat_discard_cluster (inode, clu); + clu++; + + num_clusters++; + }while (num_clusters < p_chain->size); + }else {do {exfat_clear_bitmap (inode, clu);if (exfat_get_next_cluster (sb, &clu)) - goto dec_used_clus; + goto exit; + + sbi->used_clusters--; + }while (clu !=EXFAT_EOF_CLUSTER ); + + clu = p_chain->dir; +do { +exfat_wait_bitmap (inode, clu); + +if (exfat_get_next_cluster (sb, &clu)) + goto exit; + + }while (clu !=EXFAT_EOF_CLUSTER ); + + clu = p_chain->dir; +do { +exfat_discard_cluster (inode, clu); + +if (exfat_get_next_cluster (sb, &clu)) + goto exit; - num_clusters++; }while (clu !=EXFAT_EOF_CLUSTER ); } -dec_used_clus: - sbi->used_clusters -= num_clusters; +exit:return 0 ; } --2.36.1