[RFC PATCH v4 33/34] ext4: don't mark IOMAP_F_DIRTY for buffer write

Zhang Yi
2024-04-10T15:11:54Z

The data sync dirty check in ext4_inode_datasync_dirty() is expansive
since jbd2_transaction_committed() holds journal->j_state lock when
journal is enabled, it costs a lot in high-concurrency iomap buffered
read/write paths, but we never check IOMAP_F_DIRTY in these cases, so
let's check it only in swap file, dax and direct IO cases. Tested by
Unixbench on 100GB ramdisk:

./Run -c 128 -i 10 fstime fsbuffer fsdisk

== without this patch ==
128 CPUs in system; running 128 parallel copies of tests

File Copy 1024 bufsize 2000 maxblocks 6332521.0 KBps
File Copy 256 bufsize 500 maxblocks 1639726.0 KBps
File Copy 4096 bufsize 8000 maxblocks 24018572.0 KBps

== with this patch ==
128 CPUs in system; running 128 parallel copies of tests

File Copy 1024 bufsize 2000 maxblocks 49229257.0 KBps
File Copy 256 bufsize 500 maxblocks 24057510.0 KBps
File Copy 4096 bufsize 8000 maxblocks 75704437.0 KBps

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
fs/ext4/inode.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 1cb219d347af..269503749ef5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3281,9 +3281,13 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap,
* there is no other metadata changes being made or are pending.
*/
iomap->flags = 0;
- if (ext4_inode_datasync_dirty(inode) ||
- offset + length > i_size_read(inode))
- iomap->flags |= IOMAP_F_DIRTY;
+ if ((flags & (IOMAP_DAX | IOMAP_REPORT)) ||
+ ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) ==
+ (IOMAP_WRITE | IOMAP_DIRECT))) {
+ if (offset + length > i_size_read(inode) ||
+ ext4_inode_datasync_dirty(inode))
+ iomap->flags |= IOMAP_F_DIRTY;
+ }

if (map->m_flags & EXT4_MAP_NEW)
iomap->flags |= IOMAP_F_NEW;
--
2.39.2