mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
btrfs: use a bit to track the existence of tree mod log users
The tree modification log functions are called very frequently, basically they are called every time a btree is modified (a pointer added or removed to a node, a new root for a btree is set, etc). Because of that, to avoid heavy lock contention on the lock that protects the list of tree mod log users, we have checks that test the emptiness of the list with a full memory barrier before the checks, so that when there are no tree mod log users we avoid taking the lock. Replace the memory barrier and list emptiness check with a test for a new bit set at fs_info->flags. This bit is used to indicate when there are tree mod log users, set whenever a user is added to the list and cleared when the last user is removed from the list. This makes the intention a bit more obvious and possibly more efficient (assuming test_bit() may be cheaper than a full memory barrier on some architectures). Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
406808ab2f
commit
bc03f39ec3
2 changed files with 9 additions and 5 deletions
|
@ -562,6 +562,9 @@ enum {
|
||||||
|
|
||||||
/* Indicate that we can't trust the free space tree for caching yet */
|
/* Indicate that we can't trust the free space tree for caching yet */
|
||||||
BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
|
BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
|
||||||
|
|
||||||
|
/* Indicate whether there are any tree modification log users */
|
||||||
|
BTRFS_FS_TREE_MOD_LOG_USERS,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -60,6 +60,7 @@ u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
|
||||||
if (!elem->seq) {
|
if (!elem->seq) {
|
||||||
elem->seq = btrfs_inc_tree_mod_seq(fs_info);
|
elem->seq = btrfs_inc_tree_mod_seq(fs_info);
|
||||||
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
|
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
|
||||||
|
set_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags);
|
||||||
}
|
}
|
||||||
write_unlock(&fs_info->tree_mod_log_lock);
|
write_unlock(&fs_info->tree_mod_log_lock);
|
||||||
|
|
||||||
|
@ -83,7 +84,9 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
|
||||||
list_del(&elem->list);
|
list_del(&elem->list);
|
||||||
elem->seq = 0;
|
elem->seq = 0;
|
||||||
|
|
||||||
if (!list_empty(&fs_info->tree_mod_seq_list)) {
|
if (list_empty(&fs_info->tree_mod_seq_list)) {
|
||||||
|
clear_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags);
|
||||||
|
} else {
|
||||||
struct btrfs_seq_list *first;
|
struct btrfs_seq_list *first;
|
||||||
|
|
||||||
first = list_first_entry(&fs_info->tree_mod_seq_list,
|
first = list_first_entry(&fs_info->tree_mod_seq_list,
|
||||||
|
@ -166,8 +169,7 @@ static noinline int tree_mod_log_insert(struct btrfs_fs_info *fs_info,
|
||||||
static inline bool tree_mod_dont_log(struct btrfs_fs_info *fs_info,
|
static inline bool tree_mod_dont_log(struct btrfs_fs_info *fs_info,
|
||||||
struct extent_buffer *eb)
|
struct extent_buffer *eb)
|
||||||
{
|
{
|
||||||
smp_mb();
|
if (!test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags))
|
||||||
if (list_empty(&(fs_info)->tree_mod_seq_list))
|
|
||||||
return true;
|
return true;
|
||||||
if (eb && btrfs_header_level(eb) == 0)
|
if (eb && btrfs_header_level(eb) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -185,8 +187,7 @@ static inline bool tree_mod_dont_log(struct btrfs_fs_info *fs_info,
|
||||||
static inline bool tree_mod_need_log(const struct btrfs_fs_info *fs_info,
|
static inline bool tree_mod_need_log(const struct btrfs_fs_info *fs_info,
|
||||||
struct extent_buffer *eb)
|
struct extent_buffer *eb)
|
||||||
{
|
{
|
||||||
smp_mb();
|
if (!test_bit(BTRFS_FS_TREE_MOD_LOG_USERS, &fs_info->flags))
|
||||||
if (list_empty(&(fs_info)->tree_mod_seq_list))
|
|
||||||
return false;
|
return false;
|
||||||
if (eb && btrfs_header_level(eb) == 0)
|
if (eb && btrfs_header_level(eb) == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue