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 CF781C4361B for ; Sat, 19 Dec 2020 00:16:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D04823B23 for ; Sat, 19 Dec 2020 00:16:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D04823B23 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 4E1716B005C; Fri, 18 Dec 2020 19:16:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46BEC6B005D; Fri, 18 Dec 2020 19:16:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 333246B0068; Fri, 18 Dec 2020 19:16:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id 180226B005C for ; Fri, 18 Dec 2020 19:16:57 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C8227181CBDC1 for ; Sat, 19 Dec 2020 00:16:56 +0000 (UTC) X-FDA: 77608116432.18.price88_51010a227441 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id ACFD7100EC668 for ; Sat, 19 Dec 2020 00:16:56 +0000 (UTC) X-HE-Tag: price88_51010a227441 X-Filterd-Recvd-Size: 8165 Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Sat, 19 Dec 2020 00:16:56 +0000 (UTC) Received: by mail-il1-f177.google.com with SMTP id n9so3824684ili.0 for ; Fri, 18 Dec 2020 16:16:56 -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=o+srfVk5LFUit/NQt+S2ivZ9seQ6hbpnwEWB584IB1M=; b=SaMiyBIWjpP1z8VlNM9VPbdbeQpZuMO+Ymt7hFKE3OVQV3PVyQYZaTe41AuayQ4r7u D+0JyaOGlcCJXwD0QJ0BL594q7v/7PJIhIfXbD/iOduoUfb1AR/PPG6R3AbmcVSYpbAm ovQ1Z0Y7b+pCrlyU+CgG4sY+lARHw6/0xHltrMSJ5PJh5+cFypQsXtrLXce9Y/dH1Rpp MwrS/DOBr5q00zFGlcpV5qvSu+Mpr2EdZwA1tU41g7kRErAGjXT4OGZ4WVp1vWoD2yjo bVJeGjhEzZ0pmAySe4X4Tu5S75zZlgcgfpuqM0IboeBybQTIh4uGfeN1e3irR1Lcb1qY eRAQ== 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=o+srfVk5LFUit/NQt+S2ivZ9seQ6hbpnwEWB584IB1M=; b=ElNMxMnZk2YL0pxgx90ymp2pwyXK71546Vapx3ab1THFSWsCBh0vqSKds/euF2gQx8 1vM60Ccfrb6pmoALZB2T825zlmME0FqSlCcyfseptIAcTNNOZJ0YA4XOsvE6i7Bnix0+ YmbLoQfID+bBmq4uM9IZq86IkI9lCfiGeFKEEzT+PSa6DlKakT9/0wPYta8B8B3Q5GJ8 wIDhn9I4/Q2RbDSLBsgMlwID9QCzbiCNopw0s9NTJaYYX2jJCOwWJMmSRALHTdoc4e4e iJBPmxhGEwSF9txgyMUJZ+knlHvl13zieMW1K35unBeqhXTSvC61g/IyAQ+Z5JQrJXWH eeeA== X-Gm-Message-State: AOAM531kyE6fwV4NOiDFbms2smS/fVPvXVwBvuSGajzaiYtnA6z/1jmu 0LXNokCf957U9lSClsSb4oonrEk+e0jFXYmGJYw= X-Google-Smtp-Source: ABdhPJzSxqkvV+NbAPCJQWZJzXNqRmylB8moClwA0C9kvg1T5xDU8dIs76SfXzjOTqJ1BXo3tRJj9ii5YSitobTpRSU= X-Received: by 2002:a05:6e02:c32:: with SMTP id q18mr6667563ilg.203.1608337015728; Fri, 18 Dec 2020 16:16:55 -0800 (PST) MIME-Version: 1.0 References: <20201217011157.92549-1-laoar.shao@gmail.com> <20201217011157.92549-5-laoar.shao@gmail.com> <20201218001442.GS632069@dread.disaster.area> In-Reply-To: <20201218001442.GS632069@dread.disaster.area> From: Yafang Shao Date: Sat, 19 Dec 2020 08:16:19 +0800 Message-ID: Subject: Re: [PATCH v13 4/4] xfs: use current->journal_info to avoid transaction reservation recursion To: Dave Chinner Cc: "Darrick J. Wong" , Matthew Wilcox , 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 Fri, Dec 18, 2020 at 8:14 AM Dave Chinner wrote: > > On Thu, Dec 17, 2020 at 09:11:57AM +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 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. > > > > 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.h | 26 +++++++++++++++++++------- > > 3 files changed, 36 insertions(+), 14 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. > > + */ > > Comment is wrong. This is not protecting against direct reclaim > recursion, this is protecting against writeback from within a > transaction context. > Ah, I forgot to change this comment after copy and paste. Thanks for pointing it out. > Best to remove the comment altogether, because it is largely > redundant. > Sure, I will remove these comments. > > + 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. > > + */ > > same here. > > > + 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.h b/fs/xfs/xfs_trans.h > > index 12380eaaf7ce..0c8140147b9b 100644 > > --- a/fs/xfs/xfs_trans.h > > +++ b/fs/xfs/xfs_trans.h > > @@ -268,29 +268,41 @@ 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; > > +} > > Comment is not necessary. > > > + > > 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) > > { > > + /* > > + * If xfs_trans_context_swap() handed the NOFS context to a > > + * new transaction we do not clear the context here. > > + */ > > It's a transaction context, not a "NOFS context". Setting NOFS is > just something we implement inside the transaction context. More > correct would be: > > /* > * If we handed over the context via xfs_trans_context_swap() then > * the context is no longer ours to clear. > */ > Sure, I will change it. -- Thanks Yafang