btrfs: let callers of btrfs_get_io_geometry pass the em
authorMichal Rostecki <mrostecki@suse.com>
Wed, 27 Jan 2021 13:57:27 +0000 (14:57 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 8 Feb 2021 21:59:00 +0000 (22:59 +0100)
commit420343131970fd29db129b308612f9364b06df0b
tree973c0c539d607271392e11f5b1afa3c3ddb26cd5
parent951c80f83d61bd4b21794c8aba829c3c1a45c2d0
btrfs: let callers of btrfs_get_io_geometry pass the em

Before this change, the btrfs_get_io_geometry() function was calling
btrfs_get_chunk_map() to get the extent mapping, necessary for
calculating the I/O geometry. It was using that extent mapping only
internally and freeing the pointer after its execution.

That resulted in calling btrfs_get_chunk_map() de facto twice by the
__btrfs_map_block() function. It was calling btrfs_get_io_geometry()
first and then calling btrfs_get_chunk_map() directly to get the extent
mapping, used by the rest of the function.

Change that to passing the extent mapping to the btrfs_get_io_geometry()
function as an argument.

This could improve performance in some cases.  For very large
filesystems, i.e. several thousands of allocated chunks, not only this
avoids searching two times the rbtree, saving time, it may also help
reducing contention on the lock that protects the tree - thinking of
writeback starting for multiple inodes, other tasks allocating or
removing chunks, and anything else that requires access to the rbtree.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Michal Rostecki <mrostecki@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ add Filipe's analysis ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h