linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "NeilBrown" <neilb@suse.de>
To: "Christoph Hellwig" <hch@infradead.org>
Cc: "Trond Myklebust" <trond.myklebust@hammerspace.com>,
	"Anna Schumaker" <anna.schumaker@netapp.com>,
	"Chuck Lever" <chuck.lever@oracle.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Mel Gorman" <mgorman@suse.de>,
	linux-nfs@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 03/13] MM: reclaim mustn't enter FS for swap-over-NFS
Date: Wed, 17 Nov 2021 08:35:23 +1100	[thread overview]
Message-ID: <163709852340.13692.16362531894844686350@noble.neil.brown.name> (raw)
In-Reply-To: <YZNss/ujX3yovr/k@infradead.org>

On Tue, 16 Nov 2021, Christoph Hellwig wrote:
> On Tue, Nov 16, 2021 at 01:44:04PM +1100, NeilBrown wrote:
> > +		/* ->flags can be updated non-atomicially (scan_swap_map_slots),
> > +		 * but that will never affect SWP_FS_OPS, so the data_race
> > +		 * is safe.
> > +		 */
> >  		may_enter_fs = (sc->gfp_mask & __GFP_FS) ||
> > +			(PageSwapCache(page) &&
> > +			 !data_race(page_swap_info(page)->flags & SWP_FS_OPS) &&
> > +			 (sc->gfp_mask & __GFP_IO));
> 
> You might want to move the comment and SWP_FS_OPS into a little
> inline helper.  That makes it a lot more readable and also avoids the
> overly long line in the second hunk.

Yes, that's a good idea.  Something like this....

Thanks,
NeilBrown

From a85d09cc3d671c45e32d782454afeeaaaece96c7 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Fri, 29 Oct 2021 13:35:56 +1100
Subject: [PATCH] MM: reclaim mustn't enter FS for swap-over-NFS

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.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 mm/vmscan.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index fb9584641ac7..e672fcc14bac 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1464,6 +1464,21 @@ static unsigned int demote_page_list(struct list_head *demote_pages,
 	return nr_succeeded;
 }
 
+static bool test_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_info(page)->flags & SWP_FS_OPS);
+}
+
 /*
  * shrink_page_list() returns the number of reclaimed pages
  */
@@ -1513,8 +1528,7 @@ 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));
+		may_enter_fs = test_may_enter_fs(page, sc->gfp_mask);
 
 		/*
 		 * The number of dirty pages determines if a node is marked
@@ -1682,7 +1696,8 @@ static unsigned int shrink_page_list(struct list_head *page_list,
 						goto activate_locked_split;
 				}
 
-				may_enter_fs = true;
+				may_enter_fs = test_may_enter_fs(page,
+								 sc->gfp_mask);
 
 				/* Adding to swap updated mapping */
 				mapping = page_mapping(page);
-- 
2.33.1



  reply	other threads:[~2021-11-16 21:35 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16  2:44 [PATCH 00/13] Repair SWAP-over-NFS NeilBrown
2021-11-16  2:44 ` [PATCH 06/13] SUNRPC/xprt: async tasks mustn't block waiting for memory NeilBrown
2021-11-16  2:44 ` [PATCH 05/13] SUNRPC/auth: " NeilBrown
2021-11-16  2:44 ` [PATCH 01/13] NFS: move generic_write_checks() call from nfs_file_direct_write() to nfs_file_write() NeilBrown
2021-11-16  2:44 ` [PATCH 08/13] NFS: discard NFS_RPC_SWAPFLAGS and RPC_TASK_ROOTCREDS NeilBrown
2021-11-16  2:44 ` [PATCH 03/13] MM: reclaim mustn't enter FS for swap-over-NFS NeilBrown
2021-11-16  8:32   ` Christoph Hellwig
2021-11-16 21:35     ` NeilBrown [this message]
2021-11-17  5:50       ` Christoph Hellwig
2021-11-18  1:43   ` kernel test robot
2021-11-16  2:44 ` [PATCH 12/13] MM: use AIO/DIO for reads from SWP_FS_OPS swap-space NeilBrown
2021-11-16  8:31   ` Christoph Hellwig
2021-11-16 21:46     ` NeilBrown
2021-11-16  2:44 ` [PATCH 09/13] SUNRPC: improve 'swap' handling: scheduling and PF_MEMALLOC NeilBrown
2021-11-16  2:44 ` [PATCH 04/13] SUNRPC/call_alloc: async tasks mustn't block waiting for memory NeilBrown
2021-11-16  2:44 ` [PATCH 13/13] MM: use AIO for DIO writes to swap NeilBrown
2021-11-16  2:44 ` [PATCH 10/13] NFSv4: keep state manager thread active if swap is enabled NeilBrown
2021-11-16  2:44 ` [PATCH 02/13] NFS: do not take i_rwsem for swap IO NeilBrown
2021-11-16  7:52   ` Christoph Hellwig
2021-11-16 21:50     ` NeilBrown
2021-11-17  5:49       ` Christoph Hellwig
2021-11-16  2:44 ` [PATCH 07/13] SUNRPC: remove scheduling boost for "SWAPPER" tasks NeilBrown
2021-11-16  2:44 ` [PATCH 11/13] NFS: swap-out must always use STABLE writes NeilBrown
2021-11-16  3:29 ` [PATCH 00/13] Repair SWAP-over-NFS Matthew Wilcox
2021-11-16  3:55   ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=163709852340.13692.16362531894844686350@noble.neil.brown.name \
    --to=neilb@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=anna.schumaker@netapp.com \
    --cc=chuck.lever@oracle.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=trond.myklebust@hammerspace.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox