Commit cef2193729595686f787c5858aad69b4369de757

Authored by Filipe David Borba Manana
Committed by Chris Mason
1 parent 55e50e458e

Btrfs: more efficient inode tree replace operation

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>
Reviewed-by: Zach Brown <zab@redhat.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>

Showing 1 changed file with 5 additions and 5 deletions Side-by-side Diff

... ... @@ -4688,11 +4688,11 @@
4688 4688 struct btrfs_inode *entry;
4689 4689 struct rb_node **p;
4690 4690 struct rb_node *parent;
  4691 + struct rb_node *new = &BTRFS_I(inode)->rb_node;
4691 4692 u64 ino = btrfs_ino(inode);
4692 4693  
4693 4694 if (inode_unhashed(inode))
4694 4695 return;
4695   -again:
4696 4696 parent = NULL;
4697 4697 spin_lock(&root->inode_lock);
4698 4698 p = &root->inode_tree.rb_node;
4699 4699  
4700 4700  
... ... @@ -4707,14 +4707,14 @@
4707 4707 else {
4708 4708 WARN_ON(!(entry->vfs_inode.i_state &
4709 4709 (I_WILL_FREE | I_FREEING)));
4710   - rb_erase(parent, &root->inode_tree);
  4710 + rb_replace_node(parent, new, &root->inode_tree);
4711 4711 RB_CLEAR_NODE(parent);
4712 4712 spin_unlock(&root->inode_lock);
4713   - goto again;
  4713 + return;
4714 4714 }
4715 4715 }
4716   - rb_link_node(&BTRFS_I(inode)->rb_node, parent, p);
4717   - rb_insert_color(&BTRFS_I(inode)->rb_node, &root->inode_tree);
  4716 + rb_link_node(new, parent, p);
  4717 + rb_insert_color(new, &root->inode_tree);
4718 4718 spin_unlock(&root->inode_lock);
4719 4719 }
4720 4720