From: Pranjal Shrivastava <praan@google.com>
To: Trond Myklebust <trondmy@kernel.org>
Cc: Anna Schumaker <anna@kernel.org>,
linux-nfs@vger.kernel.org, Chuck Lever <cel@kernel.org>,
Jeff Layton <jlayton@kernel.org>,
linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Logan Gunthorpe <logang@deltatee.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org,
Shivaji Kant <shivajikant@google.com>
Subject: Re: [PATCH v3 5/5] nfs: introduce nfs_direct_extract_pages helper
Date: Wed, 5 Aug 2026 21:54:13 +0000 [thread overview]
Message-ID: <anOxBdQYqAB3LV64@google.com> (raw)
In-Reply-To: <a7fe5eadb2999b8d95595e73d3b99d76df6895a4.camel@kernel.org>
On Wed, Aug 05, 2026 at 01:12:28PM -0700, Trond Myklebust wrote:
Hi Trond,
> On Wed, 2026-07-15 at 14:35 +0000, Pranjal Shrivastava wrote:
> > Introduce nfs_direct_extract_pages() in direct.c to centralize page
> > extraction and request creation for the Direct I/O path. The helper
> > manages extraction from the iters and builds a list of nfs_page
> > requests
> >
> > Refactor nfs_direct_read_schedule_iovec() and
> > nfs_direct_write_schedule_iovec() to utilize the new helper, unifying
> > the extraction logic on both paths.
> >
> > Signed-off-by: Pranjal Shrivastava <praan@google.com>
> > ---
> > fs/nfs/direct.c | 127 ++++++++++++++++++++++++----------------------
> > --
> > 1 file changed, 64 insertions(+), 63 deletions(-)
> >
> > diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
> > index b9ac0a67693c..d31e4720ffff 100644
> > --- a/fs/nfs/direct.c
> > +++ b/fs/nfs/direct.c
> > @@ -178,6 +178,50 @@ static void nfs_direct_release_pages(struct page
> > **pages, unsigned int npages,
> > }
> > }
> >
> > +static ssize_t nfs_direct_extract_pages(struct nfs_direct_req *dreq,
> > + struct iov_iter *iter,
> > + size_t size, loff_t *pos,
> > + struct list_head *list)
> > +{
> > + bool pinned = iov_iter_extract_will_pin(iter);
> > + struct page **pagevec = NULL;
> > + ssize_t result, bytes = 0;
> > + unsigned int npages, i;
> > + size_t pgbase;
> > +
> > + result = iov_iter_extract_pages(iter, &pagevec, size, ~0U,
> > 0, &pgbase);
> > + if (result <= 0)
> > + return result;
> > +
> > + npages = (result + pgbase + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > + for (i = 0; i < npages; i++) {
> > + struct nfs_page *req;
> > + unsigned int req_len = min_t(size_t, result - bytes,
> > PAGE_SIZE - pgbase);
> > +
> > + req = nfs_page_create_from_page(dreq->ctx,
> > pagevec[i],
> > + pinned, pgbase,
> > *pos,
> > + req_len);
> > + if (IS_ERR(req)) {
> > + if (!bytes)
> > + bytes = PTR_ERR(req);
> > + break;
> > + }
> > +
> > + list_add_tail(&req->wb_list, list);
> > + pgbase = 0;
> > + bytes += req_len;
> > + *pos += req_len;
> > + }
> > +
> > + if (i < npages) {
> > + iov_iter_revert(iter, result - bytes);
>
> Oopsable if bytes == PTR_ERR(req)
>
Ack. I'll catch errors in a separate variable something like:
...
for (i = 0; i < npages; i++) {
...
req = nfs_page_create_from_page(...);
if (IS_ERR(req)) {
err = PTR_ERR(req);
break;
}
...
bytes += req_len;
}
if (i < npages) {
iov_iter_revert(iter, result - bytes);
nfs_direct_release_pages(pagevec + i, npages - i, pinned);
}
kvfree(pagevec);
return bytes ? bytes : err;
> > + nfs_direct_release_pages(pagevec + i, npages - i,
> > pinned);
>
> See what happens above with swap over NFS (which sets pinned = false).
>
I see what you mean, we never got a ref (after patch 4) but we'll call
put_page() if pinned == false. I'll reduce the nfs_direct_release_pages
to the following in patch 4 (when we start using the new extract API):
static void nfs_direct_release_pages(struct page **pages, unsigned int npages,
bool pinned)
{
if (pinned)
unpin_user_pages(pages, npages);
}
Sounds good for v5?
Thanks,
Praan
prev parent reply other threads:[~2026-08-05 21:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 14:35 [PATCH v3 0/5] nfs: Modernize Direct I/O path Pranjal Shrivastava
2026-07-15 14:35 ` [PATCH v3 1/5] nfs: make nfs_page pin-aware Pranjal Shrivastava
2026-07-20 9:13 ` Christoph Hellwig
2026-07-20 13:52 ` Pranjal Shrivastava
2026-07-15 14:35 ` [PATCH v3 2/5] nfs: Track number of pinned pages in nfs_page Pranjal Shrivastava
2026-07-20 9:14 ` Christoph Hellwig
2026-07-20 14:05 ` Pranjal Shrivastava
2026-07-15 14:35 ` [PATCH v3 3/5] nfs: Introduce nfs_release_request_list helper Pranjal Shrivastava
2026-07-20 9:15 ` Christoph Hellwig
2026-07-20 9:58 ` Shivaji Kant
2026-07-20 15:03 ` Pranjal Shrivastava
2026-07-20 14:24 ` Pranjal Shrivastava
2026-07-15 14:35 ` [PATCH v3 4/5] nfs: migrate direct I/O to iov_iter_extract_pages Pranjal Shrivastava
2026-07-20 9:15 ` Christoph Hellwig
2026-07-15 14:35 ` [PATCH v3 5/5] nfs: introduce nfs_direct_extract_pages helper Pranjal Shrivastava
2026-07-20 9:15 ` Christoph Hellwig
2026-07-20 10:17 ` Shivaji Kant
2026-08-05 20:12 ` Trond Myklebust
2026-08-05 21:54 ` Pranjal Shrivastava [this message]
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=anOxBdQYqAB3LV64@google.com \
--to=praan@google.com \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=hch@lst.de \
--cc=jgg@ziepe.ca \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=shivajikant@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome