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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 407FFC4361B for ; Wed, 9 Dec 2020 10:44:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C916423B6C for ; Wed, 9 Dec 2020 10:44:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C916423B6C 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 105CA8D0016; Wed, 9 Dec 2020 05:44:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 08F728D000B; Wed, 9 Dec 2020 05:44:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC07A8D0016; Wed, 9 Dec 2020 05:44:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id D1C0D8D000B for ; Wed, 9 Dec 2020 05:44:26 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9FF9B33C4 for ; Wed, 9 Dec 2020 10:44:26 +0000 (UTC) X-FDA: 77573409732.01.eyes33_220c509273ef Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 838901004BE21 for ; Wed, 9 Dec 2020 10:44:26 +0000 (UTC) X-HE-Tag: eyes33_220c509273ef X-Filterd-Recvd-Size: 9147 Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Dec 2020 10:44:25 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id t8so1146244iov.8 for ; Wed, 09 Dec 2020 02:44:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=htf7oQLbUIT12CkPdqZFjdgF/YoqVY5s3W8UZCtazfU=; b=BDH0ED5DZ98HJqDCraITjaG60bDgQ6/mLGoFquywWqKEZtc0/RtlAKAgXDFxxgKmWH 2rbxoaPIMnSi2xtSm+EY4P4w8YojftKrWDsbyDV9XJdRDrVhOZJlFD9iGMbteHoWDMnX lhJ8jVRDYpnKQFB0KVhhwy+dzkiQXDm+sW/7OKQoq/fCD95lBZSEsfrlkR4N9FcL7K9B GRC7u4nSezTf4LTZyLuAYx3Uf7195hJNZCLUPSjFOO6Jp3j/sRCcDAW+Xnur6cC/h8hC qfKqvjmKOaA4YxSND+srbTreUbHETuLhGYNCog0hI1sFjOuaci2JdYx4j8Q2F7pT/6M1 MvkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=htf7oQLbUIT12CkPdqZFjdgF/YoqVY5s3W8UZCtazfU=; b=cHH5wXNGPp6PjVFoWfZerb8Bki7SAzoCl+CEfr4g9+2AnvAmIaEnW/hdH7VIhMlwQ5 Beko8ZXyShZIA6ZITP42BvTChfUH4cUZb/aQTBqavsu9gXjvBhVl1wrSerZ4ULJakkF9 pBPUBy++tkjzpXZu1+eOWu8i5YxezvbRKqTKbH6Y48INrrmGFXtKDgG1SbCS39Z3KbUk LrXmD8Zy2zL9LxFNsrJJucaoiBfFDMdXUYJnNTC4XgdgYb6AVtE1kfwLqiE5IthEsZdZ KZ9rNU8AqKPG8aVcHM0caA1hb9YR80Jj2UHES/k++sVZUMjiqQzS/4OyniRzpUSymjp8 H9cA== X-Gm-Message-State: AOAM532vb1xVWvNFX1fY1xvWBKGtv5hMHSa4RIWqIE2SSxQyDVYBa77p p7gJZQlPEjWsUvZzb1TwaS6ca8RgqMn0BbNFr3Q= X-Google-Smtp-Source: ABdhPJwoZCydcQ/F/M7hMYjYvOS8z4MbQe8D7XdvViM/KC8+z4gAYHKEAqye/nrRvgEL+J/XKDTJuBkLppZidNDdXdY= X-Received: by 2002:a5e:9612:: with SMTP id a18mr1987644ioq.13.1607510665449; Wed, 09 Dec 2020 02:44:25 -0800 (PST) MIME-Version: 1.0 References: <20201208122824.16118-1-laoar.shao@gmail.com> <20201208122824.16118-4-laoar.shao@gmail.com> <20201208185946.GC1943235@magnolia> <20201209035320.GI1943235@magnolia> In-Reply-To: <20201209035320.GI1943235@magnolia> From: Yafang Shao Date: Wed, 9 Dec 2020 18:43:49 +0800 Message-ID: Subject: Re: [PATCH v11 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} To: "Darrick J. Wong" Cc: Matthew Wilcox , Dave Chinner , Christoph Hellwig , Michal Hocko , Andrew Morton , David Howells , jlayton@redhat.com, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, Linux MM , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" 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: On Wed, Dec 9, 2020 at 11:53 AM Darrick J. Wong wrote: > > On Wed, Dec 09, 2020 at 09:47:38AM +0800, Yafang Shao wrote: > > On Wed, Dec 9, 2020 at 2:59 AM Darrick J. Wong wrote: > > > > > > On Tue, Dec 08, 2020 at 08:28:23PM +0800, Yafang Shao wrote: > > > > 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 | 20 +++++++------------- > > > > 1 file changed, 7 insertions(+), 13 deletions(-) > > > > > > > > diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c > > > > index 11d390f0d3f2..fe20398a214e 100644 > > > > --- a/fs/xfs/xfs_trans.c > > > > +++ b/fs/xfs/xfs_trans.c > > > > @@ -67,6 +67,9 @@ 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); > > > > > > Don't you need to check if tp is still the current transaction before > > > you clear PF_MEMALLOC_NOFS, now that the NOFS is bound to the lifespan > > > of the transaction itself instead of the reservation? > > > > > > > The current->journal_info is always the same with tp here in my verification. > > I don't know in which case they are different. > > I don't know why you changed it from the previous version. > I should explain it in the change log. Sorry about that. > > It would be better if you could explain in detail. Anyway I can add > > the check with your comment in the next version. > > xfs_trans_alloc is called to allocate a transaction. We set _NOFS and > save the old flags (which don't contain _NOFS) to this transaction. > > thread logs some changes and calls xfs_trans_roll. > > xfs_trans_roll calls xfs_trans_dup to duplicate the old transaction. > > xfs_trans_dup allocates a new transaction, which sets PF_MEMALLOC_NOFS > and saves the current context flags (in which _NOFS is set) in the new > transaction. > > xfs_trans_roll then commits the old transaction > > xfs_trans_commit frees the old transaction > > xfs_trans_free restores the old context (which didn't have _NOFS) and > now we've dropped NOFS incorrectly > > now we move on with the new transaction, but in the wrong NOFS mode. > > note that this becomes a lot more obvious once you start fiddling with > current->journal_info in the last patch. > Many thanks for the detailed explanation. I missed the rolling transaction. I will add this check in the next version. > --D > > > > > > > > > > + > > > > 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 +156,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 +163,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 +240,6 @@ xfs_trans_reserve( > > > > tp->t_blk_res = 0; > > > > } > > > > > > > > - xfs_trans_context_clear(tp); > > > > - > > > > return error; > > > > } > > > > > > > > @@ -284,6 +281,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 +877,6 @@ __xfs_trans_commit( > > > > > > > > xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); > > > > > > > > - xfs_trans_context_clear(tp); > > > > xfs_trans_free(tp); > > > > > > > > /* > > > > @@ -911,7 +909,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 +968,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); > > > > } > > > > -- > > > > 2.18.4 > > > > > > > > > > > > -- > > Thanks > > Yafang -- Thanks Yafang