Re: [PATCH v2 6/7] nfs: Optimize direct I/O to use folios for requests
From: Trond Myklebust
Date: Tue Jun 16 2026 - 11:35:58 EST
On Tue, 2026-06-16 at 13:39 +0000, Pranjal Shrivastava wrote:
> Optimize nfs_direct_extract_pages() to group contiguous pages from
> the
> same folio into single nfs_page structures. This effectively migrates
> NFS Direct I/O from being page-based to being folio-based.
>
> Reduce the number of nfs_page allocations and subsequent iterations
> by utilizing nfs_page_create_from_folio() to create aggregated
> requests.
>
> Signed-off-by: Pranjal Shrivastava <praan@xxxxxxxxxx>
> ---
> fs/nfs/direct.c | 47 +++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 37 insertions(+), 10 deletions(-)
>
> diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
> index e2a93cfb6c72..ddc6b27f5315 100644
> --- a/fs/nfs/direct.c
> +++ b/fs/nfs/direct.c
> @@ -194,23 +194,45 @@ static ssize_t nfs_direct_extract_pages(struct
> nfs_direct_req *dreq,
> return result;
>
> npages = (result + pgbase + PAGE_SIZE - 1) >> PAGE_SHIFT;
> - for (i = 0; i < npages; i++) {
> + for (i = 0; i < npages; ) {
> + unsigned int chunk_len, folio_offset;
> + unsigned int nr_to_add = 1;
> struct nfs_page *req;
> - unsigned int req_len = min_t(size_t, result - bytes,
> PAGE_SIZE - pgbase);
> + struct folio *folio;
>
> - req = nfs_page_create_from_page(dreq->ctx,
> pagevec[i],
> - pinned, pgbase,
> *pos,
> - req_len);
> + folio = page_folio(pagevec[i]);
I'm clearly missing something. The memory pointed to by these pages can
be any arbitrary user space (or kernel space) memory region. It could
be mapped device memory, for instance.
So why can you assume that page_folio() will resolve to a valid folio
here?
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trondmy@xxxxxxxxxx, trond.myklebust@xxxxxxxxxxxxxxx