Skip to contentSkip to conversation

Btrfs: move the extent buffer radix tree into the fs_info

PATCH In review Josef Bacik 3 participants 6 messages Dec 16, 2013 – Dec 17, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: move the extent buffer radix tree into the fs_info

I need to create a fake tree to test qgroups and I don't want to have to setup a fake btree_inode. The fact is we only use the radix tree for the fs_info, so everybody else who allocates an extent_io_tree is just wasting the space anyway. This patch moves the radix tree and its lock into btrfs_fs_info so there is less stuff I have to fake to do qgroup sanity tests. Thanks,

---
 fs/btrfs/ctree.h     |  4 ++++
 fs/btrfs/disk-io.c   | 14 ++++----------
 fs/btrfs/extent_io.c | 47 +++++++++++++++++++++++------------------------
 fs/btrfs/extent_io.h |  8 +++-----
 4 files changed, 34 insertions(+), 39 deletions(-)
fs/btrfs/ctree.h +4 -0
index f27faa3..944c916 100644
@@ -1691,6 +1691,10 @@ struct btrfs_fs_info {
 	spinlock_t reada_lock;
 	struct radix_tree_root reada_tree;
 
+	/* Extent buffer radix tree */
+	spinlock_t buffer_lock;
+	struct radix_tree_root buffer_radix;
+
 	/* next backup root to be overwritten */
 	int backup_root_index;
 
fs/btrfs/disk-io.c +4 -10
index 44c0875..3eb27b9 100644
@@ -1089,21 +1089,13 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr, u32 blocksize,
 struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
 					    u64 bytenr, u32 blocksize)
 {
-	struct inode *btree_inode = root->fs_info->btree_inode;
-	struct extent_buffer *eb;
-	eb = find_extent_buffer(&BTRFS_I(btree_inode)->io_tree, bytenr);
-	return eb;
+	return find_extent_buffer(root->fs_info, bytenr);
 }
 
 struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
 						 u64 bytenr, u32 blocksize)
 {
-	struct inode *btree_inode = root->fs_info->btree_inode;
-	struct extent_buffer *eb;
-
-	eb = alloc_extent_buffer(&BTRFS_I(btree_inode)->io_tree,
-				 bytenr, blocksize);
-	return eb;
+	return alloc_extent_buffer(root->fs_info, bytenr, blocksize);
 }
 
 
@@ -2145,6 +2137,7 @@ int open_ctree(struct super_block *sb,
 	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
 
 	INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);
+	INIT_RADIX_TREE(&fs_info->buffer_radix, GFP_ATOMIC);
 	INIT_LIST_HEAD(&fs_info->trans_list);
 	INIT_LIST_HEAD(&fs_info->dead_roots);
 	INIT_LIST_HEAD(&fs_info->delayed_iputs);
@@ -2159,6 +2152,7 @@ int open_ctree(struct super_block *sb,
 	spin_lock_init(&fs_info->tree_mod_seq_lock);
 	spin_lock_init(&fs_info->super_lock);
 	spin_lock_init(&fs_info->qgroup_op_lock);
+	spin_lock_init(&fs_info->buffer_lock);
 	rwlock_init(&fs_info->tree_mod_log_lock);
 	mutex_init(&fs_info->reloc_mutex);
 	seqlock_init(&fs_info->profiles_lock);
fs/btrfs/extent_io.c +23 -24

126 lines not on this page · raw message

fs/btrfs/extent_io.h +3 -5
index 92e4347..58b27e5 100644
@@ -95,12 +95,10 @@ struct extent_io_ops {
 
 struct extent_io_tree {
 	struct rb_root state;
-	struct radix_tree_root buffer;
 	struct address_space *mapping;
 	u64 dirty_bytes;
 	int track_uptodate;
 	spinlock_t lock;
-	spinlock_t buffer_lock;
 	struct extent_io_ops *ops;
 };
 
@@ -131,7 +129,7 @@ struct extent_buffer {
 	unsigned long map_start;
 	unsigned long map_len;
 	unsigned long bflags;
-	struct extent_io_tree *tree;
+	struct btrfs_fs_info *fs_info;
 	spinlock_t refs_lock;
 	atomic_t refs;
 	atomic_t io_pages;
@@ -267,11 +265,11 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
 void set_page_extent_mapped(struct page *page);
 
-struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
+struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 					  u64 start, unsigned long len);
 struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len);
 struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
-struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
+struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
 					 u64 start);
 void free_extent_buffer(struct extent_buffer *eb);
 void free_extent_buffer_stale(struct extent_buffer *eb);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Josef Bacik

