mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ufs: zero new data fragments with one request
@ 2026-11-25 17:08 Showta Ishizaki
  0 siblings, 0 replies; only message in thread
From: Showta Ishizaki @ 2026-11-25 17:08 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner
  Cc: Jan Kara, linux-fsdevel, linux-kernel, Showta Ishizaki

A block taken for a page being written is zeroed on the device with
sync_dirty_buffer(), one fragment at a time.  That is a synchronous
write for every fragment of every new block, and most of the time spent
writing a new file.

Zero the run with one sb_issue_zeroout(), after cleaning what the block
device's cache holds over it, and keep the old loop for when that fails.

Metadata stays with the loop, with -o sync too.  An indirect block is
read back through the block device's cache, so it has to be zeroed
there.

Writing 128 MiB with dd conv=fsync to virtio-blk, five times, in MB/s:
12-13 before and 87-89 after with 1K fragments, 47-50 before and
272-284 after with 4K fragments.  Creating and removing files of 128 KiB
to 1.4 MiB with -o sync, none differed from what was written, also after
a remount.

Signed-off-by: Showta Ishizaki <zakinko@snowrabbit.org>
---
 fs/ufs/balloc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 628edfde3..44ff268fd 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -17,6 +17,7 @@
 #include <linux/capability.h>
 #include <linux/bitops.h>
 #include <linux/bio.h>
+#include <linux/blkdev.h>
 #include <asm/byteorder.h>
 
 #include "ufs_fs.h"
@@ -311,12 +312,32 @@ static void ufs_change_blocknr(struct inode *inode, sector_t beg,
 	UFSD("EXIT\n");
 }
 
+/*
+ * Zero @n fragments from @beg, taken for a page being written, on the
+ * device itself.  Such a block is larger than the page when the block is,
+ * and its other fragments may be read back from the device before anything
+ * else writes them, so the zeroes have to be there already.
+ *
+ * Only for data.  A buffer the block device's cache has over the fragments
+ * is cleaned, not zeroed, and an indirect block is read through it.
+ */
+static int ufs_zero_frags_now(struct inode *inode, sector_t beg,
+			      unsigned int n)
+{
+	struct super_block *sb = inode->i_sb;
+
+	clean_bdev_aliases(sb->s_bdev, beg, n);
+	return sb_issue_zeroout(sb, beg, n, GFP_NOFS);
+}
+
 static void ufs_clear_frags(struct inode *inode, sector_t beg, unsigned int n,
 			    int sync)
 {
 	struct buffer_head *bh;
 	sector_t end = beg + n;
 
+	if (sync && !ufs_zero_frags_now(inode, beg, n))
+		return;
 	for (; beg < end; ++beg) {
 		bh = sb_getblk(inode->i_sb, beg);
 		lock_buffer(bh);

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-25 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 17:08 [PATCH] ufs: zero new data fragments with one request Showta Ishizaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®