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.7 required=3.0 tests=BAYES_00, 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 1C1A0C4361B for ; Tue, 8 Dec 2020 04:20:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83F1023A61 for ; Tue, 8 Dec 2020 04:20:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83F1023A61 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=fromorbit.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B90C48D0019; Mon, 7 Dec 2020 23:20:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B40108D0002; Mon, 7 Dec 2020 23:20:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A07C38D0019; Mon, 7 Dec 2020 23:20:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 86E398D0002 for ; Mon, 7 Dec 2020 23:20:31 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 478F4180AD804 for ; Tue, 8 Dec 2020 04:20:31 +0000 (UTC) X-FDA: 77568813462.30.ducks84_3b02547273e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 29A96180B3C85 for ; Tue, 8 Dec 2020 04:20:31 +0000 (UTC) X-HE-Tag: ducks84_3b02547273e4 X-Filterd-Recvd-Size: 5692 Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 04:20:30 +0000 (UTC) Received: from dread.disaster.area (pa49-179-6-140.pa.nsw.optusnet.com.au [49.179.6.140]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id DACF93C1F3C; Tue, 8 Dec 2020 15:20:27 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1kmUUE-001fsm-VI; Tue, 08 Dec 2020 15:20:26 +1100 Date: Tue, 8 Dec 2020 15:20:26 +1100 From: Dave Chinner To: Yafang Shao Cc: darrick.wong@oracle.com, willy@infradead.org, hch@infradead.org, mhocko@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, jlayton@redhat.com, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: Re: [PATCH v10 4/4] xfs: use current->journal_info to avoid transaction reservation recursion Message-ID: <20201208042026.GW3913616@dread.disaster.area> References: <20201208021543.76501-1-laoar.shao@gmail.com> <20201208021543.76501-5-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201208021543.76501-5-laoar.shao@gmail.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=Ubgvt5aN c=1 sm=1 tr=0 cx=a_idp_d a=uDU3YIYVKEaHT0eX+MXYOQ==:117 a=uDU3YIYVKEaHT0eX+MXYOQ==:17 a=kj9zAlcOel0A:10 a=zTNgK-yGK50A:10 a=yPCof4ZbAAAA:8 a=JfrnYn6hAAAA:8 a=7-415B0cAAAA:8 a=VwQbUJbxAAAA:8 a=20KFwNOVAAAA:8 a=pGLkceISAAAA:8 a=EgeNp9WBsctHnM1Kfy0A:9 a=CjuIK1q_8ugA:10 a=1CNFftbPRP8L7MoqJWF3:22 a=biEYGPWJfzWAr4FL6Ov7:22 a=AjGcO6oz07-iQ99wixmX:22 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 Tue, Dec 08, 2020 at 10:15:43AM +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 | 25 +++++++++++++++++++++++++ > 4 files changed, 45 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..28db93d0da97 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 (xfs_trans_context_active()) { > + redirty_page_for_writepage(wbc, page); > + unlock_page(page); > + return 0; > + } hmmm. Missing warning.... > diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h > index 44b11c64a15e..82c6735e40fc 100644 > --- a/fs/xfs/xfs_trans.h > +++ b/fs/xfs/xfs_trans.h > @@ -268,16 +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 */ > + if (WARN_ON_ONCE(current->journal_info != NULL)) > + return true; > + > + return false; > +} Ah, this is wrong. The call sites should be: if (WARN_ON_ONCE(xfs_trans_context_active())) { /* do error handling */ return error_value; } because we might want to use xfs_trans_context_active() to check if we are in a transaction context or not and that should not generate a warning. Also, placing the warning at the call site gives a more accurate indication of which IO path generated the warning.... Cheers, Dave. -- Dave Chinner david@fromorbit.com