Btrfs: Add shared reference cache
Btrfs has a cache of reference counts in leaves, allowing it to avoid reading tree leaves while deleting snapshots. To reduce contention with multiple subvolumes, this cache is private to each subvolume. This patch adds shared reference cache support. The new space balancing code plays with multiple subvols at the same time, So the old per-subvol reference cache is not well suited. Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
@@ -1091,16 +1091,26 @@ out:
|
||||
int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
||||
struct extent_buffer *buf, u32 nr_extents)
|
||||
{
|
||||
u32 nritems;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_file_extent_item *fi;
|
||||
u64 root_gen;
|
||||
u32 nritems;
|
||||
int i;
|
||||
int level;
|
||||
int ret = 0;
|
||||
int shared = 0;
|
||||
|
||||
if (!root->ref_cows)
|
||||
return 0;
|
||||
|
||||
if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) {
|
||||
shared = 0;
|
||||
root_gen = root->root_key.offset;
|
||||
} else {
|
||||
shared = 1;
|
||||
root_gen = trans->transid - 1;
|
||||
}
|
||||
|
||||
level = btrfs_header_level(buf);
|
||||
nritems = btrfs_header_nritems(buf);
|
||||
|
||||
@@ -1114,7 +1124,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
||||
goto out;
|
||||
}
|
||||
|
||||
ref->root_gen = root->root_key.offset;
|
||||
ref->root_gen = root_gen;
|
||||
ref->bytenr = buf->start;
|
||||
ref->owner = btrfs_header_owner(buf);
|
||||
ref->generation = btrfs_header_generation(buf);
|
||||
@@ -1143,8 +1153,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
||||
info++;
|
||||
}
|
||||
|
||||
BUG_ON(!root->ref_tree);
|
||||
ret = btrfs_add_leaf_ref(root, ref);
|
||||
ret = btrfs_add_leaf_ref(root, ref, shared);
|
||||
WARN_ON(ret);
|
||||
btrfs_free_leaf_ref(root, ref);
|
||||
}
|
||||
|
Reference in New Issue
Block a user