Add shared reference cache
PATCH 2/4 Add shared reference cache
Hello,
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 isn't fit for it.
Regards
Yan Zheng
---
ctree.h +12 -7
@@ -80,6 +80,10 @@/* does write ahead logging to speed up fsyncs */ #define BTRFS_TREE_LOG_OBJECTID -6ULL#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL + +/* for space balancing */ +#define BTRFS_TREE_RELOC_OBJECTID -8ULL +#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL/* dummy objectid represents multiple objectids */ #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
@@ -539,6 +543,12 @@struct list_head list; }; +struct btrfs_leaf_ref_tree { +struct rb_root root; +struct list_head list; +spinlock_t lock; +}; +struct btrfs_device ;struct btrfs_fs_devices ;struct btrfs_fs_info {
@@ -637,6 +647,8 @@struct task_struct *cleaner_kthread;int thread_pool_size; +struct btrfs_leaf_ref_tree shared_ref_tree; +struct kobject super_kobj;struct completion kobj_unregister;int do_barriers;
@@ -668,13 +680,6 @@u64 system_alloc_profile;void *bdev_holder; -}; - -struct btrfs_leaf_ref_tree { -struct rb_root root; -struct btrfs_leaf_ref *last; -struct list_head list; -spinlock_t lock; };/*
disk-io.c +2 -0
@@ -1430,6 +1430,8 @@ fs_info->btree_inode->i_mapping, GFP_NOFS); fs_info->do_barriers =1 ; +btrfs_leaf_ref_tree_init (&fs_info->shared_ref_tree); +BTRFS_I (fs_info->btree_inode)->root = tree_root;memset (&BTRFS_I (fs_info->btree_inode)->location,0 ,sizeof (struct btrfs_key ));
extent-tree.c +16 -7
@@ -1091,15 +1091,25 @@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; -int i; -int level; -int ret =0 ; +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 @@ 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 @@ 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); }
ref-cache.c +38 -20
112 lines not on this page · raw message
ref-cache.h +5 -2
@@ -27,6 +27,7 @@struct btrfs_leaf_ref {struct rb_node rb_node; +struct btrfs_leaf_ref_tree *tree;int in_tree;atomic_t usage;
@@ -64,8 +65,10 @@void btrfs_free_leaf_ref (struct btrfs_root *root,struct btrfs_leaf_ref *ref);struct btrfs_leaf_ref *btrfs_lookup_leaf_ref (struct btrfs_root *root,u64 bytenr); -int btrfs_add_leaf_ref (struct btrfs_root *root,struct btrfs_leaf_ref *ref); -int btrfs_remove_leaf_refs (struct btrfs_root *root,u64 max_root_gen); +int btrfs_add_leaf_ref (struct btrfs_root *root,struct btrfs_leaf_ref *ref, +int shared); +int btrfs_remove_leaf_refs (struct btrfs_root *root,u64 max_root_gen, +int shared);int btrfs_remove_leaf_ref (struct btrfs_root *root,struct btrfs_leaf_ref *ref);#endif
transaction.c +1 -1
@@ -650,7 +650,7 @@ ret =btrfs_end_transaction (trans, tree_root);BUG_ON (ret); - ret =btrfs_remove_leaf_refs (root, max_useless); + ret =btrfs_remove_leaf_refs (root, max_useless,0 );BUG_ON (ret);free_extent_buffer (dirty->root->node);