netfs: [WIP] Keep track of folios in a segmented bio_vec[] chain
Subsystems (17)
David Howells
maintainercover netfs: [WIP] Keep track of folios in a segmented bio_vec[] chain
Hi Willy, Christoph, et al.,
[!] This is a preview. Please don't expect this to fully compile or work.
It's been somewhat tested with AFS and CIFS, but not 9P, Ceph or NFS - and will not build with Ceph or NFS at the moment.
These patches get rid of folio_queue, rolling_buffer and ITER_FOLIOQ, replacing the folio queue construct used to manage buffers in netfslib with one based around a segmented chain of bio_vec arrays instead. There are three main aims here:
(1) The kernel file I/O subsystem seems to be moving towards consolidating on the use of bio_vec arrays, so embrace this by moving netfslib to keep track of its buffers for buffered I/O in bio_vec[] form.
(2) Netfslib already uses a bio_vec[] to handle unbuffered/DIO, so the number of different buffering schemes used can be reduced to just a single one.
(3) Always send an entire filesystem RPC request message to a TCP socket with single kernel_sendmsg() call as this is faster, more efficient and doesn't require the use of corking as it puts the entire transmission loop inside of a single tcp_sendmsg().
For the replacement of folio_queue, a segmented chain of bio_vec arrays rather than a single monolithic array is provided:
struct bvecq {
struct bvecq *next;
struct bvecq *prev;
unsigned long long fpos;
refcount_t ref;
u32 priv;
u16 nr_segs;
u16 max_segs;
bool inline_bv:1;
bool free:1;
bool unpin:1;
bool discontig:1;
struct bio_vec *bv;
struct bio_vec __bv[];
};The fields are:
(1) next, prev - Link segments together in a list. I want this to be NULL-terminated linear rather than circular to make it possible to arbitrarily glue bits on the front.
(2) fpos, discontig - Note the current file position of the first byte of the segment; all the bio_vecs in ->bv[] must be contiguous in the file space. The fpos can be used to find the folio by file position rather then from the info in the bio_vec.
If there's a discontiguity, this should break over into a new bvecq segment with the discontig flag set (though this is redundant if you keep track of the file position). Note that the beginning and end file positions in a segment need not be aligned to any filesystem block size.
(3) ref - Refcount. Each bvecq keeps a ref on the next. I'm not sure this is entirely necessary, but it makes sharing slices easier.
(4) priv - Private data for the owner. Dispensible; currently only used for storing a debug ID for tracing in a patch not included here.
(5) max_segs, nr_segs. The size of bv[] and the number of elements used. I've assumed a maximum of 65535 bio_vecs in the array (which would represent a ~1MiB allocation).
(6) bv, __bv, inline_bv. bv points to the bio_vec[] array handled by this segment. This may begin at __bv and if it does inline_bv should be set (otherwise it's impossible to distinguish a separately allocated bio_vec[] that follows immediately by coincidence).
(7) free, unpin. free is set if the memory pointed to by the bio_vecs needs freeing in some way upon I/O completion. unpin is set if this means using GUP unpinning rather than put_page().
I've also defined an iov_iter iterator type ITER_BVECQ to walk this sort of construct so that it can be passed directly to sendmsg() or block-based DIO (as cachefiles does).
This series makes the following changes to netfslib:
(1) The folio_queue chain used to hold folios for buffered I/O is replaced with a bvecq chain. Each bio_vec then holds (a portion of) one folio. Each bvecq holds a contiguous sequence of folios, but adjacent bvecqs in a chain may be discontiguous.
(2) For unbuffered/DIO, the source iov_iter is extracted into a bvecq chain.
(3) An abstract position representation ('bvecq_pos') is created that can used to hold a position in a bvecq chain. For the moment, this takes a ref on the bvecq it points to, but that may be excessive.
(4) Buffer tracking is managed with three cursors: The load_cursor, at which new folios are added as we go; the dispatch_cursor, at which new subrequests' buffers start when they're created; and the collect_cursor, the point at which folios are being unlocked.
Not all cursors are necessarily needed in all situations and during buffered writeback, we actually need a dispatch cursor per stream (one for the network filesystem and one for the cache).
(5) ->prepare_read(), buffer setting up and ->issue_read() are merged, as are the write variants, with the filesystem calling back up to netfslib to prepare its buffer. This simplifies the process of setting up a subrequest. It may even make sense to have the filesystem allocate the subrequest.
(6) For the moment, dispatch tracking is removed from netfs_io_request and netfs_io_stream. The problem is that we have several different ways (including in the retry code) in which we need to track things, some of which (e.g. retry) might happen simultaneously with the main dispatch, so keeping things separate helps. Netfslib sets up a context struct, passes it to ->issue_read/write(), which passes it back to netfs_prepare_read/write_buffer().
(7) Netfslib dispatches I/O by accumulating enough bufferage to dispatch at least one subrequest, then looping to generate as many as the filesystem wants to (they may be limited by other constraints, e.g. max RDMA segment count or negotiated max size). This loop could be moved down into the filesystem. A new method is provided by which netfslib can ask the filesystem to provide an estimate of the data that should be accumulated before dispatch begins.
(8) Reading from the cache is now managed by querying the cache to provide a list of the next data extents within the cache. For the moment this uses FIEMAP, but should at some point into the future transition to using a block-fs metadata-independent way of tracking this.
(9) AFS directories are switched to using a bvecq rather than a folio_queue to hold their contents.
(10) Make CIFS use a bvecq rather than a folio_queue for holding a temporary encryption buffer.
(11) CIFS RDMA is given the ability to extract ITER_BVECQ and support for extracting ITER_FOLIOQ, ITER_BVEC and ITER_KVEC is removed.
(12) All the folio_queue and rolling_buffer code is removed.
Two further things that I'm working on (but not in this branch) are:
(1) Make it so that a filesystem can be given a copy of a subchain which it can then tack header and trailer protocol elements upon to form a single message (I have this working for cifs) and even join copies together with intervening protocol elements to form compounds.
(2) Make it so that a filesystem can 'splice' out the contents of the TCP receive queue into a bvecq chain. This allows the socket lock to be dropped much more quickly and the copying of data read to the destination buffers to happen without the lock. I have this working for cifs too. Kernel recvmsg() doesn't then block kernel sendmsg() for anywhere near as long.
There are also some things I want to consider for the future:
(1) Create one or more batched iteration functions to 'unlock' all the folios in a bio_vec[], where 'unlock' is the appropriate action for ending a read or a write. Batching should hopefully also improve the efficiency of wrangling the marks on the xarray. Very often these marks are going to be represented by contiguous bits, so there may be a way to change them in bulk.
(2) Rather than walking the bvecq chain to get each individual folio out via bv_page, use the file position stored on the bvecq and the sum of bv_len to iterate over the appropriate range in i_pages.
(3) Change iov_iter to store the initial starting point and for iov_iter_revert() to reset to that and advance. This would (a) help prevent over-reversion and (b) dispense with the need for a prev pointer.
(4) Use bvecq to replace scatterlist. One problem with replacing scatterlist is that crypto drivers like to glue bits on the front of the scatterlists they're given (something trivial with that API) - and this is one way to achieve it.
The patches can also be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-next
Thanks,
David
David Howells (17):
netfs: Fix unbuffered/DIO writes to dispatch subrequests in strict
sequence
vfs: Implement a FIEMAP callback
iov_iter: Add a segmented queue of bio_vec[]
Add a function to kmap one page of a multipage bio_vec
netfs: Add some tools for managing bvecq chains
afs: Use a bvecq to hold dir content rather than folioq
netfs: Add a function to extract from an iter into a bvecq
cifs: Use a bvecq for buffering instead of a folioq
cifs: Support ITER_BVECQ in smb_extract_iter_to_rdma()
netfs: Switch to using bvecq rather than folio_queue and
rolling_buffer
cifs: Remove support for ITER_KVEC/BVEC/FOLIOQ from
smb_extract_iter_to_rdma()
netfs: Remove netfs_alloc/free_folioq_buffer()
netfs: Remove netfs_extract_user_iter()
iov_iter: Remove ITER_FOLIOQ
netfs: Remove folio_queue and rolling_buffer
netfs: Check for too much data being read
netfs: Combine prepare and issue ops and grab the buffers on request
Documentation/core-api/folio_queue.rst | 209 ------ Documentation/core-api/index.rst | 1 - fs/9p/vfs_addr.c | 34 +- fs/afs/dir.c | 41 +- fs/afs/dir_edit.c | 42 +- fs/afs/dir_search.c | 33 +- fs/afs/file.c | 27 +- fs/afs/fsclient.c | 8 +- fs/afs/inode.c | 18 +- fs/afs/internal.h | 16 +- fs/afs/write.c | 35 +- fs/afs/yfsclient.c | 6 +- fs/cachefiles/io.c | 350 +++++---- fs/ceph/addr.c | 109 +-- fs/ioctl.c | 29 +- fs/netfs/Makefile | 4 +- fs/netfs/buffered_read.c | 495 ++++++++----- fs/netfs/buffered_write.c | 2 +- fs/netfs/bvecq.c | 634 +++++++++++++++++ fs/netfs/direct_read.c | 123 ++-- fs/netfs/direct_write.c | 313 +++++++- fs/netfs/fscache_io.c | 6 - fs/netfs/internal.h | 164 ++++- fs/netfs/iterator.c | 313 +++----- fs/netfs/misc.c | 145 +--- fs/netfs/objects.c | 17 +- fs/netfs/read_collect.c | 124 ++-- fs/netfs/read_pgpriv2.c | 68 +- fs/netfs/read_retry.c | 226 +++--- fs/netfs/read_single.c | 177 +++-- fs/netfs/rolling_buffer.c | 222 ------ fs/netfs/stats.c | 6 +- fs/netfs/write_collect.c | 96 ++- fs/netfs/write_issue.c | 950 ++++++++++++++----------- fs/netfs/write_retry.c | 144 ++-- fs/nfs/fscache.c | 13 +- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/cifssmb.c | 13 +- fs/smb/client/file.c | 149 ++-- fs/smb/client/smb2ops.c | 78 +- fs/smb/client/smb2pdu.c | 28 +- fs/smb/client/smbdirect.c | 152 +--- fs/smb/client/transport.c | 15 +- include/linux/bvec.h | 54 ++ include/linux/fiemap.h | 3 + include/linux/folio_queue.h | 282 -------- include/linux/fscache.h | 19 + include/linux/iov_iter.h | 66 +- include/linux/netfs.h | 177 +++-- include/linux/rolling_buffer.h | 61 -- include/linux/uio.h | 17 +- include/trace/events/netfs.h | 118 ++- lib/iov_iter.c | 395 +++++----- lib/scatterlist.c | 56 +- lib/tests/kunit_iov_iter.c | 183 ++--- net/9p/client.c | 8 +- 56 files changed, 3815 insertions(+), 3261 deletions(-) delete mode 100644 Documentation/core-api/folio_queue.rst create mode 100644 fs/netfs/bvecq.c delete mode 100644 fs/netfs/rolling_buffer.c delete mode 100644 include/linux/folio_queue.h delete mode 100644 include/linux/rolling_buffer.h
David Howells
maintainerRFC PATCH 1/17 netfs: Fix unbuffered/DIO writes to dispatch subrequests in strict sequence
Fix netfslib such that when it's making an unbuffered or DIO write, to make sure that it sends each subrequest strictly sequentially, waiting till the previous one is 'committed' before sending the next so that we don't have pieces landing out of order and potentially leaving a hole if an error occurs (ENOSPC for example).
This is done by copying in just those bits of issuing, collecting and retrying subrequests that are necessary to do one subrequest at a time. Retrying, in particular, is simpler because if the current subrequest needs retrying, the source iterator can just be copied again and the subrequest prepped and issued again without needing to be concerned about whether it needs merging with the previous or next in the sequence.
Note that the issuing loop waits for a subrequest to complete right after issuing it, but this wait could be moved elsewhere allowing preparatory steps to be performed whilst the subrequest is in progress. In particular, once content encryption is available in netfslib, that could be done whilst waiting, as could cleanup of buffers that have been completed.
--- fs/netfs/direct_write.c | 228 ++++++++++++++++++++++++++++++++--- fs/netfs/internal.h | 4 +- fs/netfs/write_collect.c | 21 ---- fs/netfs/write_issue.c | 41 +------ include/trace/events/netfs.h | 4 +- 5 files changed, 221 insertions(+), 77 deletions(-)
fs/netfs/direct_write.c +212 -16
@@ -9,6 +9,202 @@#include <linux/uio.h> #include "internal.h" +/* +* Perform the cleanup rituals after an unbuffered write is complete. +*/ +static void netfs_unbuffered_write_done (struct netfs_io_request *wreq) +{ +struct netfs_inode *ictx =netfs_inode (wreq->inode); + +_enter ("R=%x" , wreq->debug_id); + +/* Okay, declare that all I/O is complete. */ +trace_netfs_rreq (wreq, netfs_rreq_trace_write_done); + +if (!wreq->error) +netfs_update_i_size (ictx, &ictx->inode, wreq->start, wreq->transferred); + +if (wreq->origin ==NETFS_DIO_WRITE && + wreq->mapping->nrpages) { +/* mmap may have got underfoot and we may now have folios +* locally covering the region we just wrote. Attempt to +* discard the folios, but leave in place any modified locally. +* ->write_iter() is prevented from interfering by the DIO +* counter. +*/ +pgoff_t first = wreq->start >>PAGE_SHIFT ; +pgoff_t last = (wreq->start + wreq->transferred -1 ) >>PAGE_SHIFT ; + +invalidate_inode_pages2_range (wreq->mapping, first, last); + } + +if (wreq->origin ==NETFS_DIO_WRITE ) +inode_dio_end (wreq->inode); + +_debug ("finished" ); +netfs_wake_rreq_flag (wreq,NETFS_RREQ_IN_PROGRESS , netfs_rreq_trace_wake_ip); +/* As we cleared NETFS_RREQ_IN_PROGRESS, we acquired its ref. */ + +if (wreq->iocb) { +size_t written =umin (wreq->transferred, wreq->len); + + wreq->iocb->ki_pos += written; +if (wreq->iocb->ki_complete) { +trace_netfs_rreq (wreq, netfs_rreq_trace_ki_complete); + wreq->iocb->ki_complete (wreq->iocb, wreq->error ?: written); + } + wreq->iocb =VFS_PTR_POISON ; + } + +netfs_clear_subrequests (wreq); +} + +/* +* Collect the subrequest results of unbuffered write subrequests. +*/ +static void netfs_unbuffered_write_collect (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_io_subrequest *subreq) +{ +trace_netfs_collect_sreq (wreq, subreq); + +spin_lock (&wreq->lock); +list_del_init (&subreq->rreq_link); +spin_unlock (&wreq->lock); + + wreq->transferred += subreq->transferred; +iov_iter_advance (&wreq->buffer.iter, subreq->transferred); + + stream->collected_to = subreq->start + subreq->transferred; + wreq->collected_to = stream->collected_to; +netfs_put_subrequest (subreq, netfs_sreq_trace_put_done); + +trace_netfs_collect_stream (wreq, stream); +trace_netfs_collect_state (wreq, wreq->collected_to,0 ); +} + +/* +* Write data to the server without going through the pagecache and without +* writing it to the local cache. We dispatch the subrequests serially and +* wait for each to complete before dispatching the next, lest we leave a gap +* in the data written due to a failure such as ENOSPC. We could, however +* attempt to do preparation such as content encryption for the next subreq +* whilst the current is in progress. +*/ +static int netfs_unbuffered_write (struct netfs_io_request *wreq) +{ +struct netfs_io_subrequest *subreq =NULL ; +struct netfs_io_stream *stream = &wreq->io_streams[0 ]; +int ret; + +_enter ("%llx" , wreq->len); + +if (wreq->origin ==NETFS_DIO_WRITE ) +inode_dio_begin (wreq->inode); + + stream->collected_to = wreq->start; + +for (;;) { +bool retry = false; + +if (!subreq) { +netfs_prepare_write (wreq, stream, wreq->start + wreq->transferred); + subreq = stream->construct; + stream->construct =NULL ; + stream->front =NULL ; + } + +/* Check if (re-)preparation failed. */ +if (unlikely (test_bit (NETFS_SREQ_FAILED , &subreq->flags))) { +netfs_write_subrequest_terminated (subreq, subreq->error); + wreq->error = subreq->error; +break ; + } + +iov_iter_truncate (&subreq->io_iter, wreq->len - wreq->transferred); +if (!iov_iter_count (&subreq->io_iter)) +break ; + + subreq->len =netfs_limit_iter (&subreq->io_iter,0 , + stream->sreq_max_len, + stream->sreq_max_segs); +iov_iter_truncate (&subreq->io_iter, subreq->len); + stream->submit_extendable_to = subreq->len; + +trace_netfs_sreq (subreq, netfs_sreq_trace_submit); + stream->issue_write (subreq); + +/* Async, need to wait. */ +netfs_wait_for_in_progress_stream (wreq, stream); + +if (test_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags)) { + retry = true; + }else if (test_bit (NETFS_SREQ_FAILED , &subreq->flags)) { + ret = subreq->error; + wreq->error = ret; +netfs_see_subrequest (subreq, netfs_sreq_trace_see_failed); + subreq =NULL ; +break ; + } + ret =0 ; + +if (!retry) { +netfs_unbuffered_write_collect (wreq, stream, subreq); + subreq =NULL ; +if (wreq->transferred >= wreq->len) +break ; +if (!wreq->iocb &&signal_pending (current)) { + ret = wreq->transferred ? -EINTR : -ERESTARTSYS ; +trace_netfs_rreq (wreq, netfs_rreq_trace_intr); +break ; + } +continue ; + } + +/* We need to retry the last subrequest, so first reset the +* iterator, taking into account what, if anything, we managed +* to transfer. +*/ + subreq->error = -EAGAIN ; +trace_netfs_sreq (subreq, netfs_sreq_trace_retry); +if (subreq->transferred >0 ) +iov_iter_advance (&wreq->buffer.iter, subreq->transferred); + +if (stream->source ==NETFS_UPLOAD_TO_SERVER && + wreq->netfs_ops->retry_request) + wreq->netfs_ops->retry_request (wreq, stream); + +__clear_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags); +__clear_bit (NETFS_SREQ_BOUNDARY , &subreq->flags); +__clear_bit (NETFS_SREQ_FAILED , &subreq->flags); + subreq->io_iter = wreq->buffer.iter; + subreq->start = wreq->start + wreq->transferred; + subreq->len = wreq->len - wreq->transferred; + subreq->transferred =0 ; + subreq->retry_count +=1 ; + stream->sreq_max_len =UINT_MAX ; + stream->sreq_max_segs =INT_MAX ; + +netfs_get_subrequest (subreq, netfs_sreq_trace_get_resubmit); + stream->prepare_write (subreq); + +__set_bit (NETFS_SREQ_IN_PROGRESS , &subreq->flags); +netfs_stat (&netfs_n_wh_retry_write_subreq); + } + +netfs_unbuffered_write_done (wreq); +_leave (" = %d" , ret); +return ret; +} + +static void netfs_unbuffered_write_async (struct work_struct *work) +{ + struct netfs_io_request *wreq = container_of(work, struct netfs_io_request, work); + +netfs_unbuffered_write (wreq); +netfs_put_request (wreq, netfs_rreq_trace_put_complete); +} +/* * Perform an unbuffered write where we may have to do an RMW operation on an * encrypted file. This can also be used for direct I/O writes.
@@ -70,35 +266,35 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter **/ wreq->buffer.iter = *iter; } + + wreq->len =iov_iter_count (&wreq->buffer.iter); }__set_bit (NETFS_RREQ_USE_IO_ITER , &wreq->flags); -if (async) -__set_bit (NETFS_RREQ_OFFLOAD_COLLECTION , &wreq->flags);/* Copy the data into the bounce buffer and encrypt it. */ // TODO /* Dispatch the write. */ __set_bit (NETFS_RREQ_UPLOAD_TO_SERVER , &wreq->flags); -if (async) - wreq->iocb = iocb; - wreq->len =iov_iter_count (&wreq->buffer.iter); - ret =netfs_unbuffered_write (wreq,is_sync_kiocb (iocb), wreq->len); -if (ret <0 ) { -_debug ("begin = %zd" , ret); - goto out; - } -if (!async) { - ret =netfs_wait_for_write (wreq); -if (ret >0 ) - iocb->ki_pos += ret; - }else { +if (async) { +INIT_WORK (&wreq->work, netfs_unbuffered_write_async); + wreq->iocb = iocb; +queue_work (system_dfl_wq, &wreq->work); ret = -EIOCBQUEUED ; + }else { + ret =netfs_unbuffered_write (wreq); +if (ret <0 ) { +_debug ("begin = %zd" , ret); + }else { + iocb->ki_pos += wreq->transferred; + ret = wreq->transferred ?: wreq->error; + } + +netfs_put_request (wreq, netfs_rreq_trace_put_complete); } -out:netfs_put_request (wreq, netfs_rreq_trace_put_return);return ret;
fs/netfs/internal.h +3 -1
@@ -198,6 +198,9 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,struct file *file, loff_t start, enum netfs_io_origin origin); +void netfs_prepare_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +loff_t start);void netfs_reissue_write (struct netfs_io_stream *stream,struct netfs_io_subrequest *subreq,struct iov_iter *source);
@@ -212,7 +215,6 @@ int netfs_advance_writethrough(struct netfs_io_request *wreq, struct writeback_c struct folio **writethrough_cache);ssize_t netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc,struct folio *writethrough_cache); -int netfs_unbuffered_write (struct netfs_io_request *wreq,bool may_wait,size_t len);/* * write_retry.c
fs/netfs/write_collect.c +0 -21
@@ -399,27 +399,6 @@ bool netfs_write_collection(struct netfs_io_request *wreq) ictx->ops->invalidate_cache (wreq); } -if ((wreq->origin ==NETFS_UNBUFFERED_WRITE || - wreq->origin ==NETFS_DIO_WRITE ) && - !wreq->error) -netfs_update_i_size (ictx, &ictx->inode, wreq->start, wreq->transferred); - -if (wreq->origin ==NETFS_DIO_WRITE && - wreq->mapping->nrpages) { -/* mmap may have got underfoot and we may now have folios -* locally covering the region we just wrote. Attempt to -* discard the folios, but leave in place any modified locally. -* ->write_iter() is prevented from interfering by the DIO -* counter. -*/ -pgoff_t first = wreq->start >>PAGE_SHIFT ; -pgoff_t last = (wreq->start + wreq->transferred -1 ) >>PAGE_SHIFT ; -invalidate_inode_pages2_range (wreq->mapping, first, last); - } - -if (wreq->origin ==NETFS_DIO_WRITE ) -inode_dio_end (wreq->inode); -_debug ("finished" );netfs_wake_rreq_flag (wreq,NETFS_RREQ_IN_PROGRESS , netfs_rreq_trace_wake_ip);/* As we cleared NETFS_RREQ_IN_PROGRESS, we acquired its ref. */
fs/netfs/write_issue.c +3 -38
53 lines not on this page · raw message
include/trace/events/netfs.h +3 -1
@@ -57,6 +57,7 @@ EM(netfs_rreq_trace_done, "DONE ") \ EM(netfs_rreq_trace_end_copy_to_cache, "END-C2C") \ EM(netfs_rreq_trace_free, "FREE ") \ + EM(netfs_rreq_trace_intr, "INTR ") \ EM(netfs_rreq_trace_ki_complete, "KI-CMPL") \ EM(netfs_rreq_trace_recollect, "RECLLCT") \EM (netfs_rreq_trace_redirty,"REDIRTY" ) \
@@ -169,7 +170,8 @@ EM(netfs_sreq_trace_put_oom, "PUT OOM ") \ EM(netfs_sreq_trace_put_wip, "PUT WIP ") \ EM(netfs_sreq_trace_put_work, "PUT WORK ") \ - E_(netfs_sreq_trace_put_terminated, "PUT TERM ") + EM(netfs_sreq_trace_put_terminated, "PUT TERM ") \ + E_(netfs_sreq_trace_see_failed, "SEE FAILED ")#define netfs_folio_traces \ EM(netfs_folio_is_uptodate, "mod-uptodate") \
David Howells
maintainerRFC PATCH 2/17 vfs: Implement a FIEMAP callback
In reply to David HowellsImplement a callback in the internal kernel FIEMAP API so that kernel users can make use of it as the filler function expects to write to userspace. This allows the FIEMAP data to be captured and parsed. This is useful for cachefiles and also potentially for knfsd and ksmbd to implement their equivalents of FIEMAP remotely rather than using SEEK_DATA/SEEK_HOLE.
--- fs/ioctl.c | 29 ++++++++++++++++++++--------- include/linux/fiemap.h | 3 +++ 2 files changed, 23 insertions(+), 9 deletions(-)
fs/ioctl.c +20 -9
@@ -93,6 +93,21 @@ static int ioctl_fibmap(struct file *filp, int __user *p)return error; } +static int fiemap_fill (struct fiemap_extent_info *fieinfo, +const struct fiemap_extent *extent) +{ +struct fiemap_extent __user *dest = fieinfo->fi_extents_start; + + dest += fieinfo->fi_extents_mapped; +if (copy_to_user (dest, extent,sizeof (*extent))) +return -EFAULT ; + + fieinfo->fi_extents_mapped++; +if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max) +return 1 ; +return 0 ; +} +/** * fiemap_fill_next_extent - Fiemap helper function * @fieinfo: Fiemap context passed into ->fiemap
@@ -112,7 +127,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, u64 phys, u64 len, u32 flags) {struct fiemap_extent extent; -struct fiemap_extent __user *dest = fieinfo->fi_extents_start; +int ret;/* only count the extents */ if (fieinfo->fi_extents_max ==0 ) {
@@ -140,13 +155,9 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, extent.fe_length = len; extent.fe_flags = flags; - dest += fieinfo->fi_extents_mapped; -if (copy_to_user (dest, &extent,sizeof (extent))) -return -EFAULT ; - - fieinfo->fi_extents_mapped++; -if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max) -return 1 ; + ret = fieinfo->fi_fill (fieinfo, &extent); +if (ret !=0 ) +return ret;/* 1 to stop. */ return (flags &FIEMAP_EXTENT_LAST ) ?1 :0 ; }EXPORT_SYMBOL (fiemap_fill_next_extent);
@@ -199,7 +210,7 @@ EXPORT_SYMBOL(fiemap_prep);static int ioctl_fiemap (struct file *filp,struct fiemap __user *ufiemap) {struct fiemap fiemap; -struct fiemap_extent_info fieinfo = {0 , }; +struct fiemap_extent_info fieinfo = { .fi_fill = fiemap_fill, };struct inode *inode =file_inode (filp);int error;
include/linux/fiemap.h +3 -0
@@ -11,12 +11,15 @@* @fi_extents_mapped: Number of mapped extents * @fi_extents_max: Size of fiemap_extent array * @fi_extents_start: Start of fiemap_extent array +* @fi_fill: Function to fill the extents array */ struct fiemap_extent_info {unsigned int fi_flags;unsigned int fi_extents_mapped;unsigned int fi_extents_max;struct fiemap_extent __user *fi_extents_start; +int (*fi_fill)(struct fiemap_extent_info *fiefinfo, +const struct fiemap_extent *extent); }; int fiemap_prep(struct inode *inode, struct fiemap_extent_info *fieinfo,
David Howells
maintainerRFC PATCH 3/17 iov_iter: Add a segmented queue of bio_vec[]
In reply to David HowellsAdd the concept of a segmented queue of bio_vec[] arrays. This allows an indefinite quantity of elements to be handled and allows things like network filesystems and crypto drivers to glue bits on the ends without having to reallocate the array.
The bvecq struct that defines each segment also carries capacity/usage information along with flags indicating whether the constituent memory regions need freeing or unpinning and the file position of the first element in a segment. The bvecq structs are refcounted to allow a queue to be extracted in batches and split between a number of subrequests.
The bvecq can have the bio_vec[] it manages allocated in with it, but this is not required. A flag is provided for if this is the case as comparing ->bv to ->__bv is not sufficient to detect this case.
Add an iterator type ITER_BVECQ for it. This is intended to replace ITER_FOLIOQ (and ITER_XARRAY).
Note that the prev pointer is only really needed for iov_iter_revert() and could be dispensed with if struct iov_iter contained the head information as well as the current point.
--- include/linux/bvec.h | 33 +++++ include/linux/iov_iter.h | 61 +++++++- include/linux/uio.h | 11 ++ lib/iov_iter.c | 288 ++++++++++++++++++++++++++++++++++++- lib/scatterlist.c | 65 +++++++++ lib/tests/kunit_iov_iter.c | 179 +++++++++++++++++++++++ 6 files changed, 633 insertions(+), 4 deletions(-)
include/linux/bvec.h +33 -0
@@ -308,4 +308,37 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec) return page_to_phys(bvec->bv_page) + bvec->bv_offset; } +/* +* Segmented bio_vec queue. +* +* These can be linked together to form messages of indefinite length and +* iterated over with an ITER_BVECQ iterator. The list is non-circular; next +* and prev are NULL at the ends. +* +* The bv pointer points to the segment array; this may be __bv if allocated +* together. The caller is responsible for determining whether or not this is +* the case as the array pointed to by bv may be follow on directly from the +* bvecq by accident of allocation (ie. ->bv == ->__bv is *not* sufficient to +* determine this). +* +* The file position and discontiguity flag allow non-contiguous data sets to +* be chained together, but still teased apart without the need to convert the +* info in the bio_vec back into a folio pointer. +*/ +struct bvecq { +struct bvecq *next;/* Next bvec in the list or NULL */ +struct bvecq *prev;/* Prev bvec in the list or NULL */ +unsigned long long fpos;/* File position */ +refcount_t ref; +u32 priv;/* Private data */ +u16 nr_segs;/* Number of elements in bv[] used */ +u16 max_segs;/* Number of elements allocated in bv[] */ +bool inline_bv:1 ;/* T if __bv[] is being used */ +bool free:1 ;/* T if the pages need freeing */ +bool unpin:1 ;/* T if the pages need unpinning, not freeing */ +bool discontig:1 ;/* T if not contiguous with previous bvecq */ +struct bio_vec *bv;/* Pointer to array of page fragments */ +struct bio_vec __bv[];/* Default array (if ->inline_bv) */ +}; +#endif /* __LINUX_BVEC_H */
include/linux/iov_iter.h +59 -2
85 lines not on this page · raw message
include/linux/uio.h +11 -0
@@ -27,6 +27,7 @@ enum iter_type {ITER_BVEC ,ITER_KVEC ,ITER_FOLIOQ , +ITER_BVECQ ,ITER_XARRAY , ITER_DISCARD, };
@@ -69,6 +70,7 @@ struct iov_iter {const struct kvec *kvec;const struct bio_vec *bvec;const struct folio_queue *folioq; +const struct bvecq *bvecq;struct xarray *xarray;void __user *ubuf; };
@@ -78,6 +80,7 @@ struct iov_iter {union {unsigned long nr_segs;u8 folioq_slot; +u16 bvecq_slot;loff_t xarray_start; }; };
@@ -150,6 +153,11 @@ static inline bool iov_iter_is_folioq(const struct iov_iter *i)return iov_iter_type (i) ==ITER_FOLIOQ ; } +static inline bool iov_iter_is_bvecq (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_BVECQ ; +} +static inline bool iov_iter_is_xarray (const struct iov_iter *i) {return iov_iter_type (i) ==ITER_XARRAY ;
@@ -298,6 +306,9 @@ void iov_iter_discard(struct iov_iter *i, unsigned int direction, size_t count);void iov_iter_folio_queue (struct iov_iter *i,unsigned int direction,const struct folio_queue *folioq,unsigned int first_slot,unsigned int offset,size_t count); +void iov_iter_bvec_queue (struct iov_iter *i,unsigned int direction, +const struct bvecq *bvecq, +unsigned int first_slot,unsigned int offset,size_t count);void iov_iter_xarray (struct iov_iter *i,unsigned int direction,struct xarray *xarray,loff_t start,size_t count); ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages,
lib/iov_iter.c +286 -2
367 lines not on this page · raw message
lib/scatterlist.c +65 -0
77 lines not on this page · raw message
lib/tests/kunit_iov_iter.c +179 -0
191 lines not on this page · raw message
David Howells
maintainerRFC PATCH 4/17 Add a function to kmap one page of a multipage bio_vec
In reply to David HowellsAdd a function to kmap one page of a multipage bio_vec by offset (which is added to the offset in the bio_vec internally). The caller is responsible for calculating how much of the page is then available.
--- include/linux/bvec.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
include/linux/bvec.h +21 -0
@@ -308,6 +308,27 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec)return page_to_phys (bvec->bv_page) + bvec->bv_offset; } +/** +* kmap_local_bvec - Map part of a bvec into the kernel virtual address space +* @bvec: bvec to map +* @offset: Offset into bvec +* +* Map the page containing the byte at @offset into the kernel virtual address +* space. The caller is responsible for making sure this doesn't overrun. +* +* Call kunmap_local on the returned address to unmap. +*/ +static inline void *kmap_local_bvec (struct bio_vec *bvec,size_t offset) +{ +#ifdef CONFIG_HIGHMEM + offset += bvec->bv_offset; + +return kmap_local_page (bvec->bv_page + offset /PAGE_SIZE ) + offset %PAGE_SIZE ; +#else +return bvec_virt (bvec) + offset; +#endif +} +/* * Segmented bio_vec queue. *
David Howells
maintainerRFC PATCH 5/17 netfs: Add some tools for managing bvecq chains
In reply to David HowellsProvide a selection of tools for managing bvec queue chains. This includes:
(1) Allocation, prepopulation, expansion, shortening and refcounting of bvecqs and bvecq chains.
This can be used to do things like creating an encryption buffer in cifs or a directory content buffer in afs. The memory segments will be appropriate disposed off according to the flags on the bvecq.
(2) Management of a bvecq chain as a rolling buffer and the management of positions within it.
(3) Loading folios, slicing chains and clearing content.
--- fs/netfs/Makefile | 1 + fs/netfs/bvecq.c | 634 +++++++++++++++++++++++++++++++++++ fs/netfs/internal.h | 87 +++++ fs/netfs/stats.c | 4 +- include/linux/netfs.h | 24 ++ include/trace/events/netfs.h | 24 ++ 6 files changed, 773 insertions(+), 1 deletion(-) create mode 100644 fs/netfs/bvecq.c
fs/netfs/Makefile +1 -0
@@ -3,6 +3,7 @@ netfs-y := \ buffered_read.o \ buffered_write.o \ + bvecq.o \ direct_read.o \ direct_write.o \ iterator.o \
fs/netfs/bvecq.c new file +634 -0
634 lines not on this page · raw message
fs/netfs/internal.h +87 -0
99 lines not on this page · raw message
fs/netfs/stats.c +3 -1
@@ -48,6 +48,7 @@ atomic_t netfs_n_wh_retry_write_subreq;atomic_t netfs_n_wb_lock_skip;atomic_t netfs_n_wb_lock_wait;atomic_t netfs_n_folioq; +atomic_t netfs_n_bvecq;int netfs_stats_show (struct seq_file *m,void *v) {
@@ -90,9 +91,10 @@ int netfs_stats_show(struct seq_file *m, void *v)atomic_read (&netfs_n_rh_retry_read_subreq),atomic_read (&netfs_n_wh_retry_write_req), atomic_read(&netfs_n_wh_retry_write_subreq)); -seq_printf (m,"Objs : rr=%u sr=%u foq=%u wsc=%u\n" , +seq_printf (m,"Objs : rr=%u sr=%u bq=%u foq=%u wsc=%u\n" ,atomic_read (&netfs_n_rh_rreq),atomic_read (&netfs_n_rh_sreq), +atomic_read (&netfs_n_bvecq),atomic_read (&netfs_n_folioq),atomic_read (&netfs_n_wh_wstream_conflict)); seq_printf(m, "WbLock : skip=%u wait=%u\n",
include/linux/netfs.h +24 -0
@@ -17,12 +17,14 @@#include <linux/workqueue.h> #include <linux/fs.h> #include <linux/pagemap.h> +#include <linux/bvec.h> #include <linux/uio.h> #include <linux/rolling_buffer.h> enum netfs_sreq_ref_trace ;typedef struct mempool mempool_t ;struct folio_queue ; +struct bvecq ;/** * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -40,6 +42,16 @@ static inline void folio_start_private_2(struct folio *folio)folio_set_private_2 (folio); } +/* +* Position in a bio_vec queue. The bvecq holds a ref on the queue segment it +* points to. +*/ +struct bvecq_pos { +struct bvecq *bvecq;/* The first bvecq */ +unsigned int offset;/* The offset within the starting slot */ +u16 slot;/* The starting slot */ +}; +enum netfs_io_source {NETFS_SOURCE_UNKNOWN ,NETFS_FILL_WITH_ZEROES ,
@@ -462,6 +474,12 @@ int netfs_alloc_folioq_buffer(struct address_space *mapping,struct folio_queue **_buffer, size_t *_cur_size, ssize_t size, gfp_t gfp);void netfs_free_folioq_buffer (struct folio_queue *fq); +void dump_bvecq (const struct bvecq *bq); +struct bvecq *netfs_alloc_bvecq (size_t nr_slots,gfp_t gfp); +struct bvecq *netfs_alloc_bvecq_buffer (size_t size,unsigned int pre_slots,gfp_t gfp); +void netfs_free_bvecq_buffer (struct bvecq *bq); +void netfs_put_bvecq (struct bvecq *bq); +int netfs_shorten_bvecq_buffer (struct bvecq *bq,unsigned int seg,size_t size);/** * netfs_inode - Get the netfs inode context from the inode
@@ -552,4 +570,10 @@ static inline void netfs_wait_for_outstanding_io(struct inode *inode) wait_var_event(&ictx->io_count, atomic_read(&ictx->io_count) == 0); } +static inline struct bvecq *netfs_get_bvecq (struct bvecq *bq) +{ +refcount_inc (&bq->ref); +return bq; +} +#endif /* _LINUX_NETFS_H */
include/trace/events/netfs.h +24 -0
@@ -778,6 +778,30 @@ TRACE_EVENT(netfs_folioq, __print_symbolic(__entry->trace, netfs_folioq_traces)) ); +TRACE_EVENT (netfs_bv_slot, + TP_PROTO(const struct bvecq *bq, int slot), + +TP_ARGS (bq, slot), + +TP_STRUCT__entry ( + __field(unsigned long, pfn) + __field(unsigned int, offset) + __field(unsigned int, len) + __field(unsigned int, slot) + ), + +TP_fast_assign ( + __entry->slot = slot; + __entry->pfn = page_to_pfn(bq->bv[slot].bv_page); + __entry->offset = bq->bv[slot].bv_offset; + __entry->len = bq->bv[slot].bv_len; + ), + +TP_printk ("bq[%x] p=%lx %x-%x" , + __entry->slot, + __entry->pfn, __entry->offset, __entry->offset + __entry->len) + ); +#undef EM#undef E_#endif /* _TRACE_NETFS_H */
David Howells
maintainerRFC PATCH 6/17 afs: Use a bvecq to hold dir content rather than folioq
In reply to David HowellsUse a bvecq to hold the contents of a directory rather than the folioq so that the latter can be phased out.
--- fs/afs/dir.c | 37 +++++----- fs/afs/dir_edit.c | 41 +++++------ fs/afs/dir_search.c | 33 ++++----- fs/afs/inode.c | 18 ++--- fs/afs/internal.h | 6 +- fs/netfs/write_issue.c | 156 ++++++----------------------------------- include/linux/netfs.h | 1 + 7 files changed, 87 insertions(+), 205 deletions(-)
fs/afs/dir.c +18 -19
@@ -136,9 +136,9 @@ static void afs_dir_dump(struct afs_vnode *dvnode)pr_warn ("DIR %llx:%llx is=%llx\n" , dvnode->fid.vid, dvnode->fid.vnode, i_size); -iov_iter_folio_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size); -iterate_folioq (&iter,iov_iter_count (&iter),NULL ,NULL , - afs_dir_dump_step); +iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size); +iterate_bvecq (&iter,iov_iter_count (&iter),NULL ,NULL , + afs_dir_dump_step); }/*
@@ -199,9 +199,9 @@ static int afs_dir_check(struct afs_vnode *dvnode)if (unlikely (!i_size))return 0 ; -iov_iter_folio_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size); - checked =iterate_folioq (&iter,iov_iter_count (&iter), dvnode,NULL , - afs_dir_check_step); +iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size); + checked =iterate_bvecq (&iter,iov_iter_count (&iter), dvnode,NULL , + afs_dir_check_step);if (checked != i_size) {afs_dir_dump (dvnode);return -EIO ;
@@ -255,15 +255,14 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)if (dvnode->directory_size < i_size) {size_t cur_size = dvnode->directory_size; - ret =netfs_alloc_folioq_buffer (NULL , - &dvnode->directory, &cur_size, i_size, + ret =netfs_expand_bvecq_buffer (&dvnode->directory, &cur_size, i_size,mapping_gfp_mask (dvnode->netfs.inode.i_mapping)); dvnode->directory_size = cur_size;if (ret <0 )return ret; } -iov_iter_folio_queue (&iter,ITER_DEST , dvnode->directory,0 ,0 , dvnode->directory_size); +iov_iter_bvec_queue (&iter,ITER_DEST , dvnode->directory,0 ,0 , dvnode->directory_size);/* AFS requires us to perform the read of a directory synchronously as * a single unit to avoid issues with the directory contents being
@@ -282,9 +281,9 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)if (ret2 <0 ) ret = ret2; - }else if (i_size <folioq_folio_size (dvnode->directory,0 )) { + }else if (i_size <PAGE_SIZE ) {/* NUL-terminate a symlink. */ -char *symlink =kmap_local_folio (folioq_folio (dvnode->directory,0 ),0 ); +char *symlink =kmap_local_bvec (&dvnode->directory->bv[0 ],0 ); symlink[i_size] =0 ;kunmap_local (symlink);
@@ -305,8 +304,8 @@ ssize_t afs_read_single(struct afs_vnode *dvnode, struct file *file) }/* -* Read the directory into a folio_queue buffer in one go, scrubbing the -* previous contents. We return -ESTALE if the caller needs to call us again. +* Read the directory into the buffer in one go, scrubbing the previous +* contents. We return -ESTALE if the caller needs to call us again. */ ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file) __acquires(&dvnode->validate_lock)
@@ -487,7 +486,7 @@ static size_t afs_dir_iterate_step(void *iter_base, size_t progress, size_t len, }/* -* Iterate through the directory folios. +* Iterate through the directory content. */ static int afs_dir_iterate_contents (struct inode *dir,struct dir_context *dir_ctx) {
@@ -502,11 +501,11 @@ static int afs_dir_iterate_contents(struct inode *dir, struct dir_context *dir_cif (i_size <=0 || dir_ctx->pos >= i_size)return 0 ; -iov_iter_folio_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size); +iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , i_size);iov_iter_advance (&iter,round_down (dir_ctx->pos,AFS_DIR_BLOCK_SIZE )); -iterate_folioq (&iter,iov_iter_count (&iter), dvnode, &ctx, - afs_dir_iterate_step); +iterate_bvecq (&iter,iov_iter_count (&iter), dvnode, &ctx, + afs_dir_iterate_step);if (ctx.error == -ESTALE )afs_invalidate_dir (dvnode, afs_dir_invalid_iter_stale);
@@ -2211,8 +2210,8 @@ int afs_single_writepages(struct address_space *mapping,if (is_dir ?test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags) :atomic64_read (&dvnode->cb_expires_at) !=AFS_NO_CB_PROMISE ) { -iov_iter_folio_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , -i_size_read (&dvnode->netfs.inode)); +iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , +i_size_read (&dvnode->netfs.inode)); ret =netfs_writeback_single (mapping, wbc, &iter); }
fs/afs/dir_edit.c +19 -22
69 lines not on this page · raw message
fs/afs/dir_search.c +15 -18
@@ -66,12 +66,11 @@ bool afs_dir_init_iter(struct afs_dir_iter *iter, const struct qstr *name)*/ union afs_xdr_dir_block *afs_dir_find_block (struct afs_dir_iter *iter,size_t block) { -struct folio_queue *fq = iter->fq;struct afs_vnode *dvnode = iter->dvnode; -struct folio *folio; +struct bvecq *bq = iter->bq;size_t blpos = block *AFS_DIR_BLOCK_SIZE ;size_t blend = (block +1 ) *AFS_DIR_BLOCK_SIZE , fpos = iter->fpos; -int slot = iter->fq_slot; +int slot = iter->bq_slot;_enter ("%zx,%d" , block, slot);
@@ -83,36 +82,34 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t blif (dvnode->directory_size < blend) goto fail; -if (!fq || blpos < fpos) { - fq = dvnode->directory; +if (!bq || blpos < fpos) { + bq = dvnode->directory; slot =0 ; fpos =0 ; }/* Search the folio queue for the folio containing the block... */ -for (; fq; fq = fq->next) { -for (; slot <folioq_count (fq); slot++) { -size_t fsize =folioq_folio_size (fq, slot); +for (; bq; bq = bq->next) { +for (; slot < bq->max_segs; slot++) { +struct bio_vec *bv = &bq->bv[slot]; +size_t bsize = bv->bv_len; -if (blend <= fpos + fsize) { +if (blend <= fpos + bsize) {/* ... and then return the mapped block. */ - folio =folioq_folio (fq, slot); -if (WARN_ON_ONCE (folio_pos (folio) != fpos)) - goto fail; - iter->fq = fq; - iter->fq_slot = slot; + iter->bq = bq; + iter->bq_slot = slot; iter->fpos = fpos; - iter->block =kmap_local_folio (folio, blpos - fpos); + iter->block =kmap_local_bvec (bv, blpos - fpos);return iter->block; } - fpos += fsize; + fpos += bsize; } slot =0 ; } fail: - iter->fq =NULL ; - iter->fq_slot =0 ; + iter->bq =NULL ; + iter->bq_slot =0 ;afs_invalidate_dir (dvnode, afs_dir_invalid_edit_get_block);return NULL ; }
fs/afs/inode.c +9 -9
@@ -31,12 +31,12 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)size_t dsize =0 ;char *p; -if (netfs_alloc_folioq_buffer (NULL , &vnode->directory, &dsize, size, +if (netfs_expand_bvecq_buffer (&vnode->directory, &dsize, size,mapping_gfp_mask (vnode->netfs.inode.i_mapping)) <0 )return ; vnode->directory_size = dsize; - p =kmap_local_folio (folioq_folio (vnode->directory,0 ),0 ); + p =kmap_local_bvec (&vnode->directory->bv[0 ],0 );memcpy (p, op->create.symlink, size);kunmap_local (p);set_bit (AFS_VNODE_DIR_READ , &vnode->flags);
@@ -45,17 +45,17 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)static void afs_put_link (void *arg) { -struct folio *folio =virt_to_folio (arg); +struct page *page =virt_to_page (arg);kunmap_local (arg); -folio_put (folio); +put_page (page); }const char *afs_get_link (struct dentry *dentry,struct inode *inode,struct delayed_call *callback) {struct afs_vnode *vnode =AFS_FS_I (inode); -struct folio *folio; +struct page *page;char *content;ssize_t ret;
@@ -84,9 +84,9 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,set_bit (AFS_VNODE_DIR_READ , &vnode->flags); good: - folio =folioq_folio (vnode->directory,0 ); -folio_get (folio); - content =kmap_local_folio (folio,0 ); + page = vnode->directory->bv[0 ].bv_page; +get_page (page); + content =kmap_local_page (page);set_delayed_call (callback, afs_put_link, content);return content; }
@@ -761,7 +761,7 @@ void afs_evict_inode(struct inode *inode)netfs_wait_for_outstanding_io (inode);truncate_inode_pages_final (&inode->i_data); -netfs_free_folioq_buffer (vnode->directory); +netfs_free_bvecq_buffer (vnode->directory);afs_set_cache_aux (vnode, &aux);netfs_clear_inode_writeback (inode, &aux);
fs/afs/internal.h +3 -3
@@ -710,7 +710,7 @@ struct afs_vnode {#define AFS_VNODE_MODIFYING 10/* Set if we're performing a modification op */ #define AFS_VNODE_DIR_READ 11/* Set if we've read a dir's contents */ -struct folio_queue *directory;/* Directory contents */ +struct bvecq *directory;/* Directory contents */ struct list_head wb_keys;/* List of keys available for writeback */ struct list_head pending_locks;/* locks waiting to be granted */ struct list_head granted_locks;/* locks granted on this file */
@@ -983,9 +983,9 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int flstruct afs_dir_iter {struct afs_vnode *dvnode;union afs_xdr_dir_block *block; -struct folio_queue *fq; +struct bvecq *bq;unsigned int fpos; -int fq_slot; +int bq_slot;unsigned int loop_check;u8 nr_slots;u8 bucket;
fs/netfs/write_issue.c +22 -134
196 lines not on this page · raw message
include/linux/netfs.h +1 -0
@@ -477,6 +477,7 @@ void netfs_free_folioq_buffer(struct folio_queue *fq);void dump_bvecq (const struct bvecq *bq);struct bvecq *netfs_alloc_bvecq (size_t nr_slots,gfp_t gfp);struct bvecq *netfs_alloc_bvecq_buffer (size_t size,unsigned int pre_slots,gfp_t gfp); +int netfs_expand_bvecq_buffer (struct bvecq **_buffer,size_t *_cur_size,ssize_t size,gfp_t gfp);void netfs_free_bvecq_buffer (struct bvecq *bq);void netfs_put_bvecq (struct bvecq *bq);int netfs_shorten_bvecq_buffer (struct bvecq *bq,unsigned int seg,size_t size);
David Howells
maintainerRFC PATCH 7/17 netfs: Add a function to extract from an iter into a bvecq
In reply to David HowellsAdd a function to extract a slice of data from an iterator of any type into a bvec queue chain.
--- fs/netfs/iterator.c | 122 ++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 3 ++ 2 files changed, 125 insertions(+)
fs/netfs/iterator.c +122 -0
@@ -13,6 +13,128 @@#include <linux/netfs.h> #include "internal.h" +/** +* netfs_extract_iter - Extract the pages from an iterator into a bvecq +* @orig: The original iterator +* @orig_len: The amount of iterator to copy +* @max_segs: Maximum number of contiguous segments +* @fpos: Starting file position to label the bvecq with +* @_bvecq_head: Where to cache the bvec queue +* @extraction_flags: Flags to qualify the request +* +* Extract the page fragments from the given amount of the source iterator and +* build bvec queue that refers to all of those bits. This allows the original +* iterator to disposed of. +* +* @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be +* allowed on the pages extracted. +* +* On success, the amount of data in the bvec is returned, the original +* iterator will have been advanced by the amount extracted. +* +* The bvecq segments are marked with indications on how to get clean up the +* extracted fragments. +*/ +ssize_t netfs_extract_iter (struct iov_iter *orig,size_t orig_len,size_t max_segs, +unsigned long long fpos,struct bvecq **_bvecq_head, +iov_iter_extraction_t extraction_flags) +{ +struct bvecq *bq_tail =NULL ; +ssize_t ret =0 ; +size_t segs_per_bq; +size_t extracted =0 ; + +_enter ("{%u,%zx},%zx" , orig->iter_type, orig->count, orig_len); + +if (max_segs ==0 ) + max_segs =ULONG_MAX ; + +/* We want the biggest pow-of-2 size that has at most 255 segs and that +* won't exceed a 4K page. +*/ + segs_per_bq = (4096 -sizeof (*bq_tail)) /sizeof (bq_tail->__bv[0 ]); +if (segs_per_bq >255 ) + segs_per_bq = (2048 -sizeof (*bq_tail)) /sizeof (bq_tail->__bv[0 ]); + +do { +struct bvecq *bq; +size_t nr_slots =iov_iter_npages (orig,umin (segs_per_bq, max_segs)); + +if (WARN_ON (nr_slots ==0 && extracted < orig_len) || +WARN_ON (nr_slots > max_segs)) +break ; + max_segs -= nr_slots; + + bq =netfs_alloc_one_bvecq (nr_slots,GFP_NOFS ); +if (!bq) { + ret = -ENOMEM ; +break ; + } + bq->free =user_backed_iter (orig); + bq->unpin =iov_iter_extract_will_pin (orig); + bq->prev = bq_tail; + bq->fpos = fpos + extracted; + +if (bq_tail) + bq_tail->next = bq; +else + *_bvecq_head = bq; + bq_tail = bq; + +if (extracted >= orig_len) +break ; + +/* Put the page list at the end of the bvec list storage. bvec +* elements are larger than page pointers, so as long as we +* work 0->last, we should be fine. +*/ +struct bio_vec *bv = bq->bv; +struct page **pages; +size_t bv_size =array_size (bq->max_segs,sizeof (*bv)); +size_t pg_size =array_size (bq->max_segs,sizeof (*pages)); + + pages = (void *)bv + bv_size - pg_size; + +do { +unsigned int cur_npages; +ssize_t got; +size_t offset; + + got =iov_iter_extract_pages (orig, &pages, orig_len - extracted, + bq->max_segs - bq->nr_segs, + extraction_flags, &offset); +if (got <0 ) { +pr_err ("Couldn't get user pages (rc=%zd)\n" , got); + ret = got; +break ; + } + +if (got > orig_len - extracted) { +pr_err ("get_pages rc=%zd more than %zu\n" , + got, orig_len - extracted); +break ; + } + + extracted += got; + got += offset; + cur_npages =DIV_ROUND_UP (got,PAGE_SIZE ); + +for (unsigned int i =0 ; i < cur_npages; i++) { +size_t len =umin (got,PAGE_SIZE ); + +bvec_set_page (&bq->bv[bq->nr_segs], + *pages++, len - offset, offset); + bq->nr_segs++; + got -= len; + offset =0 ; + } + }while (extracted < orig_len && !bvecq_is_full (bq)); + }while (extracted < orig_len && max_segs >0 ); + +return extracted ?: ret; +} +EXPORT_SYMBOL_GPL (netfs_extract_iter); +/** * netfs_extract_user_iter - Extract the pages from a user iterator into a bvec * @orig: The original iterator
include/linux/netfs.h +3 -0
@@ -448,6 +448,9 @@ void netfs_get_subrequest(struct netfs_io_subrequest *subreq, enum netfs_sreq_ref_trace what);void netfs_put_subrequest (struct netfs_io_subrequest *subreq,enum netfs_sreq_ref_trace what); +ssize_t netfs_extract_iter (struct iov_iter *orig,size_t orig_len,size_t max_segs, +unsigned long long fpos,struct bvecq **_bvecq_head, +iov_iter_extraction_t extraction_flags);ssize_t netfs_extract_user_iter (struct iov_iter *orig,size_t orig_len,struct iov_iter *new,iov_iter_extraction_t extraction_flags);
David Howells
maintainerRFC PATCH 8/17 cifs: Use a bvecq for buffering instead of a folioq
In reply to David HowellsUse a bvecq for internal buffering for crypto purposes instead of a folioq so that the latter can be phased out.
--- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/smb2ops.c | 70 +++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 38 deletions(-)
fs/smb/client/cifsglob.h +1 -1
@@ -290,7 +290,7 @@ struct smb_rqst {struct kvec *rq_iov;/* array of kvecs */ unsigned int rq_nvec;/* number of kvecs in array */ struct iov_iter rq_iter;/* Data iterator */ -struct folio_queue *rq_buffer;/* Buffer for encryption */ +struct bvecq *rq_buffer;/* Buffer for encryption */ };struct mid_q_entry ;
fs/smb/client/smb2ops.c +33 -37
154 lines not on this page · raw message
David Howells
maintainerRFC PATCH 9/17 cifs: Support ITER_BVECQ in smb_extract_iter_to_rdma()
In reply to David HowellsAdd support for ITER_BVECQ to smb_extract_iter_to_rdma().
--- fs/smb/client/smbdirect.c | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+)
fs/smb/client/smbdirect.c +60 -0
@@ -3298,6 +3298,63 @@ static ssize_t smb_extract_folioq_to_rdma(struct iov_iter *iter,return ret; } +/* +* Extract memory fragments from a BVECQ-class iterator and add them to an RDMA +* list. The folios are not pinned. +*/ +static ssize_t smb_extract_bvecq_to_rdma (struct iov_iter *iter, +struct smb_extract_to_rdma *rdma, +ssize_t maxsize) +{ +const struct bvecq *bq = iter->bvecq; +unsigned int slot = iter->bvecq_slot; +ssize_t ret =0 ; +size_t offset = iter->iov_offset; + +if (slot >= bq->nr_segs) { + bq = bq->next; +if (WARN_ON_ONCE (!bq)) +return -EIO ; + slot =0 ; + } + +do { +struct bio_vec *bv = &bq->bv[slot]; +struct page *page = bv->bv_page; +size_t bsize = bv->bv_len; + +if (offset < bsize) { +size_t part =umin (maxsize, bsize - offset); + +if (!smb_set_sge (rdma, page, bv->bv_offset + offset, part)) +return -EIO ; + + offset += part; + ret += part; + maxsize -= part; + } + +if (offset >= bsize) { + offset =0 ; + slot++; +if (slot >= bq->nr_segs) { +if (!bq->next) { +WARN_ON_ONCE (ret < iter->count); +break ; + } + bq = bq->next; + slot =0 ; + } + } + }while (rdma->nr_sge < rdma->max_sge && maxsize >0 ); + + iter->bvecq = bq; + iter->bvecq_slot = slot; + iter->iov_offset = offset; + iter->count -= ret; +return ret; +} +/* * Extract page fragments from up to the given amount of the source iterator * and build up an RDMA list that refers to all of those bits. The RDMA list
@@ -3325,6 +3382,9 @@ static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len,case ITER_FOLIOQ : ret =smb_extract_folioq_to_rdma (iter, rdma, len);break ; +case ITER_BVECQ : + ret =smb_extract_bvecq_to_rdma (iter, rdma, len); +break ;default :WARN_ON_ONCE (1 );return -EIO ;
David Howells
maintainerRFC PATCH 10/17 netfs: Switch to using bvecq rather than folio_queue and rolling_buffer
In reply to David HowellsSwitch netfslib to using bvecq, a segmented bio_vec[] queue, instead of the folio_queue and rolling_buffer constructs, to keep track of the regions of memory it is performing I/O upon. Each bvecq struct in the chain is marked with the starting file position of that sequence so that discontiguities can be handled (the contents of each individual bvecq must be contiguous).
For buffered I/O, the folios are added to the queue as the operation proceeds, much as it does now with folio_queues. For unbuffered/direct I/O, the iterator is extracted into the queue up front.
The bvecq structs are marked with information as to how the regions contained therein should be disposed of (unlock-only, free, unpin).
When setting up a subrequest, netfslib will furnish it with a slice of the main buffer queue as a pointer to starting bvecq, slot and offset and, for the moment, an ITER_BVECQ iterator is set to cover the slice in subreq->io_iter.
Notes on the implementation:
(1) This patch uses the concept of a 'bvecq position', which is a tuple of { bvecq, slot, offset }. This is lighter weight than using a full iov_iter, though that would also suffice. If not NULL, the position also holds a reference on the bvecq it is pointing to. This is probably overkill as only the hindmost position (that of collection) needs to hold a reference.
(2) There are three positions on the netfs_io_request struct. Not all are used by every request type.
Firstly, there's ->load_cursor, which is used by buffered read and write to point to the next slot to have a folio inserted into it (either loaded from the readahead_control or from writeback_iter()).
Secondly, there's ->dispatch_cursor, which is used to provide the position in the buffer from which we start dispatching a subrequest.
Thirdly, there's the ->collect_cursor, which is used by the collection routines to point to the next memory region to be cleaned up.
(3) There are two positions on the netfs_io_subrequest struct.
Firstly, there's ->dispatch_pos, which indicates the position from
which a subrequest's buffer begins. This is used as the base of the
position from which to retry (advanced by ->transfer).
Secondly, there's ->content, which is normally the same as
->dispatch_pos but if the bvecq chain got duplicated or the content
got copied, then this will point to that and will that will be
disposed of on retry. (4) Maintenance of the position structs is done with helper functions, such as bvecq_pos_attach() to hide the refcounting.
(5) When sending a write to the cache, the bvecq will be duplicated and the ends rounded up/down to the backing file's DIO block alignment.
(6) bvec_slice() is used to select a slice of the source buffer and assign it to a subrequest. The source buffer position is advanced.
(7) netfs_extract_iter() is used by unbuffered/direct I/O API functions to decant a chunk of the iov_iter supplied by the VFS into a bvecq chain
- and to label the bvecqs with appropriate disposal information (e.g. unpin, free, nothing).
There are further options that can be explored in the future:
(1) Allow the provision of a duplicated bvecq chain for just that region so that the filesystem can add bits on either end (such as adding protocol headers and trailers and gluing several things together into a compound operation).
(2) If a filesystem supports vectored/sparse read and write ops, it can be given a chain with discontiguities in it to perform in a single op (Ceph, for example, can do this).
(3) Because each bvecq notes the start file position of the regions contained therein, there's no need to translate the info in the bio_vec into folio pointers in order to unlock the page after I/O. Instead, the inode's pagecache can be iterated over and the xarray marks cleared en masse.
(4) Make MSG_SPLICE_PAGES handling read the disposal info in the bvecq and use that to indicate how it should get rid of the stuff it pasted into a sk_buff.
(5) If a bounce buffer is needed (encryption, for example), the bounce buffer can be held in a bvecq and sliced up instead of the main buffer queue.
(6) Get rid of subreq->io_iter and move the iov_iter stuff down into the filesystem. The I/O iterators are normally only needed transitorily, and the one currently in netfs_io_subrequest is unnecessary most of the time.
folio_queue and rolling_buffer will be removed in a follow up patch.
--- fs/cachefiles/io.c | 13 --- fs/netfs/Makefile | 1 - fs/netfs/buffered_read.c | 153 ++++++++++++++++++++++----------- fs/netfs/direct_read.c | 73 ++++++---------- fs/netfs/direct_write.c | 72 +++++++++------- fs/netfs/internal.h | 10 +-- fs/netfs/iterator.c | 2 + fs/netfs/misc.c | 20 +---- fs/netfs/objects.c | 16 ++-- fs/netfs/read_collect.c | 83 +++++++++++------- fs/netfs/read_pgpriv2.c | 68 ++++++++++----- fs/netfs/read_retry.c | 59 ++++++++----- fs/netfs/read_single.c | 18 ++-- fs/netfs/stats.c | 4 +- fs/netfs/write_collect.c | 40 +++++---- fs/netfs/write_issue.c | 162 +++++++++++++++++++++++++---------- fs/netfs/write_retry.c | 45 ++++++---- include/linux/netfs.h | 26 +++--- include/trace/events/netfs.h | 46 +++++----- 19 files changed, 530 insertions(+), 381 deletions(-)
fs/cachefiles/io.c +0 -13
@@ -648,7 +648,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)struct netfs_cache_resources *cres = &wreq->cache_resources;struct cachefiles_object *object =cachefiles_cres_object (cres);struct cachefiles_cache *cache = object->volume->cache; -struct netfs_io_stream *stream = &wreq->io_streams[subreq->stream_nr];const struct cred *saved_cred;size_t off, pre, post, len = subreq->len;loff_t start = subreq->start;
@@ -672,18 +671,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)iov_iter_advance (&subreq->io_iter, pre); } -/* We also need to end on the cache granularity boundary */ -if (start + len == wreq->i_size) { -size_t part = len %CACHEFILES_DIO_BLOCK_SIZE ; -size_t need =CACHEFILES_DIO_BLOCK_SIZE - part; - -if (part && stream->submit_extendable_to >= need) { - len += need; - subreq->len += need; - subreq->io_iter.count += need; - } - } - post = len & (CACHEFILES_DIO_BLOCK_SIZE -1 );if (post) { len -= post;
fs/netfs/Makefile +0 -1
@@ -15,7 +15,6 @@ netfs-y := \ read_pgpriv2.o \ read_retry.o \ read_single.o \ - rolling_buffer.o \ write_collect.o \ write_issue.o \ write_retry.o
fs/netfs/buffered_read.c +101 -52
299 lines not on this page · raw message
fs/netfs/direct_read.c +24 -49
111 lines not on this page · raw message
fs/netfs/direct_write.c +41 -31
128 lines not on this page · raw message
fs/netfs/internal.h +3 -7
@@ -7,7 +7,6 @@#include <linux/slab.h> #include <linux/seq_file.h> -#include <linux/folio_queue.h> #include <linux/netfs.h> #include <linux/fscache.h> #include <linux/fscache-cache.h>
@@ -151,9 +150,8 @@ static inline void netfs_proc_del_rreq(struct netfs_io_request *rreq) {}/* * misc.c */ -struct folio_queue *netfs_buffer_make_space (struct netfs_io_request *rreq, -enum netfs_folioq_trace trace); -void netfs_reset_iter (struct netfs_io_subrequest *subreq); +struct bvecq *netfs_buffer_make_space (struct netfs_io_request *rreq, +enum netfs_bvecq_trace trace);void netfs_wake_collector (struct netfs_io_request *rreq);void netfs_subreq_clear_in_progress (struct netfs_io_subrequest *subreq); void netfs_wait_for_in_progress_stream(struct netfs_io_request *rreq,
@@ -251,7 +249,6 @@ extern atomic_t netfs_n_wh_retry_write_req;extern atomic_t netfs_n_wh_retry_write_subreq;extern atomic_t netfs_n_wb_lock_skip;extern atomic_t netfs_n_wb_lock_wait; -extern atomic_t netfs_n_folioq;extern atomic_t netfs_n_bvecq;int netfs_stats_show (struct seq_file *m,void *v);
@@ -289,8 +286,7 @@ void netfs_prepare_write(struct netfs_io_request *wreq,struct netfs_io_stream *stream, loff_t start);void netfs_reissue_write (struct netfs_io_stream *stream, -struct netfs_io_subrequest *subreq, -struct iov_iter *source); +struct netfs_io_subrequest *subreq);void netfs_issue_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream); size_t netfs_advance_write(struct netfs_io_request *wreq,
fs/netfs/iterator.c +2 -0
@@ -135,6 +135,7 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t orig_len, size_t max_se }EXPORT_SYMBOL_GPL (netfs_extract_iter); +#if 0 /** * netfs_extract_user_iter - Extract the pages from a user iterator into a bvec * @orig: The original iterator
@@ -370,3 +371,4 @@ size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset, BUG(); }EXPORT_SYMBOL (netfs_limit_iter); +#endif
fs/netfs/misc.c +2 -18
@@ -8,6 +8,7 @@#include <linux/swap.h> #include "internal.h" +#if 0 /** * netfs_alloc_folioq_buffer - Allocate buffer space into a folio queue * @mapping: Address space to set on the folio (or NULL).
@@ -103,24 +104,7 @@ void netfs_free_folioq_buffer(struct folio_queue *fq) folio_batch_release(&fbatch); }EXPORT_SYMBOL (netfs_free_folioq_buffer); - -/* -* Reset the subrequest iterator to refer just to the region remaining to be -* read. The iterator may or may not have been advanced by socket ops or -* extraction ops to an extent that may or may not match the amount actually -* read. -*/ -void netfs_reset_iter (struct netfs_io_subrequest *subreq) -{ -struct iov_iter *io_iter = &subreq->io_iter; -size_t remain = subreq->len - subreq->transferred; - -if (io_iter->count > remain) -iov_iter_advance (io_iter, io_iter->count - remain); -else if (io_iter->count < remain) -iov_iter_revert (io_iter, remain - io_iter->count); -iov_iter_truncate (&subreq->io_iter, remain); -} +#endif /** * netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback
fs/netfs/objects.c +5 -11
@@ -119,7 +119,6 @@ static void netfs_free_request_rcu(struct rcu_head *rcu)static void netfs_deinit_request (struct netfs_io_request *rreq) {struct netfs_inode *ictx =netfs_inode (rreq->inode); -unsigned int i;trace_netfs_rreq (rreq, netfs_rreq_trace_free);
@@ -134,16 +133,9 @@ static void netfs_deinit_request(struct netfs_io_request *rreq) rreq->netfs_ops->free_request (rreq);if (rreq->cache_resources.ops) rreq->cache_resources.ops->end_operation (&rreq->cache_resources); -if (rreq->direct_bv) { -for (i =0 ; i < rreq->direct_bv_count; i++) { -if (rreq->direct_bv[i].bv_page) { -if (rreq->direct_bv_unpin) -unpin_user_page (rreq->direct_bv[i].bv_page); - } - } -kvfree (rreq->direct_bv); - } -rolling_buffer_clear (&rreq->buffer); +bvecq_pos_detach (&rreq->load_cursor); +bvecq_pos_detach (&rreq->dispatch_cursor); +bvecq_pos_detach (&rreq->collect_cursor);if (atomic_dec_and_test (&ictx->io_count))wake_up_var (&ictx->io_count);
@@ -236,6 +228,8 @@ static void netfs_free_subrequest(struct netfs_io_subrequest *subreq)trace_netfs_sreq (subreq, netfs_sreq_trace_free);if (rreq->netfs_ops->free_subrequest) rreq->netfs_ops->free_subrequest (subreq); +bvecq_pos_detach (&subreq->dispatch_pos); +bvecq_pos_detach (&subreq->content);mempool_free (subreq, rreq->netfs_ops->subrequest_pool ?: &netfs_subrequest_pool);netfs_stat_d (&netfs_n_rh_sreq);netfs_put_request (rreq, netfs_rreq_trace_put_subreq);
fs/netfs/read_collect.c +51 -32
168 lines not on this page · raw message
fs/netfs/read_pgpriv2.c +48 -20
136 lines not on this page · raw message
fs/netfs/read_retry.c +36 -23
143 lines not on this page · raw message
fs/netfs/read_single.c +13 -5
@@ -97,10 +97,15 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)if (!subreq)return -ENOMEM ; - subreq->source =NETFS_SOURCE_UNKNOWN ; - subreq->start =0 ; - subreq->len = rreq->len; - subreq->io_iter = rreq->buffer.iter; + subreq->source =NETFS_SOURCE_UNKNOWN ; + subreq->start =0 ; + subreq->len = rreq->len; + +bvecq_pos_attach (&subreq->dispatch_pos, &rreq->dispatch_cursor); +bvecq_pos_attach (&subreq->content, &rreq->dispatch_cursor); + +iov_iter_bvec_queue (&subreq->io_iter,ITER_DEST , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len);__set_bit (NETFS_SREQ_IN_PROGRESS , &subreq->flags);
@@ -174,6 +179,10 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_iteif (IS_ERR (rreq))return PTR_ERR (rreq); + ret =netfs_extract_iter (iter, rreq->len,INT_MAX ,0 , &rreq->dispatch_cursor.bvecq,0 ); +if (ret <0 ) + goto cleanup_free; + ret =netfs_single_begin_cache_read (rreq, ictx);if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) goto cleanup_free;
@@ -181,7 +190,6 @@ ssize_t netfs_read_single(struct inode *inode, struct file *file, struct iov_itenetfs_stat (&netfs_n_rh_read_single);trace_netfs_read (rreq,0 , rreq->len, netfs_read_trace_read_single); - rreq->buffer.iter = *iter;netfs_single_dispatch_read (rreq); ret =netfs_wait_for_read (rreq);
fs/netfs/stats.c +1 -3
@@ -47,7 +47,6 @@ atomic_t netfs_n_wh_retry_write_req;atomic_t netfs_n_wh_retry_write_subreq;atomic_t netfs_n_wb_lock_skip;atomic_t netfs_n_wb_lock_wait; -atomic_t netfs_n_folioq;atomic_t netfs_n_bvecq;int netfs_stats_show (struct seq_file *m,void *v)
@@ -91,11 +90,10 @@ int netfs_stats_show(struct seq_file *m, void *v)atomic_read (&netfs_n_rh_retry_read_subreq),atomic_read (&netfs_n_wh_retry_write_req), atomic_read(&netfs_n_wh_retry_write_subreq)); -seq_printf (m,"Objs : rr=%u sr=%u bq=%u foq=%u wsc=%u\n" , +seq_printf (m,"Objs : rr=%u sr=%u bq=%u wsc=%u\n" ,atomic_read (&netfs_n_rh_rreq),atomic_read (&netfs_n_rh_sreq),atomic_read (&netfs_n_bvecq), -atomic_read (&netfs_n_folioq),atomic_read (&netfs_n_wh_wstream_conflict)); seq_printf(m, "WbLock : skip=%u wait=%u\n", atomic_read(&netfs_n_wb_lock_skip),
fs/netfs/write_collect.c +23 -17
@@ -111,12 +111,12 @@ int netfs_folio_written_back(struct folio *folio)static void netfs_writeback_unlock_folios (struct netfs_io_request *wreq,unsigned int *notes) { -struct folio_queue *folioq = wreq->buffer.tail; +struct bvecq *bvecq = wreq->collect_cursor.bvecq;unsigned long long collected_to = wreq->collected_to; -unsigned int slot = wreq->buffer.first_tail_slot; +unsigned int slot = wreq->collect_cursor.slot; -if (WARN_ON_ONCE (!folioq)) { -pr_err ("[!] Writeback unlock found empty rolling buffer!\n" ); +if (WARN_ON_ONCE (!bvecq)) { +pr_err ("[!] Writeback unlock found empty buffer!\n" );netfs_dump_request (wreq);return ; }
@@ -127,9 +127,15 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,return ; } -if (slot >=folioq_nr_slots (folioq)) { - folioq =rolling_buffer_delete_spent (&wreq->buffer); -if (!folioq) +if (slot >= bvecq->nr_segs) { +/* We need to be very careful - the cleanup can catch the +* dispatcher, which could lead to us having nothing left in +* the queue, causing the front and back pointers to end up on +* different tracks. To avoid this, we must always keep at +* least one segment in the queue. +*/ + bvecq =bvecq_buffer_delete_spent (&wreq->collect_cursor); +if (!bvecq)return ; slot =0 ; }
@@ -140,7 +146,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,unsigned long long fpos, fend;size_t fsize, flen; - folio =folioq_folio (folioq, slot); + folio =page_folio (bvecq->bv[slot].bv_page);if (WARN_ONCE (!folio_test_writeback (folio),"R=%08x: folio %lx is not under writeback\n" , wreq->debug_id, folio->index))
@@ -163,15 +169,15 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq, wreq->cleaned_to = fpos + fsize; *notes |=MADE_PROGRESS ; -/* Clean up the head folioq. If we clear an entire folioq, then -* we can get rid of it provided it's not also the tail folioq +/* Clean up the head bvecq. If we clear an entire bvecq, then +* we can get rid of it provided it's not also the tail bvecq * being filled by the issuer. */ -folioq_clear (folioq, slot); + bvecq->bv[slot].bv_page =NULL ; slot++; -if (slot >=folioq_nr_slots (folioq)) { - folioq =rolling_buffer_delete_spent (&wreq->buffer); -if (!folioq) +if (slot >= bvecq->nr_segs) { + bvecq =bvecq_buffer_delete_spent (&wreq->collect_cursor); +if (!bvecq) goto done; slot =0 ; }
@@ -180,9 +186,8 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,break ; } - wreq->buffer.tail = folioq; done: - wreq->buffer.first_tail_slot = slot; + wreq->collect_cursor.slot = slot; }/*
@@ -207,7 +212,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)trace_netfs_rreq (wreq, netfs_rreq_trace_collect); reassess_streams: - issued_to =atomic64_read (&wreq->issued_to); +/* Order reading the issued_to point before reading the queue it refers to. */ + issued_to =atomic64_read_acquire (&wreq->issued_to);smp_rmb (); collected_to =ULLONG_MAX ; if (wreq->origin == NETFS_WRITEBACK ||
fs/netfs/write_issue.c +119 -43
293 lines not on this page · raw message
fs/netfs/write_retry.c +28 -17
115 lines not on this page · raw message
include/linux/netfs.h +10 -16
@@ -19,12 +19,13 @@#include <linux/pagemap.h> #include <linux/bvec.h> #include <linux/uio.h> -#include <linux/rolling_buffer.h> enum netfs_sreq_ref_trace ;typedef struct mempool mempool_t ; -struct folio_queue ; -struct bvecq ; +struct readahead_control ; +struct netfs_io_request ; +struct netfs_io_subrequest ; +struct fscache_occupancy ;/** * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -147,7 +148,6 @@ struct netfs_io_stream {unsigned int sreq_max_segs;/* 0 or max number of segments in an iterator */ unsigned int submit_off;/* Folio offset we're submitting from */ unsigned int submit_len;/* Amount of data left to submit */ -unsigned int submit_extendable_to;/* Amount I/O can be rounded up to */ void (*prepare_write)(struct netfs_io_subrequest *subreq);void (*issue_write)(struct netfs_io_subrequest *subreq);/* Collection tracking */
@@ -187,6 +187,8 @@ struct netfs_io_subrequest {struct netfs_io_request *rreq;/* Supervising I/O request */ struct work_struct work;struct list_head rreq_link;/* Link in rreq->subrequests */ +struct bvecq_pos dispatch_pos;/* Bookmark in the combined queue of the start */ +struct bvecq_pos content;/* The (copied) content of the subrequest */ struct iov_iter io_iter;/* Iterator for this subrequest */ unsigned long long start;/* Where to start the I/O */ size_t len;/* Size of the I/O */
@@ -248,13 +250,13 @@ struct netfs_io_request {struct netfs_io_stream io_streams[2 ];/* Streams of parallel I/O operations */ #define NR_IO_STREAMS 2 //wreq->nr_io_streamsstruct netfs_group *group;/* Writeback group being written back */ -struct rolling_buffer buffer;/* Unencrypted buffer */ -#define NETFS_ROLLBUF_PUT_MARK ROLLBUF_MARK_1 -#define NETFS_ROLLBUF_PAGECACHE_MARK ROLLBUF_MARK_2 +struct bvecq_pos collect_cursor;/* Clear-up point of I/O buffer */ +struct bvecq_pos load_cursor;/* Point at which new folios are loaded in */ +struct bvecq_pos dispatch_cursor;/* Point from which buffers are dispatched */ wait_queue_head_t waitq;/* Processor waiter */ void *netfs_priv;/* Private data for the netfs */ void *netfs_priv2;/* Private data for the netfs */ -struct bio_vec *direct_bv;/* DIO buffer list (when handling iovec-iter) */ +unsigned long long last_end;/* End pos of last folio submitted */ unsigned long long submitted;/* Amount submitted for I/O so far */ unsigned long long len;/* Length of the request */ size_t transferred;/* Amount to be indicated as transferred */
@@ -266,7 +268,6 @@ struct netfs_io_request {unsigned long long cleaned_to;/* Position we've cleaned folios to */ unsigned long long abandon_to;/* Position to abandon folios to */ pgoff_t no_unlock_folio;/* Don't unlock this folio after read */ -unsigned int direct_bv_count;/* Number of elements in direct_bv[] */ unsigned int debug_id;unsigned int rsize;/* Maximum read size (0 for none) */ unsigned int wsize;/* Maximum write size (0 for none) */
@@ -275,7 +276,6 @@ struct netfs_io_request {spinlock_t lock;/* Lock for queuing subreqs */ unsigned char front_folio_order;/* Order (size) of front folio */ enum netfs_io_origin origin;/* Origin of the request */ -bool direct_bv_unpin;/* T if direct_bv[] must be unpinned */ refcount_t ref;unsigned long flags;#define NETFS_RREQ_IN_PROGRESS 0/* Unlocked when the request completes (has ref) */
@@ -466,12 +466,6 @@ void netfs_end_io_write(struct inode *inode);int netfs_start_io_direct (struct inode *inode);void netfs_end_io_direct (struct inode *inode); -/* Miscellaneous APIs. */ -struct folio_queue *netfs_folioq_alloc (unsigned int rreq_id,gfp_t gfp, -unsigned int trace/*enum netfs_folioq_trace*/ ); -void netfs_folioq_free (struct folio_queue *folioq, -unsigned int trace/*enum netfs_trace_folioq*/ ); -/* Buffer wrangling helpers API. */ int netfs_alloc_folioq_buffer(struct address_space *mapping, struct folio_queue **_buffer,
include/trace/events/netfs.h +23 -23
94 lines not on this page · raw message
David Howells
maintainerRFC PATCH 11/17 cifs: Remove support for ITER_KVEC/BVEC/FOLIOQ from smb_extract_iter_to_rdma()
In reply to David Howellsnetfslib now only presents an bvecq queue and an associated ITER_BVECQ iterator to the filesystem, so it isn't going to see ITER_KVEC, ITER_BVEC or ITER_FOLIOQ iterators. So remove that code.
--- fs/smb/client/smbdirect.c | 165 -------------------------------------- 1 file changed, 165 deletions(-)
fs/smb/client/smbdirect.c +0 -165
@@ -3142,162 +3142,6 @@ static bool smb_set_sge(struct smb_extract_to_rdma *rdma,return true; } -/* -* Extract page fragments from a BVEC-class iterator and add them to an RDMA -* element list. The pages are not pinned. -*/ -static ssize_t smb_extract_bvec_to_rdma (struct iov_iter *iter, -struct smb_extract_to_rdma *rdma, -ssize_t maxsize) -{ -const struct bio_vec *bv = iter->bvec; -unsigned long start = iter->iov_offset; -unsigned int i; -ssize_t ret =0 ; - -for (i =0 ; i < iter->nr_segs; i++) { -size_t off, len; - - len = bv[i].bv_len; -if (start >= len) { - start -= len; -continue ; - } - - len =min_t (size_t, maxsize, len - start); - off = bv[i].bv_offset + start; - -if (!smb_set_sge (rdma, bv[i].bv_page, off, len)) -return -EIO ; - - ret += len; - maxsize -= len; -if (rdma->nr_sge >= rdma->max_sge || maxsize <=0 ) -break ; - start =0 ; - } - -if (ret >0 ) -iov_iter_advance (iter, ret); -return ret; -} - -/* -* Extract fragments from a KVEC-class iterator and add them to an RDMA list. -* This can deal with vmalloc'd buffers as well as kmalloc'd or static buffers. -* The pages are not pinned. -*/ -static ssize_t smb_extract_kvec_to_rdma (struct iov_iter *iter, -struct smb_extract_to_rdma *rdma, -ssize_t maxsize) -{ -const struct kvec *kv = iter->kvec; -unsigned long start = iter->iov_offset; -unsigned int i; -ssize_t ret =0 ; - -for (i =0 ; i < iter->nr_segs; i++) { -struct page *page; -unsigned long kaddr; -size_t off, len, seg; - - len = kv[i].iov_len; -if (start >= len) { - start -= len; -continue ; - } - - kaddr = (unsigned long )kv[i].iov_base + start; - off = kaddr & ~PAGE_MASK ; - len =min_t (size_t, maxsize, len - start); - kaddr &=PAGE_MASK ; - - maxsize -= len; -do { - seg =min_t (size_t, len,PAGE_SIZE - off); - -if (is_vmalloc_or_module_addr ((void *)kaddr)) - page =vmalloc_to_page ((void *)kaddr); -else - page =virt_to_page ((void *)kaddr); - -if (!smb_set_sge (rdma, page, off, seg)) -return -EIO ; - - ret += seg; - len -= seg; - kaddr +=PAGE_SIZE ; - off =0 ; - }while (len >0 && rdma->nr_sge < rdma->max_sge); - -if (rdma->nr_sge >= rdma->max_sge || maxsize <=0 ) -break ; - start =0 ; - } - -if (ret >0 ) -iov_iter_advance (iter, ret); -return ret; -} - -/* -* Extract folio fragments from a FOLIOQ-class iterator and add them to an RDMA -* list. The folios are not pinned. -*/ -static ssize_t smb_extract_folioq_to_rdma (struct iov_iter *iter, -struct smb_extract_to_rdma *rdma, -ssize_t maxsize) -{ -const struct folio_queue *folioq = iter->folioq; -unsigned int slot = iter->folioq_slot; -ssize_t ret =0 ; -size_t offset = iter->iov_offset; - -BUG_ON (!folioq); - -if (slot >=folioq_nr_slots (folioq)) { - folioq = folioq->next; -if (WARN_ON_ONCE (!folioq)) -return -EIO ; - slot =0 ; - } - -do { -struct folio *folio =folioq_folio (folioq, slot); -size_t fsize =folioq_folio_size (folioq, slot); - -if (offset < fsize) { -size_t part =umin (maxsize, fsize - offset); - -if (!smb_set_sge (rdma,folio_page (folio,0 ), offset, part)) -return -EIO ; - - offset += part; - ret += part; - maxsize -= part; - } - -if (offset >= fsize) { - offset =0 ; - slot++; -if (slot >=folioq_nr_slots (folioq)) { -if (!folioq->next) { -WARN_ON_ONCE (ret < iter->count); -break ; - } - folioq = folioq->next; - slot =0 ; - } - } - }while (rdma->nr_sge < rdma->max_sge && maxsize >0 ); - - iter->folioq = folioq; - iter->folioq_slot = slot; - iter->iov_offset = offset; - iter->count -= ret; -return ret; -} -/* * Extract memory fragments from a BVECQ-class iterator and add them to an RDMA * list. The folios are not pinned.
@@ -3373,15 +3217,6 @@ static ssize_t smb_extract_iter_to_rdma(struct iov_iter *iter, size_t len,int before = rdma->nr_sge;switch (iov_iter_type (iter)) { -case ITER_BVEC : - ret =smb_extract_bvec_to_rdma (iter, rdma, len); -break ; -case ITER_KVEC : - ret =smb_extract_kvec_to_rdma (iter, rdma, len); -break ; -case ITER_FOLIOQ : - ret =smb_extract_folioq_to_rdma (iter, rdma, len); -break ;case ITER_BVECQ : ret =smb_extract_bvecq_to_rdma (iter, rdma, len);break ;
David Howells
maintainerRFC PATCH 12/17 netfs: Remove netfs_alloc/free_folioq_buffer()
In reply to David HowellsRemove netfs_alloc/free_folioq_buffer() as these have been replaced with netfs_alloc/free_bvecq_buffer().
--- fs/afs/dir_edit.c | 1 - fs/netfs/misc.c | 98 --------------------------------------- fs/smb/client/smb2ops.c | 1 - fs/smb/client/smbdirect.c | 1 - include/linux/netfs.h | 4 -- 5 files changed, 105 deletions(-)
fs/afs/dir_edit.c +0 -1
@@ -10,7 +10,6 @@#include <linux/namei.h> #include <linux/pagemap.h> #include <linux/iversion.h> -#include <linux/folio_queue.h> #include "internal.h" #include "xdr_fs.h"
fs/netfs/misc.c +0 -98
104 lines not on this page · raw message
fs/smb/client/smb2ops.c +0 -1
@@ -13,7 +13,6 @@#include <linux/sort.h> #include <crypto/aead.h> #include <linux/fiemap.h> -#include <linux/folio_queue.h> #include <uapi/linux/magic.h> #include "cifsfs.h" #include "cifsglob.h"
fs/smb/client/smbdirect.c +0 -1
@@ -6,7 +6,6 @@*/ #include <linux/module.h> #include <linux/highmem.h> -#include <linux/folio_queue.h> #define __SMBDIRECT_SOCKET_DISCONNECT (__sc) smbd_disconnect_rdma_connection(__sc)#include "../common/smbdirect/smbdirect_pdu.h" #include "smbdirect.h"
include/linux/netfs.h +0 -4
@@ -467,10 +467,6 @@ int netfs_start_io_direct(struct inode *inode);void netfs_end_io_direct (struct inode *inode);/* Buffer wrangling helpers API. */ -int netfs_alloc_folioq_buffer (struct address_space *mapping, -struct folio_queue **_buffer, -size_t *_cur_size,ssize_t size,gfp_t gfp); -void netfs_free_folioq_buffer (struct folio_queue *fq);void dump_bvecq (const struct bvecq *bq);struct bvecq *netfs_alloc_bvecq (size_t nr_slots,gfp_t gfp);struct bvecq *netfs_alloc_bvecq_buffer (size_t size,unsigned int pre_slots,gfp_t gfp);
David Howells
maintainerRFC PATCH 13/17 netfs: Remove netfs_extract_user_iter()
In reply to David HowellsRemove netfs_extract_user_iter() as it has been replaced with netfs_extract_iter().
--- fs/netfs/iterator.c | 89 ------------------------------------------- include/linux/netfs.h | 3 -- 2 files changed, 92 deletions(-)
fs/netfs/iterator.c +0 -89
@@ -136,95 +136,6 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t orig_len, size_t max_seEXPORT_SYMBOL_GPL (netfs_extract_iter);#if 0 -/** -* netfs_extract_user_iter - Extract the pages from a user iterator into a bvec -* @orig: The original iterator -* @orig_len: The amount of iterator to copy -* @new: The iterator to be set up -* @extraction_flags: Flags to qualify the request -* -* Extract the page fragments from the given amount of the source iterator and -* build up a second iterator that refers to all of those bits. This allows -* the original iterator to disposed of. -* -* @extraction_flags can have ITER_ALLOW_P2PDMA set to request peer-to-peer DMA be -* allowed on the pages extracted. -* -* On success, the number of elements in the bvec is returned, the original -* iterator will have been advanced by the amount extracted. -* -* The iov_iter_extract_mode() function should be used to query how cleanup -* should be performed. -*/ -ssize_t netfs_extract_user_iter (struct iov_iter *orig,size_t orig_len, -struct iov_iter *new, -iov_iter_extraction_t extraction_flags) -{ -struct bio_vec *bv =NULL ; -struct page **pages; -unsigned int cur_npages; -unsigned int max_pages; -unsigned int npages =0 ; -unsigned int i; -ssize_t ret; -size_t count = orig_len, offset, len; -size_t bv_size, pg_size; - -if (WARN_ON_ONCE (!iter_is_ubuf (orig) && !iter_is_iovec (orig))) -return -EIO ; - - max_pages =iov_iter_npages (orig,INT_MAX ); - bv_size =array_size (max_pages,sizeof (*bv)); - bv =kvmalloc (bv_size,GFP_KERNEL ); -if (!bv) -return -ENOMEM ; - -/* Put the page list at the end of the bvec list storage. bvec -* elements are larger than page pointers, so as long as we work -* 0->last, we should be fine. -*/ - pg_size =array_size (max_pages,sizeof (*pages)); - pages = (void *)bv + bv_size - pg_size; - -while (count && npages < max_pages) { - ret =iov_iter_extract_pages (orig, &pages, count, - max_pages - npages, extraction_flags, - &offset); -if (ret <0 ) { -pr_err ("Couldn't get user pages (rc=%zd)\n" , ret); -break ; - } - -if (ret > count) { -pr_err ("get_pages rc=%zd more than %zu\n" , ret, count); -break ; - } - - count -= ret; - ret += offset; - cur_npages =DIV_ROUND_UP (ret,PAGE_SIZE ); - -if (npages + cur_npages > max_pages) { -pr_err ("Out of bvec array capacity (%u vs %u)\n" , - npages + cur_npages, max_pages); -break ; - } - -for (i =0 ; i < cur_npages; i++) { - len = ret >PAGE_SIZE ?PAGE_SIZE : ret; -bvec_set_page (bv + npages + i, *pages++, len - offset, offset); - ret -= len; - offset =0 ; - } - - npages += cur_npages; - } - -iov_iter_bvec (new, orig->data_source, bv, npages, orig_len - count); -return npages; -} -EXPORT_SYMBOL_GPL (netfs_extract_user_iter); -/* * Select the span of a bvec iterator we're going to use. Limit it by both maximum * size and maximum number of segments. Returns the size of the span in bytes.
include/linux/netfs.h +0 -3
@@ -451,9 +451,6 @@ void netfs_put_subrequest(struct netfs_io_subrequest *subreq,ssize_t netfs_extract_iter (struct iov_iter *orig,size_t orig_len,size_t max_segs,unsigned long long fpos,struct bvecq **_bvecq_head,iov_iter_extraction_t extraction_flags); -ssize_t netfs_extract_user_iter (struct iov_iter *orig,size_t orig_len, -struct iov_iter *new, -iov_iter_extraction_t extraction_flags);size_t netfs_limit_iter (const struct iov_iter *iter,size_t start_offset,size_t max_size,size_t max_segs);void netfs_prepare_write_failed (struct netfs_io_subrequest *subreq);
David Howells
maintainerRFC PATCH 14/17 iov_iter: Remove ITER_FOLIOQ
In reply to David HowellsRemove ITER_FOLIOQ as it's no longer used.
--- include/linux/iov_iter.h | 65 +--------- include/linux/uio.h | 12 -- lib/iov_iter.c | 235 +--------------------------------- lib/scatterlist.c | 67 +--------- lib/tests/kunit_iov_iter.c | 256 ------------------------------------- 5 files changed, 5 insertions(+), 630 deletions(-)
include/linux/iov_iter.h +2 -63
@@ -10,7 +10,6 @@#include <linux/uio.h> #include <linux/bvec.h> -#include <linux/folio_queue.h> typedef size_t (*iov_step_f )(void *iter_base,size_t progress,size_t len,void *priv,void *priv2);
@@ -194,62 +193,6 @@ size_t iterate_bvecq(struct iov_iter *iter, size_t len, void *priv, void *priv2,return progress; } -/* -* Handle ITER_FOLIOQ. -*/ -static __always_inline -size_t iterate_folioq(struct iov_iter *iter, size_t len, void *priv, void *priv2, -iov_step_f step) -{ -const struct folio_queue *folioq = iter->folioq; -unsigned int slot = iter->folioq_slot; -size_t progress =0 , skip = iter->iov_offset; - -if (slot ==folioq_nr_slots (folioq)) { -/* The iterator may have been extended. */ - folioq = folioq->next; - slot =0 ; - } - -do { -struct folio *folio =folioq_folio (folioq, slot); -size_t part, remain =0 , consumed; -size_t fsize; -void *base; - -if (!folio) -break ; - - fsize =folioq_folio_size (folioq, slot); -if (skip < fsize) { - base =kmap_local_folio (folio, skip); - part =umin (len,PAGE_SIZE - skip %PAGE_SIZE ); - remain =step (base, progress, part, priv, priv2); -kunmap_local (base); - consumed = part - remain; - len -= consumed; - progress += consumed; - skip += consumed; - } -if (skip >= fsize) { - skip =0 ; - slot++; -if (slot ==folioq_nr_slots (folioq) && folioq->next) { - folioq = folioq->next; - slot =0 ; - } - } -if (remain) -break ; - }while (len); - - iter->folioq_slot = slot; - iter->folioq = folioq; - iter->iov_offset = skip; - iter->count -= progress; -return progress; -} -/* * Handle ITER_XARRAY. */
@@ -361,8 +304,6 @@ size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv,return iterate_kvec (iter, len, priv, priv2, step);if (iov_iter_is_bvecq (iter))return iterate_bvecq (iter, len, priv, priv2, step); -if (iov_iter_is_folioq (iter)) -return iterate_folioq (iter, len, priv, priv2, step);if (iov_iter_is_xarray (iter))return iterate_xarray (iter, len, priv, priv2, step);return iterate_discard (iter, len, priv, priv2, step);
@@ -397,8 +338,8 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv,* buffer is presented in segments, which for kernel iteration are broken up by * physical pages and mapped, with the mapped address being presented. * -* [!] Note This will only handle BVEC, KVEC, BVECQ, FOLIOQ, XARRAY and -* DISCARD-type iterators; it will not handle UBUF or IOVEC-type iterators. +* [!] Note This will only handle BVEC, KVEC, BVECQ, XARRAY and DISCARD-type +* iterators; it will not handle UBUF or IOVEC-type iterators. * * A step functions, @step, must be provided, one for handling mapped kernel * addresses and the other is given user addresses which have the potential to
@@ -427,8 +368,6 @@ size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv,return iterate_kvec (iter, len, priv, priv2, step);if (iov_iter_is_bvecq (iter))return iterate_bvecq (iter, len, priv, priv2, step); -if (iov_iter_is_folioq (iter)) -return iterate_folioq (iter, len, priv, priv2, step);if (iov_iter_is_xarray (iter))return iterate_xarray (iter, len, priv, priv2, step);return iterate_discard (iter, len, priv, priv2, step);
include/linux/uio.h +0 -12
@@ -11,7 +11,6 @@#include <uapi/linux/uio.h> struct page ; -struct folio_queue ;typedef unsigned int __bitwise iov_iter_extraction_t ;
@@ -26,7 +25,6 @@ enum iter_type {ITER_IOVEC ,ITER_BVEC ,ITER_KVEC , -ITER_FOLIOQ ,ITER_BVECQ ,ITER_XARRAY , ITER_DISCARD,
@@ -69,7 +67,6 @@ struct iov_iter {const struct iovec *__iov;const struct kvec *kvec;const struct bio_vec *bvec; -const struct folio_queue *folioq;const struct bvecq *bvecq;struct xarray *xarray;void __user *ubuf;
@@ -79,7 +76,6 @@ struct iov_iter { };union {unsigned long nr_segs; -u8 folioq_slot;u16 bvecq_slot;loff_t xarray_start; };
@@ -148,11 +144,6 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)return iov_iter_type (i) ==ITER_DISCARD ; } -static inline bool iov_iter_is_folioq (const struct iov_iter *i) -{ -return iov_iter_type (i) ==ITER_FOLIOQ ; -} -static inline bool iov_iter_is_bvecq (const struct iov_iter *i) {return iov_iter_type (i) ==ITER_BVECQ ;
@@ -303,9 +294,6 @@ void iov_iter_kvec(struct iov_iter *i, unsigned int direction, const struct kvecvoid iov_iter_bvec (struct iov_iter *i,unsigned int direction,const struct bio_vec *bvec,unsigned long nr_segs,size_t count);void iov_iter_discard (struct iov_iter *i,unsigned int direction,size_t count); -void iov_iter_folio_queue (struct iov_iter *i,unsigned int direction, -const struct folio_queue *folioq, -unsigned int first_slot,unsigned int offset,size_t count);void iov_iter_bvec_queue (struct iov_iter *i,unsigned int direction,const struct bvecq *bvecq,unsigned int first_slot,unsigned int offset,size_t count);
lib/iov_iter.c +2 -233
313 lines not on this page · raw message
lib/scatterlist.c +1 -66
91 lines not on this page · raw message
lib/tests/kunit_iov_iter.c +0 -256
286 lines not on this page · raw message
David Howells
maintainerRFC PATCH 15/17 netfs: Remove folio_queue and rolling_buffer
In reply to David HowellsRemove folio_queue and rolling_buffer as they're no longer used.
--- Documentation/core-api/folio_queue.rst | 209 ------------------ Documentation/core-api/index.rst | 1 - fs/netfs/iterator.c | 149 ------------- fs/netfs/rolling_buffer.c | 222 ------------------- include/linux/folio_queue.h | 282 ------------------------- include/linux/rolling_buffer.h | 61 ------ 6 files changed, 924 deletions(-) delete mode 100644 Documentation/core-api/folio_queue.rst delete mode 100644 fs/netfs/rolling_buffer.c delete mode 100644 include/linux/folio_queue.h delete mode 100644 include/linux/rolling_buffer.h
Documentation/core-api/folio_queue.rst deleted +0 -209
@@ -1,209 +0,0 @@ -.. SPDX-License-Identifier: GPL-2.0+ - -=========== -Folio Queue -=========== - -:Author: David Howells <[email protected]> - -.. Contents: - - * Overview - * Initialisation - * Adding and removing folios - * Querying information about a folio - * Querying information about a folio_queue - * Folio queue iteration - * Folio marks - * Lockless simultaneous production/consumption issues - - -Overview -======== - -The folio_queue struct forms a single segment in a segmented list of folios -that can be used to form an I/O buffer. As such, the list can be iterated over -using the ITER_FOLIOQ iov_iter type. - -The publicly accessible members of the structure are:: - - struct folio_queue { - struct folio_queue *next; - struct folio_queue *prev; - ... - }; - -A pair of pointers are provided, ``next`` and ``prev``, that point to the -segments on either side of the segment being accessed. Whilst this is a -doubly-linked list, it is intentionally not a circular list; the outward -sibling pointers in terminal segments should be NULL. - -Each segment in the list also stores: - - * an ordered sequence of folio pointers, - * the size of each folio and - * three 1-bit marks per folio, - -but these should not be accessed directly as the underlying data structure may -change, but rather the access functions outlined below should be used. - -The facility can be made accessible by:: - - #include <linux/folio_queue.h> - -and to use the iterator:: - - #include <linux/uio.h> - - -Initialisation -============== - -A segment should be initialised by calling:: - - void folioq_init(struct folio_queue *folioq); - -with a pointer to the segment to be initialised. Note that this will not -necessarily initialise all the folio pointers, so care must be taken to check -the number of folios added. - - -Adding and removing folios -========================== - -Folios can be set in the next unused slot in a segment struct by calling one -of:: - - unsigned int folioq_append(struct folio_queue *folioq, - struct folio *folio); - - unsigned int folioq_append_mark(struct folio_queue *folioq, - struct folio *folio); - -Both functions update the stored folio count, store the folio and note its -size. The second function also sets the first mark for the folio added. Both -functions return the number of the slot used. [!] Note that no attempt is made -to check that the capacity wasn't overrun and the list will not be extended -automatically. - -A folio can be excised by calling:: - - void folioq_clear(struct folio_queue *folioq, unsigned int slot); - -This clears the slot in the array and also clears all the marks for that folio, -but doesn't change the folio count - so future accesses of that slot must check -if the slot is occupied. - - -Querying information about a folio -================================== - -Information about the folio in a particular slot may be queried by the -following function:: - - struct folio *folioq_folio(const struct folio_queue *folioq, - unsigned int slot); - -If a folio has not yet been set in that slot, this may yield an undefined -pointer. The size of the folio in a slot may be queried with either of:: - - unsigned int folioq_folio_order(const struct folio_queue *folioq, - unsigned int slot); - - size_t folioq_folio_size(const struct folio_queue *folioq, - unsigned int slot); - -The first function returns the size as an order and the second as a number of -bytes. - - -Querying information about a folio_queue -======================================== - -Information may be retrieved about a particular segment with the following -functions:: - - unsigned int folioq_nr_slots(const struct folio_queue *folioq); - - unsigned int folioq_count(struct folio_queue *folioq); - - bool folioq_full(struct folio_queue *folioq); - -The first function returns the maximum capacity of a segment. It must not be -assumed that this won't vary between segments. The second returns the number -of folios added to a segments and the third is a shorthand to indicate if the -segment has been filled to capacity. - -Not that the count and fullness are not affected by clearing folios from the -segment. These are more about indicating how many slots in the array have been -initialised, and it assumed that slots won't get reused, but rather the segment -will get discarded as the queue is consumed. - - -Folio marks -=========== - -Folios within a queue can also have marks assigned to them. These marks can be -used to note information such as if a folio needs folio_put() calling upon it. -There are three marks available to be set for each folio. - -The marks can be set by:: - - void folioq_mark(struct folio_queue *folioq, unsigned int slot); - void folioq_mark2(struct folio_queue *folioq, unsigned int slot); - -Cleared by:: - - void folioq_unmark(struct folio_queue *folioq, unsigned int slot); - void folioq_unmark2(struct folio_queue *folioq, unsigned int slot); - -And the marks can be queried by:: - - bool folioq_is_marked(const struct folio_queue *folioq, unsigned int slot); - bool folioq_is_marked2(const struct folio_queue *folioq, unsigned int slot); - -The marks can be used for any purpose and are not interpreted by this API. - - -Folio queue iteration -===================== - -A list of segments may be iterated over using the I/O iterator facility using -an ``iov_iter`` iterator of ``ITER_FOLIOQ`` type. The iterator may be -initialised with:: - - void iov_iter_folio_queue(struct iov_iter *i, unsigned int direction, - const struct folio_queue *folioq, - unsigned int first_slot, unsigned int offset, - size_t count); - -This may be told to start at a particular segment, slot and offset within a -queue. The iov iterator functions will follow the next pointers when advancing -and prev pointers when reverting when needed. - - -Lockless simultaneous production/consumption issues -=================================================== - -If properly managed, the list can be extended by the producer at the head end -and shortened by the consumer at the tail end simultaneously without the need -to take locks. The ITER_FOLIOQ iterator inserts appropriate barriers to aid -with this. - -Care must be taken when simultaneously producing and consuming a list. If the -last segment is reached and the folios it refers to are entirely consumed by -the IOV iterators, an iov_iter struct will be left pointing to the last segment -with a slot number equal to the capacity of that segment. The iterator will -try to continue on from this if there's another segment available when it is -used again, but care must be taken lest the segment got removed and freed by -the consumer before the iterator was advanced. - -It is recommended that the queue always contain at least one segment, even if -that segment has never been filled or is entirely spent. This prevents the -head and tail pointers from collapsing. - - -API Function Reference -====================== - -.. kernel-doc:: include/linux/folio_queue.h
Documentation/core-api/index.rst +0 -1
@@ -39,7 +39,6 @@ Library functionality that is used throughout the kernel. kref cleanup assoc_array - folio_queue xarray maple_tree idr
fs/netfs/iterator.c +0 -149
152 lines not on this page · raw message
fs/netfs/rolling_buffer.c deleted +0 -222
222 lines not on this page · raw message
include/linux/folio_queue.h deleted +0 -282
282 lines not on this page · raw message
include/linux/rolling_buffer.h deleted +0 -61
61 lines not on this page · raw message
David Howells
maintainerRFC PATCH 16/17 netfs: Check for too much data being read
In reply to David HowellsPut in a check in read subreq termination to detect more data being read for a subrequest than was requested.
--- fs/netfs/read_collect.c | 8 ++++++++ include/trace/events/netfs.h | 1 + 2 files changed, 9 insertions(+)
fs/netfs/read_collect.c +8 -0
@@ -545,6 +545,14 @@ void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq)break ; } +if (subreq->transferred > subreq->len) { + subreq->transferred =0 ; +__set_bit (NETFS_SREQ_FAILED , &subreq->flags); +__clear_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags); +trace_netfs_sreq (subreq, netfs_sreq_trace_too_much); + subreq->error = -EIO ; + } +/* Deal with retry requests, short reads and errors. If we retry * but don't make progress, we abandon the attempt. */
include/trace/events/netfs.h +1 -0
@@ -124,6 +124,7 @@ EM(netfs_sreq_trace_submit, "SUBMT") \ EM(netfs_sreq_trace_superfluous, "SPRFL") \ EM(netfs_sreq_trace_terminated, "TERM ") \ + EM(netfs_sreq_trace_too_much, "!TOOM") \ EM(netfs_sreq_trace_wait_for, "_WAIT") \ EM(netfs_sreq_trace_write, "WRITE") \EM (netfs_sreq_trace_write_skip,"SKIP " ) \
David Howells
maintainerRFC PATCH 17/17 netfs: Combine prepare and issue ops and grab the buffers on request
In reply to David HowellsTo try and simplify how subrequests are generated in netfslib, with the move to bvecq for buffer handling, change netfslib in the following ways:
(1) ->prepare_xxx(), buffer selection and ->issue_xxx() are now collapsed together such that one ->issue_xxx() call is made with the subrequest defined to the maximum extent; the filesystem then reduces the length of the subrequest and calls back to netfslib to grab a slice of the buffer, which may reduce the subrequest further if a maximum segment limit is set. The filesystem can then dispatch the operation.
(2) To allow buffer slicing to be done upon request by the filesystem, a dispatch context is now maintained by netfslib and this is passed to ->issue_xxx() which then calls netfs_prepare_xxx_buffer(). This also permits the context for retry to be kept separate from that of initial dispatch.
(3) The use of iov_iter is pushed down to the filesystem. Netfslib now provides the filesystem with a bvecq holding the buffer rather than an iov_iter. The bvecq can be duplicated and headers/trailers attached to hold protocol and several bvecqs can be linked together to create a compound operation.
(4) The ->issue_xxx() functions now return an error code that allows them to return an error without having to terminate the subrequest. Netfslib will handle the error immediately if it can but may request termination and punt responsibility to the result collector.
->issue_xxx() can return 0 if synchronously compete and -EIOCBQUEUED if the operation will complete (or already has completed) asynchronously.
(5) During writeback, the code now builds up an accumulation of buffered data before issuing writes on each stream (one server, one cache). It asks each stream for an estimate of how much data to accumulate before it starts generating subrequests on the stream. It is not required to use up all the data accumulated on a stream at that time unless we hit the end of the pagecache.
(6) During read-gaps, in which there are two gaps on either end of a dirty streaming write page that need to be filled, a buffer is constructed consisting of the two ends plus a sink page repeated to cover the middle portion. This is passed to the server as a single write. For something like Ceph, this should probably be done either as a vectored/sparse read or as two separate reads (if different Ceph objects are involved).
(7) During unbuffered/DIO read/write, there is a single contiguous file region to be written or read as a single stream. The dispatching function just creates subrequests and calls ->issue_xxx() repeatedly to eat through the bufferage.
(8) During buffered read, there is a single contiguous file region, to read as a single stream - however, this stream may be stitched together from subrequests to multiple sources. Which sources are used where is now determined by querying the cache to find the next couple of extents in which it has data; netfslib uses this to direct the subrequests towards the appropriate sources.
Each subrequest is given the maximum length in the current extent and then ->issue_read() is called. The filesystem then limits the size and slices off a piece of the buffer for that extent.
(9) The cache now uses fiemap internally to find out the occupied regions of a cachefile rather than SEEK_DATA/SEEK_HOLE. In future, it should keep track of the regions itself - including regions of zeros.
--- fs/9p/vfs_addr.c | 34 +- fs/afs/dir.c | 8 +- fs/afs/file.c | 27 +- fs/afs/fsclient.c | 8 +- fs/afs/internal.h | 10 +- fs/afs/write.c | 35 +- fs/afs/yfsclient.c | 6 +- fs/cachefiles/io.c | 339 ++++++++++------ fs/ceph/addr.c | 109 +++--- fs/netfs/Makefile | 2 +- fs/netfs/buffered_read.c | 392 ++++++++++++------- fs/netfs/buffered_write.c | 2 +- fs/netfs/direct_read.c | 90 ++--- fs/netfs/direct_write.c | 153 +++++--- fs/netfs/fscache_io.c | 6 - fs/netfs/internal.h | 71 +++- fs/netfs/iterator.c | 13 +- fs/netfs/misc.c | 31 ++ fs/netfs/objects.c | 3 - fs/netfs/read_collect.c | 33 +- fs/netfs/read_retry.c | 215 +++++----- fs/netfs/read_single.c | 181 +++++---- fs/netfs/write_collect.c | 39 +- fs/netfs/write_issue.c | 735 +++++++++++++++++++++-------------- fs/netfs/write_retry.c | 145 +++---- fs/nfs/fscache.c | 13 +- fs/smb/client/cifssmb.c | 13 +- fs/smb/client/file.c | 149 +++---- fs/smb/client/smb2ops.c | 9 +- fs/smb/client/smb2pdu.c | 28 +- fs/smb/client/transport.c | 15 +- include/linux/fscache.h | 19 + include/linux/netfs.h | 122 +++--- include/trace/events/netfs.h | 43 +- net/9p/client.c | 8 +- 35 files changed, 1885 insertions(+), 1221 deletions(-)
fs/9p/vfs_addr.c +30 -4
@@ -51,29 +51,54 @@ static void v9fs_begin_writeback(struct netfs_io_request *wreq)/* * Issue a subrequest to write to the server. */ -static void v9fs_issue_write (struct netfs_io_subrequest *subreq) +static int v9fs_issue_write (struct netfs_io_subrequest *subreq, +struct netfs_write_context *wctx) { +struct iov_iter iter;struct p9_fid *fid = subreq->rreq->netfs_priv;int err, len; - len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); + subreq->len =umin (subreq->len, fid->clnt->msize -P9_IOHDRSZ ); + + err =netfs_prepare_write_buffer (subreq, wctx,INT_MAX ); +if (err <0 ) +return err; + +iov_iter_bvec_queue (&iter,ITER_SOURCE , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len); + + len =p9_client_write (fid, subreq->start, &iter, &err);if (len >0 )__set_bit (NETFS_SREQ_MADE_PROGRESS , &subreq->flags);netfs_write_subrequest_terminated (subreq, len ?: err); +return err; }/** * v9fs_issue_read - Issue a read from 9P * @subreq: The read to make +* @rctx: Read generation context */ -static void v9fs_issue_read (struct netfs_io_subrequest *subreq) +static int v9fs_issue_read (struct netfs_io_subrequest *subreq, +struct netfs_read_context *rctx) {struct netfs_io_request *rreq = subreq->rreq; +struct iov_iter iter;struct p9_fid *fid = rreq->netfs_priv;unsigned long long pos = subreq->start + subreq->transferred;int total, err; - total =p9_client_read (fid, pos, &subreq->io_iter, &err); + err =netfs_prepare_read_buffer (subreq, rctx,INT_MAX ); +if (err <0 ) +return err; + +iov_iter_bvec_queue (&iter,ITER_DEST , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len); + +/* After this point, we're not allowed to return an error. */ +netfs_mark_read_submission (subreq, rctx); + + total =p9_client_read (fid, pos, &iter, &err);/* if we just extended the file size, any portion not in * cache won't be on server and is zeroes */
@@ -89,6 +114,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) subreq->error = err;netfs_read_subreq_terminated (subreq); +return -EIOCBQUEUED ; }/**
fs/afs/dir.c +5 -3
@@ -255,7 +255,8 @@ static ssize_t afs_do_read_single(struct afs_vnode *dvnode, struct file *file)if (dvnode->directory_size < i_size) {size_t cur_size = dvnode->directory_size; - ret =netfs_expand_bvecq_buffer (&dvnode->directory, &cur_size, i_size, + ret =netfs_expand_bvecq_buffer (&dvnode->directory, &cur_size, +round_up (i_size,PAGE_SIZE ),mapping_gfp_mask (dvnode->netfs.inode.i_mapping)); dvnode->directory_size = cur_size;if (ret <0 )
@@ -2210,9 +2211,10 @@ int afs_single_writepages(struct address_space *mapping,if (is_dir ?test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags) :atomic64_read (&dvnode->cb_expires_at) !=AFS_NO_CB_PROMISE ) { +size_t len =i_size_read (&dvnode->netfs.inode);iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , -i_size_read (&dvnode->netfs.inode)); - ret =netfs_writeback_single (mapping, wbc, &iter); +round_up (len,PAGE_SIZE )); + ret =netfs_writeback_single (mapping, wbc, &iter, len); }up_read (&dvnode->validate_lock);
fs/afs/file.c +16 -11
@@ -329,11 +329,13 @@ void afs_fetch_data_immediate_cancel(struct afs_call *call)/* * Fetch file data from the volume. */ -static void afs_issue_read (struct netfs_io_subrequest *subreq) +static int afs_issue_read (struct netfs_io_subrequest *subreq, +struct netfs_read_context *rctx) {struct afs_operation *op;struct afs_vnode *vnode =AFS_FS_I (subreq->rreq->inode);struct key *key = subreq->rreq->netfs_priv; +int ret; _enter("%s{%llx:%llu.%u},%x,,,", vnode->volume->name,
@@ -342,19 +344,21 @@ static void afs_issue_read(struct netfs_io_subrequest *subreq) vnode->fid.unique, key_serial(key)); + ret =netfs_prepare_read_buffer (subreq, rctx,INT_MAX ); +if (ret <0 ) +return ret; + op =afs_alloc_operation (key, vnode->volume); -if (IS_ERR (op)) { - subreq->error =PTR_ERR (op); -netfs_read_subreq_terminated (subreq); -return ; - } +if (IS_ERR (op)) +return PTR_ERR (op);afs_op_set_vnode (op,0 , vnode); op->fetch.subreq = subreq; op->ops = &afs_fetch_data_operation; -trace_netfs_sreq (subreq, netfs_sreq_trace_submit); +/* After this point, we're not allowed to return an error. */ +netfs_mark_read_submission (subreq, rctx);if (subreq->rreq->origin ==NETFS_READAHEAD || subreq->rreq->iocb) {
@@ -363,18 +367,19 @@ static void afs_issue_read(struct netfs_io_subrequest *subreq)if (!afs_begin_vnode_operation (op)) { subreq->error =afs_put_operation (op);netfs_read_subreq_terminated (subreq); -return ; +return -EIOCBQUEUED ; }if (!afs_select_fileserver (op)) { -afs_end_read (op); -return ; +afs_end_read (op);/* Error recorded here. */ +return -EIOCBQUEUED ; }afs_issue_read_call (op); }else {afs_do_sync_operation (op); } +return -EIOCBQUEUED ; }static int afs_init_request (struct netfs_io_request *rreq,struct file *file)
@@ -454,7 +459,7 @@ const struct netfs_request_ops afs_req_ops = { .update_i_size = afs_update_i_size, .invalidate_cache = afs_netfs_invalidate_cache, .begin_writeback = afs_begin_writeback, - .prepare_write = afs_prepare_write, + .estimate_write = afs_estimate_write, .issue_write = afs_issue_write, .retry_request = afs_retry_request, };
fs/afs/fsclient.c +5 -3
@@ -339,7 +339,9 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)if (call->remaining ==0 ) goto no_more_data; - call->iter = &subreq->io_iter; +iov_iter_bvec_queue (&call->def_iter,ITER_DEST , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len); + call->iov_len =umin (call->remaining, subreq->len - subreq->transferred); call->unmarshall++; fallthrough;
@@ -1085,7 +1087,7 @@ static void afs_fs_store_data64(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->write_iter = op->store.write_iter; + call->write_iter = &op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1139,7 +1141,7 @@ void afs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->write_iter = op->store.write_iter; + call->write_iter = &op->store.write_iter;/* marshall the parameters */ bp = call->request;
fs/afs/internal.h +7 -3
@@ -906,7 +906,7 @@ struct afs_operation {afs_lock_type_t type; } lock;struct { -struct iov_iter *write_iter; +struct iov_iter write_iter;loff_t pos;loff_t size;loff_t i_size;
@@ -1680,8 +1680,12 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);/* * write.c */ -void afs_prepare_write (struct netfs_io_subrequest *subreq); -void afs_issue_write (struct netfs_io_subrequest *subreq); +int afs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +const struct netfs_write_context *wctx, +struct netfs_write_estimate *estimate); +int afs_issue_write (struct netfs_io_subrequest *subreq, +struct netfs_write_context *wctx);void afs_begin_writeback (struct netfs_io_request *wreq);void afs_retry_request (struct netfs_io_request *wreq,struct netfs_io_stream *stream);extern int afs_writepages (struct address_space *,struct writeback_control *);
fs/afs/write.c +26 -9
@@ -84,17 +84,21 @@ static const struct afs_operation_ops afs_store_data_operation = { };/* -* Prepare a subrequest to write to the server. This sets the max_len -* parameter. +* Estimate the maximum size of a write we can send to the server. */ -void afs_prepare_write (struct netfs_io_subrequest *subreq) +int afs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +const struct netfs_write_context *wctx, +struct netfs_write_estimate *estimate) { -struct netfs_io_stream *stream = &subreq->rreq->io_streams[subreq->stream_nr]; +unsigned long long limit =ULLONG_MAX - wctx->issue_from; +unsigned long long max_len =256 *1024 *1024 ;//if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) -// subreq->max_len = 512 * 1024; -//else - stream->sreq_max_len =256 *1024 *1024 ; +// max_len = 512 * 1024; + + estimate->issue_at = wctx->issue_from +umin (max_len, limit); +return 0 ; }/*
@@ -140,12 +144,15 @@ static void afs_issue_write_worker(struct work_struct *work) op->flags |=AFS_OPERATION_UNINTR ; op->ops = &afs_store_data_operation; +trace_netfs_sreq (subreq, netfs_sreq_trace_submit);afs_begin_vnode_operation (op); - op->store.write_iter = &subreq->io_iter; op->store.i_size =umax (pos + len, vnode->netfs.remote_i_size); op->mtime =inode_get_mtime (&vnode->netfs.inode); +iov_iter_bvec_queue (&op->store.write_iter,ITER_SOURCE , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len); +afs_wait_for_operation (op); ret =afs_put_operation (op);switch (ret) {
@@ -169,11 +176,19 @@ static void afs_issue_write_worker(struct work_struct *work)netfs_write_subrequest_terminated (subreq, ret <0 ? ret : subreq->len); } -void afs_issue_write (struct netfs_io_subrequest *subreq) +int afs_issue_write (struct netfs_io_subrequest *subreq, +struct netfs_write_context *wctx) { +int ret; + + ret =netfs_prepare_write_buffer (subreq, wctx,INT_MAX ); +if (ret <0 ) +return ret; + subreq->work.func = afs_issue_write_worker;if (!queue_work (system_dfl_wq, &subreq->work))WARN_ON_ONCE (1 ); +return -EIOCBQUEUED ; }/*
@@ -184,6 +199,8 @@ void afs_begin_writeback(struct netfs_io_request *wreq) {if (S_ISREG (wreq->inode->i_mode))afs_get_writeback_key (wreq); + + wreq->io_streams[0 ].avail = true; }/*
fs/afs/yfsclient.c +4 -2
@@ -385,7 +385,9 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)if (call->remaining ==0 ) goto no_more_data; - call->iter = &subreq->io_iter; +iov_iter_bvec_queue (&call->def_iter,ITER_DEST , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len); + call->iov_len =min (call->remaining, subreq->len - subreq->transferred); call->unmarshall++; fallthrough;
@@ -1357,7 +1359,7 @@ void yfs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->write_iter = op->store.write_iter; + call->write_iter = &op->store.write_iter;/* marshall the parameters */ bp = call->request;
fs/cachefiles/io.c +230 -109
432 lines not on this page · raw message
fs/ceph/addr.c +56 -53
209 lines not on this page · raw message
fs/netfs/Makefile +1 -1
@@ -12,13 +12,13 @@ netfs-y := \ misc.o \ objects.o \ read_collect.o \ - read_pgpriv2.o \ read_retry.o \ read_single.o \ write_collect.o \ write_issue.o \ write_retry.o +netfs-$(CONFIG_NETFS_PGPRIV2) += read_pgpriv2.o netfs-$(CONFIG_NETFS_STATS) += stats.o netfs-$(CONFIG_FSCACHE) += \
fs/netfs/buffered_read.c +242 -150
534 lines not on this page · raw message
fs/netfs/buffered_write.c +1 -1
@@ -267,7 +267,7 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,* a file that's open for reading as ->read_folio() then has to * be able to flush it. */ -if ((file->f_mode &FMODE_READ ) || +if (//(file->f_mode & FMODE_READ) || netfs_is_cache_enabled (ctx)) {if (finfo) {netfs_stat (&netfs_n_wh_wstream_conflict);
fs/netfs/direct_read.c +41 -49
126 lines not on this page · raw message
fs/netfs/direct_write.c +91 -62
248 lines not on this page · raw message
fs/netfs/fscache_io.c +0 -6
@@ -239,10 +239,6 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie, fscache_access_io_write) < 0) goto abandon_free; - ret = cres->ops->prepare_write (cres, &start, &len, len, i_size, false); -if (ret <0 ) - goto abandon_end; -/* TODO: Consider clearing page bits now for space the write isn't * covering. This is more complicated than it appears when THPs are * taken into account.
@@ -252,8 +248,6 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie,fscache_write (cres, start, &iter, fscache_wreq_done, wreq);return ; -abandon_end: -return fscache_wreq_done (wreq, ret); abandon_free:kfree (wreq); abandon:
fs/netfs/internal.h +61 -10
120 lines not on this page · raw message
fs/netfs/iterator.c +11 -2
@@ -103,16 +103,24 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t orig_len, size_t max_se got =iov_iter_extract_pages (orig, &pages, orig_len - extracted, bq->max_segs - bq->nr_segs, extraction_flags, &offset); +if (got <0 ) {pr_err ("Couldn't get user pages (rc=%zd)\n" , got); ret = got; -break ; + goto out; + } + +if (got ==0 ) { +pr_err ("extract_pages gave nothing from %zu/%zu\n" , + extracted, orig_len); + ret = -EIO ; + goto out; }if (got > orig_len - extracted) {pr_err ("get_pages rc=%zd more than %zu\n" , got, orig_len - extracted); -break ; + goto out; } extracted += got;
@@ -131,6 +139,7 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t orig_len, size_t max_se }while (extracted < orig_len && !bvecq_is_full (bq)); }while (extracted < orig_len && max_segs >0 ); +out:return extracted ?: ret; }EXPORT_SYMBOL_GPL (netfs_extract_iter);
fs/netfs/misc.c +31 -0
@@ -232,6 +232,37 @@ void netfs_subreq_clear_in_progress(struct netfs_io_subrequest *subreq)netfs_wake_collector (rreq); } +/* +* Wait for a subrequest to come to completion. +*/ +int netfs_wait_for_in_progress_subreq (struct netfs_io_request *rreq, +struct netfs_io_subrequest *subreq) +{ +if (netfs_check_subreq_in_progress (subreq)) { +DEFINE_WAIT (myself); + +trace_netfs_rreq (rreq, netfs_rreq_trace_wait_quiesce); +for (;;) { +prepare_to_wait (&rreq->waitq, &myself,TASK_UNINTERRUPTIBLE ); + +if (!netfs_check_subreq_in_progress (subreq)) +break ; + +trace_netfs_sreq (subreq, netfs_sreq_trace_wait_for); +schedule (); + } + +trace_netfs_rreq (rreq, netfs_rreq_trace_waited_quiesce); +finish_wait (&rreq->waitq, &myself); + } + +if (test_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags)) +return -EAGAIN ; +if (test_bit (NETFS_SREQ_FAILED , &subreq->flags)) +return subreq->error; +return 0 ; +} +/* * Wait for all outstanding I/O in a stream to quiesce. */
fs/netfs/objects.c +0 -3
@@ -46,8 +46,6 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq->i_size =i_size_read (inode); rreq->debug_id =atomic_inc_return (&debug_ids); rreq->wsize =INT_MAX ; - rreq->io_streams[0 ].sreq_max_len =ULONG_MAX ; - rreq->io_streams[0 ].sreq_max_segs =0 ;spin_lock_init (&rreq->lock);INIT_LIST_HEAD (&rreq->io_streams[0 ].subrequests);INIT_LIST_HEAD (&rreq->io_streams[1 ].subrequests);
@@ -134,7 +132,6 @@ static void netfs_deinit_request(struct netfs_io_request *rreq)if (rreq->cache_resources.ops) rreq->cache_resources.ops->end_operation (&rreq->cache_resources);bvecq_pos_detach (&rreq->load_cursor); -bvecq_pos_detach (&rreq->dispatch_cursor);bvecq_pos_detach (&rreq->collect_cursor);if (atomic_dec_and_test (&ictx->io_count))
fs/netfs/read_collect.c +4 -29
@@ -36,6 +36,7 @@ static void netfs_clear_unread(struct netfs_io_subrequest *subreq)if (subreq->start + subreq->transferred >= subreq->rreq->i_size)__set_bit (NETFS_SREQ_HIT_EOF , &subreq->flags); +trace_netfs_rreq (subreq->rreq, netfs_rreq_trace_zero_unread); }/*
@@ -58,7 +59,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,flush_dcache_folio (folio);folio_mark_uptodate (folio); -if (!test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags)) { +if (!netfs_using_pgpriv2 (rreq)) { finfo =netfs_folio_info (folio);if (finfo) {trace_netfs_folio (folio, netfs_folio_trace_filled_gaps);
@@ -263,8 +264,7 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) transferred = front->len;trace_netfs_rreq (rreq, netfs_rreq_trace_set_abandon); } -if (front->start + transferred >= rreq->cleaned_to + fsize || -test_bit (NETFS_SREQ_HIT_EOF , &front->flags)) +if (front->start + transferred >= rreq->cleaned_to + fsize)netfs_read_unlock_folios (rreq, ¬es); }else { stream->collected_to = front->start + transferred;
@@ -381,31 +381,6 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)inode_dio_end (rreq->inode); } -/* -* Do processing after reading a monolithic single object. -*/ -static void netfs_rreq_assess_single (struct netfs_io_request *rreq) -{ -struct netfs_io_stream *stream = &rreq->io_streams[0 ]; - -if (!rreq->error && stream->source ==NETFS_DOWNLOAD_FROM_SERVER && -fscache_resources_valid (&rreq->cache_resources)) { -trace_netfs_rreq (rreq, netfs_rreq_trace_dirty); -netfs_single_mark_inode_dirty (rreq->inode); - } - -if (rreq->iocb) { - rreq->iocb->ki_pos += rreq->transferred; -if (rreq->iocb->ki_complete) { -trace_netfs_rreq (rreq, netfs_rreq_trace_ki_complete); - rreq->iocb->ki_complete ( - rreq->iocb, rreq->error ? rreq->error : rreq->transferred); - } - } -if (rreq->netfs_ops->done) - rreq->netfs_ops->done (rreq); -} -/* * Perform the collection of subrequests and folios. *
@@ -441,7 +416,7 @@ bool netfs_read_collection(struct netfs_io_request *rreq)netfs_rreq_assess_dio (rreq);break ;case NETFS_READ_SINGLE : -netfs_rreq_assess_single (rreq); +WARN_ON_ONCE (1 );break ;default :break ;
fs/netfs/read_retry.c +101 -114
311 lines not on this page · raw message
fs/netfs/read_single.c +109 -72
228 lines not on this page · raw message
fs/netfs/write_collect.c +25 -14
@@ -28,8 +28,8 @@ static void netfs_dump_request(const struct netfs_io_request *rreq) rreq->origin, rreq->error);pr_err (" st=%llx tsl=%zx/%llx/%llx\n" , rreq->start, rreq->transferred, rreq->submitted, rreq->len); -pr_err (" cci=%llx/%llx/%llx\n" , - rreq->cleaned_to, rreq->collected_to,atomic64_read (&rreq->issued_to)); +pr_err (" cci=%llx/%llx\n" , + rreq->cleaned_to, rreq->collected_to);pr_err (" iw=%pSR\n" , rreq->netfs_ops->issue_write);for (int i =0 ; i <NR_IO_STREAMS ; i++) {const struct netfs_io_subrequest *sreq;
@@ -38,8 +38,9 @@ static void netfs_dump_request(const struct netfs_io_request *rreq)pr_err (" str[%x] s=%x e=%d acnf=%u,%u,%u,%u\n" , s->stream_nr, s->source, s->error, s->avail, s->active, s->need_retry, s->failed); -pr_err (" str[%x] ct=%llx t=%zx\n" , - s->stream_nr, s->collected_to, s->transferred); +pr_err (" str[%x] it=%llx ct=%llx t=%zx\n" , + s->stream_nr,atomic64_read (&s->issued_to), + s->collected_to, s->transferred);list_for_each_entry (sreq, &s->subrequests, rreq_link) { pr_err(" sreq[%x:%x] sc=%u s=%llx t=%zx/%zx r=%d f=%lx\n", sreq->stream_nr, sreq->debug_index, sreq->source,
@@ -56,7 +57,7 @@ static void netfs_dump_request(const struct netfs_io_request *rreq)*/ int netfs_folio_written_back (struct folio *folio) { -enum netfs_folio_trace why = netfs_folio_trace_clear; +enum netfs_folio_trace why = netfs_folio_trace_endwb;struct netfs_inode *ictx =netfs_inode (folio->mapping->host);struct netfs_folio *finfo;struct netfs_group *group =NULL ;
@@ -76,13 +77,13 @@ int netfs_folio_written_back(struct folio *folio) group = finfo->netfs_group; gcount++;kfree (finfo); - why = netfs_folio_trace_clear_s; + why = netfs_folio_trace_endwb_s; goto end_wb; }if ((group =netfs_folio_group (folio))) {if (group ==NETFS_FOLIO_COPY_TO_CACHE ) { - why = netfs_folio_trace_clear_cc; + why = netfs_folio_trace_endwb_cc;folio_detach_private (folio); goto end_wb; }
@@ -95,7 +96,7 @@ int netfs_folio_written_back(struct folio *folio)if (!folio_test_dirty (folio)) {folio_detach_private (folio); gcount++; - why = netfs_folio_trace_clear_g; + why = netfs_folio_trace_endwb_g; } }
@@ -212,9 +213,7 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)trace_netfs_rreq (wreq, netfs_rreq_trace_collect); reassess_streams: -/* Order reading the issued_to point before reading the queue it refers to. */ - issued_to =atomic64_read_acquire (&wreq->issued_to); -smp_rmb (); + issued_to =ULLONG_MAX ; collected_to =ULLONG_MAX ; if (wreq->origin == NETFS_WRITEBACK || wreq->origin == NETFS_WRITETHROUGH ||
@@ -229,13 +228,25 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)* to the tail whilst we're doing this. */ for (s =0 ; s <NR_IO_STREAMS ; s++) { +unsigned long long s_issued_to; + stream = &wreq->io_streams[s]; -/* Read active flag before list pointers */ +/* Read active flag before issued_to */ if (!smp_load_acquire (&stream->active))continue ; - front = stream->front; -while (front) { +for (;;) { +/* Order reading the issued_to point before reading the +* queue it refers to. +*/ + s_issued_to =atomic64_read_acquire (&stream->issued_to); +if (s_issued_to < issued_to) + issued_to = s_issued_to; + + front = stream->front; +if (!front) +break ; +trace_netfs_collect_sreq (wreq, front);//_debug("sreq [%x] %llx %zx/%zx", // front->debug_index, front->start, front->transferred, front->len);
fs/netfs/write_issue.c +443 -292
219 lines not on this page · raw message
fs/netfs/write_retry.c +74 -71
145 lines not on this page · raw message
fs/smb/client/file.c +77 -72
149 lines not on this page · raw message
include/linux/netfs.h +76 -46
122 lines not on this page · raw message
include/trace/events/netfs.h +37 -6
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: [RFC PATCH 02/17] vfs: Implement a FIEMAP callback
In reply to David HowellsQuoted 5 lines · David Howells
Implement a callback in the internal kernel FIEMAP API so that kernel users can make use of it as the filler function expects to write to userspace. This allows the FIEMAP data to be captured and parsed. This is useful for cachefiles and also potentially for knfsd and ksmbd to implement their equivalents of FIEMAP remotely rather than using SEEK_DATA/SEEK_HOLE.
Hell no. FIEMAP is purely a debugging toool and must not get anywhere near a data path. NAK to all of this.
David Howells
maintainerRe: [RFC PATCH 02/17] vfs: Implement a FIEMAP callback
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · David Howells
Implement a callback in the internal kernel FIEMAP API so that kernel users can make use of it as the filler function expects to write to userspace. This allows the FIEMAP data to be captured and parsed. This is useful for cachefiles and also potentially for knfsd and ksmbd to implement their equivalents of FIEMAP remotely rather than using SEEK_DATA/SEEK_HOLE.
Hell no. FIEMAP is purely a debugging toool and must not get anywhere near a data path. NAK to all of this.
So I have to stick with SEEK_DATA/SEEK_HOLE for this?
(Before you ask, yes, I do want to keep track of this myself, but working out the best way to do that without reinventing the filesystem is the issue - well, that and finding time to do it).
David
Re: [RFC PATCH 02/17] vfs: Implement a FIEMAP callback
Quoted 9 lines · David Howells
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · David Howells
Implement a callback in the internal kernel FIEMAP API so that kernel users can make use of it as the filler function expects to write to userspace. This allows the FIEMAP data to be captured and parsed. This is useful for cachefiles and also potentially for knfsd and ksmbd to implement their equivalents of FIEMAP remotely rather than using SEEK_DATA/SEEK_HOLE.
Quoted 4 lines
Quoted 2 lines
Hell no. FIEMAP is purely a debugging toool and must not get anywhere near a data path. NAK to all of this.
So I have to stick with SEEK_DATA/SEEK_HOLE for this?
Yes. Why do you even want to move away from that? It's the far better API. Of course like all other reporting APIs it still is racy, but has far less problems than fiemap.
David Howells
maintainerRe: [RFC PATCH 02/17] vfs: Implement a FIEMAP callback
Quoted 5 lines · Christoph Hellwig
Quoted 1 line
So I have to stick with SEEK_DATA/SEEK_HOLE for this?
Yes. Why do you even want to move away from that? It's the far better API. Of course like all other reporting APIs it still is racy, but has far less problems than fiemap.
To find the next two extents of data, say, I have to make four calls into the backing filesystem rather than one - with all the context set up and locking those might incur.
Granted, the vast majority of files aren't sparse, so one pair of SEEK_DATA/SEEK_HOLE should be able to establish that.
David
Re: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
In reply to David Howellsfs/cachefiles/io.c static int cachefiles_read(struct netfs_cache_resources *cres, · line 371
Quoted 7 lines · David Howells
fs/cachefiles/io.c +7
-0+/* +* Query the occupancy of the cache in a region, returning the extent of the +* next chunk of cached data and the next hole. +*/ +static int cachefiles_query_occupancy (struct netfs_cache_resources *cres, +struct fscache_occupancy *occ) +{
Independent of fiemap or not, how is this supposed to work? File systems can create speculative preallocations any time they want, so simply querying for holes vs data will corrupt your cache trivially.
David Howells
maintainerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
Quoted 12 lines · Christoph Hellwig
fs/cachefiles/io.c static int cachefiles_read(struct netfs_cache_resources *cres, · line 371
Quoted 7 lines · David Howells
fs/cachefiles/io.c +7
-0+/* +* Query the occupancy of the cache in a region, returning the extent of the +* next chunk of cached data and the next hole. +*/ +static int cachefiles_query_occupancy (struct netfs_cache_resources *cres, +struct fscache_occupancy *occ) +{Independent of fiemap or not, how is this supposed to work? File systems can create speculative preallocations any time they want, so simply querying for holes vs data will corrupt your cache trivially.
SEEK_DATA and SEEK_HOLE avoid preallocations, I presume?
David
Re: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
Quoted 9 lines · David Howells
Quoted 7 lines
fs/cachefiles/io.c static int cachefiles_read(struct netfs_cache_resources *cres, · line 371
Quoted 3 lines
fs/cachefiles/io.c +3
-0+static int cachefiles_query_occupancy (struct netfs_cache_resources *cres, +struct fscache_occupancy *occ) +{Independent of fiemap or not, how is this supposed to work? File systems can create speculative preallocations any time they want, so simply querying for holes vs data will corrupt your cache trivially.
SEEK_DATAandSEEK_HOLEavoid preallocations, I presume?
No, they can't. The file system doesn't even know what range is a persistent preallocation or not. You need to track your cached ranges yourself.
ChenXiaoSong
reviewerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
In reply to David HowellsHi David,
I reviewed this patch in your repository's netfs-next branch (it looks slightly different from the version posted to the mailing list) and found two issues, the following additional changes are needed:
```
--- a/fs/netfs/direct_write.c
+++ b/fs/netfs/direct_write.c
@@ -161,8 +161,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
break;
}
netfs_put_subrequest(subreq,
netfs_sreq_trace_put_failed);
- subreq = NULL;
ret = subreq->error;
+ subreq = NULL;
goto failed;
}
break;
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index 697a47e96d2a..112363f17a84 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -808,6 +808,7 @@ struct netfs_writethrough *netfs_begin_writethrough(struct kiocb *iocb, size_t l
if (bvecq_buffer_init(&wreq->load_cursor, GFP_NOFS) < 0) {
netfs_put_failed_request(wreq);
mutex_unlock(&ictx->wb_lock);
+ kfree(wthru);
return ERR_PTR(-ENOMEM);
}
```David Howells
maintainerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
Quoted 3 lines · ChenXiaoSong
I reviewed this patch in your repository's netfs-next branch (it looks slightly different from the version posted to the mailing list) and found two issues, the following additional changes are needed:
Thanks! I've been testing the patches further and cleaning them up. I will hopefully post them again soon.
David
Paulo Alcantara
maintainerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
In reply to ChenXiaoSongfs/netfs/direct_write.c static int netfs_unbuffered_write(struct · line 168
Quoted 12 lines · ChenXiaoSong
fs/netfs/direct_write.c +1
-1@@ -161,8 +161,8 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq) break; }netfs_put_subrequest (subreq, netfs_sreq_trace_put_failed); - subreq =NULL ; ret = subreq->error; + subreq =NULL ; goto failed;
Thanks for the review. The above is still broken as it wolud cause an UAF on @subreq as we're putting it with netfs_put_subrequest() and then dereferencing it afterwards.
Besides, we could also get rid of 'subreq = NULL' as it is currently a no-op -- including in other places.
Let's wait for next patchset from Dave, though.
ChenXiaoSong
reviewerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
In netfs_writeback_single(), on the failure path, should we call netfs_put_failed_request() instead of netfs_put_request()?
```
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -1041,7 +1041,7 @@ int netfs_writeback_single(struct address_space *mapping,
return ret;
cleanup_free:
- netfs_put_request(wreq, netfs_rreq_trace_put_return);
+ netfs_put_failed_request(wreq, netfs_rreq_trace_put_return);
couldnt_start:
mutex_unlock(&ictx->wb_lock);
_leave(" = %d", ret);
```Thanks,
ChenXiaoSong <[email protected]>
Quoted 8 lines · Paulo Alcantara
Thanks for the review. The above is still broken as it wolud cause an UAF on @subreq as we're putting it with
netfs_put_subrequest()and then dereferencing it afterwards.Besides, we could also get rid of 'subreq = NULL' as it is currently a no-op -- including in other places.
Let's wait for next patchset from Dave, though.
David Howells
maintainerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
Quoted 2 lines · ChenXiaoSong
In
netfs_writeback_single(), on the failure path, should we callnetfs_put_failed_request()instead ofnetfs_put_request()?
It doesn't matter exactly, as the only difference really is whether it gets bumped over to a workqueue, but it's probably better to avoid that if we can.
David
ChenXiaoSong
reviewerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
netfs_put_request() only decrements the reference count by one, while netfs_put_failed_request() (refcout == 2) immediately frees the request by calling netfs_free_request().
Since the refcount == 2 after netfs_create_write_req() -> netfs_alloc_request(), on the failure path, calling netfs_put_request() will not free the request.
Please let me know if my understanding is incorrect.
Thanks,
ChenXiaoSong <[email protected]>
Quoted 2 lines · David Howells
It doesn't matter exactly, as the only difference really is whether it gets bumped over to a workqueue, but it's probably better to avoid that if we can.
David Howells
maintainerRe: [RFC PATCH 17/17] netfs: Combine prepare and issue ops and grab the buffers on request
Quoted 9 lines · ChenXiaoSong
netfs_put_request()only decrements the reference count by one, whilenetfs_put_failed_request()(refcout == 2) immediately frees the request by callingnetfs_free_request().Since the
refcount == 2afternetfs_create_write_req() -> netfs_alloc_request(), on the failure path, callingnetfs_put_request()will not free the request.Please let me know if my understanding is incorrect.
Actually, yes. You're correct. Anyway, I've made the change and pushed it.
David