From mboxrd@z Thu Jan 1 00:00:00 1970 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 46D5AC4361B for ; Wed, 9 Dec 2020 13:12:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC66D23B45 for ; Wed, 9 Dec 2020 13:12:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC66D23B45 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 5CD7C6B00E1; Wed, 9 Dec 2020 08:12:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 557386B00E2; Wed, 9 Dec 2020 08:12:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F8A08D001E; Wed, 9 Dec 2020 08:12:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 2AA826B00E1 for ; Wed, 9 Dec 2020 08:12:33 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B285D181AEF2A for ; Wed, 9 Dec 2020 13:12:32 +0000 (UTC) X-FDA: 77573782944.28.ant43_4d0b568273ef Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 6C5F16D6E for ; Wed, 9 Dec 2020 13:12:32 +0000 (UTC) X-HE-Tag: ant43_4d0b568273ef X-Filterd-Recvd-Size: 6348 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Dec 2020 13:12:31 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id 143so1066094qke.10 for ; Wed, 09 Dec 2020 05:12:31 -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=U/1xqfI5qUo3gDO+06cA0eClvvlW5lp3NGGPYOZ6sWg=; b=qsxmL+1cQe00msicjBwK/HwlXWZBf7gT2pnAsOYkUDq77RjLamhFzAW0B0ceSk6Vi3 AOPfASgjN8kTjwnBxQijmYZh/kDmttxjj1TrNK0HPm4Rr3xPtcNqwRq/zRyjoatPtcn0 Mpft7TA6nZOBZe4owiGB90EKNoA2jwgb8v3otQbZm91LETiyUFMrlUFmsOFQpr16nL85 OqyvHkUZjb7TpzHAI/FNYQCqPPGfViRt+za0XCzXfjMVF86nwOhf/CcSAOkwtWQwmyzX Uk7YxYSpynGnXKqhBXS19hrL3Keijw19VALRdQoljFvcw136cunMyLvsbokCZ7odw+B6 8ylw== 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=U/1xqfI5qUo3gDO+06cA0eClvvlW5lp3NGGPYOZ6sWg=; b=EalFOGJIp9a7EZjUxqa0MRDi3SkOPKUA7GbJPgMTagzU3S1SlGS8U/2jY7zK7ww9G6 s+uxnf8rvRazK2RfAAyHVdUGL+ypnL7jHxa6qlsk5rOk/0Ek1Sp9uEcrxAMKzwizCX5Y q7p4iBx639o4vjO3bl3My0iDRgE57WF7rwOX9IY36EVMwOZBmQG7EyCBbvPdBL1/QUjq Im9srIsXfDA+qZILE93dtDl40jc1hRkTG7IzstxksjLww2GtOykjVYuPOohrv6CCDLuL 76Wb1tkNDeXdsuyQG1pOM0eWU0TUYN+/95CtznojmLRxEhAiEm6QQeB2gAbDESfZ9lEu YpiA== X-Gm-Message-State: AOAM530ZiU+47Ggsn5Zq9/OzO4/5iw2EMWQ0kC/zPk+FohYo4jYokbi2 tMalxtsVaWLl7JXDQI73o0k= X-Google-Smtp-Source: ABdhPJxB0/jAlENo3tmNLdMytrMRXbSsuKgW8S6j4ULYI9Bw/bihb/0tXNXtJPrr5KbOt6cyGOqcXA== X-Received: by 2002:a05:620a:2290:: with SMTP id o16mr2832688qkh.101.1607519551095; Wed, 09 Dec 2020 05:12:31 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id u72sm938114qka.15.2020.12.09.05.12.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 05:12:30 -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, Yafang Shao , Christoph Hellwig Subject: [PATCH v12 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} Date: Wed, 9 Dec 2020 21:11:45 +0800 Message-Id: <20201209131146.67289-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20201209131146.67289-1-laoar.shao@gmail.com> References: <20201209131146.67289-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. So these two helpers are refactored as, - xfs_trans_context_set() Used in xfs_trans_alloc() - xfs_trans_context_clear() Used in xfs_trans_free() This patch is based on Darrick's work to fix the issue in xfs/141 in the earlier version. [1] 1. https://lore.kernel.org/linux-xfs/20201104001649.GN7123@magnolia Cc: Darrick J. Wong Cc: Matthew Wilcox (Oracle) Cc: Christoph Hellwig Cc: Dave Chinner Signed-off-by: Yafang Shao --- fs/xfs/xfs_trans.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 11d390f0d3f2..4f4645329bb2 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -67,6 +67,17 @@ xfs_trans_free( xfs_extent_busy_sort(&tp->t_busy); xfs_extent_busy_clear(tp->t_mountp, &tp->t_busy, false); =20 + + /* Detach the transaction from this thread. */ + ASSERT(current->journal_info !=3D NULL); + /* + * The PF_MEMALLOC_NOFS is bound to the transaction itself instead + * of the reservation, so we need to check if tp is still the + * current transaction before clearing the flag. + */ + if (current->journal_info =3D=3D tp) + 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); @@ -153,9 +164,6 @@ xfs_trans_reserve( int error =3D 0; bool rsvd =3D (tp->t_flags & XFS_TRANS_RESERVE) !=3D 0; =20 - /* 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 +171,9 @@ xfs_trans_reserve( */ if (blocks > 0) { error =3D xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); - if (error !=3D 0) { - xfs_trans_context_clear(tp); + if (error !=3D 0) return -ENOSPC; - } + tp->t_blk_res +=3D blocks; } =20 @@ -241,8 +248,6 @@ xfs_trans_reserve( tp->t_blk_res =3D 0; } =20 - xfs_trans_context_clear(tp); - return error; } =20 @@ -284,6 +289,8 @@ xfs_trans_alloc( INIT_LIST_HEAD(&tp->t_dfops); tp->t_firstblock =3D NULLFSBLOCK; =20 + /* Mark this thread as being in a transaction */ + xfs_trans_context_set(tp); error =3D xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { xfs_trans_cancel(tp); @@ -878,7 +885,6 @@ __xfs_trans_commit( =20 xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); =20 - xfs_trans_context_clear(tp); xfs_trans_free(tp); =20 /* @@ -911,7 +917,6 @@ __xfs_trans_commit( tp->t_ticket =3D NULL; } =20 - xfs_trans_context_clear(tp); xfs_trans_free_items(tp, !!error); xfs_trans_free(tp); =20 @@ -971,9 +976,6 @@ xfs_trans_cancel( tp->t_ticket =3D NULL; } =20 - /* 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); } --=20 2.18.4