Skip to contentSkip to conversation

improve buffered write performance with fgf order hint

PATCH New Pankaj Raghav (Samsung) 1 participant 3 messages Jun 14, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover improve buffered write performance with fgf order hint

From: Pankaj Raghav <[email protected]>

Filesystems that support large folios can set the fgf order before buffered write(see XFS iomap_write_begin()) that can provide as a hint to page cache to allocate large folios, if possible.

The first patch is a minor cleanup.
The second patch sets fgf order before starting the buffered write.

I tested the performance on Samsung SSD 990 pro on a system with 64GB RAM as follows:

$ bcachefs format -f /dev/nvme0n1;
$ mount -t bcachefs /dev/nvme0n1 /mnt
$ fio --name=bcachefs --filename=/mnt/test  --size=100G \
    --ioengine=io_uring --iodepth=16 --rw=write --bs=128k

I measured the BW(MB/s) across three runs on 6.10-rc3:
Before patches: 2730
After patches: 3430 (1.25x boost)

With -o no_data_io mount option:
Before patches: 2920
After patches: 4630 (1.5x boost)

I was not able to test the patches with ktest due to some issue with debian(some broken package issue). Maybe Kent can run it in his CI while I try to fix ktest locally?

Changes since v1:
- Avoid changing the indentation in the first patch.

Pankaj Raghav (2):
bcachefs: use FGP_WRITEBEGIN instead of combining individual flags
bcachefs: set fgf order hint before starting a buffered write

 fs/bcachefs/fs-io-buffered.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

base-commit: 03d44168cbd7fc57d5de56a3730427db758fc7f6

Signature · 1 line
2.44.1
#1 lore raw

PATCH v2 1/2 bcachefs: use FGP_WRITEBEGIN instead of combining individual flags

From: Pankaj Raghav <[email protected]>

Use FGP_WRITEBEGIN to avoid repeating the individual FGP flags before starting a buffered write.

---
 fs/bcachefs/fs-io-buffered.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/fs-io-buffered.c +2 -2
index 54873ecc635c..3c9a5a8edd1e 100644
@@ -678,7 +678,7 @@ int bch2_write_begin(struct file *file, struct address_space *mapping,
 	bch2_pagecache_add_get(inode);
 
 	folio = __filemap_get_folio(mapping, pos >> PAGE_SHIFT,
-				FGP_LOCK|FGP_WRITE|FGP_CREAT|FGP_STABLE,
+				FGP_WRITEBEGIN,
 				mapping_gfp_mask(mapping));
 	if (IS_ERR_OR_NULL(folio))
 		goto err_unlock;
@@ -820,7 +820,7 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
 	darray_init(&fs);
 
 	ret = bch2_filemap_get_contig_folios_d(mapping, pos, end,
-				   FGP_LOCK|FGP_WRITE|FGP_STABLE|FGP_CREAT,
+				   FGP_WRITEBEGIN,
 				   mapping_gfp_mask(mapping),
 				   &fs);
 	if (ret)
Signature · 1 line
2.44.1
#2 lore raw

PATCH v2 2/2 bcachefs: set fgf order hint before starting a buffered write

In reply to Pankaj Raghav (Samsung)

From: Pankaj Raghav <[email protected]>

Set the preferred folio order in the fgp_flags by calling fgf_set_order(). Page cache will try to allocate large folio of the preferred order whenever possible instead of allocating multiple 0 order folios.

This improves the buffered write performance up to 1.25x with default mount options and up to 1.57x when mounted with no_data_io option with the following fio workload:

fio --name=bcachefs --filename=/mnt/test  --size=100G \
     --ioengine=io_uring --iodepth=16 --rw=write --bs=128k
---
 fs/bcachefs/fs-io-buffered.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/fs-io-buffered.c +2 -2
index 3c9a5a8edd1e..d478703d219f 100644
@@ -678,7 +678,7 @@ int bch2_write_begin(struct file *file, struct address_space *mapping,
 	bch2_pagecache_add_get(inode);
 
 	folio = __filemap_get_folio(mapping, pos >> PAGE_SHIFT,
-				FGP_WRITEBEGIN,
+				FGP_WRITEBEGIN | fgf_set_order(len),
 				mapping_gfp_mask(mapping));
 	if (IS_ERR_OR_NULL(folio))
 		goto err_unlock;
@@ -820,7 +820,7 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
 	darray_init(&fs);
 
 	ret = bch2_filemap_get_contig_folios_d(mapping, pos, end,
-				   FGP_WRITEBEGIN,
+				   FGP_WRITEBEGIN | fgf_set_order(len),
 				   mapping_gfp_mask(mapping),
 				   &fs);
 	if (ret)
Signature · 1 line
2.44.1