Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3365424pxb; Mon, 24 Jan 2022 08:08:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGVRjBYKCQe4TjHYNlGuk4TIHNQOlFeV2TFLvC0NPKnjqdsbpO2PKRz3L9hfRZ81X1EDOm X-Received: by 2002:a17:90b:108c:: with SMTP id gj12mr2543917pjb.231.1643040491622; Mon, 24 Jan 2022 08:08:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643040491; cv=none; d=google.com; s=arc-20160816; b=zMYFPsvLzDuPFRTDkJGaauck3oL+5xLwCsB/QikpOr8y66Uspx5JdprHztlL1ElCs7 BqMRlN2XMZeCc6knLyuAawYr7vGZxD9K+k32H4lbHochE4GrhEh0nuZd3dLYrOyCmJJf +skkO+fao/wl4S4cH/LvYZsB2Hb4H1GtwhQdf+OUwFUULFuLCRFMV5zkcyVU3acUT0dp BqfQvLzPP7JL+iZmbtdO2284RJk5hyYfpYwP+6UoDtok2OY4xP4JBLJ0H1RwyIV0lCNp u3HCEoDP6y+nqLHgGlzAwcu7vRqqkcBDVkNQcOhMv0ejYKhYbFMgOJQqZivSw10fh1KM DpvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature:dkim-signature; bh=7aGIJFrJoxVYTOarUMpcVxyhqOqRdBZGTPLRKjCZ04Y=; b=Yo29Ww//1BnZwm5Nh9wXkTUXqa5PXFR3qI37zsc3fw3mjCBjinTz/oChzVicxu1jI5 dr7r5y7WbbUuCHBDtYUaVvUTVFEFdV+LM2weCOIAkB9ilxZkOQDjyPOtg+zfyxHV7Xmx HeSaIiqJVBctqHzBVn1NSI0ALwCSsq4XFPAHR5sap391cdqTe1dF6xslUaGOqw0H4YAk kgFInrfoC21NK6WlF5XUntuZTpIJcDUjOKoCe9eIHMwTh3KJ4OuWruo7haBSKzBJhKlT mvgi27GEhL/jouukjFNmHvYljxZ4WCYaO3+xly+sW0BSfKA6BvDegPbH/p/rWAjC3e8S /4rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=n+mu4ts5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l18si13325266pgh.41.2022.01.24.08.07.57; Mon, 24 Jan 2022 08:08:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=n+mu4ts5; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241169AbiAXDvP (ORCPT + 99 others); Sun, 23 Jan 2022 22:51:15 -0500 Received: from smtp-out2.suse.de ([195.135.220.29]:46874 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241175AbiAXDvJ (ORCPT ); Sun, 23 Jan 2022 22:51:09 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 82AA41F3A0; Mon, 24 Jan 2022 03:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642996268; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7aGIJFrJoxVYTOarUMpcVxyhqOqRdBZGTPLRKjCZ04Y=; b=n+mu4ts5W6++NB/HdVWdE8/u2lXQLbHMlfwpoZTqDMnapsQ13f+u7f9HhjxBTWTO5iDyLQ D0Iy1Xqj9oNV7juUdF1ZhfwDMEWP8KHBfIA5kx9sPvOBTcgObD+IXl6Guud+j9drUFn32J kIgz1fZoFZeIUalBTmx+NouK2MsD3mw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642996268; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7aGIJFrJoxVYTOarUMpcVxyhqOqRdBZGTPLRKjCZ04Y=; b=8DCw4T5/4ajAli4QaAAQISZwKGlcsbSrCUT2KT+Qt+OEuiQAoF11dpSgoz/pGYcsT324Nj PW28866cIoVuzYDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2098E1331A; Mon, 24 Jan 2022 03:51:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id rbgdMygi7mH6RAAAMHmgww (envelope-from ); Mon, 24 Jan 2022 03:51:04 +0000 Subject: [PATCH 05/23] MM: reclaim mustn't enter FS for SWP_FS_OPS swap-space From: NeilBrown To: Trond Myklebust , Anna Schumaker , Chuck Lever , Andrew Morton , Mel Gorman , Christoph Hellwig , David Howells Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 24 Jan 2022 14:48:32 +1100 Message-ID: <164299611276.26253.11555458501911153645.stgit@noble.brown> In-Reply-To: <164299573337.26253.7538614611220034049.stgit@noble.brown> References: <164299573337.26253.7538614611220034049.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If swap-out is using filesystem operations (SWP_FS_OPS), then it is not safe to enter the FS for reclaim. So only down-grade the requirement for swap pages to __GFP_IO after checking that SWP_FS_OPS are not being used. This makes the calculation of "may_enter_fs" slightly more complex, so move it into a separate function. with that done, there is little value in maintaining the bool variable any more. So replace the may_enter_fs variable with a may_enter_fs() function. This removes any risk for the variable becoming out-of-date. Signed-off-by: NeilBrown --- mm/swap.h | 8 ++++++++ mm/vmscan.c | 29 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/mm/swap.h b/mm/swap.h index 13e72a5023aa..5c676e55f288 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -47,6 +47,10 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag, struct page *swapin_readahead(swp_entry_t entry, gfp_t flag, struct vm_fault *vmf); +static inline unsigned int page_swap_flags(struct page *page) +{ + return page_swap_info(page)->flags; +} #else /* CONFIG_SWAP */ static inline int swap_readpage(struct page *page, bool do_poll) { @@ -126,4 +130,8 @@ static inline void clear_shadow_from_swap_cache(int type, unsigned long begin, { } +static inline unsigned int page_swap_flags(struct page *page) +{ + return 0; +} #endif /* CONFIG_SWAP */ diff --git a/mm/vmscan.c b/mm/vmscan.c index 5c734ffc6057..ad5026d06aa8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1506,6 +1506,22 @@ static unsigned int demote_page_list(struct list_head *demote_pages, return nr_succeeded; } +static bool may_enter_fs(struct page *page, gfp_t gfp_mask) +{ + if (gfp_mask & __GFP_FS) + return true; + if (!PageSwapCache(page) || !(gfp_mask & __GFP_IO)) + return false; + /* + * We can "enter_fs" for swap-cache with only __GFP_IO + * providing this isn't SWP_FS_OPS. + * ->flags can be updated non-atomicially (scan_swap_map_slots), + * but that will never affect SWP_FS_OPS, so the data_race + * is safe. + */ + return !data_race(page_swap_flags(page) & SWP_FS_OPS); +} + /* * shrink_page_list() returns the number of reclaimed pages */ @@ -1531,7 +1547,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, struct address_space *mapping; struct page *page; enum page_references references = PAGEREF_RECLAIM; - bool dirty, writeback, may_enter_fs; + bool dirty, writeback; unsigned int nr_pages; cond_resched(); @@ -1555,9 +1571,6 @@ static unsigned int shrink_page_list(struct list_head *page_list, if (!sc->may_unmap && page_mapped(page)) goto keep_locked; - may_enter_fs = (sc->gfp_mask & __GFP_FS) || - (PageSwapCache(page) && (sc->gfp_mask & __GFP_IO)); - /* * The number of dirty pages determines if a node is marked * reclaim_congested. kswapd will stall and start writing @@ -1602,7 +1615,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, * not to fs). In this case mark the page for immediate * reclaim and continue scanning. * - * Require may_enter_fs because we would wait on fs, which + * Require may_enter_fs() because we would wait on fs, which * may not have submitted IO yet. And the loop driver might * enter reclaim, and deadlock if it waits on a page for * which it is needed to do the write (loop masks off @@ -1634,7 +1647,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, /* Case 2 above */ } else if (writeback_throttling_sane(sc) || - !PageReclaim(page) || !may_enter_fs) { + !PageReclaim(page) || !may_enter_fs(page, sc->gfp_mask)) { /* * This is slightly racy - end_page_writeback() * might have just cleared PageReclaim, then @@ -1724,8 +1737,6 @@ static unsigned int shrink_page_list(struct list_head *page_list, goto activate_locked_split; } - may_enter_fs = true; - /* Adding to swap updated mapping */ mapping = page_mapping(page); } @@ -1795,7 +1806,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, if (references == PAGEREF_RECLAIM_CLEAN) goto keep_locked; - if (!may_enter_fs) + if (!may_enter_fs(page, sc->gfp_mask)) goto keep_locked; if (!sc->may_writepage) goto keep_locked;