From patchwork Mon Jul 23 13:04:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 10540201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCDBB90E3 for ; Mon, 23 Jul 2018 13:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAF7F287A3 for ; Mon, 23 Jul 2018 13:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF8B1287BB; Mon, 23 Jul 2018 13:04:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A9B1287D5 for ; Mon, 23 Jul 2018 13:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388130AbeGWOF0 (ORCPT ); Mon, 23 Jul 2018 10:05:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49718 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388123AbeGWOFZ (ORCPT ); Mon, 23 Jul 2018 10:05:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 131E34064306 for ; Mon, 23 Jul 2018 13:04:16 +0000 (UTC) Received: from bfoster.bos.redhat.com (dhcp-41-2.bos.redhat.com [10.18.41.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id F17BC111AF23 for ; Mon, 23 Jul 2018 13:04:15 +0000 (UTC) From: Brian Foster To: linux-xfs@vger.kernel.org Subject: [PATCH v2 15/15] xfs: bypass final dfops roll in trans commit path Date: Mon, 23 Jul 2018 09:04:14 -0400 Message-Id: <20180723130414.47980-16-bfoster@redhat.com> In-Reply-To: <20180723130414.47980-1-bfoster@redhat.com> References: <20180723130414.47980-1-bfoster@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Jul 2018 13:04:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Jul 2018 13:04:16 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bfoster@redhat.com' RCPT:'' Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Once xfs_defer_finish() has completed all deferred operations, it checks the dirty state of the transaction and rolls it once more to return a clean transaction for the caller. This primarily to cover the case where repeated xfs_defer_finish() calls are made in a loop and we need to make sure that the caller starts the next iteration with a clean transaction. Otherwise we risk transaction reservation overrun. This final transaction roll is not required in the transaction commit path, however, because the transaction is immediately committed and freed after dfops completion. Refactor the final roll into a separate helper such that we can avoid it in the transaction commit path. Lift the dfops reset as well so dfops remains valid until after the last call to xfs_defer_trans_roll(). The reset is also unnecessary in the transaction commit path because the transaction is about to complete. This eliminates unnecessary regrants of transactions where the associated transaction roll can be replaced by a transaction commit. Signed-off-by: Brian Foster Reviewed-by: Bill O'Donnell Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_defer.c | 35 ++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_defer.h | 1 + fs/xfs/xfs_trans.c | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c index cbee0a86c978..2d4c4b09977e 100644 --- a/fs/xfs/libxfs/xfs_defer.c +++ b/fs/xfs/libxfs/xfs_defer.c @@ -341,7 +341,7 @@ xfs_defer_reset( * If an inode is provided, relog it to the new transaction. */ int -xfs_defer_finish( +xfs_defer_finish_noroll( struct xfs_trans **tp) { struct xfs_defer_ops *dop = (*tp)->t_dfops; @@ -430,21 +430,30 @@ xfs_defer_finish( cleanup_fn(*tp, state, error); } - /* - * Roll the transaction once more to avoid returning to the caller - * with a dirty transaction. - */ - if ((*tp)->t_flags & XFS_TRANS_DIRTY) { - error = xfs_defer_trans_roll(tp); - dop = (*tp)->t_dfops; - } out: - if (error) { + if (error) trace_xfs_defer_finish_error((*tp)->t_mountp, dop, error); - } else { + else trace_xfs_defer_finish_done((*tp)->t_mountp, dop, _RET_IP_); - xfs_defer_reset(dop); - } + + return error; +} + +int +xfs_defer_finish( + struct xfs_trans **tp) +{ + int error; + + /* + * Finish and roll the transaction once more to avoid returning to the + * caller with a dirty transaction. + */ + error = xfs_defer_finish_noroll(tp); + if (!error && ((*tp)->t_flags & XFS_TRANS_DIRTY)) + error = xfs_defer_trans_roll(tp); + if (!error) + xfs_defer_reset((*tp)->t_dfops); return error; } diff --git a/fs/xfs/libxfs/xfs_defer.h b/fs/xfs/libxfs/xfs_defer.h index 56f927803940..85c41fe4dbae 100644 --- a/fs/xfs/libxfs/xfs_defer.h +++ b/fs/xfs/libxfs/xfs_defer.h @@ -48,6 +48,7 @@ enum xfs_defer_ops_type { void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type, struct list_head *h); +int xfs_defer_finish_noroll(struct xfs_trans **tp); int xfs_defer_finish(struct xfs_trans **tp); void __xfs_defer_cancel(struct xfs_defer_ops *dop); void xfs_defer_init(struct xfs_trans *tp, struct xfs_defer_ops *dop); diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index cd553aa9ecb0..7bf5c1202719 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -933,7 +933,7 @@ __xfs_trans_commit( /* finish deferred items on final commit */ if (!regrant && tp->t_dfops) { - error = xfs_defer_finish(&tp); + error = xfs_defer_finish_noroll(&tp); if (error) { xfs_defer_cancel(tp); goto out_unreserve;