linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: more efficient inode tree replace operation
@ 2013-09-02 11:19 Filipe David Borba Manana
  2013-09-03 18:19 ` Zach Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Filipe David Borba Manana @ 2013-09-02 11:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Filipe David Borba Manana

Instead of removing the current inode from the red black tree
and then add the new one, just use the red black tree replace
operation, which is more efficient.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
 fs/btrfs/inode.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 26992ee..aa22926 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4688,11 +4688,11 @@ static void inode_tree_add(struct inode *inode)
 	struct btrfs_inode *entry;
 	struct rb_node **p;
 	struct rb_node *parent;
+	struct rb_node *new = &BTRFS_I(inode)->rb_node;
 	u64 ino = btrfs_ino(inode);
 
 	if (inode_unhashed(inode))
 		return;
-again:
 	parent = NULL;
 	spin_lock(&root->inode_lock);
 	p = &root->inode_tree.rb_node;
@@ -4707,14 +4707,14 @@ again:
 		else {
 			WARN_ON(!(entry->vfs_inode.i_state &
 				  (I_WILL_FREE | I_FREEING)));
-			rb_erase(parent, &root->inode_tree);
+			rb_replace_node(parent, new, &root->inode_tree);
 			RB_CLEAR_NODE(parent);
 			spin_unlock(&root->inode_lock);
-			goto again;
+			return;
 		}
 	}
-	rb_link_node(&BTRFS_I(inode)->rb_node, parent, p);
-	rb_insert_color(&BTRFS_I(inode)->rb_node, &root->inode_tree);
+	rb_link_node(new, parent, p);
+	rb_insert_color(new, &root->inode_tree);
 	spin_unlock(&root->inode_lock);
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Btrfs: more efficient inode tree replace operation
  2013-09-02 11:19 [PATCH] Btrfs: more efficient inode tree replace operation Filipe David Borba Manana
@ 2013-09-03 18:19 ` Zach Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Zach Brown @ 2013-09-03 18:19 UTC (permalink / raw)
  To: Filipe David Borba Manana; +Cc: linux-btrfs

On Mon, Sep 02, 2013 at 12:19:13PM +0100, Filipe David Borba Manana wrote:
> Instead of removing the current inode from the red black tree
> and then add the new one, just use the red black tree replace
> operation, which is more efficient.

Yup, this looks correct to me.

Reviewed-by: Zach Brown <zab@redhat.com>

- z

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-09-03 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-02 11:19 [PATCH] Btrfs: more efficient inode tree replace operation Filipe David Borba Manana
2013-09-03 18:19 ` Zach Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).