btrfs: add per subvolume cached inode tree
PATCH 5/6 btrfs: add per subvolume cached inode tree
This patch adds per subvolume red-black tree to keep trace of cached inodes. The red-black tree helps the balancing code to find cached inodes whose inode numbers within a given range.
Signed-off-by Yan Zheng <[email protected]>
---
fs/btrfs/btrfs_inode.h +3 -0
@@ -72,6 +72,9 @@ struct btrfs_inode {*/ struct list_head ordered_operations; +/* node for the red-black tree that links inodes in subvolume root */ +struct rb_node rb_node; +/* the space_info for where this inode's data allocations are done */ struct btrfs_space_info *space_info;
fs/btrfs/ctree.h +5 -6
@@ -981,6 +981,10 @@ struct btrfs_root {spinlock_t list_lock;struct list_head orphan_list; +spinlock_t inode_lock; +/* red-black tree that keeps track of in-memory inodes */ +struct rb_root inode_tree; +/* * right now this just gets used so that a root has its own devid * for stat. It may be used for more later
@@ -2175,7 +2179,6 @@ int btrfs_page_mkwrite(struct vm_area_stint btrfs_readpage (struct file *file,struct page *page);void btrfs_delete_inode (struct inode *inode);void btrfs_put_inode (struct inode *inode); -void btrfs_read_locked_inode (struct inode *inode);int btrfs_write_inode (struct inode *inode,int wait);void btrfs_dirty_inode (struct inode *inode);struct inode *btrfs_alloc_inode (struct super_block *sb);
@@ -2183,12 +2186,8 @@ void btrfs_destroy_inode(struct inode *iint btrfs_init_cachep (void );void btrfs_destroy_cachep (void );long btrfs_ioctl_trans_end (struct file *file); -struct inode *btrfs_ilookup (struct super_block *s,u64 objectid, -struct btrfs_root *root,int wait); -struct inode *btrfs_iget_locked (struct super_block *s,u64 objectid, -struct btrfs_root *root);struct inode *btrfs_iget (struct super_block *s,struct btrfs_key *location, -struct btrfs_root *root,int *is_new); +struct btrfs_root *root);int btrfs_commit_write (struct file *file,struct page *page,unsigned from,unsigned to); struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
fs/btrfs/disk-io.c +2 -0
@@ -1598,6 +1598,7 @@ struct btrfs_root *open_ctree(struct sup fs_info->btree_inode->i_mapping->a_ops = &btree_aops; fs_info->btree_inode->i_mapping->backing_dev_info = &fs_info->bdi; +RB_CLEAR_NODE (&BTRFS_I (fs_info->btree_inode)->rb_node);extent_io_tree_init (&BTRFS_I (fs_info->btree_inode)->io_tree, fs_info->btree_inode->i_mapping,GFP_NOFS );
@@ -2181,6 +2182,7 @@ int write_ctree_super(struct btrfs_transint btrfs_free_fs_root (struct btrfs_fs_info *fs_info,struct btrfs_root *root) { +WARN_ON (!RB_EMPTY_ROOT (&root->inode_tree));radix_tree_delete (&fs_info->fs_roots_radix, (unsigned long )root->root_key.objectid);if (root->anon_super.s_dev) {
fs/btrfs/export.c +2 -2
@@ -78,7 +78,7 @@ static struct dentry *btrfs_get_dentry(sbtrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); key.offset =0 ; - inode =btrfs_iget (sb, &key, root,NULL ); + inode =btrfs_iget (sb, &key, root);if (IS_ERR (inode))return (void *)inode;
@@ -192,7 +192,7 @@ static struct dentry *btrfs_get_parent(sbtrfs_set_key_type (&key,BTRFS_INODE_ITEM_KEY ); key.offset =0 ; -return d_obtain_alias (btrfs_iget (root->fs_info->sb, &key, root,NULL )); +return d_obtain_alias (btrfs_iget (root->fs_info->sb, &key, root)); }const struct export_operations btrfs_export_ops = {
fs/btrfs/inode.c +51 -29
139 lines not on this page · raw message
fs/btrfs/super.c +7 -16
@@ -52,7 +52,6 @@#include "export.h" #include "compression.h" -static struct super_operations btrfs_super_ops;static void btrfs_put_super (struct super_block *sb)
@@ -322,7 +321,7 @@ static int btrfs_fill_super(struct superstruct dentry *root_dentry;struct btrfs_super_block *disk_super;struct btrfs_root *tree_root; -struct btrfs_inode *bi; +struct btrfs_key key;int err; sb->s_maxbytes =MAX_LFS_FILESIZE ;
@@ -341,23 +340,15 @@ static int btrfs_fill_super(struct super } sb->s_fs_info = tree_root; disk_super = &tree_root->fs_info->super_copy; - inode =btrfs_iget_locked (sb,BTRFS_FIRST_FREE_OBJECTID , - tree_root->fs_info->fs_root); - bi =BTRFS_I (inode); - bi->location.objectid = inode->i_ino; - bi->location.offset =0 ; - bi->root = tree_root->fs_info->fs_root; - -btrfs_set_key_type (&bi->location,BTRFS_INODE_ITEM_KEY ); -if (!inode) { - err = -ENOMEM ; + key.objectid =BTRFS_FIRST_FREE_OBJECTID ; + key.type =BTRFS_INODE_ITEM_KEY ; + key.offset =0 ; + inode =btrfs_iget (sb, &key, tree_root->fs_info->fs_root); +if (IS_ERR (inode)) { + err =PTR_ERR (inode); goto fail_close; } -if (inode->i_state &I_NEW ) { -btrfs_read_locked_inode (inode); -unlock_new_inode (inode); - } root_dentry =d_alloc_root (inode);if (!root_dentry) {