From patchwork Wed Jul 25 05:58:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubo X-Patchwork-Id: 1235471 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2AF454025E for ; Wed, 25 Jul 2012 06:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756302Ab2GYF7u (ORCPT ); Wed, 25 Jul 2012 01:59:50 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:1352 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751974Ab2GYF7m (ORCPT ); Wed, 25 Jul 2012 01:59:42 -0400 X-IronPort-AV: E=Sophos;i="4.77,652,1336320000"; d="scan'208";a="5475686" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 25 Jul 2012 13:58:45 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q6P5xWH0005253 for ; Wed, 25 Jul 2012 13:59:40 +0800 Received: from localhost.localdomain ([10.167.225.27]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012072514000595-856932 ; Wed, 25 Jul 2012 14:00:05 +0800 From: Liu Bo To: Subject: [PATCH 3/6 v3][RFC] Btrfs: break clear_state_bit into two parts Date: Wed, 25 Jul 2012 13:58:39 +0800 Message-Id: <1343195922-31405-4-git-send-email-liubo2009@cn.fujitsu.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1343195922-31405-1-git-send-email-liubo2009@cn.fujitsu.com> References: <1343195922-31405-1-git-send-email-liubo2009@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/07/25 14:00:05, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/07/25 14:00:14, Serialize complete at 2012/07/25 14:00:14 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 --- 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) {