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 2C23EC433FE for ; Wed, 9 Dec 2020 01:41:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A06ED238E4 for ; Wed, 9 Dec 2020 01:41:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A06ED238E4 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 D5C8A6B0078; Tue, 8 Dec 2020 20:41:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D11526B007D; Tue, 8 Dec 2020 20:41:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFB946B007E; Tue, 8 Dec 2020 20:41:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id A7FBA6B0078 for ; Tue, 8 Dec 2020 20:41:18 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6BB1A181AEF1D for ; Wed, 9 Dec 2020 01:41:18 +0000 (UTC) X-FDA: 77572041036.05.start61_4c07c6a273eb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 4D91C180206ED for ; Wed, 9 Dec 2020 01:41:18 +0000 (UTC) X-HE-Tag: start61_4c07c6a273eb X-Filterd-Recvd-Size: 8855 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Dec 2020 01:41:16 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id t9so98122ilf.2 for ; Tue, 08 Dec 2020 17:41:16 -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=iAGWTxNYiR5ootYJRUnUUI04QhdswVTJD/R6XwstuWM=; b=HB/rAKzJr5CG+rq2DeWaPCAmqtQN1wgBJx6FeZmzTHWzYSyhwWT6zlgTr7NxOc+CBn 1d52HA3170acxH6axHMsipNoDhhHBrZYXL7gLCMl0yWpgijY4omt0IcDaDj/NEG5gF5H q1EafboB2/cpJuRinDHJ0lgR/M0goLFmG2o7Wmijj9zhGHPIkeiTMu9Qlv2NQdaZaDt5 CM40N0DOVcuN5ugpTuESqvMDuEdkvVZPy4y2p1TV1W4eJtF+w3aaWXT3T4P4QUqoWziZ XByaOhvEsPitAECL4YMtMYHGeRxxqQHouGqgJ8+i7JKxE8QVee+q/A9cLG348f65gvQ0 1rRw== 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=iAGWTxNYiR5ootYJRUnUUI04QhdswVTJD/R6XwstuWM=; b=h+TPAeZibiXbZHdV2EbK3CuhEOZ8cY3iE1aFfJaf7PLFYh0qJlwC7jcKEfMT86bCPP hSxZ/JwiJmFq3FQqnc/lLm5iA5YscopkBbQxmj6W8+1THsnn1eY+MiheviL9B8VWCBMi 5nkjvDFEOeQqeLrJctHTL4EvgqMPLI3I2hCzspkLOQfKGgNPEE6opiWQXhMW4BafEQZm WoMCgtrV64Os+f71H87rMNcJWFr29S6oaby20CWKY2K72mzEjKBSyn9uc9bwMF0O182X HKhoQT8hOJBzAYcUbmOdWtwZQlYpkxweSEZi3V5tAf4QLPIQ48/9bOSP4eBY7cLGjN4q ZEAw== X-Gm-Message-State: AOAM530kKaSG8fQV80wyMsHSeexrom6r7qCMmbpJWTSkfTSPkeQ6Zmso O1CZzVNWr/UEX5mMAI7zlxPB+vz9fRu3IYmT2Wo= X-Google-Smtp-Source: ABdhPJwYEbLB3evwd4abSi2gz55NeZ/XnLzHrSL8vccVrF859VvYv+M/ufOp7NWH+xP5cHBIkbG+AhvacQbYO4UR5S4= X-Received: by 2002:a05:6e02:c32:: with SMTP id q18mr58174ilg.203.1607478076247; Tue, 08 Dec 2020 17:41:16 -0800 (PST) MIME-Version: 1.0 References: <20201208122824.16118-1-laoar.shao@gmail.com> <20201208122824.16118-5-laoar.shao@gmail.com> <20201208185959.GD1943235@magnolia> In-Reply-To: <20201208185959.GD1943235@magnolia> From: Yafang Shao Date: Wed, 9 Dec 2020 09:40:40 +0800 Message-ID: Subject: Re: [PATCH v11 4/4] xfs: use current->journal_info to avoid transaction reservation recursion 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 3:00 AM Darrick J. Wong wrote: > > On Tue, Dec 08, 2020 at 08:28:24PM +0800, Yafang Shao wrote: > > PF_FSTRANS which is used to avoid transaction reservation recursion, is > > dropped since commit 9070733b4efa ("xfs: abstract PF_FSTRANS to > > PF_MEMALLOC_NOFS") and commit 7dea19f9ee63 ("mm: introduce > > memalloc_nofs_{save,restore} API") and replaced by PF_MEMALLOC_NOFS which > > means to avoid filesystem reclaim recursion. > > > > As these two flags have different meanings, we'd better reintroduce > > PF_FSTRANS back. To avoid wasting the space of PF_* flags in task_struct, > > we can reuse the current->journal_info to do that, per Willy. As the > > check of transaction reservation recursion is used by XFS only, we can > > move the check into xfs_vm_writepage(s), per Dave. > > > > To better abstract that behavoir, two new helpers are introduced, as > > follows, > > - xfs_trans_context_active > > To check whehter current is in fs transcation or not > > - xfs_trans_context_swap > > Transfer the transaction context when rolling a permanent transaction > > > > These two new helpers are instroduced in xfs_trans.h. > > > > Cc: Darrick J. Wong > > Cc: Matthew Wilcox (Oracle) > > Cc: Christoph Hellwig > > Cc: Dave Chinner > > Cc: Michal Hocko > > Cc: David Howells > > Cc: Jeff Layton > > Signed-off-by: Yafang Shao > > --- > > fs/iomap/buffered-io.c | 7 ------- > > fs/xfs/xfs_aops.c | 17 +++++++++++++++++ > > fs/xfs/xfs_trans.c | 3 +++ > > fs/xfs/xfs_trans.h | 22 ++++++++++++++++++++++ > > 4 files changed, 42 insertions(+), 7 deletions(-) > > > > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > > index 10cc7979ce38..3c53fa6ce64d 100644 > > --- a/fs/iomap/buffered-io.c > > +++ b/fs/iomap/buffered-io.c > > @@ -1458,13 +1458,6 @@ iomap_do_writepage(struct page *page, struct writeback_control *wbc, void *data) > > PF_MEMALLOC)) > > goto redirty; > > > > - /* > > - * Given that we do not allow direct reclaim to call us, we should > > - * never be called in a recursive filesystem reclaim context. > > - */ > > - if (WARN_ON_ONCE(current->flags & PF_MEMALLOC_NOFS)) > > - goto redirty; > > - > > /* > > * Is this page beyond the end of the file? > > * > > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > > index 2371187b7615..0da0242d42c3 100644 > > --- a/fs/xfs/xfs_aops.c > > +++ b/fs/xfs/xfs_aops.c > > @@ -568,6 +568,16 @@ xfs_vm_writepage( > > { > > struct xfs_writepage_ctx wpc = { }; > > > > + /* > > + * Given that we do not allow direct reclaim to call us, we should > > + * never be called while in a filesystem transaction. > > + */ > > + if (WARN_ON_ONCE(xfs_trans_context_active())) { > > + redirty_page_for_writepage(wbc, page); > > + unlock_page(page); > > + return 0; > > + } > > + > > return iomap_writepage(page, wbc, &wpc.ctx, &xfs_writeback_ops); > > } > > > > @@ -579,6 +589,13 @@ xfs_vm_writepages( > > struct xfs_writepage_ctx wpc = { }; > > > > xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); > > + /* > > + * Given that we do not allow direct reclaim to call us, we should > > + * never be called while in a filesystem transaction. > > + */ > > + if (WARN_ON_ONCE(xfs_trans_context_active())) > > + return 0; > > + > > return iomap_writepages(mapping, wbc, &wpc.ctx, &xfs_writeback_ops); > > } > > > > diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c > > index fe20398a214e..08d4916ffb13 100644 > > --- a/fs/xfs/xfs_trans.c > > +++ b/fs/xfs/xfs_trans.c > > @@ -124,6 +124,9 @@ xfs_trans_dup( > > tp->t_rtx_res = tp->t_rtx_res_used; > > ntp->t_pflags = tp->t_pflags; > > This one line (ntp->t_pflags = tp->t_pflags) should move to > xfs_trans_context_swap. > Make sense to me. Will update it. > --D > > > > > + /* 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); > > > > diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h > > index 44b11c64a15e..d596a375e3bf 100644 > > --- a/fs/xfs/xfs_trans.h > > +++ b/fs/xfs/xfs_trans.h > > @@ -268,16 +268,38 @@ xfs_trans_item_relog( > > return lip->li_ops->iop_relog(lip, tp); > > } > > > > +static inline bool > > +xfs_trans_context_active(void) > > +{ > > + /* Use journal_info to indicate current is in a transaction */ > > + return current->journal_info != NULL; > > +} > > + > > static inline void > > xfs_trans_context_set(struct xfs_trans *tp) > > { > > + ASSERT(!current->journal_info); > > + current->journal_info = tp; > > tp->t_pflags = memalloc_nofs_save(); > > } > > > > static inline void > > xfs_trans_context_clear(struct xfs_trans *tp) > > { > > + ASSERT(current->journal_info == tp); > > + current->journal_info = NULL; > > memalloc_nofs_restore(tp->t_pflags); > > } > > > > +/* > > + * Transfer the transaction context when rolling a permanent > > + * transaction. > > + */ > > +static inline void > > +xfs_trans_context_swap(struct xfs_trans *tp, struct xfs_trans *ntp) > > +{ > > + ASSERT(current->journal_info == tp); > > + current->journal_info = ntp; > > +} > > + > > #endif /* __XFS_TRANS_H__ */ > > -- > > 2.18.4 > > -- Thanks Yafang