From: Mike Snitzer <snitzer@kernel.org>
To: trondmy@kernel.org
Cc: linux-nfs@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 4/3] NFS: add RWF_DONTCACHE support to LOCALIO
Date: Thu, 24 Apr 2025 17:29:09 -0400 [thread overview]
Message-ID: <aAqtJazDu6NDCvJ_@kernel.org> (raw)
In-Reply-To: <cover.1745381692.git.trond.myklebust@hammerspace.com>
If DONTCACHE is used by the NFS client set NFS_IOHDR_DONTCACHE. And
update LOCALIO so that it uses DONTCACHE, as a side-effect of setting
IOCB_DONTCACHE, if NFS_IOHDR_DONTCACHE was set.
Tweaked nfs_local_iocb_alloc() so that it uses kiocb_set_rw_flags().
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
fs/nfs/localio.c | 27 +++++++++++++++++----------
fs/nfs/pagelist.c | 4 ++++
fs/nfs/read.c | 2 ++
fs/nfs/write.c | 2 ++
include/linux/nfs_page.h | 1 +
include/linux/nfs_xdr.h | 1 +
6 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c
index b1911d9b6be21..ee46eb3f65776 100644
--- a/fs/nfs/localio.c
+++ b/fs/nfs/localio.c
@@ -331,26 +331,30 @@ nfs_local_iocb_free(struct nfs_local_kiocb *iocb)
static struct nfs_local_kiocb *
nfs_local_iocb_alloc(struct nfs_pgio_header *hdr,
- struct file *file, gfp_t flags)
+ struct file *file, int type, gfp_t gfp)
{
+ rwf_t flags = 0;
struct nfs_local_kiocb *iocb;
- iocb = kmalloc(sizeof(*iocb), flags);
+ iocb = kmalloc(sizeof(*iocb), gfp);
if (iocb == NULL)
return NULL;
iocb->bvec = nfs_bvec_alloc_and_import_pagevec(hdr->page_array.pagevec,
- hdr->page_array.npages, flags);
- if (iocb->bvec == NULL) {
- kfree(iocb);
- return NULL;
- }
+ hdr->page_array.npages, gfp);
+ if (iocb->bvec == NULL)
+ goto out;
if (localio_O_DIRECT_semantics &&
test_bit(NFS_IOHDR_ODIRECT, &hdr->flags)) {
iocb->kiocb.ki_filp = file;
iocb->kiocb.ki_flags = IOCB_DIRECT;
- } else
+ } else {
init_sync_kiocb(&iocb->kiocb, file);
+ if (test_bit(NFS_IOHDR_DONTCACHE, &hdr->flags))
+ flags |= RWF_DONTCACHE;
+ if (flags && kiocb_set_rw_flags(&iocb->kiocb, flags, type))
+ goto out;
+ }
iocb->kiocb.ki_pos = hdr->args.offset;
iocb->hdr = hdr;
@@ -358,6 +362,9 @@ nfs_local_iocb_alloc(struct nfs_pgio_header *hdr,
iocb->aio_complete_work = NULL;
return iocb;
+out:
+ kfree(iocb);
+ return NULL;
}
static void
@@ -499,7 +506,7 @@ nfs_do_local_read(struct nfs_pgio_header *hdr,
dprintk("%s: vfs_read count=%u pos=%llu\n",
__func__, hdr->args.count, hdr->args.offset);
- iocb = nfs_local_iocb_alloc(hdr, file, GFP_KERNEL);
+ iocb = nfs_local_iocb_alloc(hdr, file, READ, GFP_KERNEL);
if (iocb == NULL)
return -ENOMEM;
iocb->localio = localio;
@@ -698,7 +705,7 @@ nfs_do_local_write(struct nfs_pgio_header *hdr,
__func__, hdr->args.count, hdr->args.offset,
(hdr->args.stable == NFS_UNSTABLE) ? "unstable" : "stable");
- iocb = nfs_local_iocb_alloc(hdr, file, GFP_NOIO);
+ iocb = nfs_local_iocb_alloc(hdr, file, WRITE, GFP_NOIO);
if (iocb == NULL)
return -ENOMEM;
iocb->localio = localio;
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 11968dcb72431..eefda82c1ece8 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -824,6 +824,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
int io_flags)
{
desc->pg_moreio = 0;
+ desc->pg_dontcache = 0;
desc->pg_inode = inode;
desc->pg_ops = pg_ops;
desc->pg_completion_ops = compl_ops;
@@ -932,6 +933,9 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *desc,
return desc->pg_error;
}
+ if (desc->pg_dontcache)
+ set_bit(NFS_IOHDR_DONTCACHE, &hdr->flags);
+
if ((desc->pg_ioflags & FLUSH_COND_STABLE) &&
(desc->pg_moreio || nfs_reqs_to_commit(&cinfo)))
desc->pg_ioflags &= ~FLUSH_COND_STABLE;
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 81bd1b9aba176..51f4eaa1512bb 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -316,6 +316,8 @@ int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
nfs_readpage_release(new, error);
goto out;
}
+ if (folio_test_dropbehind(folio))
+ pgio->pg_dontcache = 1;
return 0;
out:
return error;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index e0ac439ab211b..88b7bd64c7864 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -684,6 +684,8 @@ static int nfs_page_async_flush(struct folio *folio,
static int nfs_do_writepage(struct folio *folio, struct writeback_control *wbc,
struct nfs_pageio_descriptor *pgio)
{
+ if (folio_test_dropbehind(folio))
+ pgio->pg_dontcache = 1;
nfs_pageio_cond_complete(pgio, folio->index);
return nfs_page_async_flush(folio, wbc, pgio);
}
diff --git a/include/linux/nfs_page.h b/include/linux/nfs_page.h
index 1a017b5b476fa..44bd9141820c4 100644
--- a/include/linux/nfs_page.h
+++ b/include/linux/nfs_page.h
@@ -118,6 +118,7 @@ struct nfs_pageio_descriptor {
u32 pg_mirror_idx; /* current mirror */
unsigned short pg_maxretrans;
unsigned char pg_moreio : 1;
+ unsigned char pg_dontcache : 1;
};
/* arbitrarily selected limit to number of mirrors */
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 4f0d89893bcb8..3e82dea65c8c9 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -1634,6 +1634,7 @@ enum {
NFS_IOHDR_RESEND_MDS,
NFS_IOHDR_UNSTABLE_WRITES,
NFS_IOHDR_ODIRECT,
+ NFS_IOHDR_DONTCACHE,
};
struct nfs_io_completion;
--
2.44.0
next prev parent reply other threads:[~2025-04-24 21:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 4:25 [RFC PATCH 0/3] Initial NFS client support for RWF_DONTCACHE trondmy
2025-04-23 4:25 ` [RFC PATCH 1/3] filemap: Add a helper for filesystems implementing dropbehind trondmy
2025-04-24 21:30 ` Mike Snitzer
2025-04-23 4:25 ` [RFC PATCH 2/3] filemap: Mark folios as dropbehind in generic_perform_write() trondmy
2025-04-24 21:30 ` Mike Snitzer
2025-04-23 4:25 ` [RFC PATCH 3/3] NFS: Enable the RWF_DONTCACHE flag for the NFS client trondmy
2025-04-24 21:31 ` Mike Snitzer
2025-04-23 14:38 ` [RFC PATCH 0/3] Initial NFS client support for RWF_DONTCACHE Chuck Lever
2025-04-23 15:22 ` Matthew Wilcox
2025-04-23 15:30 ` Chuck Lever
2025-04-24 16:51 ` Mike Snitzer
2025-04-24 16:59 ` Chuck Lever
2025-04-24 21:29 ` Mike Snitzer [this message]
2025-07-14 6:22 ` Christoph Hellwig
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=aAqtJazDu6NDCvJ_@kernel.org \
--to=snitzer@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.