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.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 E65A5C1B0D8 for ; Thu, 17 Dec 2020 01:12:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E8F12076D for ; Thu, 17 Dec 2020 01:12:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E8F12076D 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 E1BB66B006E; Wed, 16 Dec 2020 20:12:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DCAFC8D0001; Wed, 16 Dec 2020 20:12:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1EC56B0071; Wed, 16 Dec 2020 20:12:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id A4B276B006E for ; Wed, 16 Dec 2020 20:12:33 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 67F731EF3 for ; Thu, 17 Dec 2020 01:12:33 +0000 (UTC) X-FDA: 77600998986.25.car67_4617d3527430 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 49FCA1804E3A0 for ; Thu, 17 Dec 2020 01:12:33 +0000 (UTC) X-HE-Tag: car67_4617d3527430 X-Filterd-Recvd-Size: 7393 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Dec 2020 01:12:32 +0000 (UTC) Received: by mail-vs1-f43.google.com with SMTP id p7so14048163vsf.8 for ; Wed, 16 Dec 2020 17:12: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=9alW6vAYyuzuIAm2W1sBzzo1XFQKdglwiDiVNpF1K2U=; b=Wi5ul+TpVrtbHopu2Iwb3DlGk1ZxVzDtLAsRdQMTu0GERUdvG2WVNpqpfK16fgUS9h yhq0822cOkKhzQ7ZRWz8Npvm048BUEnToPYJy+xnZwyVe3RDHJLz0OF/hw55IGWeldgE 5eN4vwFCW486dOUy2PHx60b2avDZZplCXBLtp/MZ7UGJPsDYcXQeO1lq3yyxiP14Ndbr c3KSA6WFYM51Cm3HJNKmNc96A2rjtwuTYDUHTxjQG6h9I+beliWreu54pMsFr24ff8cW Bl8HuQt0co6Qc5ubOg4BSBFIANtBrd9eSaTpbhD0uV6moRHkdHgfcLJJB4b+Q/X3+GZ2 HG7Q== 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=9alW6vAYyuzuIAm2W1sBzzo1XFQKdglwiDiVNpF1K2U=; b=B7B0RQp+50ucAwB04b+kc1B333bccJlEcdCfvt6FN3BXKlBtBr2UQharWtcQCeNlri yniID3Pu46MBDZX0i3Pw3yv+E8xyRacTyYu/11sYN/YwjmWOTY97u3Fbq243S5NTXj5N WIR9DOkqXr/OYonmeQznMxGGKkBQed83YVvTYozFq+SCFDK4+wKA6yPRCJ8e++wMoMnC xAnW0uGmXuTxPgOteWq8thl5QuylOiX6ccBxgYFu6KzE8I3rHm+GC7lmQ5x1SFWSetSr jP9szcrpbTHG2e4IgdsIO1UsoGVYx2qgwA5JBAHh0CAhlAq6QkW4I8iAQYwvv3xQZuYw yL2Q== X-Gm-Message-State: AOAM530JjdETpSdGBq+RGhHPpReQbV6h+jA9YyhNnaNlkpo+Z4QdW8Z3 8//fhegJVFTGqNzC9Wk2hjY= X-Google-Smtp-Source: ABdhPJymD38OIInUxz/A6UMIS832ePfAYJx4qTFdpzI+xn54beO/QqmFh11xxFmKvkJ1ebq2NwfIEA== X-Received: by 2002:a67:1142:: with SMTP id 63mr15960710vsr.24.1608167552295; Wed, 16 Dec 2020 17:12:32 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id i63sm2900760uad.4.2020.12.16.17.12.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Dec 2020 17:12: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, Yafang Shao , Christoph Hellwig Subject: [PATCH v13 4/4] xfs: use current->journal_info to avoid transaction reservation recursion Date: Thu, 17 Dec 2020 09:11:57 +0800 Message-Id: <20201217011157.92549-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20201217011157.92549-1-laoar.shao@gmail.com> References: <20201217011157.92549-1-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. 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 write= back_control *wbc, void *data) PF_MEMALLOC)) goto redirty; =20 - /* - * 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 =3D { }; =20 + /* + * 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); } =20 @@ -579,6 +589,13 @@ xfs_vm_writepages( struct xfs_writepage_ctx wpc =3D { }; =20 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); } =20 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); } =20 +static inline bool +xfs_trans_context_active(void) +{ + /* Use journal_info to indicate current is in a transaction */ + return current->journal_info !=3D NULL; +} + static inline void xfs_trans_context_set(struct xfs_trans *tp) { + ASSERT(!current->journal_info); + current->journal_info =3D tp; tp->t_pflags =3D memalloc_nofs_save(); } =20 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. + */ + if (current->journal_info !=3D tp) + return; + + current->journal_info =3D NULL; memalloc_nofs_restore(tp->t_pflags); } =20 static inline void xfs_trans_context_swap(struct xfs_trans *tp, struct xfs_trans *ntp) { + ASSERT(current->journal_info =3D=3D tp); + current->journal_info =3D ntp; ntp->t_pflags =3D tp->t_pflags; - /* - * For the rolling transaction, we have to set NOFS in the old - * transaction's t_pflags so that when we clear the context on - * the old transaction we don't actually change the thread's NOFS - * state. - */ - tp->t_pflags =3D current->flags | PF_MEMALLOC_NOFS; } =20 #endif /* __XFS_TRANS_H__ */ --=20 2.18.4