ufs: zero new data fragments with one request
PATCH 1/1 ufs: zero new data fragments with one request
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.
--- fs/ufs/balloc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
fs/ufs/balloc.c +21 -0
@@ -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