From patchwork Tue Jun 21 08:49:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubo X-Patchwork-Id: 900472 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5L8oXlQ018295 for ; Tue, 21 Jun 2011 08:50:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753980Ab1FUIuT (ORCPT ); Tue, 21 Jun 2011 04:50:19 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:54104 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752749Ab1FUIuI (ORCPT ); Tue, 21 Jun 2011 04:50:08 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id B676717013F; Tue, 21 Jun 2011 16:50:05 +0800 (CST) Received: from mailserver.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 p5L8o4g4019623; Tue, 21 Jun 2011 16:50:04 +0800 Received: from localhost.localdomain ([10.167.225.27]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011062116494122-627581 ; Tue, 21 Jun 2011 16:49:41 +0800 From: Liu Bo To: Cc: , , Subject: [PATCH 04/12 v3] Btrfs: introduce first sub trans Date: Tue, 21 Jun 2011 16:49:45 +0800 Message-Id: <1308646193-7086-5-git-send-email-liubo2009@cn.fujitsu.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1308646193-7086-1-git-send-email-liubo2009@cn.fujitsu.com> References: <1308646193-7086-1-git-send-email-liubo2009@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-06-21 16:49:41, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-06-21 16:49:42, Serialize complete at 2011-06-21 16:49:42 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 21 Jun 2011 08:50:35 +0000 (UTC) In multi-thread situations, writeback of a file may span across several sub transactions, and we need to introduce first_sub_trans to get sub_transid of teh first sub transaction recorded, so that log code can skip file extents which have been logged or committed onto disk. Signed-off-by: Liu Bo --- fs/btrfs/btrfs_inode.h | 9 +++++++++ fs/btrfs/inode.c | 13 ++++++++++++- fs/btrfs/transaction.h | 17 ++++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 52d7eca..8eca5de 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -80,6 +80,15 @@ struct btrfs_inode { /* sequence number for NFS changes */ u64 sequence; + /* used to avoid race of first_sub_trans */ + spinlock_t sub_trans_lock; + + /* + * sub transid of the trans that first modified this inode before + * a trans commit or a log sync + */ + u64 first_sub_trans; + /* * transid of the trans_handle that last modified this inode */ diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ff9d4d1..93c9d22 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6468,7 +6468,16 @@ again: set_page_dirty(page); SetPageUptodate(page); - BTRFS_I(inode)->last_trans = root->fs_info->generation; + spin_lock(&BTRFS_I(inode)->sub_trans_lock); + + if (BTRFS_I(inode)->first_sub_trans > root->fs_info->sub_generation || + BTRFS_I(inode)->last_trans <= BTRFS_I(inode)->logged_trans || + BTRFS_I(inode)->last_trans <= root->fs_info->last_trans_committed) + BTRFS_I(inode)->first_sub_trans = root->fs_info->sub_generation; + + spin_unlock(&BTRFS_I(inode)->sub_trans_lock); + + BTRFS_I(inode)->last_trans = root->fs_info->sub_generation; BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); @@ -6714,6 +6723,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ei->space_info = NULL; ei->generation = 0; ei->sequence = 0; + ei->first_sub_trans = 0; ei->last_trans = 0; ei->last_sub_trans = 0; ei->logged_trans = 0; @@ -6740,6 +6750,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) extent_io_tree_init(&ei->io_tree, &inode->i_data); extent_io_tree_init(&ei->io_failure_tree, &inode->i_data); mutex_init(&ei->log_mutex); + spin_lock_init(&ei->sub_trans_lock); btrfs_ordered_inode_tree_init(&ei->ordered_tree); INIT_LIST_HEAD(&ei->i_orphan); INIT_LIST_HEAD(&ei->delalloc_inodes); diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index 45876b0..f5ca0fd 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -73,7 +73,22 @@ struct btrfs_pending_snapshot { static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, struct inode *inode) { - BTRFS_I(inode)->last_trans = trans->transaction->transid; + spin_lock(&BTRFS_I(inode)->sub_trans_lock); + + /* + * We have joined in a transaction, so btrfs_commit_transaction will + * definitely wait for us and it does not need to add a extra + * trans_mutex lock here. + */ + if (BTRFS_I(inode)->first_sub_trans > trans->transid || + BTRFS_I(inode)->last_trans <= BTRFS_I(inode)->logged_trans || + BTRFS_I(inode)->last_trans <= + BTRFS_I(inode)->root->fs_info->last_trans_committed) + BTRFS_I(inode)->first_sub_trans = trans->transid; + + spin_unlock(&BTRFS_I(inode)->sub_trans_lock); + + BTRFS_I(inode)->last_trans = trans->transid; BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; }