I need to create a fake tree to test qgroups and I don't want to have to setup a fake btree_inode. The fact is we only use the radix tree for the fs_info, so everybody else who allocates an extent_io_tree is just wasting the space anyway. This patch moves the radix tree and its lock into btrfs_fs_info so there is less stuff I have to fake to do qgroup sanity tests. Thanks,

This would make the fs_info::buffer_lock a global hotspot if alloc_extent_buffer and release_extent_buffer are called frequently.

But, you can get rid of the buffer_lock completely, because the radix tree can be safely protected by rcu_read_lock/_unlock:

* alloc_extent_buffer uses radix_preload that turns off preepmtion by itself, so the lock here would be pointless

* release_extent_buffer locks around radix_tree_delete, here a rcu locking will be ok as well

* radix_tree_lookup(buffer_tree) is done in rcu section already

I'm ok with this patch as an incremental change, replacing the locks with RCU is trivial but I'd rather take a conservative approach should we need to bisect that someday.

David "I should not send RCU comments at 2 a.m." Sterba

#2 lore raw
Quoted 10 lines · David Sterba
Quoted 5 lines · Josef Bacik

I need to create a fake tree to test qgroups and I don't want to have to setup a fake btree_inode. The fact is we only use the radix tree for the fs_info, so everybody else who allocates an extent_io_tree is just wasting the space anyway. This patch moves the radix tree and its lock into btrfs_fs_info so there is less stuff I have to fake to do qgroup sanity tests. Thanks,

This would make the fs_info::buffer_lock a global hotspot if alloc_extent_buffer and release_extent_buffer are called frequently.

But since the only place that was really using it was the metadata btree, the lock shouldn't be hotter than before right?

-chris

#3 lore raw
Quoted 8 lines · Chris Mason
Quoted 7 lines · David Sterba
Quoted 5 lines · Josef Bacik

I need to create a fake tree to test qgroups and I don't want to have to setup a fake btree_inode. The fact is we only use the radix tree for the fs_info, so everybody else who allocates an extent_io_tree is just wasting the space anyway. This patch moves the radix tree and its lock into btrfs_fs_info so there is less stuff I have to fake to do qgroup sanity tests. Thanks,

Quoted 6 lines
Quoted 3 lines

This would make the fs_info::buffer_lock a global hotspot if alloc_extent_buffer and release_extent_buffer are called frequently.

But since the only place that was really using it was the metadata btree, the lock shouldn't be hotter than before right?

Right. What confused me first is that the number of trees that are initialized by extent_io_tree_init is higher, but the only user is metadata btree.

#4 lore raw
In reply to David Sterba
Quoted 6 lines · David Sterba
Quoted 5 lines · Josef Bacik

I need to create a fake tree to test qgroups and I don't want to have to setup a fake btree_inode. The fact is we only use the radix tree for the fs_info, so everybody else who allocates an extent_io_tree is just wasting the space anyway. This patch moves the radix tree and its lock into btrfs_fs_info so there is less stuff I have to fake to do qgroup sanity tests. Thanks,

Quoted 8 lines

This would make the fs_info::buffer_lock a global hotspot if alloc_extent_buffer and release_extent_buffer are called frequently.

But, you can get rid of the buffer_lock completely, because the radix tree can be safely protected by rcu_read_lock/_unlock:

* alloc_extent_buffer uses radix_preload that turns off preepmtion by itself, so the lock here would be pointless

Except you still need a lock for other inserts.

Quoted 3 lines

* release_extent_buffer locks around radix_tree_delete, here a rcu locking will be ok as well

No it won't. RCU just makes sure readers don't get screwed, you still need to have real locking around the insertions/deletions, look at pagecache, we have mapping->tree_lock for this even though it uses rcu for the lookups. Thanks,

Josef

#5 lore raw
Quoted 11 lines · Josef Bacik
Quoted 2 lines

* alloc_extent_buffer uses radix_preload that turns off preepmtion by itself, so the lock here would be pointless

Except you still need a lock for other inserts.

Quoted 3 lines

* release_extent_buffer locks around radix_tree_delete, here a rcu locking will be ok as well

No it won't. RCU just makes sure readers don't get screwed, you still need to have real locking around the insertions/deletions, look at pagecache, we have mapping->tree_lock for this even though it uses rcu for the lookups.

Oh, my bad sorry, that would be too easy.