All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alan D. Brunelle" <Alan.Brunelle@hp.com>
To: undisclosed-recipients:;
Subject: [RFC PATCH] Streamline split extent insertions
Date: Tue, 10 Jun 2008 14:15:36 -0400	[thread overview]
Message-ID: <484EC4C8.3040402@hp.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Since we know the spot in the RB tree where the split off extent is
going, streamline the insertion process for the new extent. Just compile
tested, it's really a question of how deep trees are expected to be
(quite deep, I'd suspect), and how often splits are done (have no clue).

Anyways, just checking to see if this is worth pursuing...

Alan

[-- Attachment #2: split_left.patch --]
[-- Type: text/x-diff, Size: 2196 bytes --]

diff -r 41243548e445 extent_io.c
--- a/extent_io.c	Tue Jun 10 10:40:46 2008 -0400
+++ b/extent_io.c	Tue Jun 10 14:09:20 2008 -0400
@@ -173,6 +173,38 @@ static struct rb_node *tree_insert(struc
 	rb_link_node(node, parent, p);
 	rb_insert_color(node, root);
 	return NULL;
+}
+
+/*
+ * tree_insert_left - insert split off node to a /known/ left node in a tree
+ * @root:	root of the whole tree
+ * @parent:	new node's parent
+ * @child:	new node
+ *
+ * Since we /know/ the position to insert into (the /left/ of the
+ * given parent), we can short-circuit the complete tree search.
+ *
+ * There are really two cases:
+ *	(1) The parent's left is NULL, this means that the new node is
+ *	    to be placed there.
+ *
+ *	(2) The parent's left is non-NULL, we then search for the
+ *	    right-most decendent of the parent's left-child. This is
+ *	    a simple decent down the right links.
+ *
+ * Note: We could (should?) complicate the code to add in checks for
+ *       already existing (or overlapping) entries...
+ */
+static void tree_insert_left(struct rb_root *root, struct rb_node *parent,
+			     struct rb_node *child)
+{
+	struct rb_node **link;
+
+	for (link = &parent->rb_left; *link; link = &parent->rb_right)
+		parent = *link;
+
+	rb_link_node(child, parent, link);
+	rb_insert_color(child, root);
 }
 
 static struct rb_node *__etree_search(struct extent_io_tree *tree, u64 offset,
@@ -369,20 +401,12 @@ static int split_state(struct extent_io_
 static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
 		       struct extent_state *prealloc, u64 split)
 {
-	struct rb_node *node;
 	prealloc->start = orig->start;
 	prealloc->end = split - 1;
 	prealloc->state = orig->state;
 	orig->start = split;
 
-	node = tree_insert(&tree->state, prealloc->end, &prealloc->rb_node);
-	if (node) {
-		struct extent_state *found;
-		found = rb_entry(node, struct extent_state, rb_node);
-		printk("found node %Lu %Lu on insert of %Lu %Lu\n", found->start, found->end, prealloc->start, prealloc->end);
-		free_extent_state(prealloc);
-		return -EEXIST;
-	}
+	tree_insert_left(&tree->state, &orig->rb_node, &prealloc->rb_node);
 	prealloc->tree = tree;
 	return 0;
 }

                 reply	other threads:[~2008-06-10 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=484EC4C8.3040402@hp.com \
    --to=alan.brunelle@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.