From: Showta Ishizaki <zakinko@snowrabbit.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Showta Ishizaki <zakinko@snowrabbit.org>
Subject: [PATCH] ufs: zero new data fragments with one request
Date: Thu, 26 Nov 2026 02:08:59 +0900 [thread overview]
Message-ID: <20261126-ufs-05-v1@snowrabbit.org> (raw)
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
reply other threads:[~2026-11-25 17:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126-ufs-05-v1@snowrabbit.org \
--to=zakinko@snowrabbit.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®