From patchwork Wed Jan 13 10:22:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12016417 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 25621C433E0 for ; Wed, 13 Jan 2021 10:23:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 97C972337F for ; Wed, 13 Jan 2021 10:23:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97C972337F 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 2349F8D0033; Wed, 13 Jan 2021 05:23:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E48F8D0032; Wed, 13 Jan 2021 05:23:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 122298D0033; Wed, 13 Jan 2021 05:23:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id EFF1A8D0032 for ; Wed, 13 Jan 2021 05:23:32 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B5672824CA00 for ; Wed, 13 Jan 2021 10:23:32 +0000 (UTC) X-FDA: 77700365064.15.eyes69_4a14af22751d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 8DD121814B0C7 for ; Wed, 13 Jan 2021 10:23:32 +0000 (UTC) X-HE-Tag: eyes69_4a14af22751d X-Filterd-Recvd-Size: 6991 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 10:23:32 +0000 (UTC) Received: by mail-ot1-f53.google.com with SMTP id x13so1399299oto.8 for ; Wed, 13 Jan 2021 02:23:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Hoa9myK143cV0+5FfOAtzs2mXHnYs56TUMaxDFngxI=; b=A27KBa9Qa0CiPAirttd1MC3c+k7HXbqbNcZaGLIuO02YysUlSXQe9nftLGDAbk+k1Y m5vlobOmcK2hqS2qzoIMlFmrlm78z+S5YpNhleNyEkdCDlJlMZcES7zOwZhpVJukDoJ2 G+FqJ4ETTUSzfZYR716nzjqMzhCkMlQ2b5rYQ5iLd+G60zEIWQ2zHlTq6sZS+LfN9Ybv tekBdi0j5Nf8H44wvix5j6SwwlNGbKwSwkCWxj7UDmWeGm5H6CZCtAkXVp3L4YyVyagJ bp1r3zK3LekfVEfyXBfd7B/4W8GGe5gvL/tuUO9t0ZoNqLhWuY9jEgf6aI4mkHb8vFx6 LfzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Hoa9myK143cV0+5FfOAtzs2mXHnYs56TUMaxDFngxI=; b=IDS90LopqNKNWlGv6Yw6pgZ8UBFSkw/T/zc3Ognn+BYHhyyhGswHCdn5NCBn9PCPkm wseuBqC7qN6O1R/BJIAd30PRaXBlY8V/SRec6ygHI+K/j2C+W28VVUFI1ELFY0M6qBLY NgQ5ggd0haPeGFEA56CGsiRZaDVoPMmpMeJJflI+C9ra9LCQVHflxjCVdxpOIXWxgfhY 2XJOozteN01J5f38tNiiiBIC0ZJl2El4syXPAiGs9O4GxABCK9+HHVSxHY1mY+X82FL/ CMT8AmZytip8KJEnU/SJoMd8j6Up+ZbP++//h2kh1OLQwBu78NADM4u7GJ1AyHjCin7m sx9Q== X-Gm-Message-State: AOAM533bE/fMPwPyHn5LSQ+uY5mGtUHpvKzHaiGaEicU2od0uL/MxzCj sj+AE2FnwNjHePlBZbk9klU= X-Google-Smtp-Source: ABdhPJzMbFRs70OCbw4e3J96c+SlsfFE7Ic6psQgivnf/qYiMFYIWrf1tQemCSk4aiSnqSS+tSYWsg== X-Received: by 2002:a9d:12d7:: with SMTP id g81mr761901otg.103.1610533411738; Wed, 13 Jan 2021 02:23:31 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id z8sm335571oon.10.2021.01.13.02.23.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jan 2021 02:23:31 -0800 (PST) From: Yafang Shao To: darrick.wong@oracle.com, willy@infradead.org, david@fromorbit.com, hch@infradead.org, mhocko@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, jlayton@redhat.com Cc: linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, Yafang Shao , Christoph Hellwig Subject: [PATCH v15 4/4] xfs: use current->journal_info to avoid transaction reservation recursion Date: Wed, 13 Jan 2021 18:22:24 +0800 Message-Id: <20210113102224.13655-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210113102224.13655-1-laoar.shao@gmail.com> References: <20210113102224.13655-1-laoar.shao@gmail.com> MIME-Version: 1.0 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: 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. [oliver.sang@intel.com: reported a Assertion_failed in the prev version] Cc: Darrick J. Wong Cc: Matthew Wilcox (Oracle) Cc: Christoph Hellwig Cc: Dave Chinner Cc: Michal Hocko Cc: David Howells Cc: Jeff Layton Cc: kernel test robot Signed-off-by: Yafang Shao --- fs/iomap/buffered-io.c | 7 ------- fs/xfs/xfs_aops.c | 10 ++++++++++ fs/xfs/xfs_trans.h | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 10 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..eed4881d4461 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -568,6 +568,12 @@ xfs_vm_writepage( { struct xfs_writepage_ctx wpc = { }; + 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 +585,10 @@ xfs_vm_writepages( struct xfs_writepage_ctx wpc = { }; xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); + + 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 3645fd0d74b8..e2f3251d6cce 100644 --- a/fs/xfs/xfs_trans.h +++ b/fs/xfs/xfs_trans.h @@ -268,24 +268,40 @@ xfs_trans_item_relog( return lip->li_ops->iop_relog(lip, tp); } +static inline bool +xfs_trans_context_active(void) +{ + 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) { - if (!tp->t_pflags) - memalloc_nofs_restore(tp->t_pflags); + /* + * If we handed over the context via xfs_trans_context_swap() then + * the context is no longer needed to clear. + */ + if (current->journal_info != tp) + return; + + current->journal_info = NULL; + memalloc_nofs_restore(tp->t_pflags); } static inline void xfs_trans_context_swap(struct xfs_trans *tp, struct xfs_trans *ntp) { + ASSERT(current->journal_info == tp); + current->journal_info = ntp; ntp->t_pflags = tp->t_pflags; - tp->t_pflags = -1; } #endif /* __XFS_TRANS_H__ */