From: Zhang Xiaoxu zhangxiaoxu5@huawei.com
hulk inclusion category: feature bugzilla: 185871, https://gitee.com/openeuler/kernel/issues/I4MIQ0 CVE: NA
---------------------------
This reverts commit bb24e7e6309ae1bbc80062366b8f9bb2e8fcc025.
In order to improve the dio reads performance, we enable the parallel dio reads.
And make it configuratable
Conflict: fs/ext4/Kconfig fs/ext4/inode.c
Signed-off-by: Zhang Xiaoxu zhangxiaoxu5@huawei.com Reviewed-by: Zhang Yi yi.zhang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- fs/ext4/Kconfig | 5 +++++ fs/ext4/inode.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig index a453cc87082b5..de836b75c6f2b 100644 --- a/fs/ext4/Kconfig +++ b/fs/ext4/Kconfig @@ -120,3 +120,8 @@ config EXT4_DEBUG If you select Y here, then you will be able to turn on debugging with a command such as: echo 1 > /sys/module/ext4/parameters/mballoc_debug +config EXT4_PARALLEL_DIO_READ + bool "EXT4 parallel dio reads" + depends on EXT4_FS + help + Enable parallel dio read. diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index fb4de707cd9ad..2f5231899d342 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3795,15 +3795,31 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) { + struct address_space *mapping = iocb->ki_filp->f_mapping; + struct inode *inode = mapping->host; +#ifdef CONFIG_EXT4_PARALLEL_DIO_READ + size_t count = iov_iter_count(iter); +#else int unlocked = 0; - struct inode *inode = iocb->ki_filp->f_mapping->host; +#endif ssize_t ret; loff_t offset = iocb->ki_pos; loff_t size = i_size_read(inode);
if (offset >= size) return 0; - +#ifdef CONFIG_EXT4_PARALLEL_DIO_READ + /* + * Shared inode_lock is enough for us - it protects against concurrent + * writes & truncates and since we take care of writing back page cache, + * we are protected against page writeback as well. + */ + inode_lock_shared(inode); + ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, + iocb->ki_pos + count - 1); + if (ret) + goto out_unlock; +#else if (ext4_should_dioread_nolock(inode)) { /* * Nolock dioread optimization may be dynamically disabled @@ -3813,18 +3829,24 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) inode_dio_begin(inode); smp_mb(); if (unlikely(ext4_test_inode_state(inode, - EXT4_STATE_DIOREAD_LOCK))) + EXT4_STATE_DIOREAD_LOCK))) inode_dio_end(inode); else unlocked = 1; } +#endif + ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, - iter, ext4_dio_get_block, - NULL, NULL, + iter, ext4_dio_get_block, NULL, NULL, +#ifdef CONFIG_EXT4_PARALLEL_DIO_READ + 0); +out_unlock: + inode_unlock_shared(inode); +#else unlocked ? 0 : DIO_LOCKING); - if (unlocked) inode_dio_end(inode); +#endif return ret; }
From: Zhang Xiaoxu zhangxiaoxu5@huawei.com
hulk inclusion category: feature bugzilla: 185871, https://gitee.com/openeuler/kernel/issues/I4MIQ0 CVE: NA
-----------------------------------------------
This reverts commit 5b2a409373fc4bfd03ca25a90832783b16392543.
Conflict: fs/ext4/ext4.h fs/ext4/extents.c fs/ext4/inode.c fs/ext4/ioctl.c fs/ext4/move_extent.c fs/ext4/super.c
Signed-off-by: Zhang Xiaoxu zhangxiaoxu5@huawei.com Reviewed-by: Zhang Yi yi.zhang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- fs/ext4/ext4.h | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3575553642fd8..6787d12d5abf3 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1631,8 +1631,10 @@ enum { EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */ EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/ EXT4_STATE_NEWENTRY, /* File just added to dir */ +#ifndef CONFIG_EXT4_PARALLEL_DIO_READ EXT4_STATE_DIOREAD_LOCK, /* Disable support for dio read nolocking */ +#endif EXT4_STATE_MAY_INLINE_DATA, /* may have in-inode data */ EXT4_STATE_EXT_PRECACHED, /* extents have been precached */ EXT4_STATE_LUSTRE_EA_INODE, /* Lustre-style ea_inode */ @@ -3341,6 +3343,7 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh) set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state); }
+#ifndef CONFIG_EXT4_PARALLEL_DIO_READ /* * Disable DIO read nolock optimization, so new dioreaders will be forced * to grab i_mutex @@ -3355,6 +3358,10 @@ static inline void ext4_inode_resume_unlocked_dio(struct inode *inode) smp_mb(); ext4_clear_inode_state(inode, EXT4_STATE_DIOREAD_LOCK); } +#else +#define ext4_inode_block_unlocked_dio(inode) +#define ext4_inode_resume_unlocked_dio(inode) +#endif
#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
From: Matthew Bobrowski mbobrowski@mbobrowski.org
stable inclusion from stable-v4.19.93 commit 0af1ad3b1ce50fdcb0996c0cd918ce08dc82c14c category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4MIQ0 CVE: NA
-----------------------------------------------
[ Upstream commit 548feebec7e93e58b647dba70b3303dcb569c914 ]
This patch updates the lock pattern in ext4_direct_IO_read() to not block on inode lock in cases of IOCB_NOWAIT direct I/O reads. The locking condition implemented here is similar to that of 942491c9e6d6 ("xfs: fix AIM7 regression").
Fixes: 16c54688592c ("ext4: Allow parallel DIO reads") Signed-off-by: Matthew Bobrowski mbobrowski@mbobrowski.org Reviewed-by: Jan Kara jack@suse.cz Reviewed-by: Ritesh Harjani riteshh@linux.ibm.com Link: https://lore.kernel.org/r/c5d5e759f91747359fbd2c6f9a36240cf75ad79f.157294932... Signed-off-by: Theodore Ts'o tytso@mit.edu Signed-off-by: Sasha Levin sashal@kernel.org Signed-off-by: Zhang Xiaoxu zhangxiaoxu5@huawei.com Reviewed-by: Zhang Yi yi.zhang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- fs/ext4/inode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 2f5231899d342..6213816056cd6 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3814,7 +3814,13 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) * writes & truncates and since we take care of writing back page cache, * we are protected against page writeback as well. */ - inode_lock_shared(inode); + if (iocb->ki_flags & IOCB_NOWAIT) { + if (!inode_trylock_shared(inode)) + return -EAGAIN; + } else { + inode_lock_shared(inode); + } + ret = filemap_write_and_wait_range(mapping, iocb->ki_pos, iocb->ki_pos + count - 1); if (ret)
From: Zhang Xiaoxu zhangxiaoxu5@huawei.com
hulk inclusion category: feature bugzilla: 185871, https://gitee.com/openeuler/kernel/issues/I4MIQ0 CVE: NA
-------------------------------------------------
Enable CONFIG_EXT4_PARALLEL_DIO_READ as default.
The configuration is used for control whether the ext4 is supported parallel dio reads. Enable it can improve the dio read performance, but has adversely affected for mixed dio read/write.
Signed-off-by: Zhang Xiaoxu zhangxiaoxu5@huawei.com Reviewed-by: Zhang Yi yi.zhang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- arch/arm64/configs/hulk_defconfig | 1 + arch/arm64/configs/openeuler_defconfig | 1 + 2 files changed, 2 insertions(+)
diff --git a/arch/arm64/configs/hulk_defconfig b/arch/arm64/configs/hulk_defconfig index e80f4b7fde56d..adaf13d8f59ee 100644 --- a/arch/arm64/configs/hulk_defconfig +++ b/arch/arm64/configs/hulk_defconfig @@ -4842,6 +4842,7 @@ CONFIG_EXT4_FS_POSIX_ACL=y CONFIG_EXT4_FS_SECURITY=y # CONFIG_EXT4_ENCRYPTION is not set # CONFIG_EXT4_DEBUG is not set +CONFIG_EXT4_PARALLEL_DIO_READ=y CONFIG_JBD2=y # CONFIG_JBD2_DEBUG is not set CONFIG_FS_MBCACHE=y diff --git a/arch/arm64/configs/openeuler_defconfig b/arch/arm64/configs/openeuler_defconfig index c2cb98dcf340b..548e88c579350 100644 --- a/arch/arm64/configs/openeuler_defconfig +++ b/arch/arm64/configs/openeuler_defconfig @@ -5148,6 +5148,7 @@ CONFIG_EXT4_FS_POSIX_ACL=y CONFIG_EXT4_FS_SECURITY=y # CONFIG_EXT4_ENCRYPTION is not set # CONFIG_EXT4_DEBUG is not set +CONFIG_EXT4_PARALLEL_DIO_READ=y CONFIG_JBD2=m # CONFIG_JBD2_DEBUG is not set CONFIG_FS_MBCACHE=m