From patchwork Thu May 19 08:11:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubo X-Patchwork-Id: 796462 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4J8DQCH004728 for ; Thu, 19 May 2011 08:13:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932418Ab1ESINF (ORCPT ); Thu, 19 May 2011 04:13:05 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:64987 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756642Ab1ESIM6 (ORCPT ); Thu, 19 May 2011 04:12:58 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 2080F170143; Thu, 19 May 2011 16:12:55 +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 p4J8CsxJ006610; Thu, 19 May 2011 16:12:54 +0800 Received: from localhost.localdomain ([10.167.225.27]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011051916130138-329867 ; Thu, 19 May 2011 16:13:01 +0800 From: Liu Bo To: Cc: , , Liu Bo Subject: [PATCH 4/9] Btrfs: introduce first sub trans Date: Thu, 19 May 2011 16:11:27 +0800 Message-Id: <1305792692-10635-5-git-send-email-liubo2009@cn.fujitsu.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1305792692-10635-1-git-send-email-liubo2009@cn.fujitsu.com> References: <1305792692-10635-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-05-19 16:13:01, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-05-19 16:13:02, Serialize complete at 2011-05-19 16:13:02 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 (demeter2.kernel.org [140.211.167.43]); Thu, 19 May 2011 08:13:26 +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 the first sub transaction recorded, so that log code can skip file extents which have been logged or committed into 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 57c3bb2..fb5617a 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -79,6 +79,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 d823467..acd5a38 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6569,7 +6569,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); @@ -6763,6 +6772,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; @@ -6786,6 +6796,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) extent_io_tree_init(&ei->io_tree, &inode->i_data, GFP_NOFS); extent_io_tree_init(&ei->io_failure_tree, &inode->i_data, GFP_NOFS); 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 6dcdd28..d531aea 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -83,7 +83,22 @@ static inline void btrfs_update_inode_block_group( 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; }