public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna.schumaker@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/4] NFS/localio: prevent direct reclaim recursion into NFS via nfs_writepages
Date: Wed,  7 Jan 2026 11:08:55 -0500	[thread overview]
Message-ID: <20260107160858.6847-2-snitzer@kernel.org> (raw)
In-Reply-To: <20260107160858.6847-1-snitzer@kernel.org>

From: Mike Snitzer <snitzer@hammerspace.com>

LOCALIO is an NFS loopback mount optimization that avoids using the
network for READ, WRITE and COMMIT if the NFS client and server are
determined to be on the same system. But because LOCALIO is still
fundamentally "just NFS loopback mount" it is susceptible to recursion
deadlock via direct reclaim, e.g.: NFS LOCALIO down to XFS and then
back into NFS via nfs_writepages.

Fix LOCALIO's potential for direct reclaim deadlock by ensuring that
all its page cache allocations are done from GFP_NOFS context.

Thanks to Ben Coddington for pointing out commit ad22c7a043c2 ("xfs:
prevent stack overflows from page cache allocation").

Reported-by: John Cagle <john.cagle@hammerspace.com>
Tested-by: Allen Lu <allen.lu@hammerspace.com>
Suggested-by: Benjamin Coddington <bcodding@hammerspace.com>
Fixes: 70ba381e1a43 ("nfs: add LOCALIO support")
Signed-off-by: Mike Snitzer <snitzer@hammerspace.com>
---
 fs/nfs/localio.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c
index d21047f7e4528..c38e7d4685e2f 100644
--- a/fs/nfs/localio.c
+++ b/fs/nfs/localio.c
@@ -291,6 +291,18 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 }
 EXPORT_SYMBOL_GPL(nfs_local_open_fh);
 
+/*
+ * Ensure all page cache allocations are done from GFP_NOFS context to
+ * prevent direct reclaim recursion back into NFS via nfs_writepages.
+ */
+static void
+nfs_local_mapping_set_gfp_nofs_context(struct address_space *m)
+{
+	gfp_t gfp_mask = mapping_gfp_mask(m);
+
+	mapping_set_gfp_mask(m, (gfp_mask & ~(__GFP_FS)));
+}
+
 static void
 nfs_local_iocb_free(struct nfs_local_kiocb *iocb)
 {
@@ -315,6 +327,7 @@ nfs_local_iocb_alloc(struct nfs_pgio_header *hdr,
 		return NULL;
 	}
 
+	nfs_local_mapping_set_gfp_nofs_context(file->f_mapping);
 	init_sync_kiocb(&iocb->kiocb, file);
 
 	iocb->hdr = hdr;
@@ -1004,6 +1017,8 @@ nfs_local_run_commit(struct file *filp, struct nfs_commit_data *data)
 			end = LLONG_MAX;
 	}
 
+	nfs_local_mapping_set_gfp_nofs_context(filp->f_mapping);
+
 	dprintk("%s: commit %llu - %llu\n", __func__, start, end);
 	return vfs_fsync_range(filp, start, end, 0);
 }
-- 
2.44.0


  reply	other threads:[~2026-01-07 16:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-03 17:14 [PATCH 0/4] Fix misc localio issues Trond Myklebust
2026-01-03 17:14 ` [PATCH 1/4] NFS/localio: Stop further I/O upon hitting an error Trond Myklebust
2026-01-05 17:19   ` Mike Snitzer
2026-01-05 17:35     ` Trond Myklebust
2026-01-03 17:14 ` [PATCH 2/4] NFS/localio: Deal with page bases that are > PAGE_SIZE Trond Myklebust
2026-01-05 17:40   ` Mike Snitzer
2026-01-03 17:14 ` [PATCH 3/4] NFS/localio: Handle short writes by retrying Trond Myklebust
2026-01-05 18:04   ` Mike Snitzer
2026-01-05 18:09     ` Trond Myklebust
2026-01-05 18:30       ` Mike Snitzer
2026-01-03 17:15 ` [PATCH 4/4] NFS/localio: Cleanup the nfs_local_pgio_done() parameters Trond Myklebust
2026-01-05 17:24   ` Mike Snitzer
2026-01-07 16:08 ` [PATCH 0/4] NFS/localio: various improvements Mike Snitzer
2026-01-07 16:08   ` Mike Snitzer [this message]
2026-01-07 16:08   ` [PATCH 2/4] NFS/localio: use GFP_NOIO and non-memreclaim workqueue in nfs_local_commit Mike Snitzer
2026-01-07 16:08   ` [PATCH 3/4] NFS/localio: remove -EAGAIN handling in nfs_local_doio() Mike Snitzer
2026-01-07 16:08   ` [PATCH 4/4] NFS/localio: switch nfs_local_do_read and nfs_local_do_write to return void Mike Snitzer

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=20260107160858.6847-2-snitzer@kernel.org \
    --to=snitzer@kernel.org \
    --cc=anna.schumaker@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --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