linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] exfat: reduce block requests when zeroing a cluster
@ 2022-03-25  3:00 Yuezhang.Mo
  2022-03-25  5:48 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Yuezhang.Mo @ 2022-03-25  3:00 UTC (permalink / raw)
  To: Namjae Jeon, sj1557.seo
  Cc: linux-fsdevel, linux-kernel, Andy.Wu, Wataru.Aoyama

If 'dirsync' is enabled, when zeroing a cluster, submitting
sector by sector will generate many block requests, will
cause the block device to not fully perform its performance.

This commit makes the sectors in a cluster to be submitted in
once, it will reduce the number of block requests. This will
make the block device to give full play to its performance.

Test create 1000 directories on SD card with:

$ time (for ((i=0;i<1000;i++)); do mkdir dir${i}; done)

Performance has been improved by more than 73% on imx6q-sabrelite.

Cluster size       Before         After       Improvement
64  KBytes         3m34.036s      0m56.052s   73.8%
128 KBytes         6m2.644s       1m13.354s   79.8%
256 KBytes         11m22.202s     1m39.451s   85.4%

imx6q-sabrelite:
  - CPU: 792 MHz x4
  - Memory: 1GB DDR3
  - SD Card: SanDisk 8GB Class 4

Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
---
 fs/exfat/fatent.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c
index c3c9afee7418..b7de3d0758f4 100644
--- a/fs/exfat/fatent.c
+++ b/fs/exfat/fatent.c
@@ -6,6 +6,7 @@
 #include <linux/slab.h>
 #include <asm/unaligned.h>
 #include <linux/buffer_head.h>
+#include <linux/blk_types.h>
 
 #include "exfat_raw.h"
 #include "exfat_fs.h"
@@ -233,10 +234,10 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
 {
 	struct super_block *sb = dir->i_sb;
 	struct exfat_sb_info *sbi = EXFAT_SB(sb);
-	struct buffer_head *bhs[MAX_BUF_PER_PAGE];
-	int nr_bhs = MAX_BUF_PER_PAGE;
+	struct buffer_head *bh;
+	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
 	sector_t blknr, last_blknr;
-	int err, i, n;
+	int i;
 
 	blknr = exfat_cluster_to_sector(sbi, clu);
 	last_blknr = blknr + sbi->sect_per_clus;
@@ -250,30 +251,23 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
 	}
 
 	/* Zeroing the unused blocks on this cluster */
-	while (blknr < last_blknr) {
-		for (n = 0; n < nr_bhs && blknr < last_blknr; n++, blknr++) {
-			bhs[n] = sb_getblk(sb, blknr);
-			if (!bhs[n]) {
-				err = -ENOMEM;
-				goto release_bhs;
-			}
-			memset(bhs[n]->b_data, 0, sb->s_blocksize);
-		}
-
-		err = exfat_update_bhs(bhs, n, IS_DIRSYNC(dir));
-		if (err)
-			goto release_bhs;
+	for (i = blknr; i < last_blknr; i++) {
+		bh = sb_getblk(sb, i);
+		if (!bh)
+			return -ENOMEM;
 
-		for (i = 0; i < n; i++)
-			brelse(bhs[i]);
+		memset(bh->b_data, 0, sb->s_blocksize);
+		set_buffer_uptodate(bh);
+		mark_buffer_dirty(bh);
+		brelse(bh);
 	}
-	return 0;
 
-release_bhs:
-	exfat_err(sb, "failed zeroed sect %llu\n", (unsigned long long)blknr);
-	for (i = 0; i < n; i++)
-		bforget(bhs[i]);
-	return err;
+	if (IS_DIRSYNC(dir))
+		return filemap_write_and_wait_range(mapping,
+				EXFAT_BLK_TO_B(blknr, sb),
+				EXFAT_BLK_TO_B(last_blknr, sb) - 1);
+
+	return 0;
 }
 
 int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] exfat: reduce block requests when zeroing a cluster
  2022-03-25  3:00 [PATCH] exfat: reduce block requests when zeroing a cluster Yuezhang.Mo
@ 2022-03-25  5:48 ` Christoph Hellwig
  2022-03-25  7:22   ` Yuezhang.Mo
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2022-03-25  5:48 UTC (permalink / raw)
  To: Yuezhang.Mo
  Cc: Namjae Jeon, sj1557.seo, linux-fsdevel, linux-kernel, Andy.Wu,
	Wataru.Aoyama

On Fri, Mar 25, 2022 at 03:00:55AM +0000, Yuezhang.Mo@sony.com wrote:
> +#include <linux/blk_types.h>

blk_types.h is not a header for public use.  What do you want it for?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] exfat: reduce block requests when zeroing a cluster
  2022-03-25  5:48 ` Christoph Hellwig
@ 2022-03-25  7:22   ` Yuezhang.Mo
  2022-03-25  7:33     ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Yuezhang.Mo @ 2022-03-25  7:22 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Namjae Jeon, sj1557.seo, linux-fsdevel, linux-kernel, Andy.Wu,
	Wataru.Aoyama

Hi Christoph Hellwig,

Thank you for your comment.

> On Fri, Mar 25, 2022 at 03:00:55AM +0000, Yuezhang.Mo@sony.com wrote:
> > +#include <linux/blk_types.h>
> 
> blk_types.h is not a header for public use.  What do you want it for?

+	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;

The type of 'sb->s_bdev' is 'struct block_device'.
I want to include the definition of 'struct block_device'('struct block_device' is defined in <linux/blk_types.h>).

Should I change to include <linux/blkdev.h>?

Best Regards,
Yuezhang Mo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] exfat: reduce block requests when zeroing a cluster
  2022-03-25  7:22   ` Yuezhang.Mo
@ 2022-03-25  7:33     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-03-25  7:33 UTC (permalink / raw)
  To: Yuezhang.Mo
  Cc: Christoph Hellwig, Namjae Jeon, sj1557.seo, linux-fsdevel,
	linux-kernel, Andy.Wu, Wataru.Aoyama

On Fri, Mar 25, 2022 at 07:22:54AM +0000, Yuezhang.Mo@sony.com wrote:
> Hi Christoph Hellwig,
> 
> Thank you for your comment.
> 
> > On Fri, Mar 25, 2022 at 03:00:55AM +0000, Yuezhang.Mo@sony.com wrote:
> > > +#include <linux/blk_types.h>
> > 
> > blk_types.h is not a header for public use.  What do you want it for?
> 
> +	struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping;
> 
> The type of 'sb->s_bdev' is 'struct block_device'.
> I want to include the definition of 'struct block_device'('struct block_device' is defined in <linux/blk_types.h>).

Oh, I missed that.  We really should not derefrence bd_inode in file
systems.  So maybe we need to add a sync_blockdev_range abstraction if
we want to support this use case.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-25  7:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25  3:00 [PATCH] exfat: reduce block requests when zeroing a cluster Yuezhang.Mo
2022-03-25  5:48 ` Christoph Hellwig
2022-03-25  7:22   ` Yuezhang.Mo
2022-03-25  7:33     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).