From patchwork Wed Jan 13 10:22:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12016415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BDD6C433E0 for ; Wed, 13 Jan 2021 10:23:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8B3C323117 for ; Wed, 13 Jan 2021 10:23:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B3C323117 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DA6F38D0031; Wed, 13 Jan 2021 05:23:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D57D38D002E; Wed, 13 Jan 2021 05:23:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6D088D0031; Wed, 13 Jan 2021 05:23:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AECC48D002E for ; Wed, 13 Jan 2021 05:23:26 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 713FC33C4 for ; Wed, 13 Jan 2021 10:23:26 +0000 (UTC) X-FDA: 77700364812.23.prose13_59017822751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 4E87D37604 for ; Wed, 13 Jan 2021 10:23:26 +0000 (UTC) X-HE-Tag: prose13_59017822751d X-Filterd-Recvd-Size: 7530 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 10:23:25 +0000 (UTC) Received: by mail-ot1-f44.google.com with SMTP id i6so1435301otr.2 for ; Wed, 13 Jan 2021 02:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XxclDVwqVJvNjL6ogvvc7lutzmJKTCIl3aL2mVuveRU=; b=ayzzHhYzcClTcR5UidZ9RaV7JooeTbg7NYZeAKxe+8VXLL4MzCKSEQ+HRiDI3hcGRV lpycfcOJxoosIgx3X6xdop/IL+4QW5enr6e+YLrZMvNP/zfEA+JQ8ZoTOOZ9AUAdCYKL N2YwIn+bjH9pdPanotuQS37H/zfAVEh5kjkWNLHyLlIAgOk+O6L1ngtZGclIZyM/urzg gszDoW00rAbwKLEld222Gf8/1aG465V1HN89e/8R+i0WLj4Z7uusaomm/YBxTNnEaAVA 9Da+RFc607qjDU/QocHb0I+2wQHexo0B1KZsab0gPXqreVTPPXHqSxmzRQzni59RCt02 lgQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XxclDVwqVJvNjL6ogvvc7lutzmJKTCIl3aL2mVuveRU=; b=pPwgcSK/7AY1mBDZm+70DeBiLnSgO4KBNRaeRDeCnDZcA2pPTFJq8Mm6o2U1mIDSei t0Votd6uYpJfSarLPzLJyVW3y9YBYdukTrAjsbksZaPvN7IaSfYCrT/Y0hPJnvcoizFs iCDk/1FM+a7jIl7GgOa1akLtvl2jjB46U9HP66R2dtsFF1nksP1+RwZE5yDe97px3HIx Yapvl+bvol83k3NL2uLKtrptaj2SM299M9NLamkkqxHkVqttsc4CILQ4wvrWkGw1TAIT C1fO5n7hRzXDybfEqmO7zJ8Aj0Qivr795UTbSlw9X3ozwVEKjey/a5ts4M7cg55m6j8a G9vw== X-Gm-Message-State: AOAM531kbG7kGEO6fTsahmLLCgnphXMe1Ga71gxmAf7hJPttmznWdN/E k3Gf6Oe+Tt5eKUW5drO8N4E= X-Google-Smtp-Source: ABdhPJy3SuuCBXWeZ64qnoWABbZ8wtAGotjYfWPZu33kh0kuO2TTGVs0UOsxp8cqTnyLedLhUOmebA== X-Received: by 2002:a9d:694a:: with SMTP id p10mr722519oto.149.1610533405317; Wed, 13 Jan 2021 02:23:25 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id z8sm335571oon.10.2021.01.13.02.23.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jan 2021 02:23:24 -0800 (PST) From: Yafang Shao To: darrick.wong@oracle.com, willy@infradead.org, david@fromorbit.com, hch@infradead.org, mhocko@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, jlayton@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, Yafang Shao , Christoph Hellwig Subject: [PATCH v15 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} Date: Wed, 13 Jan 2021 18:22:23 +0800 Message-Id: <20210113102224.13655-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210113102224.13655-1-laoar.shao@gmail.com> References: <20210113102224.13655-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The xfs_trans context should be active after it is allocated, and deactive when it is freed. The rolling transaction should be specially considered, because in the case when we clear the old transaction the thread's NOFS state shouldn't be changed, as a result we have to set NOFS in the old transaction's t_pflags in xfs_trans_context_swap(). So these helpers are refactored as, - xfs_trans_context_set() Used in xfs_trans_alloc() - xfs_trans_context_clear() Used in xfs_trans_free() And a new helper is instroduced to handle the rolling transaction, - xfs_trans_context_swap() Used in rolling transaction This patch is based on Darrick's work[1] to fix the issue in xfs/141 in the earlier version and Dave's suggestion[2]. [1]. https://lore.kernel.org/linux-xfs/20201104001649.GN7123@magnolia [2]. https://lore.kernel.org/linux-xfs/20201218000705.GR632069@dread.disaster.area Cc: Dave Chinner Cc: Darrick J. Wong Cc: Matthew Wilcox (Oracle) Cc: Christoph Hellwig Signed-off-by: Yafang Shao --- fs/xfs/xfs_trans.c | 25 +++++++++++-------------- fs/xfs/xfs_trans.h | 10 +++++++++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 43107af569fe..b76e850c9ae7 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -67,6 +67,10 @@ xfs_trans_free( xfs_extent_busy_sort(&tp->t_busy); xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); + + /* Detach the transaction from this thread. */ + xfs_trans_context_clear(tp); + trace_xfs_trans_free(tp, _RET_IP_); if (!(tp->t_flags & XFS_TRANS_NO_WRITECOUNT)) sb_end_intwrite(tp->t_mountp->m_super); @@ -119,7 +123,9 @@ xfs_trans_dup( ntp->t_rtx_res = tp->t_rtx_res - tp->t_rtx_res_used; tp->t_rtx_res = tp->t_rtx_res_used; - ntp->t_pflags = tp->t_pflags; + + /* Associate the new transaction with this thread. */ + xfs_trans_context_swap(tp, ntp); /* move deferred ops over to the new tp */ xfs_defer_move(ntp, tp); @@ -153,9 +159,6 @@ xfs_trans_reserve( int error = 0; bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; - /* Mark this thread as being in a transaction */ - xfs_trans_context_set(tp); - /* * Attempt to reserve the needed disk blocks by decrementing * the number needed from the number available. This will @@ -163,10 +166,9 @@ xfs_trans_reserve( */ if (blocks > 0) { error = xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); - if (error != 0) { - xfs_trans_context_clear(tp); + if (error != 0) return -ENOSPC; - } + tp->t_blk_res += blocks; } @@ -241,8 +243,6 @@ xfs_trans_reserve( tp->t_blk_res = 0; } - xfs_trans_context_clear(tp); - return error; } @@ -284,6 +284,8 @@ xfs_trans_alloc( INIT_LIST_HEAD(&tp->t_dfops); tp->t_firstblock = NULLFSBLOCK; + /* Mark this thread as being in a transaction */ + xfs_trans_context_set(tp); error = xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { xfs_trans_cancel(tp); @@ -878,7 +880,6 @@ __xfs_trans_commit( xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); - xfs_trans_context_clear(tp); xfs_trans_free(tp); /* @@ -911,7 +912,6 @@ __xfs_trans_commit( tp->t_ticket = NULL; } - xfs_trans_context_clear(tp); xfs_trans_free_items(tp, !!error); xfs_trans_free(tp); @@ -971,9 +971,6 @@ xfs_trans_cancel( tp->t_ticket = NULL; } - /* mark this thread as no longer being in a transaction */ - xfs_trans_context_clear(tp); - xfs_trans_free_items(tp, dirty); xfs_trans_free(tp); } diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h index 44b11c64a15e..3645fd0d74b8 100644 --- a/fs/xfs/xfs_trans.h +++ b/fs/xfs/xfs_trans.h @@ -277,7 +277,15 @@ xfs_trans_context_set(struct xfs_trans *tp) static inline void xfs_trans_context_clear(struct xfs_trans *tp) { - memalloc_nofs_restore(tp->t_pflags); + if (!tp->t_pflags) + memalloc_nofs_restore(tp->t_pflags); +} + +static inline void +xfs_trans_context_swap(struct xfs_trans *tp, struct xfs_trans *ntp) +{ + ntp->t_pflags = tp->t_pflags; + tp->t_pflags = -1; } #endif /* __XFS_TRANS_H__ */