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=-3.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 7E61FC433E0 for ; Fri, 26 Jun 2020 09:03:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2349920DD4 for ; Fri, 26 Jun 2020 09:03:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="uZ5YHRup" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2349920DD4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 840E06B000A; Fri, 26 Jun 2020 05:03:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F05A6B000D; Fri, 26 Jun 2020 05:03:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B95B6B000E; Fri, 26 Jun 2020 05:03:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0073.hostedemail.com [216.40.44.73]) by kanga.kvack.org (Postfix) with ESMTP id 4F8AA6B000A for ; Fri, 26 Jun 2020 05:03:04 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F1ADA83E0 for ; Fri, 26 Jun 2020 09:03:03 +0000 (UTC) X-FDA: 76970773446.30.glue09_5503fd726e54 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id C7AC2180B3AA7 for ; Fri, 26 Jun 2020 09:03:03 +0000 (UTC) X-HE-Tag: glue09_5503fd726e54 X-Filterd-Recvd-Size: 4141 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Fri, 26 Jun 2020 09:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=S16fz6lo9KryqIgQOCLtuAMJm3zEkBOc3oSqDZv4FDI=; b=uZ5YHRupN53fy0Q7TGZ81ef3mj RwajTvvDVxXo97RTwKcwHYn0Ft4Psidug4IqSqdZm1Ho21Bb0FeKzkyIgO312i1QSZOTDmSxte4WA ZP6D5s6rl9shXGLjtc7RmG+Sgim+rqk8YuRKvnFX1oMGVv6/FSO7dhGOainjzdsuE8oxXYE1GQJjB lcvfjIV0V+/x3v8/yynAoj9YVz9GLueHzDazgQEsK58lHlsAojkvF5UWzfaGUWjl+l5gITKgW7w6h CPAtnxKAT9l+TIIT3mTxDcxuIsRwI/BNv+AJky1IxMTD8FKDpFLQ9haUxNkEv4WLTDNqiUPnbOlz3 Jv8BHQcw==; Received: from hch by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jokG2-0001Jo-FB; Fri, 26 Jun 2020 09:02:50 +0000 Date: Fri, 26 Jun 2020 10:02:50 +0100 From: Christoph Hellwig To: Yafang Shao Cc: david@fromorbit.com, mhocko@kernel.org, darrick.wong@oracle.com, hch@infradead.org, akpm@linux-foundation.org, bfoster@redhat.com, vbabka@suse.cz, holger@applied-asynchrony.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] xfs: reintroduce PF_FSTRANS for transaction reservation recursion protection Message-ID: <20200626090250.GC30103@infradead.org> References: <1593011142-10209-1-git-send-email-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1593011142-10209-1-git-send-email-laoar.shao@gmail.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: C7AC2180B3AA7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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, Jun 24, 2020 at 11:05:42AM -0400, 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. That change is subtle. > Let's take the exmple of the check of WARN_ON_ONCE(current->flags & > PF_MEMALLOC_NOFS)) to explain why this abstraction from PF_FSTRANS to > PF_MEMALLOC_NOFS is not proper. > > Bellow comment is quoted from Dave, > > It wasn't for memory allocation recursion protection in XFS - it was for > > transaction reservation recursion protection by something trying to flush > > data pages while holding a transaction reservation. Doing > > this could deadlock the journal because the existing reservation > > could prevent the nested reservation for being able to reserve space > > in the journal and that is a self-deadlock vector. > > IOWs, this check is not protecting against memory reclaim recursion > > bugs at all (that's the previous check [1]). This check is > > protecting against the filesystem calling writepages directly from a > > context where it can self-deadlock. > > So what we are seeing here is that the PF_FSTRANS -> > > PF_MEMALLOC_NOFS abstraction lost all the actual useful information > > about what type of error this check was protecting against. > > [1]. Bellow check is to avoid memory reclaim recursion. > if (WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == > PF_MEMALLOC)) > goto redirty; > > Suggested-by: Dave Chinner > Signed-off-by: Yafang Shao > Cc: Michal Hocko This generally looks sane, but: - adds a bunch of overly long lines for no good reason - doesn't really hide this behind a useful informatin, e.g. a xfs_trans_context_start/end helpers for the normal case, plus an extra helper with kswapd in the name for that case. The latter should also help to isolate a bit against the mm-area changes to the memalloc flags proposed.