ext4: dio take shared inode lock when overwriting preallocated blocks
authorZhang Yi <yi.zhang@huawei.com>
Mon, 26 Dec 2022 06:20:15 +0000 (14:20 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 15 Feb 2023 02:23:38 +0000 (21:23 -0500)
commit240930fb7e6b52229bdee5b1423bfeab0002fed2
treeba99d79049b6e9505cf469affbf9fac6226db916
parent934b0de1e9fdea93c4c7f2e18915c54fae67bdc6
ext4: dio take shared inode lock when overwriting preallocated blocks

In the dio write path, we only take shared inode lock for the case of
aligned overwriting initialized blocks inside EOF. But for overwriting
preallocated blocks, it may only need to split unwritten extents, this
procedure has been protected under i_data_sem lock, it's safe to
release the exclusive inode lock and take shared inode lock.

This could give a significant speed up for multi-threaded writes. Test
on Intel Xeon Gold 6140 and nvme SSD with below fio parameters.

 direct=1
 ioengine=libaio
 iodepth=10
 numjobs=10
 runtime=60
 rw=randwrite
 size=100G

And the test result are:
Before:
 bs=4k       IOPS=11.1k, BW=43.2MiB/s
 bs=16k      IOPS=11.1k, BW=173MiB/s
 bs=64k      IOPS=11.2k, BW=697MiB/s

After:
 bs=4k       IOPS=41.4k, BW=162MiB/s
 bs=16k      IOPS=41.3k, BW=646MiB/s
 bs=64k      IOPS=13.5k, BW=843MiB/s

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20221226062015.3479416-1-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/file.c