Add dirty range scoping to jbd2
Subsystems (6)
v2 cover Add dirty range scoping to jbd2
Changes from v1:
- Relocated the code which resets dirty range upon transaction completion. (Jan)
- Cc'd [email protected] because we see this issue with v4.14 and v4.19 stable kernels in the field.
---
This patch series fixes the issue I described here:
https://www.spinics.net/lists/linux-block/msg38274.html
Essentially the issue is that journal_finish_inode_data_buffers() operates on the entire address space of each of the inodes associated with a given journal entry. This means that if we have an inode where we are constantly appending dirty pages we can end up waiting for an indefinite amount of time in journal_finish_inode_data_buffers().
This series improves this situation in ext4 by scoping each of the inode dirty ranges associated with a given transaction. Other users of jbd2 which don't (yet?) take advantage of this scoping (ocfs2) will continue to have the old behavior.
Ross Zwisler (3):
mm: add filemap_fdatawait_range_keep_errors()
jbd2: introduce jbd2_inode dirty range scoping
ext4: use jbd2_inode dirty range scoping
fs/ext4/ext4_jbd2.h | 12 +++++------ fs/ext4/inode.c | 13 +++++++++--- fs/ext4/move_extent.c | 3 ++- fs/jbd2/commit.c | 23 ++++++++++++++------ fs/jbd2/journal.c | 2 ++ fs/jbd2/transaction.c | 49 ++++++++++++++++++++++++------------------- include/linux/fs.h | 2 ++ include/linux/jbd2.h | 22 +++++++++++++++++++ mm/filemap.c | 22 +++++++++++++++++++ 9 files changed, 111 insertions(+), 37 deletions(-)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 1/3 mm: add filemap_fdatawait_range_keep_errors()
In the spirit of filemap_fdatawait_range() and filemap_fdatawait_keep_errors(), introduce filemap_fdatawait_range_keep_errors() which both takes a range upon which to wait and does not clear errors from the address space.
--- include/linux/fs.h | 2 ++ mm/filemap.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/linux/fs.h +2 -0
@@ -2712,6 +2712,8 @@ extern int filemap_flush(struct address_space *);extern int filemap_fdatawait_keep_errors (struct address_space *mapping);extern int filemap_fdatawait_range (struct address_space *,loff_t lstart,loff_t lend); +extern int filemap_fdatawait_range_keep_errors (struct address_space *mapping, +loff_t start_byte,loff_t end_byte);static inline int filemap_fdatawait (struct address_space *mapping) {
mm/filemap.c +22 -0
@@ -553,6 +553,28 @@ int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte, }EXPORT_SYMBOL (filemap_fdatawait_range); +/** +* filemap_fdatawait_range_keep_errors - wait for writeback to complete +* @mapping: address space structure to wait for +* @start_byte: offset in bytes where the range starts +* @end_byte: offset in bytes where the range ends (inclusive) +* +* Walk the list of under-writeback pages of the given address space in the +* given range and wait for all of them. Unlike filemap_fdatawait_range(), +* this function does not clear error status of the address space. +* +* Use this function if callers don't handle errors themselves. Expected +* call sites are system-wide / filesystem-wide data flushers: e.g. sync(2), +* fsfreeze(8) +*/ +int filemap_fdatawait_range_keep_errors (struct address_space *mapping, +loff_t start_byte,loff_t end_byte) +{ +__filemap_fdatawait_range (mapping, start_byte, end_byte); +return filemap_check_and_keep_errors (mapping); +} +EXPORT_SYMBOL (filemap_fdatawait_range_keep_errors); +/** * file_fdatawait_range - wait for writeback to complete * @file: file pointing to address space structure to wait for
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 2/3 jbd2: introduce jbd2_inode dirty range scoping
In reply to Ross ZwislerCurrently both journal_submit_inode_data_buffers() and journal_finish_inode_data_buffers() operate on the entire address space of each of the inodes associated with a given journal entry. The consequence of this is that if we have an inode where we are constantly appending dirty pages we can end up waiting for an indefinite amount of time in journal_finish_inode_data_buffers() while we wait for all the pages under writeback to be written out.
The easiest way to cause this type of workload is do just dd from /dev/zero to a file until it fills the entire filesystem. This can cause journal_finish_inode_data_buffers() to wait for the duration of the entire dd operation.
We can improve this situation by scoping each of the inode dirty ranges associated with a given transaction. We do this via the jbd2_inode structure so that the scoping is contained within jbd2 and so that it follows the lifetime and locking rules for that structure.
This allows us to limit the writeback & wait in journal_submit_inode_data_buffers() and journal_finish_inode_data_buffers() respectively to the dirty range for a given struct jdb2_inode, keeping us from waiting forever if the inode in question is still being appended to.
--- fs/jbd2/commit.c | 23 ++++++++++++++------ fs/jbd2/journal.c | 2 ++ fs/jbd2/transaction.c | 49 ++++++++++++++++++++++++------------------- include/linux/jbd2.h | 22 +++++++++++++++++++ 4 files changed, 69 insertions(+), 27 deletions(-)
fs/jbd2/commit.c +17 -6
@@ -187,14 +187,15 @@ static int journal_wait_on_commit_record(journal_t *journal,* use writepages() because with dealyed allocation we may be doing * block allocation in writepages(). */ -static int journal_submit_inode_data_buffers (struct address_space *mapping) +static int journal_submit_inode_data_buffers (struct address_space *mapping, +loff_t dirty_start,loff_t dirty_end) {int ret;struct writeback_control wbc = { .sync_mode =WB_SYNC_ALL , .nr_to_write = mapping->nrpages *2 , - .range_start =0 , - .range_end =i_size_read (mapping->host), + .range_start = dirty_start, + .range_end = dirty_end, }; ret =generic_writepages (mapping, &wbc);
@@ -218,6 +219,9 @@ static int journal_submit_data_buffers(journal_t *journal,spin_lock (&journal->j_list_lock);list_for_each_entry (jinode, &commit_transaction->t_inode_list, i_list) { +loff_t dirty_start = jinode->i_dirty_start; +loff_t dirty_end = jinode->i_dirty_end; +if (!(jinode->i_flags &JI_WRITE_DATA ))continue ; mapping = jinode->i_vfs_inode->i_mapping;
@@ -230,7 +234,8 @@ static int journal_submit_data_buffers(journal_t *journal,* only allocated blocks here. */ trace_jbd2_submit_inode_data (jinode->i_vfs_inode); - err =journal_submit_inode_data_buffers (mapping); + err =journal_submit_inode_data_buffers (mapping, dirty_start, + dirty_end);if (!ret) ret = err;spin_lock (&journal->j_list_lock);
@@ -257,12 +262,16 @@ static int journal_finish_inode_data_buffers(journal_t *journal,/* For locking, see the comment in journal_submit_data_buffers() */ spin_lock (&journal->j_list_lock);list_for_each_entry (jinode, &commit_transaction->t_inode_list, i_list) { +loff_t dirty_start = jinode->i_dirty_start; +loff_t dirty_end = jinode->i_dirty_end; +if (!(jinode->i_flags &JI_WAIT_DATA ))continue ; jinode->i_flags |=JI_COMMIT_RUNNING ;spin_unlock (&journal->j_list_lock); - err =filemap_fdatawait_keep_errors ( - jinode->i_vfs_inode->i_mapping); + err =filemap_fdatawait_range_keep_errors ( + jinode->i_vfs_inode->i_mapping, dirty_start, + dirty_end);if (!ret) ret = err;spin_lock (&journal->j_list_lock);
@@ -282,6 +291,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal, &jinode->i_transaction->t_inode_list); }else { jinode->i_transaction =NULL ; + jinode->i_dirty_start =0 ; + jinode->i_dirty_end =0 ; } }spin_unlock (&journal->j_list_lock);
fs/jbd2/journal.c +2 -0
@@ -2574,6 +2574,8 @@ void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode) jinode->i_next_transaction =NULL ; jinode->i_vfs_inode = inode; jinode->i_flags =0 ; + jinode->i_dirty_start =0 ; + jinode->i_dirty_end =0 ;INIT_LIST_HEAD (&jinode->i_list); }
fs/jbd2/transaction.c +28 -21
73 lines not on this page · raw message
include/linux/jbd2.h +22 -0
@@ -451,6 +451,22 @@ struct jbd2_inode {* @i_flags: Flags of inode [j_list_lock] */ unsigned long i_flags; + +/** +* @i_dirty_start: +* +* Offset in bytes where the dirty range for this inode starts. +* [j_list_lock] +*/ +loff_t i_dirty_start; + +/** +* @i_dirty_end: +* +* Inclusive offset in bytes where the dirty range for this inode +* ends. [j_list_lock] +*/ +loff_t i_dirty_end; };struct jbd2_revoke_table_s ;
@@ -1397,6 +1413,12 @@ extern int jbd2_journal_force_commit(journal_t *);extern int jbd2_journal_force_commit_nested (journal_t *);extern int jbd2_journal_inode_add_write (handle_t *handle,struct jbd2_inode *inode);extern int jbd2_journal_inode_add_wait (handle_t *handle,struct jbd2_inode *inode); +extern int jbd2_journal_inode_ranged_write (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length); +extern int jbd2_journal_inode_ranged_wait (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length);extern int jbd2_journal_begin_ordered_truncate (journal_t *journal,struct jbd2_inode *inode,loff_t new_size);extern void jbd2_journal_init_jbd_inode (struct jbd2_inode *jinode,struct inode *inode);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Re: [PATCH v2 2/3] jbd2: introduce jbd2_inode dirty range scoping
Quoted 7 lines · Ross Zwisler
include/linux/jbd2.h +0
-0@@ -1397,6 +1413,12 @@ extern int jbd2_journal_force_commit(journal_t *);extern int jbd2_journal_force_commit_nested (journal_t *);extern int jbd2_journal_inode_add_write (handle_t *handle,struct jbd2_inode *inode);
include/linux/jbd2.h extern int jbd2_journal_force_commit(journal_t *); · line 1424
Quoted 10 lines
include/linux/jbd2.h +6
-0extern int jbd2_journal_inode_add_wait (handle_t *handle,struct jbd2_inode *inode); +extern int jbd2_journal_inode_ranged_write (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length); +extern int jbd2_journal_inode_ranged_wait (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length);extern int jbd2_journal_begin_ordered_truncate (journal_t *journal,struct jbd2_inode *inode,loff_t new_size);extern void jbd2_journal_init_jbd_inode (struct jbd2_inode *jinode,struct inode *inode);
You're adding two new functions that are called from outside the jbd2 subsystem. To support compiling jbd2 as a module, we also need to add EXPORT_SYMBOL declarations for these two functions.
I'll take care of this when applying this change.
Thanks, applied.
- Ted
Re: [PATCH v2 2/3] jbd2: introduce jbd2_inode dirty range scoping
Quoted 23 lines · Theodore Ts'o
Quoted 7 lines · Ross Zwisler
include/linux/jbd2.h +0
-0@@ -1397,6 +1413,12 @@ extern int jbd2_journal_force_commit(journal_t *);extern int jbd2_journal_force_commit_nested (journal_t *);extern int jbd2_journal_inode_add_write (handle_t *handle,struct jbd2_inode *inode);include/linux/jbd2.h extern int jbd2_journal_force_commit(journal_t *); · line 1424
Quoted 10 lines
include/linux/jbd2.h +6
-0extern int jbd2_journal_inode_add_wait (handle_t *handle,struct jbd2_inode *inode); +extern int jbd2_journal_inode_ranged_write (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length); +extern int jbd2_journal_inode_ranged_wait (handle_t *handle, +struct jbd2_inode *inode,loff_t start_byte, +loff_t length);extern int jbd2_journal_begin_ordered_truncate (journal_t *journal,struct jbd2_inode *inode,loff_t new_size);extern void jbd2_journal_init_jbd_inode (struct jbd2_inode *jinode,struct inode *inode);You're adding two new functions that are called from outside the jbd2 subsystem. To support compiling jbd2 as a module, we also need to add
EXPORT_SYMBOLdeclarations for these two functions.
Quoted 1 line
I'll take care of this when applying this change.
Ah, yep, great catch. Thanks!
PATCH v2 3/3 ext4: use jbd2_inode dirty range scoping
In reply to Ross ZwislerUse the newly introduced jbd2_inode dirty range scoping to prevent us from waiting forever when trying to complete a journal transaction.
--- fs/ext4/ext4_jbd2.h | 12 ++++++------ fs/ext4/inode.c | 13 ++++++++++--- fs/ext4/move_extent.c | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-)
fs/ext4/ext4_jbd2.h +6 -6
@@ -361,20 +361,20 @@ static inline int ext4_journal_force_commit(journal_t *journal) }static inline int ext4_jbd2_inode_add_write (handle_t *handle, -struct inode *inode) +struct inode *inode,loff_t start_byte,loff_t length) {if (ext4_handle_valid (handle)) -return jbd2_journal_inode_add_write (handle, -EXT4_I (inode)->jinode); +return jbd2_journal_inode_ranged_write (handle, +EXT4_I (inode)->jinode, start_byte, length);return 0 ; }static inline int ext4_jbd2_inode_add_wait (handle_t *handle, -struct inode *inode) +struct inode *inode,loff_t start_byte,loff_t length) {if (ext4_handle_valid (handle)) -return jbd2_journal_inode_add_wait (handle, -EXT4_I (inode)->jinode); +return jbd2_journal_inode_ranged_wait (handle, +EXT4_I (inode)->jinode, start_byte, length);return 0 ; }
fs/ext4/inode.c +10 -3
@@ -731,10 +731,16 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, !(flags & EXT4_GET_BLOCKS_ZERO) && !ext4_is_quota_file(inode) && ext4_should_order_data(inode)) { +loff_t start_byte = + (loff_t )map->m_lblk << inode->i_blkbits; +loff_t length = (loff_t )map->m_len << inode->i_blkbits; +if (flags &EXT4_GET_BLOCKS_IO_SUBMIT ) - ret =ext4_jbd2_inode_add_wait (handle, inode); + ret =ext4_jbd2_inode_add_wait (handle, inode, + start_byte, length);else - ret =ext4_jbd2_inode_add_write (handle, inode); + ret =ext4_jbd2_inode_add_write (handle, inode, + start_byte, length);if (ret)return ret; }
@@ -4085,7 +4091,8 @@ static int __ext4_block_zero_page_range(handle_t *handle, err =0 ;mark_buffer_dirty (bh);if (ext4_should_order_data (inode)) - err =ext4_jbd2_inode_add_write (handle, inode); + err =ext4_jbd2_inode_add_write (handle, inode, from, + length); } unlock:
fs/ext4/move_extent.c +2 -1
@@ -390,7 +390,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,/* Even in case of data=writeback it is reasonable to pin * inode to transaction, to prevent unexpected data loss */ - *err =ext4_jbd2_inode_add_write (handle, orig_inode); + *err =ext4_jbd2_inode_add_write (handle, orig_inode, + (loff_t )orig_page_offset <<PAGE_SHIFT , replaced_size); unlock_pages:unlock_page (pagep[0 ]);
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
Re: [PATCH v2 3/3] ext4: use jbd2_inode dirty range scoping
Quoted 6 lines · Ross Zwisler
Use the newly introduced
jbd2_inodedirty range scoping to prevent us from waiting forever when trying to complete a journal transaction.Signed-off-by Ross Zwisler <[email protected]>Reviewed-by Jan Kara <[email protected]>
Applied, thanks.
- Ted
kbuild test robot
build botRe: [PATCH v2 3/3] ext4: use jbd2_inode dirty range scoping
In reply to Ross ZwislerThank you for the patch! Yet something to improve:
Hi Ross,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Ross-Zwisler/mm-add-filemap_fdatawait_range_keep_errors/20190623-181603
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
>> ERROR: "jbd2_journal_inode_ranged_wait" [fs/ext4/ext4.ko] undefined! >> ERROR: "jbd2_journal_inode_ranged_write" [fs/ext4/ext4.ko] undefined!
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v2 3/3] ext4: use jbd2_inode dirty range scoping
Quoted 12 lines · kbuild test robot
Hi Ross,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.2-rc6 next-20190621]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Ross-Zwisler/mm-add-filemap_fdatawait_range_keep_errors/20190623-181603
config: x86_64-rhel-7.6 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:
Quoted 10 lines
# save the attached .config to linux build tree make ARCH=x86_64If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All errors (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
ERROR: "
jbd2_journal_inode_ranged_wait" [fs/ext4/ext4.ko] undefined!
ERROR: "jbd2_journal_inode_ranged_write" [fs/ext4/ext4.ko] undefined!
Yep, this is caused by the lack of EXPORT_SYMBOL() calls for these two new jbd2 functions. Ted also pointed this out and fixed this up when he was committing:
https://patchwork.kernel.org/patch/11007139/#22717091
Thank you for the report!