[PATCH -next v2 3/7] ext4: avoid starting handle when dio writing an unwritten extent

Zhang Yi posted 7 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH -next v2 3/7] ext4: avoid starting handle when dio writing an unwritten extent
Posted by Zhang Yi 1 month, 2 weeks ago
From: Zhang Yi <yi.zhang@huawei.com>

Since we have deferred the split of the unwritten extent until after I/O
completion, it is not necessary to initiate the journal handle when
submitting the I/O.

This can improve the write performance of concurrent DIO for multiple
files. The fio tests below show a ~25% performance improvement when
wirting to unwritten files on my VM with a mem disk.

  [unwritten]
  direct=1
  ioengine=psync
  numjobs=16
  rw=write     # write/randwrite
  bs=4K
  iodepth=1
  directory=/mnt
  size=5G
  runtime=30s
  overwrite=0
  norandommap=1
  fallocate=native
  ramp_time=5s
  group_reporting=1

 [w/o]
  w:  IOPS=62.5k, BW=244MiB/s
  rw: IOPS=56.7k, BW=221MiB/s

 [w]
  w:  IOPS=79.6k, BW=311MiB/s
  rw: IOPS=70.2k, BW=274MiB/s

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/file.c  | 4 +---
 fs/ext4/inode.c | 9 +++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 7a8b30932189..9f571acc7782 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -418,9 +418,7 @@ static const struct iomap_dio_ops ext4_dio_write_ops = {
  *   updating inode i_disksize and/or orphan handling with exclusive lock.
  *
  * - shared locking will only be true mostly with overwrites, including
- *   initialized blocks and unwritten blocks. For overwrite unwritten blocks
- *   we protect splitting extents by i_data_sem in ext4_inode_info, so we can
- *   also release exclusive i_rwsem lock.
+ *   initialized blocks and unwritten blocks.
  *
  * - Otherwise we will switch to exclusive i_rwsem lock.
  */
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index ffde24ff7347..ff3ad1a2df45 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3817,9 +3817,14 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 			ret = ext4_map_blocks(NULL, inode, &map, 0);
 			/*
 			 * For atomic writes the entire requested length should
-			 * be mapped.
+			 * be mapped. For DAX we convert extents to initialized
+			 * ones before copying the data, otherwise we do it
+			 * after I/O so there's no need to call into
+			 * ext4_iomap_alloc().
 			 */
-			if (map.m_flags & EXT4_MAP_MAPPED) {
+			if ((map.m_flags & EXT4_MAP_MAPPED) ||
+			    (!(flags & IOMAP_DAX) &&
+			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
 				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
 				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
 					goto out;
-- 
2.52.0
Re: [PATCH -next v2 3/7] ext4: avoid starting handle when dio writing an unwritten extent
Posted by Ojaswin Mujoo 1 month, 1 week ago
On Tue, Dec 23, 2025 at 09:17:58AM +0800, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
> 
> Since we have deferred the split of the unwritten extent until after I/O
> completion, it is not necessary to initiate the journal handle when
> submitting the I/O.
> 
> This can improve the write performance of concurrent DIO for multiple
> files. The fio tests below show a ~25% performance improvement when
> wirting to unwritten files on my VM with a mem disk.
> 
>   [unwritten]
>   direct=1
>   ioengine=psync
>   numjobs=16
>   rw=write     # write/randwrite
>   bs=4K
>   iodepth=1
>   directory=/mnt
>   size=5G
>   runtime=30s
>   overwrite=0
>   norandommap=1
>   fallocate=native
>   ramp_time=5s
>   group_reporting=1
> 
>  [w/o]
>   w:  IOPS=62.5k, BW=244MiB/s
>   rw: IOPS=56.7k, BW=221MiB/s
> 
>  [w]
>   w:  IOPS=79.6k, BW=311MiB/s
>   rw: IOPS=70.2k, BW=274MiB/s
> 
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> Reviewed-by: Jan Kara <jack@suse.cz>

Looks good, feel free to add:
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Regards,
ojaswin

> ---
>  fs/ext4/file.c  | 4 +---
>  fs/ext4/inode.c | 9 +++++++--
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index 7a8b30932189..9f571acc7782 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -418,9 +418,7 @@ static const struct iomap_dio_ops ext4_dio_write_ops = {
>   *   updating inode i_disksize and/or orphan handling with exclusive lock.
>   *
>   * - shared locking will only be true mostly with overwrites, including
> - *   initialized blocks and unwritten blocks. For overwrite unwritten blocks
> - *   we protect splitting extents by i_data_sem in ext4_inode_info, so we can
> - *   also release exclusive i_rwsem lock.
> + *   initialized blocks and unwritten blocks.
>   *
>   * - Otherwise we will switch to exclusive i_rwsem lock.
>   */
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index ffde24ff7347..ff3ad1a2df45 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3817,9 +3817,14 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
>  			ret = ext4_map_blocks(NULL, inode, &map, 0);
>  			/*
>  			 * For atomic writes the entire requested length should
> -			 * be mapped.
> +			 * be mapped. For DAX we convert extents to initialized
> +			 * ones before copying the data, otherwise we do it
> +			 * after I/O so there's no need to call into
> +			 * ext4_iomap_alloc().
>  			 */
> -			if (map.m_flags & EXT4_MAP_MAPPED) {
> +			if ((map.m_flags & EXT4_MAP_MAPPED) ||
> +			    (!(flags & IOMAP_DAX) &&
> +			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
>  				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
>  				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
>  					goto out;
> -- 
> 2.52.0
>
Re: [PATCH -next v2 3/7] ext4: avoid starting handle when dio writing an unwritten extent
Posted by Baokun Li 1 month, 1 week ago
On 2025-12-23 09:17, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> Since we have deferred the split of the unwritten extent until after I/O
> completion, it is not necessary to initiate the journal handle when
> submitting the I/O.
>
> This can improve the write performance of concurrent DIO for multiple
> files. The fio tests below show a ~25% performance improvement when
> wirting to unwritten files on my VM with a mem disk.
>
>   [unwritten]
>   direct=1
>   ioengine=psync
>   numjobs=16
>   rw=write     # write/randwrite
>   bs=4K
>   iodepth=1
>   directory=/mnt
>   size=5G
>   runtime=30s
>   overwrite=0
>   norandommap=1
>   fallocate=native
>   ramp_time=5s
>   group_reporting=1
>
>  [w/o]
>   w:  IOPS=62.5k, BW=244MiB/s
>   rw: IOPS=56.7k, BW=221MiB/s
>
>  [w]
>   w:  IOPS=79.6k, BW=311MiB/s
>   rw: IOPS=70.2k, BW=274MiB/s
>
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
> Reviewed-by: Jan Kara <jack@suse.cz>

Looks good. Feel free to add:

Reviewed-by: Baokun Li <libaokun1@huawei.com>

> ---
>  fs/ext4/file.c  | 4 +---
>  fs/ext4/inode.c | 9 +++++++--
>  2 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index 7a8b30932189..9f571acc7782 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -418,9 +418,7 @@ static const struct iomap_dio_ops ext4_dio_write_ops = {
>   *   updating inode i_disksize and/or orphan handling with exclusive lock.
>   *
>   * - shared locking will only be true mostly with overwrites, including
> - *   initialized blocks and unwritten blocks. For overwrite unwritten blocks
> - *   we protect splitting extents by i_data_sem in ext4_inode_info, so we can
> - *   also release exclusive i_rwsem lock.
> + *   initialized blocks and unwritten blocks.
>   *
>   * - Otherwise we will switch to exclusive i_rwsem lock.
>   */
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index ffde24ff7347..ff3ad1a2df45 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3817,9 +3817,14 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
>  			ret = ext4_map_blocks(NULL, inode, &map, 0);
>  			/*
>  			 * For atomic writes the entire requested length should
> -			 * be mapped.
> +			 * be mapped. For DAX we convert extents to initialized
> +			 * ones before copying the data, otherwise we do it
> +			 * after I/O so there's no need to call into
> +			 * ext4_iomap_alloc().
>  			 */
> -			if (map.m_flags & EXT4_MAP_MAPPED) {
> +			if ((map.m_flags & EXT4_MAP_MAPPED) ||
> +			    (!(flags & IOMAP_DAX) &&
> +			     (map.m_flags & EXT4_MAP_UNWRITTEN))) {
>  				if ((!(flags & IOMAP_ATOMIC) && ret > 0) ||
>  				   (flags & IOMAP_ATOMIC && ret >= orig_mlen))
>  					goto out;