Skip to content

Commit ee0876b

Browse files
jankaratytso
authored andcommitted
ext4: do not ask jbd2 to write data for delalloc buffers
Currently we ask jbd2 to write all dirty allocated buffers before committing a transaction when doing writeback of delay allocated blocks. However this is unnecessary since we move all pages to writeback state before dropping a transaction handle and then submit all the necessary IO. We still need the transaction commit to wait for all the outstanding writeback before flushing disk caches during transaction commit to avoid data exposure issues though. Use the new jbd2 capability and ask it to only wait for outstanding writeback during transaction commit when writing back data in ext4_writepages(). Tested-by: "HUANG Weller (CM/ESW12-CN)" <Weller.Huang@cn.bosch.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 41617e1 commit ee0876b

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ enum {
581581
#define EXT4_GET_BLOCKS_ZERO 0x0200
582582
#define EXT4_GET_BLOCKS_CREATE_ZERO (EXT4_GET_BLOCKS_CREATE |\
583583
EXT4_GET_BLOCKS_ZERO)
584+
/* Caller will submit data before dropping transaction handle. This
585+
* allows jbd2 to avoid submitting data before commit. */
586+
#define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400
584587

585588
/*
586589
* The bit position of these flags must not overlap with any of the

‎fs/ext4/ext4_jbd2.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,24 @@ static inline int ext4_journal_force_commit(journal_t *journal)
359359
return 0;
360360
}
361361

362-
static inline int ext4_jbd2_file_inode(handle_t *handle, struct inode *inode)
362+
static inline int ext4_jbd2_inode_add_write(handle_t *handle,
363+
struct inode *inode)
363364
{
364365
if (ext4_handle_valid(handle))
365366
return jbd2_journal_inode_add_write(handle,
366367
EXT4_I(inode)->jinode);
367368
return 0;
368369
}
369370

371+
static inline int ext4_jbd2_inode_add_wait(handle_t *handle,
372+
struct inode *inode)
373+
{
374+
if (ext4_handle_valid(handle))
375+
return jbd2_journal_inode_add_wait(handle,
376+
EXT4_I(inode)->jinode);
377+
return 0;
378+
}
379+
370380
static inline void ext4_update_inode_fsync_trans(handle_t *handle,
371381
struct inode *inode,
372382
int datasync)

‎fs/ext4/inode.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
695695
!(flags & EXT4_GET_BLOCKS_ZERO) &&
696696
!IS_NOQUOTA(inode) &&
697697
ext4_should_order_data(inode)) {
698-
ret = ext4_jbd2_file_inode(handle, inode);
698+
if (flags & EXT4_GET_BLOCKS_IO_SUBMIT)
699+
ret = ext4_jbd2_inode_add_wait(handle, inode);
700+
else
701+
ret = ext4_jbd2_inode_add_write(handle, inode);
699702
if (ret)
700703
return ret;
701704
}
@@ -2319,7 +2322,8 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd)
23192322
* the data was copied into the page cache.
23202323
*/
23212324
get_blocks_flags = EXT4_GET_BLOCKS_CREATE |
2322-
EXT4_GET_BLOCKS_METADATA_NOFAIL;
2325+
EXT4_GET_BLOCKS_METADATA_NOFAIL |
2326+
EXT4_GET_BLOCKS_IO_SUBMIT;
23232327
dioread_nolock = ext4_should_dioread_nolock(inode);
23242328
if (dioread_nolock)
23252329
get_blocks_flags |= EXT4_GET_BLOCKS_IO_CREATE_EXT;
@@ -3634,7 +3638,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
36343638
err = 0;
36353639
mark_buffer_dirty(bh);
36363640
if (ext4_should_order_data(inode))
3637-
err = ext4_jbd2_file_inode(handle, inode);
3641+
err = ext4_jbd2_inode_add_write(handle, inode);
36383642
}
36393643

36403644
unlock:

‎fs/ext4/move_extent.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
400400

401401
/* Even in case of data=writeback it is reasonable to pin
402402
* inode to transaction, to prevent unexpected data loss */
403-
*err = ext4_jbd2_file_inode(handle, orig_inode);
403+
*err = ext4_jbd2_inode_add_write(handle, orig_inode);
404404

405405
unlock_pages:
406406
unlock_page(pagep[0]);

0 commit comments

Comments
 (0)