linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs: try to avoid doing a search in btrfs_next_leaf
Date: Mon, 24 Sep 2012 16:02:59 -0400	[thread overview]
Message-ID: <1348516979-2343-1-git-send-email-jbacik@fusionio.com> (raw)

Things like btrfs_drop_extents call btrfs_next_leaf to see if there is
anything else they need on the next leaf.  This will result in a re-search,
but if we are already at the last leaf in the tree or if the first item in
the next leaf doesn't match the objectid of the one we want we can just
return without doing the search at all.  This helps in things like fsync()
where our tree is pretty shallow and we're likely to be on the last leaf
often.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
 fs/btrfs/ctree.c |   27 +++++++++++++++++++++++++++
 fs/btrfs/ctree.h |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 6d183f6..64ea61c 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2441,6 +2441,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
 	lowest_level = p->lowest_level;
 	WARN_ON(lowest_level && ins_len > 0);
 	WARN_ON(p->nodes[0] != NULL);
+	p->shecantgoanyfarthercapt = 1;
 
 	if (ins_len < 0) {
 		lowest_unlock = 2;
@@ -2568,6 +2569,13 @@ cow_done:
 
 		if (level != 0) {
 			int dec = 0;
+
+			/*
+			 * Slot is not the last in the node, we can go farther
+			 * capt.
+			 */
+			if (slot < btrfs_header_nritems(b))
+				p->shecantgoanyfarthercapt = 0;
 			if (ret && slot > 0) {
 				dec = 1;
 				slot -= 1;
@@ -5612,8 +5620,27 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
 	nritems = btrfs_header_nritems(path->nodes[0]);
 	if (nritems == 0)
 		return 1;
+	if (path->shecantgoanyfarthercapt)
+		return 1;
+	if (!path->nodes[1])
+		return 1;
 
 	btrfs_item_key_to_cpu(path->nodes[0], &key, nritems - 1);
+
+	/*
+	 * If we have the level above us locked already just check and see if
+	 * the key in the next leaf even has the same objectid, and if not
+	 * return 1 and avoid the search.
+	 */
+	if (path->locks[1] &&
+	    path->slots[1] + 1 < btrfs_header_nritems(path->nodes[1])) {
+		struct btrfs_key tmp;
+
+		btrfs_node_key_to_cpu(path->nodes[1], &tmp,
+				      path->slots[1] + 1);
+		if (key.objectid != tmp.objectid)
+			return 1;
+	}
 again:
 	level = 1;
 	next = NULL;
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 6f2e7e6..2e5c6c5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -571,6 +571,7 @@ struct btrfs_path {
 	unsigned int skip_locking:1;
 	unsigned int leave_spinning:1;
 	unsigned int search_commit_root:1;
+	unsigned int shecantgoanyfarthercapt:1;
 };
 
 /*
-- 
1.7.7.6


             reply	other threads:[~2012-09-24 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24 20:02 Josef Bacik [this message]
2012-09-30 11:28 ` [PATCH] Btrfs: try to avoid doing a search in btrfs_next_leaf Alex Lyakas
2012-10-01 16:45   ` Josef Bacik
2012-10-02  8:17     ` Alex Lyakas
2012-10-02 14:25 ` David Sterba
2012-10-02 14:32   ` Josef Bacik
2012-10-02 15:05     ` David Sterba
2012-10-02 15:27       ` Josef Bacik
2012-10-02 15:30         ` Arne Jansen
2012-10-03 12:57           ` Alex Lyakas
2012-10-03 13:32             ` Josef Bacik

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=1348516979-2343-1-git-send-email-jbacik@fusionio.com \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 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).