Skip to content

Commit 9faac62

Browse files
riteshharjanitytso
authored andcommitted
ext4: optimize file overwrites
In case if the file already has underlying blocks/extents allocated then we don't need to start a journal txn and can directly return the underlying mapping. Currently ext4_iomap_begin() is used by both DAX & DIO path. We can check if the write request is an overwrite & then directly return the mapping information. This could give a significant perf boost for multi-threaded writes specially random overwrites. On PPC64 VM with simulated pmem(DAX) device, ~10x perf improvement could be seen in random writes (overwrite). Also bcoz this optimizes away the spinlock contention during jbd2 slab cache allocation (jbd2_journal_handle). On x86 VM, ~2x perf improvement was observed. Reported-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com> Link: https://lore.kernel.org/r/88e795d8a4d5cd22165c7ebe857ba91d68d8813e.1600401668.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 7eb90a2 commit 9faac62

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎fs/ext4/inode.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,14 +3436,26 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
34363436
map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits,
34373437
EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1;
34383438

3439-
if (flags & IOMAP_WRITE)
3439+
if (flags & IOMAP_WRITE) {
3440+
/*
3441+
* We check here if the blocks are already allocated, then we
3442+
* don't need to start a journal txn and we can directly return
3443+
* the mapping information. This could boost performance
3444+
* especially in multi-threaded overwrite requests.
3445+
*/
3446+
if (offset + length <= i_size_read(inode)) {
3447+
ret = ext4_map_blocks(NULL, inode, &map, 0);
3448+
if (ret > 0 && (map.m_flags & EXT4_MAP_MAPPED))
3449+
goto out;
3450+
}
34403451
ret = ext4_iomap_alloc(inode, &map, flags);
3441-
else
3452+
} else {
34423453
ret = ext4_map_blocks(NULL, inode, &map, 0);
3454+
}
34433455

34443456
if (ret < 0)
34453457
return ret;
3446-
3458+
out:
34473459
ext4_set_iomap(inode, iomap, &map, offset, length);
34483460

34493461
return 0;

0 commit comments

Comments
 (0)