diff options
author | Zheng Yan <zheng.yan@oracle.com> | 2008-09-26 10:04:53 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-26 10:04:53 -0400 |
commit | e465768938f95388723b0fd3c50a0ae48173edb9 (patch) | |
tree | 0f624a9a98dedfafae902e12b384d27e1100cd3a /fs/btrfs/extent-tree.c | |
parent | e8569813849b5da394a195c7e76b4faa452b12d1 (diff) |
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>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3e2f969de42d..9ab099bc01a4 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -1091,16 +1091,26 @@ out: | |||
1091 | int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 1091 | int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1092 | struct extent_buffer *buf, u32 nr_extents) | 1092 | struct extent_buffer *buf, u32 nr_extents) |
1093 | { | 1093 | { |
1094 | u32 nritems; | ||
1095 | struct btrfs_key key; | 1094 | struct btrfs_key key; |
1096 | struct btrfs_file_extent_item *fi; | 1095 | struct btrfs_file_extent_item *fi; |
1096 | u64 root_gen; | ||
1097 | u32 nritems; | ||
1097 | int i; | 1098 | int i; |
1098 | int level; | 1099 | int level; |
1099 | int ret = 0; | 1100 | int ret = 0; |
1101 | int shared = 0; | ||
1100 | 1102 | ||
1101 | if (!root->ref_cows) | 1103 | if (!root->ref_cows) |
1102 | return 0; | 1104 | return 0; |
1103 | 1105 | ||
1106 | if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { | ||
1107 | shared = 0; | ||
1108 | root_gen = root->root_key.offset; | ||
1109 | } else { | ||
1110 | shared = 1; | ||
1111 | root_gen = trans->transid - 1; | ||
1112 | } | ||
1113 | |||
1104 | level = btrfs_header_level(buf); | 1114 | level = btrfs_header_level(buf); |
1105 | nritems = btrfs_header_nritems(buf); | 1115 | nritems = btrfs_header_nritems(buf); |
1106 | 1116 | ||
@@ -1114,7 +1124,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
1114 | goto out; | 1124 | goto out; |
1115 | } | 1125 | } |
1116 | 1126 | ||
1117 | ref->root_gen = root->root_key.offset; | 1127 | ref->root_gen = root_gen; |
1118 | ref->bytenr = buf->start; | 1128 | ref->bytenr = buf->start; |
1119 | ref->owner = btrfs_header_owner(buf); | 1129 | ref->owner = btrfs_header_owner(buf); |
1120 | ref->generation = btrfs_header_generation(buf); | 1130 | ref->generation = btrfs_header_generation(buf); |
@@ -1143,8 +1153,7 @@ int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
1143 | info++; | 1153 | info++; |
1144 | } | 1154 | } |
1145 | 1155 | ||
1146 | BUG_ON(!root->ref_tree); | 1156 | ret = btrfs_add_leaf_ref(root, ref, shared); |
1147 | ret = btrfs_add_leaf_ref(root, ref); | ||
1148 | WARN_ON(ret); | 1157 | WARN_ON(ret); |
1149 | btrfs_free_leaf_ref(root, ref); | 1158 | btrfs_free_leaf_ref(root, ref); |
1150 | } | 1159 | } |