-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRAhzRXHqcMeLMyaSiRxhvAZXjcogUCZ4pRKQAKCRCRxhvAZXjc ov2dAQCULWjTBWdF8Ro2bfNeXzWvUUnSPjoLJ9B4xlrOB9c2MAEAiwkKHkzAxUco hCvaRJc3H2ze2wrgbIABPKB2noQVVwk= =4ojv -----END PGP SIGNATURE----- Merge tag 'vfs-6.14-rc1.netfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs Pull vfs netfs updates from Christian Brauner: "This contains read performance improvements and support for monolithic single-blob objects that have to be read/written as such (e.g. AFS directory contents). The implementation of the two parts is interwoven as each makes the other possible. - Read performance improvements The read performance improvements are intended to speed up some loss of performance detected in cifs and to a lesser extend in afs. The problem is that we queue too many work items during the collection of read results: each individual subrequest is collected by its own work item, and then they have to interact with each other when a series of subrequests don't exactly align with the pattern of folios that are being read by the overall request. Whilst the processing of the pages covered by individual subrequests as they complete potentially allows folios to be woken in parallel and with minimum delay, it can shuffle wakeups for sequential reads out of order - and that is the most common I/O pattern. The final assessment and cleanup of an operation is then held up until the last I/O completes - and for a synchronous sequential operation, this means the bouncing around of work items just adds latency. Two changes have been made to make this work: (1) All collection is now done in a single "work item" that works progressively through the subrequests as they complete (and also dispatches retries as necessary). (2) For readahead and AIO, this work item be done on a workqueue and can run in parallel with the ultimate consumer of the data; for synchronous direct or unbuffered reads, the collection is run in the application thread and not offloaded. Functions such as smb2_readv_callback() then just tell netfslib that the subrequest has terminated; netfslib does a minimal bit of processing on the spot - stat counting and tracing mostly - and then queues/wakes up the worker. This simplifies the logic as the collector just walks sequentially through the subrequests as they complete and walks through the folios, if buffered, unlocking them as it goes. It also keeps to a minimum the amount of latency injected into the filesystem's low-level I/O handling The way netfs supports filesystems using the deprecated PG_private_2 flag is changed: folios are flagged and added to a write request as they complete and that takes care of scheduling the writes to the cache. The originating read request can then just unlock the pages whatever happens. - Single-blob object support Single-blob objects are files for which the content of the file must be read from or written to the server in a single operation because reading them in parts may yield inconsistent results. AFS directories are an example of this as there exists the possibility that the contents are generated on the fly and would differ between reads or might change due to third party interference. Such objects will be written to and retrieved from the cache if one is present, though we allow/may need to propose multiple subrequests to do so. The important part is that read from/write to the *server* is monolithic. Single blob reading is, for the moment, fully synchronous and does result collection in the application thread and, also for the moment, the API is supplied the buffer in the form of a folio_queue chain rather than using the pagecache. - Related afs changes This series makes a number of changes to the kafs filesystem, primarily in the area of directory handling: - AFS's FetchData RPC reply processing is made partially asynchronous which allows the netfs_io_request's outstanding operation counter to be removed as part of reducing the collection to a single work item. - Directory and symlink reading are plumbed through netfslib using the single-blob object API and are now cacheable with fscache. This also allows the afs_read struct to be eliminated and netfs_io_subrequest to be used directly instead. - Directory and symlink content are now stored in a folio_queue buffer rather than in the pagecache. This means we don't require the RCU read lock and xarray iteration to access it, and folios won't randomly disappear under us because the VM wants them back. - The vnode operation lock is changed from a mutex struct to a private lock implementation. The problem is that the lock now needs to be dropped in a separate thread and mutexes don't permit that. - When a new directory or symlink is created, we now initialise it locally and mark it valid rather than downloading it (we know what it's likely to look like). - We now use the in-directory hashtable to reduce the number of entries we need to scan when doing a lookup. The edit routines have to maintain the hash chains. - Cancellation (e.g. by signal) of an async call after the rxrpc_call has been set up is now offloaded to the worker thread as there will be a notification from rxrpc upon completion. This avoids a double cleanup. - A "rolling buffer" implementation is created to abstract out the two separate folio_queue chaining implementations I had (one for read and one for write). - Functions are provided to create/extend a buffer in a folio_queue chain and tear it down again. This is used to handle AFS directories, but could also be used to create bounce buffers for content crypto and transport crypto. - The was_async argument is dropped from netfs_read_subreq_terminated() Instead we wake the read collection work item by either queuing it or waking up the app thread. - We don't need to use BH-excluding locks when communicating between the issuing thread and the collection thread as neither of them now run in BH context. - Also included are a number of new tracepoints; a split of the netfslib write collection code to put retrying into its own file (it gets more complicated with content encryption). - There are also some minor fixes AFS included, including fixing the AFS directory format struct layout, reducing some directory over-invalidation and making afs_mkdir() translate EEXIST to ENOTEMPY (which is not available on all systems the servers support). - Finally, there's a patch to try and detect entry into the folio unlock function with no folio_queue structs in the buffer (which isn't allowed in the cases that can get there). This is a debugging patch, but should be minimal overhead" * tag 'vfs-6.14-rc1.netfs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (31 commits) netfs: Report on NULL folioq in netfs_writeback_unlock_folios() afs: Add a tracepoint for afs_read_receive() afs: Locally initialise the contents of a new symlink on creation afs: Use the contained hashtable to search a directory afs: Make afs_mkdir() locally initialise a new directory's content netfs: Change the read result collector to only use one work item afs: Make {Y,}FS.FetchData an asynchronous operation afs: Fix cleanup of immediately failed async calls afs: Eliminate afs_read afs: Use netfslib for symlinks, allowing them to be cached afs: Use netfslib for directories afs: Make afs_init_request() get a key if not given a file netfs: Add support for caching single monolithic objects such as AFS dirs netfs: Add functions to build/clean a buffer in a folio_queue afs: Add more tracepoints to do with tracking validity cachefiles: Add auxiliary data trace cachefiles: Add some subrequest tracepoints netfs: Remove some extraneous directory invalidations afs: Fix directory format encoding struct afs: Fix EEXIST error returned from afs_rmdir() to be ENOTEMPTY ...
290 lines
8.8 KiB
C
290 lines
8.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Network filesystem read subrequest retrying.
|
|
*
|
|
* Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
|
#include <linux/slab.h>
|
|
#include "internal.h"
|
|
|
|
static void netfs_reissue_read(struct netfs_io_request *rreq,
|
|
struct netfs_io_subrequest *subreq)
|
|
{
|
|
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
|
|
__set_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags);
|
|
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
|
|
subreq->rreq->netfs_ops->issue_read(subreq);
|
|
}
|
|
|
|
/*
|
|
* Go through the list of failed/short reads, retrying all retryable ones. We
|
|
* need to switch failed cache reads to network downloads.
|
|
*/
|
|
static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)
|
|
{
|
|
struct netfs_io_subrequest *subreq;
|
|
struct netfs_io_stream *stream = &rreq->io_streams[0];
|
|
struct list_head *next;
|
|
|
|
_enter("R=%x", rreq->debug_id);
|
|
|
|
if (list_empty(&stream->subrequests))
|
|
return;
|
|
|
|
if (rreq->netfs_ops->retry_request)
|
|
rreq->netfs_ops->retry_request(rreq, NULL);
|
|
|
|
/* If there's no renegotiation to do, just resend each retryable subreq
|
|
* up to the first permanently failed one.
|
|
*/
|
|
if (!rreq->netfs_ops->prepare_read &&
|
|
!rreq->cache_resources.ops) {
|
|
list_for_each_entry(subreq, &stream->subrequests, rreq_link) {
|
|
if (test_bit(NETFS_SREQ_FAILED, &subreq->flags))
|
|
break;
|
|
if (__test_and_clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
|
|
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
|
|
subreq->retry_count++;
|
|
netfs_reset_iter(subreq);
|
|
netfs_reissue_read(rreq, subreq);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
/* Okay, we need to renegotiate all the download requests and flip any
|
|
* failed cache reads over to being download requests and negotiate
|
|
* those also. All fully successful subreqs have been removed from the
|
|
* list and any spare data from those has been donated.
|
|
*
|
|
* What we do is decant the list and rebuild it one subreq at a time so
|
|
* that we don't end up with donations jumping over a gap we're busy
|
|
* populating with smaller subrequests. In the event that the subreq
|
|
* we just launched finishes before we insert the next subreq, it'll
|
|
* fill in rreq->prev_donated instead.
|
|
*
|
|
* Note: Alternatively, we could split the tail subrequest right before
|
|
* we reissue it and fix up the donations under lock.
|
|
*/
|
|
next = stream->subrequests.next;
|
|
|
|
do {
|
|
struct netfs_io_subrequest *from, *to, *tmp;
|
|
struct iov_iter source;
|
|
unsigned long long start, len;
|
|
size_t part;
|
|
bool boundary = false;
|
|
|
|
/* Go through the subreqs and find the next span of contiguous
|
|
* buffer that we then rejig (cifs, for example, needs the
|
|
* rsize renegotiating) and reissue.
|
|
*/
|
|
from = list_entry(next, struct netfs_io_subrequest, rreq_link);
|
|
to = from;
|
|
start = from->start + from->transferred;
|
|
len = from->len - from->transferred;
|
|
|
|
_debug("from R=%08x[%x] s=%llx ctl=%zx/%zx",
|
|
rreq->debug_id, from->debug_index,
|
|
from->start, from->transferred, from->len);
|
|
|
|
if (test_bit(NETFS_SREQ_FAILED, &from->flags) ||
|
|
!test_bit(NETFS_SREQ_NEED_RETRY, &from->flags))
|
|
goto abandon;
|
|
|
|
list_for_each_continue(next, &stream->subrequests) {
|
|
subreq = list_entry(next, struct netfs_io_subrequest, rreq_link);
|
|
if (subreq->start + subreq->transferred != start + len ||
|
|
test_bit(NETFS_SREQ_BOUNDARY, &subreq->flags) ||
|
|
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
|
|
break;
|
|
to = subreq;
|
|
len += to->len;
|
|
}
|
|
|
|
_debug(" - range: %llx-%llx %llx", start, start + len - 1, len);
|
|
|
|
/* Determine the set of buffers we're going to use. Each
|
|
* subreq gets a subset of a single overall contiguous buffer.
|
|
*/
|
|
netfs_reset_iter(from);
|
|
source = from->io_iter;
|
|
source.count = len;
|
|
|
|
/* Work through the sublist. */
|
|
subreq = from;
|
|
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
|
|
if (!len)
|
|
break;
|
|
subreq->source = NETFS_DOWNLOAD_FROM_SERVER;
|
|
subreq->start = start - subreq->transferred;
|
|
subreq->len = len + subreq->transferred;
|
|
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
|
|
__clear_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags);
|
|
subreq->retry_count++;
|
|
|
|
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
|
|
|
|
/* Renegotiate max_len (rsize) */
|
|
stream->sreq_max_len = subreq->len;
|
|
if (rreq->netfs_ops->prepare_read &&
|
|
rreq->netfs_ops->prepare_read(subreq) < 0) {
|
|
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
|
|
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
|
|
goto abandon;
|
|
}
|
|
|
|
part = umin(len, stream->sreq_max_len);
|
|
if (unlikely(stream->sreq_max_segs))
|
|
part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
|
|
subreq->len = subreq->transferred + part;
|
|
subreq->io_iter = source;
|
|
iov_iter_truncate(&subreq->io_iter, part);
|
|
iov_iter_advance(&source, part);
|
|
len -= part;
|
|
start += part;
|
|
if (!len) {
|
|
if (boundary)
|
|
__set_bit(NETFS_SREQ_BOUNDARY, &subreq->flags);
|
|
} else {
|
|
__clear_bit(NETFS_SREQ_BOUNDARY, &subreq->flags);
|
|
}
|
|
|
|
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
|
|
netfs_reissue_read(rreq, subreq);
|
|
if (subreq == to)
|
|
break;
|
|
}
|
|
|
|
/* If we managed to use fewer subreqs, we can discard the
|
|
* excess; if we used the same number, then we're done.
|
|
*/
|
|
if (!len) {
|
|
if (subreq == to)
|
|
continue;
|
|
list_for_each_entry_safe_from(subreq, tmp,
|
|
&stream->subrequests, rreq_link) {
|
|
trace_netfs_sreq(subreq, netfs_sreq_trace_discard);
|
|
list_del(&subreq->rreq_link);
|
|
netfs_put_subrequest(subreq, false, netfs_sreq_trace_put_done);
|
|
if (subreq == to)
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
/* We ran out of subrequests, so we need to allocate some more
|
|
* and insert them after.
|
|
*/
|
|
do {
|
|
subreq = netfs_alloc_subrequest(rreq);
|
|
if (!subreq) {
|
|
subreq = to;
|
|
goto abandon_after;
|
|
}
|
|
subreq->source = NETFS_DOWNLOAD_FROM_SERVER;
|
|
subreq->start = start;
|
|
subreq->len = len;
|
|
subreq->debug_index = atomic_inc_return(&rreq->subreq_counter);
|
|
subreq->stream_nr = stream->stream_nr;
|
|
subreq->retry_count = 1;
|
|
|
|
trace_netfs_sreq_ref(rreq->debug_id, subreq->debug_index,
|
|
refcount_read(&subreq->ref),
|
|
netfs_sreq_trace_new);
|
|
netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
|
|
|
|
list_add(&subreq->rreq_link, &to->rreq_link);
|
|
to = list_next_entry(to, rreq_link);
|
|
trace_netfs_sreq(subreq, netfs_sreq_trace_retry);
|
|
|
|
stream->sreq_max_len = umin(len, rreq->rsize);
|
|
stream->sreq_max_segs = 0;
|
|
if (unlikely(stream->sreq_max_segs))
|
|
part = netfs_limit_iter(&source, 0, part, stream->sreq_max_segs);
|
|
|
|
netfs_stat(&netfs_n_rh_download);
|
|
if (rreq->netfs_ops->prepare_read(subreq) < 0) {
|
|
trace_netfs_sreq(subreq, netfs_sreq_trace_reprep_failed);
|
|
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
|
|
goto abandon;
|
|
}
|
|
|
|
part = umin(len, stream->sreq_max_len);
|
|
subreq->len = subreq->transferred + part;
|
|
subreq->io_iter = source;
|
|
iov_iter_truncate(&subreq->io_iter, part);
|
|
iov_iter_advance(&source, part);
|
|
|
|
len -= part;
|
|
start += part;
|
|
if (!len && boundary) {
|
|
__set_bit(NETFS_SREQ_BOUNDARY, &to->flags);
|
|
boundary = false;
|
|
}
|
|
|
|
netfs_reissue_read(rreq, subreq);
|
|
} while (len);
|
|
|
|
} while (!list_is_head(next, &stream->subrequests));
|
|
|
|
return;
|
|
|
|
/* If we hit an error, fail all remaining incomplete subrequests */
|
|
abandon_after:
|
|
if (list_is_last(&subreq->rreq_link, &stream->subrequests))
|
|
return;
|
|
subreq = list_next_entry(subreq, rreq_link);
|
|
abandon:
|
|
list_for_each_entry_from(subreq, &stream->subrequests, rreq_link) {
|
|
if (!subreq->error &&
|
|
!test_bit(NETFS_SREQ_FAILED, &subreq->flags) &&
|
|
!test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags))
|
|
continue;
|
|
subreq->error = -ENOMEM;
|
|
__set_bit(NETFS_SREQ_FAILED, &subreq->flags);
|
|
__clear_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Retry reads.
|
|
*/
|
|
void netfs_retry_reads(struct netfs_io_request *rreq)
|
|
{
|
|
struct netfs_io_subrequest *subreq;
|
|
struct netfs_io_stream *stream = &rreq->io_streams[0];
|
|
|
|
/* Wait for all outstanding I/O to quiesce before performing retries as
|
|
* we may need to renegotiate the I/O sizes.
|
|
*/
|
|
list_for_each_entry(subreq, &stream->subrequests, rreq_link) {
|
|
wait_on_bit(&subreq->flags, NETFS_SREQ_IN_PROGRESS,
|
|
TASK_UNINTERRUPTIBLE);
|
|
}
|
|
|
|
trace_netfs_rreq(rreq, netfs_rreq_trace_resubmit);
|
|
netfs_retry_read_subrequests(rreq);
|
|
}
|
|
|
|
/*
|
|
* Unlock any the pages that haven't been unlocked yet due to abandoned
|
|
* subrequests.
|
|
*/
|
|
void netfs_unlock_abandoned_read_pages(struct netfs_io_request *rreq)
|
|
{
|
|
struct folio_queue *p;
|
|
|
|
for (p = rreq->buffer.tail; p; p = p->next) {
|
|
for (int slot = 0; slot < folioq_count(p); slot++) {
|
|
struct folio *folio = folioq_folio(p, slot);
|
|
|
|
if (folio && !folioq_is_marked2(p, slot)) {
|
|
trace_netfs_folio(folio, netfs_folio_trace_abandon);
|
|
folio_unlock(folio);
|
|
}
|
|
}
|
|
}
|
|
}
|