All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Bo <liubo2009@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 3/6 v3][RFC] Btrfs: break clear_state_bit into two parts
Date: Wed, 25 Jul 2012 13:58:39 +0800	[thread overview]
Message-ID: <1343195922-31405-4-git-send-email-liubo2009@cn.fujitsu.com> (raw)
In-Reply-To: <1343195922-31405-1-git-send-email-liubo2009@cn.fujitsu.com>

clear_state_bit() can be broken into two parts:
1) a part for clearing bits,
2) a part for freeing the state or merging it with adjacent ones.

And the first one does not need to touch the tree, so holding read locks
is enough, and this gives us the oppotunity to rework tree's lock with
rwlock.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
---
 fs/btrfs/extent_io.c |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 4c6dd85..a84d904 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -425,11 +425,10 @@ static struct extent_state *next_state(struct extent_state *state)
  * If no bits are set on the state struct after clearing things, the
  * struct is freed and removed from the tree
  */
-static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
-					    struct extent_state *state,
-					    int *bits, int wake)
+static int __clear_state_bit(struct extent_io_tree *tree,
+			     struct extent_state *state,
+			     int *bits, int wake)
 {
-	struct extent_state *next;
 	int bits_to_clear = *bits & ~EXTENT_CTLBITS;
 
 	if ((bits_to_clear & EXTENT_DIRTY) && (state->state & EXTENT_DIRTY)) {
@@ -441,6 +440,14 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
 	state->state &= ~bits_to_clear;
 	if (wake)
 		wake_up(&state->wq);
+	return 0;
+}
+
+static struct extent_state *
+try_free_or_merge_state(struct extent_io_tree *tree, struct extent_state *state)
+{
+	struct extent_state *next = NULL;
+
 	if (state->state == 0) {
 		next = next_state(state);
 		if (state->tree) {
@@ -457,6 +464,13 @@ static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
 	return next;
 }
 
+static struct extent_state *clear_state_bit(struct extent_io_tree *tree,
+			   struct extent_state *state, int *bits, int wake)
+{
+	__clear_state_bit(tree, state, bits, wake);
+	return try_free_or_merge_state(tree, state);
+}
+
 static struct extent_state *
 alloc_extent_state_atomic(struct extent_state *prealloc)
 {
-- 
1.6.5.2


  parent reply	other threads:[~2012-07-25  5:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-25  5:58 [PATCH 0/6 v3][RFC] rwlock for extent state Liu Bo
2012-07-25  5:58 ` [PATCH 1/6 v3][RFC] Btrfs: merge adjacent states as much as possible Liu Bo
2012-07-25  5:58 ` [PATCH 2/6 v3][RFC] Btrfs: add helper function to test if we can merge state Liu Bo
2012-07-25  5:58 ` Liu Bo [this message]
2012-07-25  5:58 ` [PATCH 4/6 v3][RFC] Btrfs: apply rwlock for extent state Liu Bo
2012-07-25  5:58 ` [PATCH 5/6 v3][RFC] Btrfs: batch merge state in readpage endio Liu Bo
2012-07-25  5:58 ` [PATCH 6/6 v3][RFC] Btrfs: async helper for state merge Liu Bo

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=1343195922-31405-4-git-send-email-liubo2009@cn.fujitsu.com \
    --to=liubo2009@cn.fujitsu.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 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.