NFS: honour the netfs subrequest range when issuing reads
Subsystems (2)
PATCH 1/1 NFS: honour the netfs subrequest range when issuing reads
netfs splits the folio into folio_size/rsize subrequests. Each subrequest calls nfs_netfs_issue_read() separately. nfs_netfs_issue_read() discards subreq->start and subreq->len, converts them into a page index range, and hands each folio in that range to nfs_read_add_folio(), which submits the whole folio.
A folio larger than rsize is therefore read once per subrequest. On a mount with rsize=4096, a 128K (order-5) folio is covered by 32 subrequests; each submits the whole folio, which nfs_pageio_add_request() splits into 32 RPCs at pg_bsize. That is 1024 concurrent READs for one folio, with every 4K page targeted by 32 of them, all pointing their receive buffer at the same page.
Under sec=sys every reply carries the same plaintext in the page, so the duplicate writes are byte-identical and only the wasted bandwidth remains.
With sec=krb5p the payload is separately encrypted per reply, so the bytes on the wire differ even though the data is the same, and gss_unwrap_resp_priv() decrypts in place in rq_rcv_buf. One reply's ciphertext lands on top of another's before it is unwrapped, and the integrity check fails with GSS_S_FAILURE. The subrequest completes with -EIO and netfs leaves the folio non-uptodate.
The defect dates to the netfs conversion but stayed latent at the common case of rsize of 4096 or greater and with order-0 folios, folio_size/rsize is 1 and each subrequest's whole folio read happens to cover exactly the range asked for. The 'commit 49b29a573da8 ("nfs:
add support for large folios")' made folios up to order-5, which exposes the same loop at any rsize smaller than folio.
Fix nfs_netfs_issue_read() to intersect each folio with the subrequest's byte range and submit only that. nfs_read_add_folio() is split into a range taking helper, nfs_read_add_folio_range(). nfs_read_add_folio() keeps its existing behaviour, so the two legacy callers, nfs_do_read_folio() and nfs_readahead(), are unaffected.
Once a request can cover only part of a folio, nfs_page_group_set_uptodate() must stop marking the whole folio uptodate. nfs_page_group_sync_on_bit() synchronises across one nfs_page group, not across the folio's other subrequests, so a group that completes cleanly would mark a folio that is only partly filled. Skip the marking when netfs owns the folio.
With the patch, 30 MiB read over sec=krb5p,fsc,rsize=4096 issues exactly 7680 READs, one per page, compared to earlier every page was fetched up to 32 times. Folio sizes and the netfs subrequest shape are unchanged.
--- fs/nfs/fscache.c | 21 ++++++++++++++---- fs/nfs/internal.h | 4 ++++ fs/nfs/read.c | 56 ++++++++++++++++++++++++++++++----------------- 3 files changed, 57 insertions(+), 24 deletions(-)
fs/nfs/fscache.c +17 -4
@@ -303,12 +303,14 @@ static void nfs_netfs_issue_read(struct netfs_io_subrequest *sreq)struct inode *inode = sreq->rreq->inode;struct nfs_open_context *ctx = sreq->rreq->netfs_priv;struct page *page; +unsigned long long pos = sreq->start + sreq->transferred; +unsigned long long end = sreq->start + sreq->len;unsigned long idx;pgoff_t start, last;int err; - start = (sreq->start + sreq->transferred) >>PAGE_SHIFT ; - last = ((sreq->start + sreq->len - sreq->transferred -1 ) >>PAGE_SHIFT ); + start = pos >>PAGE_SHIFT ; + last = ((end -1 ) >>PAGE_SHIFT );nfs_pageio_init_read (&pgio, inode, false, &nfs_async_read_completion_ops);
@@ -322,8 +324,19 @@ static void nfs_netfs_issue_read(struct netfs_io_subrequest *sreq) pgio.pg_netfs = netfs;/* used in completion */ xa_for_each_range (&sreq->rreq->mapping->i_pages, idx, page, start, last) { -/* nfs_read_add_folio() may schedule() due to pNFS layout and other RPCs */ - err =nfs_read_add_folio (&pgio, ctx,page_folio (page)); +struct folio *folio =page_folio (page); +unsigned long long fpos =folio_pos (folio); +size_t fsize =folio_size (folio); +size_t offset, len; + +/* Read only the part of the folio the subrequest asked for. */ + offset = pos > fpos ? pos - fpos :0 ; + len =min (end, fpos + fsize) - (fpos + offset); +if (!len) +continue ; + +/* nfs_read_add_folio_range() may schedule() due to pNFS layout and other RPCs */ + err =nfs_read_add_folio_range (&pgio, ctx, folio, offset, len);if (err <0 ) { netfs->error = err; goto out;
fs/nfs/internal.h +4 -0
@@ -611,6 +611,10 @@ extern bool nfs_read_alloc_scratch(struct nfs_pgio_header *hdr, size_t size);extern int nfs_read_add_folio (struct nfs_pageio_descriptor *pgio,struct nfs_open_context *ctx,struct folio *folio); +extern int nfs_read_add_folio_range (struct nfs_pageio_descriptor *pgio, +struct nfs_open_context *ctx, +struct folio *folio, +size_t offset,size_t len);extern void nfs_pageio_complete_read (struct nfs_pageio_descriptor *pgio);extern void nfs_pageio_reset_read_mds (struct nfs_pageio_descriptor *pgio);
fs/nfs/read.c +36 -20
91 lines not on this page · raw message
Signature · 1 line
2.55.0