NFS: Fix netfs read subrequest range and retry accounting
Subsystems (2)
v2 cover NFS: Fix netfs read subrequest range and retry accounting
While addressing an issue where netfs repeatedly reads whole folio when rsize is smaller than the folio size, a related bug was identified in how nfs_netfs_put() handles retried or reissued subrequests that already have transferred bytes.
This series fixes both issues:
- Patch 1 fixes an accounting bug in nfs_netfs_put(): it assigns the current ->issue_read() call's byte count to sreq->transferred instead of adding to it, discarding progress from an earlier attempt such as a partial cache read, so the subrequest under-reports what it holds. Accumulate instead, with the existing min_t() clamp now bounding the cumulative total.
- Patch 2 ensures nfs_netfs_issue_read() requests only the subrequest's byte range rather than repeatedly submitting the whole folio.
Changes in v2:
- Added patch 1 to fix sreq->transferred accumulation on completion, following review feedback from Sashiko.
- Patch 2 is unchanged from v1.
Abhinandan Ekande (2):
NFS: Accumulate transferred bytes on netfs read completion
NFS: honour the netfs subrequest range when issuing reads
fs/nfs/fscache.c | 21 ++++++++++++++---- fs/nfs/fscache.h | 1 + fs/nfs/internal.h | 4 ++++ fs/nfs/read.c | 56 ++++++++++++++++++++++++++++++----------------- 4 files changed, 58 insertions(+), 24 deletions(-)
Signature · 1 line
2.55.0
PATCH v2 1/2 NFS: Accumulate transferred bytes on netfs read completion
When netfs retries a read subrequest that already made progress, it resets subreq->start and subreq->len to the full original extent and leaves subreq->transferred holding the byte count read so far.
nfs_netfs_alloc() is called on every ->issue_read(), including retries, and kzalloc()s netfs->transferred to zero. nfs_netfs_read_completion() only tracks the bytes read during the current ->issue_read() call. nfs_netfs_put() then assigns that value to sreq->transferred rather than adding to it.
The subrequest therefore reports less than it holds. If it hit EOF, nfs_netfs_read_completion() has set NETFS_SREQ_CLEAR_TAIL and the collector calls netfs_clear_unread(), which zeroes data that was already read and then marks the subrequest complete, with no error reported. Otherwise netfs_read_subreq_terminated() sees subreq->transferred < subreq->len with no error and, as NFS never sets NETFS_SREQ_MADE_PROGRESS, fails the read with -ENODATA.
Accumulate instead of assigning. The min_t() clamp is kept and now bounds the cumulative total.
The retry is reached when a NETFS_READ_FROM_CACHE subrequest fails after a partial transfer and netfs reissues it against the server. It is masked today because nfs_netfs_issue_read() reads the whole folio for every subrequest, so the accumulator exceeds sreq->len on its own and the clamp arrives at the right answer by accident. Next patch in this series restricts the read to the subrequest's range and removes that masking.
--- fs/nfs/fscache.h | 1 + 1 file changed, 1 insertion(+)
fs/nfs/fscache.h +1 -0
@@ -73,6 +73,7 @@ static inline void nfs_netfs_put(struct nfs_netfs_io_data *netfs)* length, and thus avoid netfs's "Subreq overread" warning message. */ netfs->sreq->transferred =min_t (s64, netfs->sreq->len, + netfs->sreq->transferred +atomic64_read (&netfs->transferred)); netfs->sreq->error = netfs->error;netfs_read_subreq_terminated (netfs->sreq);
Signature · 1 line
2.55.0
PATCH v2 2/2 NFS: honour the netfs subrequest range when issuing reads
In reply to Abhinandan Ekandenetfs 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