btrfs: reduce lock contention when eb cache miss for btree search
authorRobbie Ko <robbieko@synology.com>
Tue, 15 Oct 2024 07:41:37 +0000 (15:41 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 11 Nov 2024 13:34:17 +0000 (14:34 +0100)
commit99785998ed1cea142e20f4904ced26537a37bf74
tree6a74924622cadb1e916864a2ba97a9882c978884
parenta9c50c975656e551ea4bfe0f292b05d0e2a664c5
btrfs: reduce lock contention when eb cache miss for btree search

When crawling btree, if an eb cache miss occurs, we change to use the eb
read lock and release all previous locks (including the parent lock) to
reduce lock contention.

If an eb cache miss occurs in a leaf and needs to execute IO, before this
change we released locks only from level 2 and up and we read a leaf's
content from disk while holding a lock on its parent (level 1), causing
the unnecessary lock contention on the parent, after this change we
release locks from level 1 and up, but we lock level 0, and read leaf's
content from disk.

Because we have prepared the check parameters and the read lock of eb we
hold, we can ensure that no race will occur during the check and cause
unexpected errors.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.c