ext4: Convert ext4 DAX IO to iomap framework
Subsystems (6)
Jan Kara
reviewerv2 cover ext4: Convert ext4 DAX IO to iomap framework
Hello,
this is a second revision of my patches to convert ext4 DAX IO paths to the new iomap framework and removes the old bh-based DAX functions. As a result ext4 gains PMD page fault support, also some other minor bugs get fixed. The patch set is based on Ross' DAX PMD page fault support series [1]. It passes xfstests both in DAX and non-DAX mode.
I have pushed out updated version of these patches including the follow-up DAX patches to:
git://get.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git dax
for easy testing. Once Dave pushes out a stable branch with Ross' patches, we pull those into ext4 tree and then pull these patches on top of that (provided nobody will have other objections to the current series).
Changes since v1:
* Changed ext4_iomap_begin() and ext4_iomap_end() to not keep transaction handle running between these two functions as that causes lock ordering issues.
Honza
Jan Kara
reviewerPATCH v2 1/11 ext4: Factor out checks from ext4_file_write_iter()
Factor out checks of 'from' and whether we are overwriting out of ext4_file_write_iter() so that the function is easier to follow.
--- fs/ext4/file.c | 97 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 47 deletions(-)
fs/ext4/file.c +50 -47
@@ -88,6 +88,51 @@ ext4_unaligned_aio(struct inode *inode, struct iov_iter *from, loff_t pos)return 0 ; } +/* Is IO overwriting allocated and initialized blocks? */ +static bool ext4_overwrite_io (struct inode *inode,loff_t pos,loff_t len) +{ +struct ext4_map_blocks map; +unsigned int blkbits = inode->i_blkbits; +int err, blklen; + +if (pos + len >i_size_read (inode)) +return false; + + map.m_lblk = pos >> blkbits; + map.m_len =EXT4_MAX_BLOCKS (len, pos, blkbits); + blklen = map.m_len; + + err =ext4_map_blocks (NULL , inode, &map,0 ); +/* +* 'err==len' means that all of the blocks have been preallocated, +* regardless of whether they have been initialized or not. To exclude +* unwritten extents, we need to check m_flags. +*/ +return err == blklen && (map.m_flags &EXT4_MAP_MAPPED ); +} + +static ssize_t ext4_write_checks (struct kiocb *iocb,struct iov_iter *from) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret; + + ret =generic_write_checks (iocb, from); +if (ret <=0 ) +return ret; +/* +* If we have encountered a bitmap-format file, the size limit +* is smaller than s_maxbytes, which is for extent-mapped files. +*/ +if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) { +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); + +if (iocb->ki_pos >= sbi->s_bitmap_maxbytes) +return -EFBIG ; +iov_iter_truncate (from, sbi->s_bitmap_maxbytes - iocb->ki_pos); + } +return iov_iter_count (from); +} +static ssize_t ext4_file_write_iter (struct kiocb *iocb,struct iov_iter *from) {
@@ -98,7 +143,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)ssize_t ret;inode_lock (inode); - ret =generic_write_checks (iocb, from); + ret =ext4_write_checks (iocb, from);if (ret <=0 ) goto out;
@@ -114,53 +159,11 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)ext4_unwritten_wait (inode); } -/* -* If we have encountered a bitmap-format file, the size limit -* is smaller than s_maxbytes, which is for extent-mapped files. -*/ -if (!(ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))) { -struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); - -if (iocb->ki_pos >= sbi->s_bitmap_maxbytes) { - ret = -EFBIG ; - goto out; - } -iov_iter_truncate (from, sbi->s_bitmap_maxbytes - iocb->ki_pos); - } - iocb->private = &overwrite; -if (o_direct) { -size_t length =iov_iter_count (from); -loff_t pos = iocb->ki_pos; - -/* check whether we do a DIO overwrite or not */ -if (ext4_should_dioread_nolock (inode) && !unaligned_aio && - pos + length <=i_size_read (inode)) { -struct ext4_map_blocks map; -unsigned int blkbits = inode->i_blkbits; -int err, len; - - map.m_lblk = pos >> blkbits; - map.m_len =EXT4_MAX_BLOCKS (length, pos, blkbits); - len = map.m_len; - - err =ext4_map_blocks (NULL , inode, &map,0 ); -/* -* 'err==len' means that all of blocks has -* been preallocated no matter they are -* initialized or not. For excluding -* unwritten extents, we need to check -* m_flags. There are two conditions that -* indicate for initialized extents. 1) If we -* hit extent cache, EXT4_MAP_MAPPED flag is -* returned; 2) If we do a real lookup, -* non-flags are returned. So we should check -* these two conditions. -*/ -if (err == len && (map.m_flags &EXT4_MAP_MAPPED )) - overwrite =1 ; - } - } +/* Check whether we do a DIO overwrite or not */ +if (o_direct &&ext4_should_dioread_nolock (inode) && !unaligned_aio && +ext4_overwrite_io (inode, iocb->ki_pos,iov_iter_count (from))) + overwrite =1 ; ret =__generic_file_write_iter (iocb, from);inode_unlock (inode);
Signature · 1 line
2.6.6
Re: [PATCH 01/11] ext4: Factor out checks from ext4_file_write_iter()
Quoted 4 lines · Jan Kara
Factor out checks of 'from' and whether we are overwriting out of
ext4_file_write_iter()so that the function is easier to follow.Signed-off-by Jan Kara <[email protected]>
Jan Kara
reviewerPATCH v2 2/11 ext4: Let S_DAX set only if DAX is really supported
In reply to Jan KaraCurrently we have S_DAX set inode->i_flags for a regular file whenever ext4 is mounted with dax mount option. However in some cases we cannot really do DAX - e.g. when inode is marked to use data journalling, when inode data is being encrypted, or when inode is stored inline. Make sure S_DAX flag is appropriately set/cleared in these cases.
--- fs/ext4/inline.c | 10 ++++++++++ fs/ext4/inode.c | 9 ++++++++- fs/ext4/super.c | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-)
fs/ext4/inline.c +10 -0
@@ -299,6 +299,11 @@ static int ext4_create_inline_data(handle_t *handle,EXT4_I (inode)->i_inline_size = len +EXT4_MIN_INLINE_DATA_SIZE ;ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS );ext4_set_inode_flag (inode,EXT4_INODE_INLINE_DATA ); +/* +* Propagate changes to inode->i_flags as well - e.g. S_DAX may +* get cleared +*/ +ext4_set_inode_flags (inode);get_bh (is.iloc.bh); error =ext4_mark_iloc_dirty (handle, inode, &is.iloc);
@@ -442,6 +447,11 @@ static int ext4_destroy_inline_data_nolock(handle_t *handle, } }ext4_clear_inode_flag (inode,EXT4_INODE_INLINE_DATA ); +/* +* Propagate changes to inode->i_flags as well - e.g. S_DAX may +* get set. +*/ +ext4_set_inode_flags (inode);get_bh (is.iloc.bh); error =ext4_mark_iloc_dirty (handle, inode, &is.iloc);
fs/ext4/inode.c +8 -1
@@ -4355,7 +4355,9 @@ void ext4_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &EXT4_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; -if (test_opt (inode->i_sb,DAX ) &&S_ISREG (inode->i_mode)) +if (test_opt (inode->i_sb,DAX ) &&S_ISREG (inode->i_mode) && + !ext4_should_journal_data (inode) && !ext4_has_inline_data (inode) && + !ext4_encrypted_inode (inode)) new_fl |=S_DAX ;inode_set_flags (inode, new_fl,S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX );
@@ -5623,6 +5625,11 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)ext4_clear_inode_flag (inode,EXT4_INODE_JOURNAL_DATA ); }ext4_set_aops (inode); +/* +* Update inode->i_flags after EXT4_INODE_JOURNAL_DATA was updated. +* E.g. S_DAX may get cleared / set. +*/ +ext4_set_inode_flags (inode);jbd2_journal_unlock_updates (journal);percpu_up_write (&sbi->s_journal_flag_rwsem);
fs/ext4/super.c +5 -0
@@ -1126,6 +1126,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT );ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA ); +/* +* Update inode->i_flags - e.g. S_DAX may get disabled +*/ +ext4_set_inode_flags (inode); }return res; }
@@ -1140,6 +1144,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, len, 0);if (!res) {ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT ); +/* Update inode->i_flags - e.g. S_DAX may get disabled */ res =ext4_mark_inode_dirty (handle, inode);if (res)EXT4_ERROR_INODE (inode,"Failed to mark inode dirty" );
Signature · 1 line
2.6.6
Re: [PATCH 02/11] ext4: Let S_DAX set only if DAX is really supported
Quoted 8 lines · Jan Kara
Currently we have
S_DAXsetinode->i_flagsfor a regular file whenever ext4 is mounted with dax mount option. However in some cases we cannot really do DAX - e.g. when inode is marked to use data journalling, when inode data is being encrypted, or when inode is stored inline. Make sureS_DAXflag is appropriately set/cleared in these cases.Signed-off-by Jan Kara <[email protected]>---
<>
Quoted 16 lines
fs/ext4/super.c +4
-0@@ -1126,6 +1126,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT );ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA ); +/* +* Update inode->i_flags - e.g. S_DAX may get disabled +*/ +ext4_set_inode_flags (inode); }return res; }
fs/ext4/super.c static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, · line 1147
Quoted 4 lines
fs/ext4/super.c +1
-0@@ -1140,6 +1144,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, len, 0);if (!res) {ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT ); +/* Update inode->i_flags - e.g. S_DAX may get disabled */
Missing call to ext4_set_inode_flags(inode)?
Quoted 6 lines
fs/ext4/super.c +0
-0res =ext4_mark_inode_dirty (handle, inode);if (res)EXT4_ERROR_INODE (inode,"Failed to mark inode dirty" );Signature · 1 line
2.6.6
Jan Kara
reviewerRe: [PATCH 02/11] ext4: Let S_DAX set only if DAX is really supported
Quoted 24 lines · Ross Zwisler
Quoted 8 lines · Jan Kara
Currently we have
S_DAXsetinode->i_flagsfor a regular file whenever ext4 is mounted with dax mount option. However in some cases we cannot really do DAX - e.g. when inode is marked to use data journalling, when inode data is being encrypted, or when inode is stored inline. Make sureS_DAXflag is appropriately set/cleared in these cases.Signed-off-by Jan Kara <[email protected]>---
<>
Quoted 14 lines
fs/ext4/super.c +4
-0@@ -1126,6 +1126,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT );ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA ); +/* +* Update inode->i_flags - e.g. S_DAX may get disabled +*/ +ext4_set_inode_flags (inode); }return res;
Quoted 8 lines
fs/ext4/super.c static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, · line 1147
Quoted 6 lines
fs/ext4/super.c +1
-0}@@ -1140,6 +1144,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, len, 0);if (!res) {ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT ); +/* Update inode->i_flags - e.g. S_DAX may get disabled */ Missing call to
ext4_set_inode_flags(inode)?
Yeah, fixed. Thanks!
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Ross Zwisler
Reviewed-byRe: [PATCH 02/11] ext4: Let S_DAX set only if DAX is really supported
Quoted 34 lines · Jan Kara
Quoted 24 lines · Ross Zwisler
Quoted 8 lines · Jan Kara
Currently we have
S_DAXsetinode->i_flagsfor a regular file whenever ext4 is mounted with dax mount option. However in some cases we cannot really do DAX - e.g. when inode is marked to use data journalling, when inode data is being encrypted, or when inode is stored inline. Make sureS_DAXflag is appropriately set/cleared in these cases.Signed-off-by Jan Kara <[email protected]>---
<>
Quoted 14 lines
fs/ext4/super.c +4
-0@@ -1126,6 +1126,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT );ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA ); +/* +* Update inode->i_flags - e.g. S_DAX may get disabled +*/ +ext4_set_inode_flags (inode); }return res;Quoted 8 lines
fs/ext4/super.c static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, · line 1147
Quoted 6 lines
fs/ext4/super.c +1
-0}@@ -1140,6 +1144,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, len, 0);if (!res) {ext4_set_inode_flag (inode,EXT4_INODE_ENCRYPT ); +/* Update inode->i_flags - e.g. S_DAX may get disabled */ Missing call to
ext4_set_inode_flags(inode)?
Quoted 1 line
Yeah, fixed. Thanks!
Cool, you can add:
Jan Kara
reviewerPATCH v2 3/11 ext4: Convert DAX reads to iomap infrastructure
In reply to Jan KaraImplement basic iomap_begin function that handles reading and use it for DAX reads.
--- fs/ext4/ext4.h | 2 ++ fs/ext4/file.c | 38 +++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-)
fs/ext4/ext4.h +2 -0
@@ -3271,6 +3271,8 @@ static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len) return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize); } +extern struct iomap_ops ext4_iomap_ops; +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */
fs/ext4/file.c +37 -1
@@ -31,6 +31,42 @@#include "xattr.h" #include "acl.h" +#ifdef CONFIG_FS_DAX +static ssize_t ext4_dax_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret; + +inode_lock_shared (inode); +/* +* Recheck under inode lock - at this point we are sure it cannot +* change anymore +*/ +if (!IS_DAX (inode)) { +inode_unlock_shared (inode); +/* Fallback to buffered IO in case we cannot support DAX */ +return generic_file_read_iter (iocb, to); + } + ret =dax_iomap_rw (iocb, to, &ext4_iomap_ops); +inode_unlock_shared (inode); + +file_accessed (iocb->ki_filp); +return ret; +} +#endif + +static ssize_t ext4_file_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +if (!iov_iter_count (to)) +return 0 ;/* skip atime */ + +#ifdef CONFIG_FS_DAX +if (IS_DAX (file_inode (iocb->ki_filp))) +return ext4_dax_read_iter (iocb, to); +#endif +return generic_file_read_iter (iocb, to); +} +/* * Called when an inode is released. Note that this is different * from ext4_file_open: open gets called at every open, but release
@@ -690,7 +726,7 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence)const struct file_operations ext4_file_operations = { .llseek = ext4_llseek, - .read_iter = generic_file_read_iter, + .read_iter = ext4_file_read_iter, .write_iter = ext4_file_write_iter, .unlocked_ioctl = ext4_ioctl, #ifdef CONFIG_COMPAT
fs/ext4/inode.c +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.6.6
Re: [PATCH 03/11] ext4: Convert DAX reads to iomap infrastructure
Quoted 36 lines · Jan Kara
Implement basic
iomap_beginfunction that handles reading and use it for DAX reads.Signed-off-by Jan Kara <[email protected]>--- fs/ext4/ext4.h | 2 ++ fs/ext4/file.c | 38 +++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-)fs/ext4/ext4.h +2
-0@@ -3271,6 +3271,8 @@ static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len) return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize); } +extern struct iomap_ops ext4_iomap_ops; +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */ fs/ext4/file.c +5
-0@@ -31,6 +31,42 @@#include "xattr.h" #include "acl.h" +#ifdef CONFIG_FS_DAX +static ssize_t ext4_dax_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret;
fs/ext4/file.c line 48
Quoted 10 lines
fs/ext4/file.c +10
-0+ +inode_lock_shared (inode); +/* +* Recheck under inode lock - at this point we are sure it cannot +* change anymore +*/ +if (!IS_DAX (inode)) { +inode_unlock_shared (inode); +/* Fallback to buffered IO in case we cannot support DAX */ +return generic_file_read_iter (iocb, to);
Is this not also racy, since we've just dropped the inode lock? What's to prevent this sequence?
Thread 0 Thread 1
-------- --------ext4_file_read_iter()
IS_DAX() returns true
changes S_DAX to false
ext4_dax_read_iter()
inode_lock_shared()
IS_DAX() returns false
inode_unlock_shared()
changes S_DAX to true
generic_file_read_iter() on a DAX inode
Or are we okay in this scenario?
Jan Kara
reviewerRe: [PATCH 03/11] ext4: Convert DAX reads to iomap infrastructure
Quoted 64 lines · Ross Zwisler
Quoted 36 lines · Jan Kara
Implement basic
iomap_beginfunction that handles reading and use it for DAX reads.Signed-off-by Jan Kara <[email protected]>--- fs/ext4/ext4.h | 2 ++ fs/ext4/file.c | 38 +++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-)fs/ext4/ext4.h +2
-0@@ -3271,6 +3271,8 @@ static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len) return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize); } +extern struct iomap_ops ext4_iomap_ops; +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */ fs/ext4/file.c +5
-0@@ -31,6 +31,42 @@#include "xattr.h" #include "acl.h" +#ifdef CONFIG_FS_DAX +static ssize_t ext4_dax_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret;fs/ext4/file.c line 48
Quoted 10 lines
fs/ext4/file.c +10
-0+ +inode_lock_shared (inode); +/* +* Recheck under inode lock - at this point we are sure it cannot +* change anymore +*/ +if (!IS_DAX (inode)) { +inode_unlock_shared (inode); +/* Fallback to buffered IO in case we cannot support DAX */ +return generic_file_read_iter (iocb, to);Is this not also racy, since we've just dropped the inode lock? What's to prevent this sequence?
Thread 0 Thread 1
-------- --------ext4_file_read_iter()
IS_DAX()returns true
changesS_DAXto false
ext4_dax_read_iter()
inode_lock_shared()
IS_DAX()returns false
inode_unlock_shared()
changesS_DAXto true
generic_file_read_iter()on a DAX inode
Quoted 1 line
Or are we okay in this scenario?
Yup, I'm aware of this. The real problem is that there's no way to serialize with buffered reads for ext4 (they take only page locks) so currently you can have buffered reads in flight when inode gets switched to DAX mode. I agree there is a potential for breakage and it needs to be resolved eventually but the problem is not new and these patches don't make it really any worse so I just somewhat fixed it up by patch 2/11 and left full solution to a separate patch set.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Ross Zwisler
Reviewed-byRe: [PATCH 03/11] ext4: Convert DAX reads to iomap infrastructure
Quoted 67 lines · Jan Kara
Quoted 64 lines · Ross Zwisler
Quoted 36 lines · Jan Kara
Implement basic
iomap_beginfunction that handles reading and use it for DAX reads.Signed-off-by Jan Kara <[email protected]>--- fs/ext4/ext4.h | 2 ++ fs/ext4/file.c | 38 +++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-)fs/ext4/ext4.h +2
-0@@ -3271,6 +3271,8 @@ static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len) return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize); } +extern struct iomap_ops ext4_iomap_ops; +#endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG/* Bad CRC detected */ fs/ext4/file.c +5
-0@@ -31,6 +31,42 @@#include "xattr.h" #include "acl.h" +#ifdef CONFIG_FS_DAX +static ssize_t ext4_dax_read_iter (struct kiocb *iocb,struct iov_iter *to) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret;fs/ext4/file.c line 48
Quoted 10 lines
fs/ext4/file.c +10
-0+ +inode_lock_shared (inode); +/* +* Recheck under inode lock - at this point we are sure it cannot +* change anymore +*/ +if (!IS_DAX (inode)) { +inode_unlock_shared (inode); +/* Fallback to buffered IO in case we cannot support DAX */ +return generic_file_read_iter (iocb, to);Is this not also racy, since we've just dropped the inode lock? What's to prevent this sequence?
Thread 0 Thread 1
-------- --------ext4_file_read_iter()
IS_DAX()returns true
changesS_DAXto false
ext4_dax_read_iter()
inode_lock_shared()
IS_DAX()returns false
inode_unlock_shared()
changesS_DAXto true
generic_file_read_iter()on a DAX inodeQuoted 1 line
Or are we okay in this scenario?
Quoted 7 lines
Yup, I'm aware of this. The real problem is that there's no way to serialize with buffered reads for ext4 (they take only page locks) so currently you can have buffered reads in flight when inode gets switched to DAX mode. I agree there is a potential for breakage and it needs to be resolved eventually but the problem is not new and these patches don't make it really any worse so I just somewhat fixed it up by patch 2/11 and left full solution to a separate patch set.
Fair enough. You can add:
Jan Kara
reviewerPATCH v2 4/11 ext4: Use iomap for zeroing blocks in DAX mode
In reply to Jan KaraUse iomap infrastructure for zeroing blocks when in DAX mode. ext4_iomap_begin() handles read requests just fine and that's all that is needed for iomap_zero_range().
--- fs/ext4/inode.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/inode.c +4 -2
@@ -3849,8 +3849,10 @@ static int ext4_block_zero_page_range(handle_t *handle,if (length > max || length <0 ) length = max; -if (IS_DAX (inode)) -return dax_zero_page_range (inode, from, length, ext4_get_block); +if (IS_DAX (inode)) { +return iomap_zero_range (inode, from, length,NULL , + &ext4_iomap_ops); + }return __ext4_block_zero_page_range (handle, mapping, from, length); }
Signature · 1 line
2.6.6
Re: [PATCH 04/11] ext4: Use iomap for zeroing blocks in DAX mode
Quoted 5 lines · Jan Kara
Use iomap infrastructure for zeroing blocks when in DAX mode.
ext4_iomap_begin()handles read requests just fine and that's all that is needed foriomap_zero_range().Signed-off-by Jan Kara <[email protected]>
Jan Kara
reviewerPATCH v2 5/11 ext4: DAX iomap write support
In reply to Jan KaraImplement DAX writes using the new iomap infrastructure instead of overloading the direct IO path.
--- fs/ext4/file.c | 40 ++++++++++++++++++ fs/ext4/inode.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 160 insertions(+), 6 deletions(-)
fs/ext4/file.c +40 -0
@@ -169,6 +169,41 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *from)return iov_iter_count (from); } +#ifdef CONFIG_FS_DAX +static ssize_t +ext4_dax_write_iter (struct kiocb *iocb,struct iov_iter *from) +{ +struct inode *inode =file_inode (iocb->ki_filp); +ssize_t ret; +bool overwrite = false; + +inode_lock (inode); + ret =ext4_write_checks (iocb, from); +if (ret <=0 ) + goto out; + ret =file_remove_privs (iocb->ki_filp); +if (ret) + goto out; + ret =file_update_time (iocb->ki_filp); +if (ret) + goto out; + +if (ext4_overwrite_io (inode, iocb->ki_pos,iov_iter_count (from))) { + overwrite = true; +downgrade_write (&inode->i_rwsem); + } + ret =dax_iomap_rw (iocb, from, &ext4_iomap_ops); +out: +if (!overwrite) +inode_unlock (inode); +else +inode_unlock_shared (inode); +if (ret >0 ) + ret =generic_write_sync (iocb, ret); +return ret; +} +#endif +static ssize_t ext4_file_write_iter (struct kiocb *iocb,struct iov_iter *from) {
@@ -178,6 +213,11 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)int overwrite =0 ;ssize_t ret; +#ifdef CONFIG_FS_DAX +if (IS_DAX (inode)) +return ext4_dax_write_iter (iocb, from); +#endif +inode_lock (inode); ret =ext4_write_checks (iocb, from);if (ret <=0 )
fs/ext4/inode.c +120 -6
146 lines not on this page · raw message
Signature · 1 line
2.6.6
Jan Kara
reviewerPATCH v2 6/11 ext4: Avoid split extents for DAX writes
In reply to Jan KaraCurrently mapping of blocks for DAX writes happen with EXT4_GET_BLOCKS_PRE_IO flag set. That has a result that each ext4_map_blocks() call creates a separate written extent, although it could be merged to the neighboring extents in the extent tree. The reason for using this flag is that in case the extent is unwritten, we need to convert it to written one and zero it out. However this "convert mapped range to written" operation is already implemented by ext4_map_blocks() for the case of data writes into unwritten extent. So just use flags for that mode of operation, simplify the code, and avoid unnecessary split extents.
--- fs/ext4/inode.c | 17 ----------------- 1 file changed, 17 deletions(-)
fs/ext4/inode.c +0 -17
@@ -3351,7 +3351,6 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,return PTR_ERR (handle); ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_PRE_IO |EXT4_GET_BLOCKS_CREATE_ZERO );if (ret <0 ) {ext4_journal_stop (handle);
@@ -3360,22 +3359,6 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, goto retry;return ret; } -/* For DAX writes we need to zero out unwritten extents */ -if (map.m_flags &EXT4_MAP_UNWRITTEN ) { -/* -* We are protected by i_mmap_sem or i_rwsem so we know -* block cannot go away from under us even though we -* dropped i_data_sem. Convert extent to written and -* write zeros there. -*/ - ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_CONVERT | -EXT4_GET_BLOCKS_CREATE_ZERO ); -if (ret <0 ) { -ext4_journal_stop (handle); -return ret; - } - }/* * If we added blocks beyond i_size we need to make sure they
Signature · 1 line
2.6.6
Re: [PATCH 06/11] ext4: Avoid split extents for DAX writes
Quoted 11 lines · Jan Kara
Currently mapping of blocks for DAX writes happen with
EXT4_GET_BLOCKS_PRE_IOflag set. That has a result that eachext4_map_blocks()call creates a separate written extent, although it could be merged to the neighboring extents in the extent tree. The reason for using this flag is that in case the extent is unwritten, we need to convert it to written one and zero it out. However this "convert mapped range to written" operation is already implemented byext4_map_blocks()for the case of data writes into unwritten extent. So just use flags for that mode of operation, simplify the code, and avoid unnecessary split extents.
Quoted 1 line
Signed-off-by Jan Kara <[email protected]>
The code that this patch modifies was just introduced in the previous patch. Is there a reason to keep both patches, or would it be cleaner just to squash them and have one patch that introduces the code as you intend for it to end up?
Quoted 42 lines
--- fs/ext4/inode.c | 17 ----------------- 1 file changed, 17 deletions(-)fs/ext4/inode.c +0
-17@@ -3351,7 +3351,6 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,return PTR_ERR (handle); ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_PRE_IO |EXT4_GET_BLOCKS_CREATE_ZERO );if (ret <0 ) {ext4_journal_stop (handle);@@ -3360,22 +3359,6 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, goto retry;return ret; } -/* For DAX writes we need to zero out unwritten extents */ -if (map.m_flags &EXT4_MAP_UNWRITTEN ) { -/* -* We are protected by i_mmap_sem or i_rwsem so we know -* block cannot go away from under us even though we -* dropped i_data_sem. Convert extent to written and -* write zeros there. -*/ - ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_CONVERT | -EXT4_GET_BLOCKS_CREATE_ZERO ); -if (ret <0 ) { -ext4_journal_stop (handle); -return ret; - } - }/* * If we added blocks beyond i_size we need to make sure they Signature · 1 line
2.6.6
Jan Kara
reviewerRe: [PATCH 06/11] ext4: Avoid split extents for DAX writes
Quoted 12 lines · Ross Zwisler
Quoted 11 lines · Jan Kara
Currently mapping of blocks for DAX writes happen with
EXT4_GET_BLOCKS_PRE_IOflag set. That has a result that eachext4_map_blocks()call creates a separate written extent, although it could be merged to the neighboring extents in the extent tree. The reason for using this flag is that in case the extent is unwritten, we need to convert it to written one and zero it out. However this "convert mapped range to written" operation is already implemented byext4_map_blocks()for the case of data writes into unwritten extent. So just use flags for that mode of operation, simplify the code, and avoid unnecessary split extents.
Quoted 6 lines
Quoted 1 line
Signed-off-by Jan Kara <[email protected]>The code that this patch modifies was just introduced in the previous patch. Is there a reason to keep both patches, or would it be cleaner just to squash them and have one patch that introduces the code as you intend for it to end up?
Well, the previous patch just mostly moved the block allocation logic from dedicated DAX get_block function into iomap_begin(). This patch changes the block allocation logic so I prefer to keep them separate - mostly for the sake of documenting the change how allocation of blocks for DAX works in the changelog.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerPATCH v2 7/11 dax: Introduce IOMAP_FAULT flag
In reply to Jan KaraIntroduce a flag telling iomap operations whether they are handling a fault or other IO. That may influence behavior wrt inode size and similar things.
--- fs/dax.c | 4 ++-- fs/iomap.c | 5 +++-- include/linux/iomap.h | 1 + 3 files changed, 6 insertions(+), 4 deletions(-)
fs/dax.c +2 -2
@@ -1266,7 +1266,7 @@ int dax_iomap_fault(struct vm_area_struct *vma, struct vm_fault *vmf,loff_t pos = (loff_t )vmf->pgoff <<PAGE_SHIFT ;sector_t sector;struct iomap iomap = {0 }; -unsigned flags =0 ; +unsigned flags =IOMAP_FAULT ;int error, major =0 ;int locked_status =0 ;void *entry;
@@ -1467,7 +1467,7 @@ int dax_iomap_pmd_fault(struct vm_area_struct *vma, unsigned long address,struct address_space *mapping = vma->vm_file->f_mapping;unsigned long pmd_addr = address &PMD_MASK ;bool write = flags &FAULT_FLAG_WRITE ; -unsigned int iomap_flags = write ?IOMAP_WRITE :0 ; +unsigned int iomap_flags = (write ?IOMAP_WRITE :0 ) |IOMAP_FAULT ;struct inode *inode = mapping->host;int result =VM_FAULT_FALLBACK ;struct iomap iomap = {0 };
fs/iomap.c +3 -2
@@ -467,8 +467,9 @@ int iomap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, offset =page_offset (page);while (length >0 ) { - ret =iomap_apply (inode, offset, length,IOMAP_WRITE , - ops, page, iomap_page_mkwrite_actor); + ret =iomap_apply (inode, offset, length, +IOMAP_WRITE |IOMAP_FAULT , ops, page, + iomap_page_mkwrite_actor);if (unlikely (ret <=0 )) goto out_unlock; offset += ret;
include/linux/iomap.h +1 -0
@@ -49,6 +49,7 @@ struct iomap {#define IOMAP_WRITE (1 << 0)/* writing, must allocate blocks */ #define IOMAP_ZERO (1 << 1)/* zeroing operation, may skip holes */ #define IOMAP_REPORT (1 << 2)/* report extent status, e.g. FIEMAP */ +#define IOMAP_FAULT (1 << 3)/* mapping for page fault */ struct iomap_ops {/*
Signature · 1 line
2.6.6
Re: [PATCH 07/11] dax: Introduce IOMAP_FAULT flag
Quoted 5 lines · Jan Kara
Introduce a flag telling iomap operations whether they are handling a fault or other IO. That may influence behavior wrt inode size and similar things.
Signed-off-by Jan Kara <[email protected]>
Looks fine.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 07/11] dax: Introduce IOMAP_FAULT flag
In reply to Jan KaraQuoted 5 lines · Jan Kara
Introduce a flag telling iomap operations whether they are handling a fault or other IO. That may influence behavior wrt inode size and similar things.
Signed-off-by Jan Kara <[email protected]>
Looks fine in general - I'm a bit worried about which flags combinations are valid, but as this is my fault I'll sort it out after we get your series in:
Jan Kara
reviewerPATCH v2 8/11 ext4: Convert DAX faults to iomap infrastructure
In reply to Jan KaraConvert DAX faults to use iomap infrastructure. We would not have to start transaction in ext4_dax_fault() anymore since ext4_iomap_begin takes care of that but so far we do that to avoid lock inversion of transaction start with DAX entry lock which gets acquired in dax_iomap_fault() before calling ->iomap_begin handler.
--- fs/ext4/file.c | 9 +++++---- fs/ext4/inode.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-)
fs/ext4/file.c +5 -4
@@ -275,7 +275,7 @@ static int ext4_dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf)if (IS_ERR (handle)) result =VM_FAULT_SIGBUS ;else - result =dax_fault (vma, vmf, ext4_dax_get_block); + result =dax_iomap_fault (vma, vmf, &ext4_iomap_ops);if (write) {if (!IS_ERR (handle))
@@ -309,9 +309,10 @@ static int ext4_dax_pmd_fault(struct vm_area_struct *vma, unsigned long addr,if (IS_ERR (handle)) result =VM_FAULT_SIGBUS ; -else - result =dax_pmd_fault (vma, addr, pmd, flags, - ext4_dax_get_block); +else { + result =dax_iomap_pmd_fault (vma, addr, pmd, flags, + &ext4_iomap_ops); + }if (write) {if (!IS_ERR (handle))
fs/ext4/inode.c +9 -5
@@ -3361,12 +3361,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, }/* -* If we added blocks beyond i_size we need to make sure they +* If we added blocks beyond i_size, we need to make sure they * will get truncated if we crash before updating i_size in -* ext4_iomap_end(). +* ext4_iomap_end(). For faults we don't need to do that (and +* even cannot because for orphan list operations inode_lock is +* required) - if we happen to instantiate block beyond i_size, +* it is because we race with truncate which has already added +* the inode to the orphan list. */ -if (first_block + map.m_len > - (inode->i_size + (1 << blkbits) -1 ) >> blkbits) { +if (!(flags &IOMAP_FAULT ) && first_block + map.m_len > + (i_size_read (inode) + (1 << blkbits) -1 ) >> blkbits) {int err; err =ext4_orphan_add (handle, inode);
@@ -3412,7 +3416,7 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length,int blkbits = inode->i_blkbits;bool truncate = false; -if (!(flags &IOMAP_WRITE )) +if (!(flags &IOMAP_WRITE ) || (flags &IOMAP_FAULT ))return 0 ; handle =ext4_journal_start (inode,EXT4_HT_INODE ,2 );
Signature · 1 line
2.6.6
Jan Kara
reviewerPATCH v2 9/11 ext4: Rip out DAX handling from direct IO path
In reply to Jan KaraReads and writes for DAX inodes should no longer end up in direct IO code. Rip out the support and add a warning.
--- fs/ext4/inode.c | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-)
fs/ext4/inode.c +15 -34
@@ -3594,19 +3594,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) iocb->private =NULL ;if (overwrite) get_block_func = ext4_dio_get_block_overwrite; -else if (IS_DAX (inode)) { -/* -* We can avoid zeroing for aligned DAX writes beyond EOF. Other -* writes need zeroing either because they can race with page -* faults or because they use partial blocks. -*/ -if (round_down (offset,1 <<inode->i_blkbits) >= inode->i_size && -ext4_aligned_io (inode, offset, count)) - get_block_func = ext4_dio_get_block; -else - get_block_func = ext4_dax_get_block; - dio_flags =DIO_LOCKING ; - }else if (!ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ) || +else if (!ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ) ||round_down (offset,1 << inode->i_blkbits) >= inode->i_size) { get_block_func = ext4_dio_get_block; dio_flags =DIO_LOCKING |DIO_SKIP_HOLES ;
@@ -3620,14 +3608,9 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)#ifdef CONFIG_EXT4_FS_ENCRYPTION BUG_ON (ext4_encrypted_inode (inode) &&S_ISREG (inode->i_mode));#endif -if (IS_DAX (inode)) { - ret =dax_do_io (iocb, inode, iter, get_block_func, - ext4_end_io_dio, dio_flags); - }else - ret =__blockdev_direct_IO (iocb, inode, - inode->i_sb->s_bdev, iter, - get_block_func, - ext4_end_io_dio,NULL , dio_flags); + ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, iter, + get_block_func, ext4_end_io_dio,NULL , + dio_flags);if (ret >0 && !overwrite &&ext4_test_inode_state (inode,EXT4_STATE_DIO_UNWRITTEN )) {
@@ -3696,6 +3679,7 @@ 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; +size_t count =iov_iter_count (iter);ssize_t ret;/*
@@ -3704,19 +3688,12 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter)* we are protected against page writeback as well. */ inode_lock_shared (inode); -if (IS_DAX (inode)) { - ret =dax_do_io (iocb, inode, iter, ext4_dio_get_block,NULL ,0 ); - }else { -size_t count =iov_iter_count (iter); - - ret =filemap_write_and_wait_range (mapping, iocb->ki_pos, - iocb->ki_pos + count); -if (ret) - goto out_unlock; - ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, - iter, ext4_dio_get_block, -NULL ,NULL ,0 ); - } + ret =filemap_write_and_wait_range (mapping, iocb->ki_pos, + iocb->ki_pos + count); +if (ret) + goto out_unlock; + ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, + iter, ext4_dio_get_block,NULL ,NULL ,0 ); out_unlock:inode_unlock_shared (inode);return ret;
@@ -3745,6 +3722,10 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter)if (ext4_has_inline_data (inode))return 0 ; +/* DAX uses iomap path now */ +if (WARN_ON_ONCE (IS_DAX (inode))) +return 0 ; +trace_ext4_direct_IO_enter (inode, offset, count,iov_iter_rw (iter));if (iov_iter_rw (iter) ==READ ) ret =ext4_direct_IO_read (iocb, iter);
Signature · 1 line
2.6.6
Re: [PATCH 09/11] ext4: Rip out DAX handling from direct IO path
Quoted 17 lines · Jan Kara
Reads and writes for DAX inodes should no longer end up in direct IO code. Rip out the support and add a warning.
Signed-off-by Jan Kara <[email protected]>--- fs/ext4/inode.c | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-)fs/ext4/inode.c +0
-1@@ -3594,19 +3594,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) iocb->private =NULL ;if (overwrite) get_block_func = ext4_dio_get_block_overwrite; -else if (IS_DAX (inode)) {
fs/ext4/inode.c static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) · line 3607
Quoted 10 lines
fs/ext4/inode.c +0
-10-/* -* We can avoid zeroing for aligned DAX writes beyond EOF. Other -* writes need zeroing either because they can race with page -* faults or because they use partial blocks. -*/ -if (round_down (offset,1 <<inode->i_blkbits) >= inode->i_size && -ext4_aligned_io (inode, offset, count)) - get_block_func = ext4_dio_get_block; -else - get_block_func = ext4_dax_get_block;
This was the last use of ext4_dax_get_block(), so that function can safely be removed. I can do that in a separate patch, if you don't want to pull it into this set.
Otherwise this looks correct to me.
Jan Kara
reviewerRe: [PATCH 09/11] ext4: Rip out DAX handling from direct IO path
Quoted 24 lines · Ross Zwisler
Quoted 23 lines · Jan Kara
Reads and writes for DAX inodes should no longer end up in direct IO code. Rip out the support and add a warning.
Signed-off-by Jan Kara <[email protected]>--- fs/ext4/inode.c | 49 +++++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-)fs/ext4/inode.c +0
-7@@ -3594,19 +3594,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) iocb->private =NULL ;if (overwrite) get_block_func = ext4_dio_get_block_overwrite; -else if (IS_DAX (inode)) { -/* -* We can avoid zeroing for aligned DAX writes beyond EOF. Other -* writes need zeroing either because they can race with page -* faults or because they use partial blocks. -*/ - if (round_down(offset, 1<<inode->i_blkbits) >= inode->i_size &&
Quoted 8 lines
fs/ext4/inode.c static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) · line 3607
Quoted 4 lines
fs/ext4/inode.c +0
-4- ext4_aligned_io(inode, offset, count)) - get_block_func = ext4_dio_get_block; - else - get_block_func = ext4_dax_get_block;This was the last use of
ext4_dax_get_block(), so that function can safely be removed. I can do that in a separate patch, if you don't want to pull it into this set.
Good point. Added removal to this patch.
Quoted 3 lines
Otherwise this looks correct to me.
Reviewed-by Ross Zwisler <[email protected]>
Thanks.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerPATCH v2 10/11 ext2: Use iomap_zero_range() for zeroing truncated page in DAX path
In reply to Jan KaraCurrently the last user of ext2_get_blocks() for DAX inodes was dax_truncate_page(). Convert that to iomap_zero_range() so that all DAX IO uses the iomap path.
--- fs/ext2/inode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/ext2/inode.c +8 -3
@@ -850,6 +850,9 @@ struct iomap_ops ext2_iomap_ops = { .iomap_begin = ext2_iomap_begin, .iomap_end = ext2_iomap_end, }; +#else +/* Define empty ops for !CONFIG_FS_DAX case to avoid ugly ifdefs */ +struct iomap_ops ext2_iomap_ops;#endif /* CONFIG_FS_DAX */ int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
@@ -1293,9 +1296,11 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)inode_dio_wait (inode); -if (IS_DAX (inode)) - error =dax_truncate_page (inode, newsize, ext2_get_block); -else if (test_opt (inode->i_sb,NOBH )) +if (IS_DAX (inode)) { + error =iomap_zero_range (inode, newsize, +PAGE_ALIGN (newsize) - newsize,NULL , + &ext2_iomap_ops); + }else if (test_opt (inode->i_sb,NOBH )) error =nobh_truncate_page (inode->i_mapping, newsize, ext2_get_block);else
Signature · 1 line
2.6.6
Re: [PATCH 10/11] ext2: Use iomap_zero_range() for zeroing truncated page in DAX path
Quoted 5 lines · Jan Kara
Currently the last user of
ext2_get_blocks()for DAX inodes wasdax_truncate_page(). Convert that toiomap_zero_range()so that all DAX IO uses the iomap path.Signed-off-by Jan Kara <[email protected]>
Jan Kara
reviewerPATCH v2 11/11 dax: Rip out get_block based IO support
In reply to Jan KaraNo one uses functions using the get_block callback anymore. Rip them out and update documentation.
--- Documentation/filesystems/dax.txt | 21 ++- fs/dax.c | 315 -------------------------------------- include/linux/dax.h | 12 -- 3 files changed, 10 insertions(+), 338 deletions(-)
Documentation/filesystems/dax.txt +10 -11
@@ -58,22 +58,21 @@ Implementation Tips for Filesystem Writers Filesystem support consists of - adding support to mark inodes as being DAX by setting the S_DAX flag in i_flags -- implementing the direct_IO address space operation, and calling - dax_do_io() instead of blockdev_direct_IO() if S_DAX is set +- implementing ->read_iter and ->write_iter operations which use dax_iomap_rw() + when inode has S_DAX flag set - implementing an mmap file operation for DAX files which sets the VM_MIXEDMAP and VM_HUGEPAGE flags on the VMA, and setting the vm_ops to - include handlers for fault, pmd_fault and page_mkwrite (which should - probably call dax_fault(), dax_pmd_fault() and dax_mkwrite(), passing the - appropriate get_block() callback) -- calling dax_truncate_page() instead of block_truncate_page() for DAX files -- calling dax_zero_page_range() instead of zero_user() for DAX files + include handlers for fault, pmd_fault, page_mkwrite, pfn_mkwrite (which + should probably call dax_iomap_fault(), dax_iomap_pmd_fault(), + dax_pfn_mkwrite() passing the appropriate iomap operations) +- calling iomap_zero_range() passing appropriate iomap operations instead of + block_truncate_page() for DAX files - ensuring that there is sufficient locking between reads, writes, truncates and page faults -The get_block() callback passed to the DAX functions may return -uninitialised extents. If it does, it must ensure that simultaneous -calls to get_block() (for example by a page-fault racing with a read() -or a write()) work correctly. +The iomap handlers for allocating blocks must make sure that allocated blocks +are zeroed out and converted to written extents before being returned to avoid +exposure of uninitialized data through mmap. These filesystems may be used for inspiration: - ext2: see Documentation/filesystems/ext2.txt
fs/dax.c +0 -315
333 lines not on this page · raw message
include/linux/dax.h +0 -12
@@ -38,13 +38,8 @@ static inline void *dax_radix_locked_entry(sector_t sector, unsigned long flags)ssize_t dax_iomap_rw (struct kiocb *iocb,struct iov_iter *iter,struct iomap_ops *ops); -ssize_t dax_do_io (struct kiocb *,struct inode *,struct iov_iter *, -get_block_t ,dio_iodone_t ,int flags); -int dax_zero_page_range (struct inode *,loff_t from,unsigned len,get_block_t ); -int dax_truncate_page (struct inode *,loff_t from,get_block_t );int dax_iomap_fault (struct vm_area_struct *vma,struct vm_fault *vmf,struct iomap_ops *ops); -int dax_fault (struct vm_area_struct *,struct vm_fault *,get_block_t );int dax_delete_mapping_entry (struct address_space *mapping,pgoff_t index);void dax_wake_mapping_entry_waiter (struct address_space *mapping,pgoff_t index,void *entry,bool wake_all);
@@ -73,12 +68,6 @@ static inline int __dax_zero_page_range(struct block_device *bdev, }#endif -static inline int dax_pmd_fault (struct vm_area_struct *vma,unsigned long addr, -pmd_t *pmd,unsigned int flags,get_block_t gb) -{ -return VM_FAULT_FALLBACK ; -} -#ifdef CONFIG_FS_DAX_PMD static inline unsigned int dax_radix_order (void *entry) {
@@ -101,7 +90,6 @@ static inline int dax_iomap_pmd_fault(struct vm_area_struct *vma, }#endif int dax_pfn_mkwrite (struct vm_area_struct *,struct vm_fault *); -#define dax_mkwrite (vma, vmf, gb) dax_fault(vma, vmf, gb)static inline bool vma_is_dax (struct vm_area_struct *vma) {
Signature · 1 line
2.6.6
Re: [PATCH 11/11] dax: Rip out get_block based IO support
Quoted 22 lines · Jan Kara
No one uses functions using the
get_blockcallback anymore. Rip them out and update documentation.Signed-off-by Jan Kara <[email protected]>--- Documentation/filesystems/dax.txt | 21 ++- fs/dax.c | 315 -------------------------------------- include/linux/dax.h | 12 -- 3 files changed, 10 insertions(+), 338 deletions(-)Documentation/filesystems/dax.txt +2
-2@@ -58,22 +58,21 @@ Implementation Tips for Filesystem Writers Filesystem support consists of - adding support to mark inodes as being DAX by setting the S_DAX flag in i_flags -- implementing the direct_IO address space operation, and calling - dax_do_io() instead of blockdev_direct_IO() if S_DAX is set +- implementing ->read_iter and ->write_iter operations which use dax_iomap_rw() + when inode has S_DAX flag set
Documentation/filesystems/dax.txt Implementation Tips for Filesystem Writers · line 67
Quoted 10 lines
Documentation/filesystems/dax.txt +3
-5- implementing an mmap file operation for DAX files which sets the VM_MIXEDMAP and VM_HUGEPAGE flags on the VMA, and setting the vm_ops to - include handlers for fault, pmd_fault and page_mkwrite (which should - probably call dax_fault(), dax_pmd_fault() and dax_mkwrite(), passing the - appropriate get_block() callback) -- calling dax_truncate_page() instead of block_truncate_page() for DAX files -- calling dax_zero_page_range() instead of zero_user() for DAX files + include handlers for fault, pmd_fault, page_mkwrite, pfn_mkwrite (which + should probably call dax_iomap_fault(), dax_iomap_pmd_fault(), + dax_pfn_mkwrite() passing the appropriate iomap operations)
One tiny nit - the list of operations that the filesystem needs to support is 4 entries long (fault, pmd_fault, page_mkwrite, pfn_mkwrite), but the list of functions in DAX to call is only 3 entries long (dax_iomap_fault(), dax_iomap_pmd_fault(), dax_pfn_mkwrite()) This is probably because both fault() and page_mkwrite() end up calling dax_iomap_fault(). Can you please add a little text to make this clearer?
Yay for getting rid of the old buffer_head based DAX code!
Jan Kara
reviewerRe: [PATCH 11/11] dax: Rip out get_block based IO support
Quoted 32 lines · Ross Zwisler
Quoted 31 lines · Jan Kara
No one uses functions using the
get_blockcallback anymore. Rip them out and update documentation.Signed-off-by Jan Kara <[email protected]>--- Documentation/filesystems/dax.txt | 21 ++- fs/dax.c | 315 -------------------------------------- include/linux/dax.h | 12 -- 3 files changed, 10 insertions(+), 338 deletions(-)Documentation/filesystems/dax.txt +4
-7@@ -58,22 +58,21 @@ Implementation Tips for Filesystem Writers Filesystem support consists of - adding support to mark inodes as being DAX by setting the S_DAX flag in i_flags -- implementing the direct_IO address space operation, and calling - dax_do_io() instead of blockdev_direct_IO() if S_DAX is set +- implementing ->read_iter and ->write_iter operations which use dax_iomap_rw() + when inode has S_DAX flag set - implementing an mmap file operation for DAX files which sets the VM_MIXEDMAP and VM_HUGEPAGE flags on the VMA, and setting the vm_ops to - include handlers for fault, pmd_fault and page_mkwrite (which should - probably call dax_fault(), dax_pmd_fault() and dax_mkwrite(), passing the - appropriate get_block() callback) -- calling dax_truncate_page() instead of block_truncate_page() for DAX files -- calling dax_zero_page_range() instead of zero_user() for DAX files + include handlers for fault, pmd_fault, page_mkwrite, pfn_mkwrite (which + should probably call dax_iomap_fault(), dax_iomap_pmd_fault(),
Quoted 8 lines
Documentation/filesystems/dax.txt Implementation Tips for Filesystem Writers · line 67
Quoted 1 line
Documentation/filesystems/dax.txt +1
-0+ dax_pfn_mkwrite() passing the appropriate iomap operations)One tiny nit - the list of operations that the filesystem needs to support is 4 entries long (fault,
pmd_fault,page_mkwrite,pfn_mkwrite), but the list of functions in DAX to call is only 3 entries long (dax_iomap_fault(),dax_iomap_pmd_fault(),dax_pfn_mkwrite()) This is probably because bothfault()andpage_mkwrite()end up callingdax_iomap_fault(). Can you please add a little text to make this clearer?
OK, added.
Quoted 3 lines
Yay for getting rid of the old
buffer_headbased DAX code!Reviewed-by Ross Zwisler <[email protected]>
Thanks.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Jan Kara
Hello,
this is a second revision of my patches to convert ext4 DAX IO paths to the new iomap framework and removes the old bh-based DAX functions. As a result ext4 gains PMD page fault support, also some other minor bugs get fixed. The patch set is based on Ross' DAX PMD page fault support series [1]. It passes xfstests both in DAX and non-DAX mode.
Quoted 8 lines
I have pushed out updated version of these patches including the follow-up DAX patches to:
git://get.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.gitdaxfor easy testing. Once Dave pushes out a stable branch with Ross' patches, we pull those into ext4 tree and then pull these patches on top of that (provided nobody will have other objections to the current series).
Done:
git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.git dax-4.10-iomap-pmd
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 1 line · Dave Chinner
git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.gitdax-4.10-iomap-pmd
Can you add Jan's patch to add IOMAP_FAULT from the series we're replying to to the branch quickly as well? That way I can use it as the base for the next spin of the direct I/O series without creating conflicts.
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · Dave Chinner
git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.gitdax-4.10-iomap-pmdCan you add Jan's patch to add
IOMAP_FAULTfrom the series we're replying to to the branch quickly as well? That way I can use it as the base for the next spin of the direct I/O series without creating conflicts.
Ok, I'll add that now, and push out later today.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]