netfs: Keep track of folios in a segmented bio_vec[] chain
Subsystems (20)
David Howells
maintainerv7 cover netfs: Keep track of folios in a segmented bio_vec[] chain
Hi Christian,
Could you add these patches to the VFS tree for next?
The 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_slots;
u16 max_slots;
enum bvecq_mem mem_type:2;
bool inline_bv: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 and whether this bvecq is discontiguous with the previous. When accessing the pagecache to clear flags/locks, the fpos can be used to look up folios by file position rather than by finding those folios from the info stored in the bio_vecs.
When the file position is relevant, the model I'm working with is that all the segments pointed to by a single bvecq must represent contiguous data, but adjacent bvecqs within a chain need not be contiguous. This allows a bvecq chain to be used to provide bufferage for a sparse read or write RPC such as can be done with Ceph.
If a bvecq segment is not contiguous with the previous one, ->discontig should be set (this is technically redundant if one keeps track of the fpos as a bvecq chain is processed).
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_slots, nr_slots. The size of bv[] and the number of slots 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) mem_type. Indicates how the memory attached to the bio_vecs should be disposed of when the bvecq is destroyed. It can be one of:
BVECQ_MEM_EXTERNAL - Externally tracked ref; don't put
BVECQ_MEM_PAGECACHE - Pagecache; must be put
BVECQ_MEM_GUP - Pinned by from GUP; needs unpin
BVECQ_MEM_ALLOCED - Plain alloc'd pages; can be mempooled
[!] I'm not sure that this is a good name for this member or for the
enum values.
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) Remove the writethrough code as the locking is really tricky to get right and it looks like it could deadlock with Ceph if snapshots are used.
(2) 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.
(3) For unbuffered/DIO, the source iov_iter is extracted into a bvecq chain.
(4) 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.
(5) 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 need a dispatch cursor per stream (one for the network filesystem and one for the cache).
(6) ->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.
(7) Retry dispatch tracking is added to netfs_io_request so that the buffer preparation functions can find it. Retry requires an additional buffer cursor.
(8) 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.
(9) Reading from the cache is now managed by querying the cache to provide a list of the next two data extents within the cache.
(10) AFS directories are switched to using a bvecq rather than a folio_queue to hold their contents.
(11) CIFS is switch to using a bvecq rather than a folio_queue for holding a temporary encryption buffer.
(12) CIFS RDMA is given the ability to extract ITER_BVECQ and support for extracting ITER_FOLIOQ is removed.
(13) All the folio_queue and rolling_buffer code is removed.
Cachefiles is also modified:
(1) On-demand mode for Erofs is removed.
(2) The object type in the cachefiles file xattr is now correctly set to CACHEFILES_CONTENT_{SINGLE,ALL,BACKFS_MAP} rather than just being 0, to indicate whether we have a single monolithic blob, all the data up to cache i_size with no holes or a sparse file with the data mapped by the backing file system (as currently upstream).
(3) For "ALL" type files, the cache's i_size is used to track how much data is saved in the cache and no longer bears any relation to the netfs i_size. The actual object size is stored in the xattr.
(4) For most typical files which are contiguous and written progressively, the object type is now set to "ALL". For anything else, cachefiles uses SEEK_DATA/HOLE to find extent outlines at before (this is the current behaviour and needs to be fixed, but in a separate set of patches as it's not trivial).
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
Changes
=======
ver #7)
- Rebased on v7.2-rc4.
- Added three fix patches to the front from Yichong Chen that conflict with other patches in the series.
- Fixed a number of bugs reported by Sashiko[5].
- Fixed double page put in iov_kunit_destroy_bvecq().
- Fixed bvecq_alloc_buffer2() to handle pre_slots>0 and size==0 correctly.
- Fixes bvecq_expand_buffer() to use a barrer to set tail->nr_slots.
- Added functions to insert barriers when reading or setting bvecq::next and fixed some places to use them.
- Fixed more meta block mapping in afs_edit_dir_remove().
- Added a patch to fix missing unmap in afs_dir_search_bucket().
- Removed the writethrough stat counter as the code gets removed.
- Cleaned up the cachefiles-ondemand removal patch:
- Fix removal of code that's conditional on !ONDEMAND.
- Removed msg_id_next field.
- Removed ondemand trace elements.
- Removed documentation.
- Fixed cachefiles_resize_cookie() to only consider a resize a shrink if the new size is less than the object size.
- Fixed cachefiles_resize_cookie() to update object->object_size on expansion.
- Add a comment on exclusion in cachefiles_collect_write().
- Fixed netfs_single_dispatch_read() to allow for the cache to have rounded out the stored data to DIO size.
- Fixed netfs_prepare_read_iterator() to clamp subreq len to sreq_max_len (obsoleted by last patch).
- Changed write subreq collection to never retry cache writes. Shouldn't see them in the retry path either then.
- Fixed netfs_pgpriv2_unlock_copied_folios() to return made_progress instead of false if we hit the end of the bvecq chain.
- Modified buffered read collection to abandon the rest of a read request if a subreq over-reads as the buffer may have been corrupted. The read termination function no longer winds subreq->transferred back.
- Fixed netfs_issue_read() to call the right termination func in the fail path.
- Fixed netfs_dispatch_unbuffered_reads(), netfs_single_dispatch_read()
and netfs_retry_read_subrequests() to handle failed ->issue_read().
- Fixed afs_issue_read() to return after calling afs_end_read() as this
op is then released.
- Fixed cifs_issue_write() to always release credits on failure.
- Fixed cifs_issue_read() to not release credits twice.
- Fixed netfs_issue_writes() to advance stream->issued_to and
stream->dispatch_cursor on early failure of ->issue_write().
- Fixed netfs_issue_read() to only call netfs_all_subreqs_queued() if
stream->buffered is zero. - Fixed ceph_netfs_issue_op_inline() to do a retry if file got uninlined by someone else.
- Fixed ceph_netfs_issue_op_inline() to not return an error directly once it's got a prepared buffer.
- Fixed nfs_netfs_issue_read() to return an int.
ver #6)
- Rebased on v7.2-rc3.
- Added a patch to remove erofs on-demand support from cachefiles.
- Added a patch to remove the writethrough code as it's really tricky to get the locking right and it looks like can deadlock itself with Ceph.
- Fixed a number of bugs reported by Sashiko[4].
- Fixed iov_iter_single_seg_count(), iov_iter_alignment_bvecq() and iov_npages_bvecq() to handle zero-length segments and segments with no stuff remaining.
- Fixed bvecq_extract() to use GFP_NOFS rather than GFP_KERNEL.
- Fixed bvecq_alloc_buffer2()'s use of alloc_pages_bulk().
- Fixed netfs_extract_iter() to break out of the inner loop if max_pages hits zero.
- Added a patch to fix meta block mapping in afs_edit_dir_remove().
- Fixed afs_init_new_symlink() to clear the tail of the symlink page.
- Fixed cachefiles_begin_operation() to deal with a NULL file.
- Fixed slot check in netfs_read_gaps() to be >=, not >.
- Fixed netfs_pgpriv2_copy_folio() to update creq->last_end.
- Fixed netfs_read_single() to return -EIO if the buffer isn't big enough.
- Add a comment to netfs_write_folio() to indicate that truncate must not run concurrently with writeback and must exclude/wait for it.
- In netfs_read_subreq_terminated(), move the netfs_sreq_trace_too_much
trace line earlier before ->transferred is clobbered.
- In netfs_read_subreq_terminated(), make the transfer-too-long case
avoid retrying and just end with EIO (in case data further along in the
buffer got corrupted).
- Fixed netfs_collect_read_results() if it sees front->transferred >
front->len, to just use front->len instead.
- Fixed ceph_netfs_issue_op_inline() to prep the buffer before setting
NETFS_SREQ_HIT_EOF so that subreq->content is set. - Alter netfs_read_to_pagecache() to not round up reading from zero-containing cache granules as no I/O is required.
- Made ->issue_write() return an error so that errors before any buffer is sliced off don't result in an infinite loop in netfs_issue_writes().
- Made ->issue_read() return an error also for similiar reasons.
- In netfs_writepages(), handle -ENOMEM from bvecq prealloc before caling netfs_queue_wb_folio() rather than doing it on the combined error return of that and netfs_issue_streams() which can result in a double unlock.
- Fix netfs_writeback_single() to write nothing if len == 0.
ver #5)
- Rebased on v7.2-rc2 as that has a bunch of outstanding netfs and afs bugfixes included.
ver #4)
- Fixed a number of bugs reported by Sashiko[3].
- Added a patch to fix an underflow in iov_iter_extract_xarray_pages().
- Added a patch to fix alloc failure in iov_iter_extract_bvec_pages().
- Added a patch to remove an unused var in kunit code.
- Added a patch to fix the folio offset in extract_xarray_to_sg().
- Added a patch to fix the exclusion over writeback to make it cover collection too.
- Fixed double fput() in cachefiles.
- Fixed the collection of cache writes to handle cancellation better.
- Fixed iterate_bvecq() to skip bvecq structs with nr_slots==0.
- Add a comment into iterate_bvecq() that a slot with bv_len>0 must have a valid bv_page.
- Fixed iov_iter_bvecq_advance(), iov_iter_bvecq_revert(), iter_count_bvecq_pages(), iov_iter_extract_bvecq_pages() and extract_bvecq_to_sg() to correctly handle empty bvecqs.
- Fixed extract_bvecq_to_sg() to be limited by iter->count.
- Fixed bvecq_expand_buffer() to take an unsigned size param.
- Fixed bvecq_expand_buffer() to not mix memory types in alloc'd bvecqs.
- Fixed bvecq_shorten_buffer() occasional retention of zero-length slots.
- Fixed slot validity check polarity in bvecq_pos_advance(); also don't use inner loop otherwise break then exits the wrong loop.
- Fixed bvecq_zero(), bvecq_slice() and bvecq_extract to use a barrier when
checking bq->nr_slots.
- Restructured bvecq_zero() to be similar to bvecq_pos_advance().
- Fixed an off-by-one error in bvecq_pos_step() and added a missing slot
reset.
- Fixed a break in netfs_extract_iter() that should have been a goto.
- Fixed netfs_extract_iter() to limit number of pages extracted to remnant
of max_pages.
- Fixed an uninit var in afs_do_read_symlink().
- Fixed netfs_read_gaps() to fill a multipart bvecq chain correctly.
- Fixed netfs_dispatch_unbuffered_reads() to initialise collect_cursor as
netfs_rreq_assess_dio() uses it to flush the data read.
- Fixed netfs_extract_iter() to init the slot counter outside the extract
loop to avoid overwriting already loaded slots.
- Fixed callers of bvecq_delete_spent() to update bvecq_pos::slot before
calling.
- Fixed netfs_reissue_write() to make sure subreq->content is unset before
setting.
- Altered netfs_extract_iter() to free any allocated bvecq chain if no pages
were extracted and an error occurred (and to initialise the return
pointer to NULL). Also, made it return an empty bvecq if nothing was
extracted, but no error occurred.
- Fixed ceph_netfs_issue_read() to just return if
ceph_netfs_issue_op_inline() returns anything other than 1 to avoid a
double termination.
- Fixed ceph_netfs_issue_read() to do the size calculation in the right
order to avoid the op expanding to larger than the buffer.
- Fixed netfs_issue_read(), in the NETFS_FILL_WITH_ZEROES case, to deduct
subreq->len from stream->buffered rather than just setting it to 0.
- Fixed netfs_perform_write() to put the folio if netfs_advance_writethrough()
fails.
- Restored the old ->prepare_write op specifically for
fscache_write_to_cache() which is still used by Ceph.
- Fixed undefined return in netfs_pgpriv2_issue_stream().
- Fixed netfs_collect_write_results() to try to make sure a request isn't
left paused if there are no further server-bound subreqs.
- Fixed netfs_queue_wb_folio() to redirty the folio before unlocking it if
it can't allocate a bvecq.
- Fixed netfs_writepages() to cancel the pagecache iteration after ENOMEM.
- Fixed netfs_advance/end_writethrough() to advance the dispatch cursor.
- Fixed netfs_retry_read_subrequests() to use barriers when walking
stream->subrequests as the app may add another subreq before pausing.
- Fixed netfs_prepare_write_retry_buffer() to use ->retry_start and
->retry_buffered rather than ->issue_from and ->buffered.
- Fixed netfs_retry_write_stream() to use barriers when walking
stream->subrequests as the app may add another subreq before pausing. - Fixed netfs_retry_write_stream() to check the correct length when adding additional subreqs.
- Fixed nfs_netfs_issue_read() to set -ENOMEM, not 0, on alloc failure.
- Fixed nfs_netfs_issue_read() to only terminate the subreq once.
- Fixed cifs_issue_read() to release the credits if cifs_reopen_file() fails.
- Rebased on v7.1.
ver #3)
- Rebased to -rc7 as the patches wouldn't apply for Christian.
- Prepended a fix for a warning from generic/464 (the problem also exists upstream, just not the warning).
- Renamed kmap_local_bvec() to bvec_kmap_partial() as requested by Christoph.
- Adjusted smbdirect patch descriptions as requested by Stefan Metzmacher.
ver #2)
- Fixed a number of bugs reported by Sashiko[1].
- Split a bunch of fixes out and posted them separately[2].
[1] https://sashiko.dev/#/patchset/20260326104544.509518-1-dhowells%40redhat.com
[2] https://lore.kernel.org/linux-fsdevel/20260512-infozentrum-becher-7f86c47c96c8@brauner/T/#t
[3] https://sashiko.dev/#/patchset/20260608145432.681865-1-dhowells%40redhat.com
[4] https://sashiko.dev/#/patchset/20260706153408.1231650-1-dhowells%40redhat.com
[5] https://sashiko.dev/#/patchset/20260716103030.3065561-1-dhowells%40redhat.com
David Howells (25):
afs: Fix missing kunmap in afs_dir_search_bucket()
afs: Fix afs_edit_dir_remove() to get, not find, block 0
afs: Fix double-unmap of directory block
mm: Make readahead store folio count in readahead_control
netfs: Bulk load the readahead-provided folios up front Add a function to kmap one page of a multipage bio_vec
iov_iter: Make iov_iter_get_pages*() wrap iov_iter_extract_pages()
iov_iter: Add a segmented queue of bio_vec[]
netfs: Add some tools for managing bvecq chains
netfs: Add a function to extract from an iter into a bvecq
afs: Use a bvecq to hold dir content rather than folioq
cifs: Use a bvecq for buffering instead of a folioq
smbdirect: Support ITER_BVECQ in smbdirect_map_sges_from_iter()
netfs: Remove the writethrough code
cachefiles: Don't rely on backing fs storage map for most use cases
netfs: Add the cache object ID to netfs_read/write tracepoints
netfs: Switch to using bvecq rather than folio_queue and
rolling_buffer
smbdirect: Remove support for ITER_FOLIOQ from
smbdirect_map_sges_from_iter()
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: Limit the minimum trigger for progress reporting
netfs: Combine prepare and issue ops and grab the buffers on request
Gao Xiang (1):
cachefiles,netfs: sunset ondemand mode
Yichong Chen (3):
netfs: clear PG_private_2 on copy-to-cache append failure
netfs: handle single writeback rolling buffer allocation failure
netfs: release readahead folios on iterator preparation failure
Documentation/core-api/folio_queue.rst | 209 ---- Documentation/core-api/index.rst | 1 - .../filesystems/caching/cachefiles.rst | 179 --- Documentation/filesystems/netfs_library.rst | 2 +- fs/9p/vfs_addr.c | 61 +- fs/afs/dir.c | 40 +- fs/afs/dir_edit.c | 54 +- fs/afs/dir_search.c | 44 +- fs/afs/file.c | 31 +- fs/afs/fsclient.c | 8 +- fs/afs/inode.c | 2 +- fs/afs/internal.h | 22 +- fs/afs/symlink.c | 37 +- fs/afs/write.c | 36 +- fs/afs/yfsclient.c | 6 +- fs/cachefiles/Kconfig | 12 - fs/cachefiles/Makefile | 1 - fs/cachefiles/daemon.c | 76 +- fs/cachefiles/interface.c | 98 +- fs/cachefiles/internal.h | 142 +-- fs/cachefiles/io.c | 563 ++++++--- fs/cachefiles/namei.c | 27 +- fs/cachefiles/ondemand.c | 761 ------------ fs/cachefiles/xattr.c | 24 +- fs/ceph/Kconfig | 1 + fs/ceph/addr.c | 123 +- fs/netfs/Kconfig | 3 + fs/netfs/Makefile | 4 +- fs/netfs/buffered_read.c | 527 +++++--- fs/netfs/buffered_write.c | 59 +- fs/netfs/bvecq.c | 768 ++++++++++++ fs/netfs/direct_read.c | 115 +- fs/netfs/direct_write.c | 162 +-- fs/netfs/fscache_io.c | 4 +- fs/netfs/internal.h | 107 +- fs/netfs/iterator.c | 390 ++---- fs/netfs/main.c | 1 - fs/netfs/misc.c | 168 +-- fs/netfs/objects.c | 22 +- fs/netfs/read_collect.c | 208 ++-- fs/netfs/read_pgpriv2.c | 204 +++- fs/netfs/read_retry.c | 252 ++-- fs/netfs/read_single.c | 181 ++- fs/netfs/rolling_buffer.c | 222 ---- fs/netfs/stats.c | 10 +- fs/netfs/write_collect.c | 246 ++-- fs/netfs/write_issue.c | 1077 +++++++++-------- fs/netfs/write_retry.c | 178 +-- fs/nfs/Kconfig | 1 + fs/nfs/fscache.c | 24 +- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/cifssmb.c | 13 +- fs/smb/client/file.c | 145 +-- fs/smb/client/smb2ops.c | 82 +- fs/smb/client/smb2pdu.c | 28 +- fs/smb/client/transport.c | 15 +- fs/smb/smbdirect/connection.c | 135 +-- include/linux/bvec.h | 18 + include/linux/bvecq.h | 358 ++++++ include/linux/folio_queue.h | 282 ----- include/linux/fscache.h | 17 + include/linux/iov_iter.h | 87 +- include/linux/netfs.h | 184 +-- include/linux/pagemap.h | 10 + include/linux/rolling_buffer.h | 61 - include/linux/uio.h | 17 +- include/trace/events/cachefiles.h | 195 +-- include/trace/events/netfs.h | 159 ++- kernel/bpf/btf.c | 2 - lib/iov_iter.c | 557 +++++---- lib/scatterlist.c | 82 +- lib/tests/kunit_iov_iter.c | 131 +- mm/readahead.c | 5 + net/9p/client.c | 8 +- 74 files changed, 4937 insertions(+), 5149 deletions(-) delete mode 100644 Documentation/core-api/folio_queue.rst delete mode 100644 fs/cachefiles/ondemand.c create mode 100644 fs/netfs/bvecq.c delete mode 100644 fs/netfs/rolling_buffer.c create mode 100644 include/linux/bvecq.h delete mode 100644 include/linux/folio_queue.h delete mode 100644 include/linux/rolling_buffer.h
David Howells
maintainerPATCH v7 1/29 netfs: clear PG_private_2 on copy-to-cache append failure
From: Yichong Chen <[email protected]>
netfs_pgpriv2_copy_to_cache() marks the folio with PG_private_2 before netfs_pgpriv2_copy_folio() appends it to the copy-to-cache rolling buffer.
If the append fails, the folio is not queued for cache writeback, so the PG_private_2 state and its reference must be released immediately.
--- fs/netfs/read_pgpriv2.c | 1 + 1 file changed, 1 insertion(+)
fs/netfs/read_pgpriv2.c +1 -0
@@ -54,6 +54,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio/* Attach the folio to the rolling buffer. */ if (rolling_buffer_append (&creq->buffer, folio,0 ) <0 ) { +folio_end_private_2 (folio);clear_bit (NETFS_RREQ_FOLIO_COPY_TO_CACHE , &creq->flags);return ; }
David Howells
maintainerPATCH v7 2/29 netfs: handle single writeback rolling buffer allocation failure
In reply to David HowellsFrom: Yichong Chen <[email protected]>
netfs_write_folio_single() takes an extra folio reference before appending the folio to the rolling buffer.
rolling_buffer_append() can fail if it cannot allocate another folio_queue. Check the return value and drop the extra folio reference before returning the error.
--- fs/netfs/write_issue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/netfs/write_issue.c +6 -1
@@ -720,6 +720,7 @@ static int netfs_write_folio_single(struct netfs_io_request *wreq,size_t iter_off =0 ;size_t fsize =folio_size (folio), flen;loff_t fpos =folio_pos (folio); +ssize_t ret;bool to_eof = false;bool no_debug = false;
@@ -748,7 +749,11 @@ static int netfs_write_folio_single(struct netfs_io_request *wreq,/* Attach the folio to the rolling buffer. */ folio_get (folio); -rolling_buffer_append (&wreq->buffer, folio,NETFS_ROLLBUF_PUT_MARK ); + ret =rolling_buffer_append (&wreq->buffer, folio,NETFS_ROLLBUF_PUT_MARK ); +if (ret <0 ) { +folio_put (folio); +return ret; + }/* Move the submission point forward to allow for write-streaming data * not starting at the front of the page. We don't do write-streaming
David Howells
maintainerPATCH v7 3/29 netfs: release readahead folios on iterator preparation failure
In reply to David HowellsFrom: Yichong Chen <[email protected]>
netfs_prepare_read_iterator() batches readahead folios in put_batch so that the folio references can be dropped after the I/O iterator has been prepared.
If rolling_buffer_load_from_ra() fails after earlier folios have been batched, the function returns immediately and leaves those references held. Release the batch before returning the error.
--- fs/netfs/buffered_read.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/netfs/buffered_read.c +3 -1
@@ -102,8 +102,10 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq, added =rolling_buffer_load_from_ra (&rreq->buffer, ractl, &put_batch); -if (added <0 ) +if (added <0 ) { +folio_batch_release (&put_batch);return added; + } rreq->submitted += added; }folio_batch_release (&put_batch);
David Howells
maintainerPATCH v7 4/29 afs: Fix missing kunmap in afs_dir_search_bucket()
In reply to David HowellsFix afs_dir_search_bucket() to kunmap the block it's using in the "bad:" path.
--- fs/afs/dir_search.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/afs/dir_search.c +1 -2
@@ -173,12 +173,11 @@ int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name, ret = -ENOENT ; found: +bad:if (iter->block) {kunmap_local (iter->block); iter->block =NULL ; } - -bad:if (ret == -ESTALE )afs_invalidate_dir (iter->dvnode, afs_dir_invalid_iter_stale);_leave (" = %d" , ret);
David Howells
maintainerPATCH v7 5/29 afs: Fix afs_edit_dir_remove() to get, not find, block 0
In reply to David HowellsFix afs_edit_dir_remove() to use afs_dir_get_block() to get block 0 rather than afs_dir_find_block() as the latter caches the found block in the afs_dir_iter and may[*] switch out the page it's on if another afs_dir_find_block() is done. This parallels what afs_edit_dir_add() does.
[*] There's more than one block per page.
--- fs/afs/dir_edit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/afs/dir_edit.c +1 -1
@@ -415,7 +415,7 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,if (!afs_dir_init_iter (&iter, name))return ; - meta =afs_dir_find_block (&iter,0 ); + meta =afs_dir_get_block (&iter,0 );if (!meta)return ;
David Howells
maintainerPATCH v7 6/29 afs: Fix double-unmap of directory block
In reply to David HowellsFix afs_edit_dir_remove() to use a cleanup function to unmap the block pointed to by afs_dir_iter::block if it's left pointing to something rather than manually kunmapping the blocks. Manually kunmapping without clearing iter.blocks can result in a double-kunmap if afs_dir_find_block() is called twice in a row (which would be the case if the block being modified is not first in the hash chain).
--- fs/afs/dir_edit.c | 9 ++------- fs/afs/dir_search.c | 10 ++-------- fs/afs/internal.h | 8 ++++++++ 3 files changed, 12 insertions(+), 15 deletions(-)
fs/afs/dir_edit.c +2 -7
@@ -442,7 +442,7 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,/* Check and clear the entry. */ de = &block->dirents[slot];if (de->u.valid !=1 ) - goto error_unmap; + goto error; trace_afs_edit_dir(vnode, why, afs_edit_dir_delete, b, slot, ntohl(de->u.vnode), ntohl(de->u.unique),
@@ -458,7 +458,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,/* Clear the constituent entries. */ next = de->u.hash_next;memset (de,0 ,sizeof (*de) * iter.nr_slots); -kunmap_local (block);/* Adjust the hash chain: if iter->prev_entry is 0, the hashtable head * index is previous; otherwise it's slot number of the previous entry.
@@ -485,7 +484,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, pde = &pblock->dirents[ps]; prev_next = pde->u.hash_next;if (prev_next !=htons (entry)) { -kunmap_local (pblock); pr_warn("%llx:%llx:%x: not prev in chain b=%x p=%x,%x e=%x %*s", vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique, iter.bucket, iter.prev_entry, prev_next, entry,
@@ -493,7 +491,6 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, goto error; } pde->u.hash_next = next; -kunmap_local (pblock); }netfs_single_mark_inode_dirty (&vnode->netfs.inode);
@@ -503,18 +500,16 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,_debug ("Remove %s from %u[%u]" , name->name, b, slot); out_unmap: +afs_dir_end_iter (&iter);kunmap_local (meta);_leave ("" );return ; already_invalidated: -kunmap_local (block);trace_afs_edit_dir (vnode, why, afs_edit_dir_delete_inval,0 ,0 ,0 ,0 , name->name); goto out_unmap; -error_unmap: -kunmap_local (block); error:trace_afs_edit_dir (vnode, why, afs_edit_dir_delete_error,0 ,0 ,0 ,0 , name->name);
fs/afs/dir_search.c +2 -8
@@ -75,10 +75,7 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t bl_enter ("%zx,%d" , block, slot); -if (iter->block) { -kunmap_local (iter->block); - iter->block =NULL ; - } +afs_dir_end_iter (iter);if (dvnode->directory_size < blend) goto fail;
@@ -174,10 +171,7 @@ int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name, ret = -ENOENT ; found: bad: -if (iter->block) { -kunmap_local (iter->block); - iter->block =NULL ; - } +afs_dir_end_iter (iter);if (ret == -ESTALE )afs_invalidate_dir (iter->dvnode, afs_dir_invalid_iter_stale);_leave (" = %d" , ret);
fs/afs/internal.h +8 -0
@@ -1133,6 +1133,14 @@ int afs_dir_search_bucket(struct afs_dir_iter *iter, const struct qstr *name,int afs_dir_search (struct afs_vnode *dvnode,const struct qstr *name,struct afs_fid *_fid,afs_dataversion_t *_dir_version); +static inline void afs_dir_end_iter (struct afs_dir_iter *iter) +{ +if (iter->block) { +kunmap_local (iter->block); + iter->block =NULL ; + } +} +/* * dir_silly.c */
David Howells
maintainerPATCH v7 7/29 mm: Make readahead store folio count in readahead_control
In reply to David HowellsMake readahead store folio count in readahead_control so that the filesystem can know in advance how many folios it needs to keep track of.
This is cleared by read_pages() in case it is called from a loop.
The count is accessed by the filesystem with readahead_folio_count().
--- include/linux/pagemap.h | 10 ++++++++++ mm/readahead.c | 5 +++++ 2 files changed, 15 insertions(+)
include/linux/pagemap.h +10 -0
@@ -1348,6 +1348,7 @@ struct readahead_control {struct file_ra_state *ra;/* private: use the readahead_* accessors instead */ pgoff_t _index; +unsigned int _nr_folios;unsigned int _nr_pages;unsigned int _batch_count;bool dropbehind;
@@ -1527,6 +1528,15 @@ static inline size_t readahead_batch_length(const struct readahead_control *rac)return rac->_batch_count *PAGE_SIZE ; } +/** +* readahead_folio_count - Get the number of folios in this readahead request. +* @rac: The readahead request. +*/ +static inline unsigned int readahead_folio_count (const struct readahead_control *rac) +{ +return rac->_nr_folios; +} +static inline unsigned long dir_pages (const struct inode *inode) { return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >>
mm/readahead.c +5 -0
@@ -188,6 +188,7 @@ static void read_pages(struct readahead_control *rac)if (unlikely (rac->_workingset))psi_memstall_leave (&rac->_pflags); rac->_workingset = false; + rac->_nr_folios =0 ;BUG_ON (readahead_count (rac)); }
@@ -303,6 +304,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,if (i == mark)folio_set_readahead (folio); ractl->_workingset |=folio_test_workingset (folio); + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages; i += min_nrpages; }
@@ -473,6 +475,7 @@ static inline int ra_alloc_folio(struct readahead_control *ractl, pgoff_t index,return err; } + ractl->_nr_folios++; ractl->_nr_pages +=1UL << order; ractl->_workingset |=folio_test_workingset (folio);return 0 ;
@@ -822,6 +825,7 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true;psi_memstall_enter (&ractl->_pflags); } + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages; ractl->_index = folio->index; }
@@ -851,6 +855,7 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true;psi_memstall_enter (&ractl->_pflags); } + ractl->_nr_folios++; ractl->_nr_pages += min_nrpages;if (ra) { ra->size += min_nrpages;
David Howells
maintainerPATCH v7 8/29 netfs: Bulk load the readahead-provided folios up front
In reply to David HowellsLoad all the folios by the VM for readahead up front into the folio queue. With the number of folios provided by the VM, the folio queue can be fully allocated first and then the loading happen in one go inside the RCU read lock. The folio refs acquired from readahead are dropped in bulk once the first subrequest is dispatched as it's quite a slow operation. The collector waits for NETFS_RREQ_NEED_PUT_RA_REFS to be cleared so that it doesn't unlock folios before the xarray has been scanned for them.
This simplifies the buffer handling later and isn't noticeably slower as the xarray doesn't need to be modified and the folios are all already pre-locked.
--- fs/netfs/buffered_read.c | 99 ++++++++++++++++++++-------------- fs/netfs/internal.h | 1 + fs/netfs/misc.c | 19 +++++++ fs/netfs/read_collect.c | 7 +++ fs/netfs/rolling_buffer.c | 75 ++++++++++++++++++++++++++ include/linux/netfs.h | 1 + include/linux/rolling_buffer.h | 3 ++ include/trace/events/netfs.h | 3 ++ 8 files changed, 169 insertions(+), 39 deletions(-)
fs/netfs/buffered_read.c +60 -39
@@ -54,6 +54,42 @@ static void netfs_rreq_expand(struct netfs_io_request *rreq, } } +/* +* Drop the folio refs acquired from the readahead API. +*/ +static void netfs_bulk_drop_ra_refs (struct netfs_io_request *rreq) +{ +struct folio_batch fbatch; +struct folio *folio; +pgoff_t nr_pages =DIV_ROUND_UP (rreq->len,PAGE_SIZE ); +pgoff_t first = rreq->start /PAGE_SIZE ; +XA_STATE (xas, &rreq->mapping->i_pages, first); + +folio_batch_init (&fbatch); + +rcu_read_lock (); + +xas_for_each (&xas, folio, first + nr_pages -1 ) { +if (xas_retry (&xas, folio)) +continue ; + +if (!folio_batch_add (&fbatch, folio)) +folio_batch_release (&fbatch); + } + +rcu_read_unlock (); +folio_batch_release (&fbatch); +trace_netfs_rreq (rreq, netfs_rreq_trace_ra_put_ref); +clear_bit_unlock (NETFS_RREQ_NEED_PUT_RA_REFS , &rreq->flags); +wake_up (&rreq->waitq); +} + +static void netfs_maybe_bulk_drop_ra_refs (struct netfs_io_request *rreq) +{ +if (test_bit (NETFS_RREQ_NEED_PUT_RA_REFS , &rreq->flags)) +netfs_bulk_drop_ra_refs (rreq); +} +/* * Begin an operation, and fetch the stored zero point value from the cookie if * available.
@@ -74,12 +110,8 @@ static int netfs_begin_cache_read(struct netfs_io_request *rreq, struct netfs_in* * Returns the limited size if successful and -ENOMEM if insufficient memory * available. -* -* [!] NOTE: This must be run in the same thread as ->issue_read() was called -* in as we access the readahead_control struct. */ -static ssize_t netfs_prepare_read_iterator (struct netfs_io_subrequest *subreq, -struct readahead_control *ractl) +static ssize_t netfs_prepare_read_iterator (struct netfs_io_subrequest *subreq) {struct netfs_io_request *rreq = subreq->rreq;size_t rsize = subreq->len;
@@ -87,30 +119,6 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq,if (subreq->source ==NETFS_DOWNLOAD_FROM_SERVER ) rsize =umin (rsize, rreq->io_streams[0 ].sreq_max_len); -if (ractl) { -/* If we don't have sufficient folios in the rolling buffer, -* extract a folioq's worth from the readahead region at a time -* into the buffer. Note that this acquires a ref on each page -* that we will need to release later - but we don't want to do -* that until after we've started the I/O. -*/ -struct folio_batch put_batch; - -folio_batch_init (&put_batch); -while (rreq->submitted < subreq->start + rsize) { -ssize_t added; - - added =rolling_buffer_load_from_ra (&rreq->buffer, ractl, - &put_batch); -if (added <0 ) { -folio_batch_release (&put_batch); -return added; - } - rreq->submitted += added; - } -folio_batch_release (&put_batch); - } - subreq->len = rsize;if (unlikely (rreq->io_streams[0 ].sreq_max_segs)) { size_t limit = netfs_limit_iter(&rreq->buffer.iter, 0, rsize,
@@ -208,8 +216,7 @@ static void netfs_issue_read(struct netfs_io_request *rreq,* slicing up the region to be read according to available cache blocks and * network rsize. */ -static void netfs_read_to_pagecache (struct netfs_io_request *rreq, -struct readahead_control *ractl) +static void netfs_read_to_pagecache (struct netfs_io_request *rreq) {unsigned long long start = rreq->start;ssize_t size = rreq->len;
@@ -288,7 +295,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq,break ; issue: - slice =netfs_prepare_read_iterator (subreq, ractl); + slice =netfs_prepare_read_iterator (subreq);if (slice <0 ) { ret = slice;netfs_cancel_read (subreq, ret);
@@ -302,6 +309,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq, }netfs_issue_read (rreq, subreq); +netfs_maybe_bulk_drop_ra_refs (rreq);if (test_bit (NETFS_RREQ_PAUSE , &rreq->flags))netfs_wait_for_paused_read (rreq);
@@ -340,6 +348,7 @@ void netfs_readahead(struct readahead_control *ractl)struct netfs_io_request *rreq;struct netfs_inode *ictx =netfs_inode (ractl->mapping->host);unsigned long long start =readahead_pos (ractl); +ssize_t added;size_t size =readahead_length (ractl);int ret;
@@ -360,11 +369,23 @@ void netfs_readahead(struct readahead_control *ractl)netfs_rreq_expand (rreq, ractl); - rreq->submitted = rreq->start; -if (rolling_buffer_init (&rreq->buffer, rreq->debug_id,ITER_DEST ) <0 ) +/* Load the folios to be read into a bvecq chain. Note that this +* acquires a ref on each folio that we will need to release later - +* but we don't want to do that until after we've started the I/O. +*/ + added =rolling_buffer_bulk_load_from_ra (&rreq->buffer, ractl, rreq->debug_id); +if (added <0 ) { + ret = added; goto cleanup_free; -netfs_read_to_pagecache (rreq, ractl); + } +__set_bit (NETFS_RREQ_NEED_PUT_RA_REFS , &rreq->flags); + + rreq->submitted = rreq->start + added; + rreq->cleaned_to = rreq->start; + rreq->front_folio_order =folio_order (rreq->buffer.tail->vec.folios[0 ]); +netfs_read_to_pagecache (rreq); +netfs_maybe_bulk_drop_ra_refs (rreq);return netfs_put_request (rreq, netfs_rreq_trace_put_return); cleanup_free:
@@ -457,7 +478,7 @@ static int netfs_read_gaps(struct file *file, struct folio *folio)iov_iter_bvec (&rreq->buffer.iter,ITER_DEST , bvec, i, rreq->len); rreq->submitted = rreq->start + flen; -netfs_read_to_pagecache (rreq,NULL ); +netfs_read_to_pagecache (rreq); ret =netfs_wait_for_read (rreq);if (ret >=0 ) {
@@ -532,7 +553,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)if (ret <0 ) goto discard; -netfs_read_to_pagecache (rreq,NULL ); +netfs_read_to_pagecache (rreq); ret =netfs_wait_for_read (rreq);netfs_put_request (rreq, netfs_rreq_trace_put_return);return ret <0 ? ret :0 ;
@@ -689,7 +710,7 @@ int netfs_write_begin(struct netfs_inode *ctx,if (ret <0 ) goto error_put; -netfs_read_to_pagecache (rreq,NULL ); +netfs_read_to_pagecache (rreq); ret =netfs_wait_for_read (rreq);netfs_put_request (rreq, netfs_rreq_trace_put_return);if (ret <0 )
@@ -754,7 +775,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,if (ret <0 ) goto error_put; -netfs_read_to_pagecache (rreq,NULL ); +netfs_read_to_pagecache (rreq); ret =netfs_wait_for_read (rreq);netfs_put_request (rreq, netfs_rreq_trace_put_return);return ret <0 ? ret :0 ;
fs/netfs/internal.h +1 -0
@@ -78,6 +78,7 @@ ssize_t netfs_wait_for_read(struct netfs_io_request *rreq);ssize_t netfs_wait_for_write (struct netfs_io_request *rreq);void netfs_wait_for_paused_read (struct netfs_io_request *rreq);void netfs_wait_for_paused_write (struct netfs_io_request *rreq); +void netfs_wait_for_put_ra_refs (struct netfs_io_request *rreq);/* * objects.c
fs/netfs/misc.c +19 -0
@@ -563,3 +563,22 @@ void netfs_wait_for_paused_write(struct netfs_io_request *rreq) {return netfs_wait_for_pause (rreq, netfs_write_collection); } + +/* +* Wait for the readahead-acquired refs to be put. +*/ +void netfs_wait_for_put_ra_refs (struct netfs_io_request *rreq) +{ +DEFINE_WAIT (myself); + +for (;;) { +trace_netfs_rreq (rreq, netfs_rreq_trace_wait_put_ra_refs); +prepare_to_wait (&rreq->waitq, &myself,TASK_UNINTERRUPTIBLE ); +if (!test_bit (NETFS_RREQ_NEED_PUT_RA_REFS , &rreq->flags)) +break ; +schedule (); + } + +trace_netfs_rreq (rreq, netfs_rreq_trace_waited_put_ra_refs); +finish_wait (&rreq->waitq, &myself); +}
fs/netfs/read_collect.c +7 -0
@@ -118,6 +118,13 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq, slot =0 ; } +/* We have to wait for readahead refs to have been released before we +* can unlock any folios as the ref-dropper walks i_pages and the only +* thing preventing these folios from being removed is the folio lock. +*/ +if (test_bit (NETFS_RREQ_NEED_PUT_RA_REFS , &rreq->flags)) +netfs_wait_for_put_ra_refs (rreq); +for (;;) {struct folio *folio;unsigned long long fpos, fend;
fs/netfs/rolling_buffer.c +75 -0
81 lines not on this page · raw message
include/linux/netfs.h +1 -0
@@ -278,6 +278,7 @@ struct netfs_io_request {#define NETFS_RREQ_FOLIO_COPY_TO_CACHE 10/* Copy current folio to cache from read */ #define NETFS_RREQ_UPLOAD_TO_SERVER 11/* Need to write to the server */ #define NETFS_RREQ_USE_IO_ITER 12/* Use ->io_iter rather than ->i_pages */ +#define NETFS_RREQ_NEED_PUT_RA_REFS 17/* Need to put the folio refs RA gave us */ #define NETFS_RREQ_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark * write to cache on read */ const struct netfs_request_ops *netfs_ops;
include/linux/rolling_buffer.h +3 -0
@@ -48,6 +48,9 @@ int rolling_buffer_make_space(struct rolling_buffer *roll);ssize_t rolling_buffer_load_from_ra (struct rolling_buffer *roll,struct readahead_control *ractl,struct folio_batch *put_batch); +ssize_t rolling_buffer_bulk_load_from_ra (struct rolling_buffer *roll, +struct readahead_control *ractl, +unsigned int rreq_id);ssize_t rolling_buffer_append (struct rolling_buffer *roll,struct folio *folio,unsigned int flags);struct folio_queue *rolling_buffer_delete_spent (struct rolling_buffer *roll);
include/trace/events/netfs.h +3 -0
@@ -59,6 +59,7 @@ EM(netfs_rreq_trace_free, "FREE ") \ EM(netfs_rreq_trace_intr, "INTR ") \ EM(netfs_rreq_trace_ki_complete, "KI-CMPL") \ + EM(netfs_rreq_trace_ra_put_ref, "RA-PUT ") \ EM(netfs_rreq_trace_recollect, "RECLLCT") \ EM(netfs_rreq_trace_redirty, "REDIRTY") \EM (netfs_rreq_trace_resubmit,"RESUBMT" ) \
@@ -70,9 +71,11 @@ EM(netfs_rreq_trace_unpause, "UNPAUSE") \ EM(netfs_rreq_trace_wait_ip, "WAIT-IP") \ EM(netfs_rreq_trace_wait_pause, "--PAUSED--") \ + EM(netfs_rreq_trace_wait_put_ra_refs, "WAIT-P-RA") \ EM(netfs_rreq_trace_wait_quiesce, "WAIT-QUIESCE") \ EM(netfs_rreq_trace_waited_ip, "DONE-IP") \ EM(netfs_rreq_trace_waited_pause, "--UNPAUSED--") \ + EM(netfs_rreq_trace_waited_put_ra_refs, "DONE-P-RA") \ EM(netfs_rreq_trace_waited_quiesce, "DONE-QUIESCE") \ EM(netfs_rreq_trace_wake_ip, "WAKE-IP") \EM (netfs_rreq_trace_wake_queue,"WAKE-Q " ) \
David Howells
maintainerPATCH v7 9/29 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/linux/bvec.h +18 -0
@@ -343,4 +343,22 @@ static inline phys_addr_t bvec_phys(const struct bio_vec *bvec) return page_to_phys(bvec->bv_page) + bvec->bv_offset; } +/** +* bvec_kmap_partial - 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 *bvec_kmap_partial (struct bio_vec *bvec,size_t offset) +{ + offset += bvec->bv_offset; + +return kmap_local_page (bvec->bv_page + (offset >>PAGE_SHIFT )) + + (offset & ~PAGE_MASK ); +} +#endif /* __LINUX_BVEC_H */
David Howells
maintainerPATCH v7 10/29 iov_iter: Make iov_iter_get_pages*() wrap iov_iter_extract_pages()
In reply to David HowellsMake iov_iter_get_pages*() wrap iov_iter_extract_pages() for kernel iterator types (e.g. ITER_BVEC, ITER_FOLIOQ, ITER_XARRAY). The pages obtained have their refcounts incremented afterwards if they're not slab pages. ITER_KVEC is left returning -EFAULT.
--- lib/iov_iter.c | 164 ++++++------------------------------------------- 1 file changed, 19 insertions(+), 145 deletions(-)
lib/iov_iter.c +19 -145
@@ -910,118 +910,34 @@ static int want_pages_array(struct page ***res, size_t size,return count; } -static ssize_t iter_folioq_get_pages (struct iov_iter *iter, +/* +* Wrap iov_iter_extract_pages() and then pin the non-slab pages we got back. +* This only works for non-user iterator types as get_pages uses get_user_pages +* not pin_user_pages. +*/ +static ssize_t iter_get_kernel_pages (struct iov_iter *iter,struct page ***ppages,size_t maxsize,unsigned maxpages,size_t *_start_offset) { -const struct folio_queue *folioq = iter->folioq;struct page **pages; -unsigned int slot = iter->folioq_slot; -size_t extracted =0 , count = iter->count, iov_offset = iter->iov_offset; +ssize_t ret, done; -if (slot >=folioq_nr_slots (folioq)) { - folioq = folioq->next; - slot =0 ; -if (WARN_ON (iov_offset !=0 )) -return -EIO ; - } + ret =iov_iter_extract_pages (iter, ppages, maxsize, maxpages, +0 , _start_offset); +if (ret <=0 ) +return ret; - maxpages =want_pages_array (ppages, maxsize, iov_offset & ~PAGE_MASK , maxpages); -if (!maxpages) -return -ENOMEM ; - *_start_offset = iov_offset & ~PAGE_MASK ; pages = *ppages; +for (done = ret + *_start_offset; done >0 ; done -=PAGE_SIZE ) { +struct folio *folio =page_folio (*pages); -for (;;) { -struct folio *folio =folioq_folio (folioq, slot); -size_t offset = iov_offset, fsize =folioq_folio_size (folioq, slot); -size_t part =PAGE_SIZE - offset %PAGE_SIZE ; - -if (offset < fsize) { - part =umin (part,umin (maxsize - extracted, fsize - offset)); - count -= part; - iov_offset += part; - extracted += part; - - *pages =folio_page (folio, offset /PAGE_SIZE ); -get_page (*pages); - pages++; - maxpages--; - } - -if (maxpages ==0 || extracted >= maxsize) -break ; - -if (iov_offset >= fsize) { - iov_offset =0 ; - slot++; -if (slot ==folioq_nr_slots (folioq) && folioq->next) { - folioq = folioq->next; - slot =0 ; - } - } - } - - iter->count = count; - iter->iov_offset = iov_offset; - iter->folioq = folioq; - iter->folioq_slot = slot; -return extracted; -} - -static ssize_t iter_xarray_populate_pages (struct page **pages,struct xarray *xa, -pgoff_t index,unsigned int nr_pages) -{ -XA_STATE (xas, xa, index); -struct folio *folio; -unsigned int ret =0 ; - -rcu_read_lock (); -for (folio =xas_load (&xas); folio; folio =xas_next (&xas)) { -if (xas_retry (&xas, folio)) -continue ; - -/* Has the folio moved or been split? */ -if (unlikely (folio !=xas_reload (&xas))) { -xas_reset (&xas); -continue ; - } - - pages[ret] =folio_file_page (folio, xas.xa_index); -folio_get (folio); -if (++ret == nr_pages) -break ; +if (!folio_test_slab (folio)) +folio_get (folio); + pages++; } -rcu_read_unlock ();return ret; } -static ssize_t iter_xarray_get_pages (struct iov_iter *i, -struct page ***pages,size_t maxsize, -unsigned maxpages,size_t *_start_offset) -{ -unsigned nr, offset, count; -pgoff_t index; -loff_t pos; - - pos = i->xarray_start + i->iov_offset; - index = pos >>PAGE_SHIFT ; - offset = pos & ~PAGE_MASK ; - *_start_offset = offset; - - count =want_pages_array (pages, maxsize, offset, maxpages); -if (!count) -return -ENOMEM ; - nr =iter_xarray_populate_pages (*pages, i->xarray, index, count); -if (nr ==0 ) -return 0 ; - - maxsize =min_t (size_t, nr *PAGE_SIZE - offset, maxsize); - i->iov_offset += maxsize; - i->count -= maxsize; -return maxsize; -} -/* must be done on non-empty ITER_UBUF or ITER_IOVEC one */ static unsigned long first_iovec_segment (const struct iov_iter *i,size_t *size) {
@@ -1044,22 +960,6 @@ static unsigned long first_iovec_segment(const struct iov_iter *i, size_t *size)BUG ();// if it had been empty, we wouldn't get called } -/* must be done on non-empty ITER_BVEC one */ -static struct page *first_bvec_segment (const struct iov_iter *i, -size_t *size,size_t *start) -{ -struct page *page; -size_t skip = i->iov_offset, len; - - len = i->bvec->bv_len - skip; -if (*size > len) - *size = len; - skip += i->bvec->bv_offset; - page = i->bvec->bv_page + skip /PAGE_SIZE ; - *start = skip %PAGE_SIZE ; -return page; -} -static ssize_t __iov_iter_get_pages_alloc (struct iov_iter *i,struct page ***pages,size_t maxsize,unsigned int maxpages,size_t *start)
@@ -1095,36 +995,10 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i,iov_iter_advance (i, maxsize);return maxsize; } -if (iov_iter_is_bvec (i)) { -struct page **p; -struct page *page; - page =first_bvec_segment (i, &maxsize, start); - n =want_pages_array (pages, maxsize, *start, maxpages); -if (!n) -return -ENOMEM ; - p = *pages; -for (int k =0 ; k < n; k++) { -struct folio *folio =page_folio (page + k); - p[k] = page + k; -if (!folio_test_slab (folio)) -folio_get (folio); - } - maxsize =min_t (size_t, maxsize, n *PAGE_SIZE - *start); - i->count -= maxsize; - i->iov_offset += maxsize; -if (i->iov_offset == i->bvec->bv_len) { - i->iov_offset =0 ; - i->bvec++; - i->nr_segs--; - } -return maxsize; - } -if (iov_iter_is_folioq (i)) -return iter_folioq_get_pages (i, pages, maxsize, maxpages, start); -if (iov_iter_is_xarray (i)) -return iter_xarray_get_pages (i, pages, maxsize, maxpages, start); -return -EFAULT ; +if (iov_iter_is_kvec (i)) +return -EFAULT ; +return iter_get_kernel_pages (i, pages, maxsize, maxpages, start); } ssize_t iov_iter_get_pages2(struct iov_iter *i, struct page **pages,
David Howells
maintainerPATCH v7 11/29 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/bvecq.h | 56 +++++++ include/linux/iov_iter.h | 74 +++++++- include/linux/uio.h | 11 ++ lib/iov_iter.c | 334 ++++++++++++++++++++++++++++++++++++- lib/scatterlist.c | 67 +++++++- lib/tests/kunit_iov_iter.c | 260 +++++++++++++++++++++++++++++ 6 files changed, 796 insertions(+), 6 deletions(-) create mode 100644 include/linux/bvecq.h
include/linux/bvecq.h new file +56 -0
@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Implementation of a segmented queue of bio_vec[]. +* +* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#ifndef _LINUX_BVECQ_H +#define _LINUX_BVECQ_H + +#include <linux/bvec.h> + +/* +* The type of memory retention used by the elements in bvecq->bv[] and how to +* clean it up. +*/ +enum bvecq_mem { +BVECQ_MEM_EXTERNAL ,/* Externally retained memory - no freeing */ +BVECQ_MEM_PAGECACHE ,/* Ref'd pagecache pages - must put */ +BVECQ_MEM_GUP ,/* Pinned memory from get_user_pages() - unpin */ +BVECQ_MEM_ALLOCED ,/* Memory alloc'd by bvecq - can be freed/pooled */ +}__mode (byte ); + +/* +* 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 bio_vec 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_slots;/* Number of elements in bv[] used */ +u16 max_slots;/* Number of elements allocated in bv[] */ +enum bvecq_mem mem_type:3 ;/* What sort of memory and how to free it */ +bool inline_bv:1 ;/* T if __bv[] is being used */ +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_BVECQ_H */
include/linux/iov_iter.h +72 -2
104 lines not on this page · raw message
include/linux/uio.h +11 -0
@@ -26,6 +26,7 @@ enum iter_type {ITER_IOVEC ,ITER_BVEC ,ITER_KVEC , +ITER_BVECQ ,ITER_FOLIOQ ,ITER_XARRAY , ITER_DISCARD,
@@ -68,6 +69,7 @@ struct iov_iter {const struct iovec *__iov;const struct kvec *kvec;const struct bio_vec *bvec; +const struct bvecq *bvecq;const struct folio_queue *folioq;struct xarray *xarray;void __user *ubuf;
@@ -77,6 +79,7 @@ struct iov_iter { };union {unsigned long nr_segs; +u16 bvecq_slot;u8 folioq_slot;loff_t xarray_start; };
@@ -145,6 +148,11 @@ 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_bvecq (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_BVECQ ; +} +static inline bool iov_iter_is_folioq (const struct iov_iter *i) {return iov_iter_type (i) ==ITER_FOLIOQ ;
@@ -295,6 +303,9 @@ 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_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_folio_queue (struct iov_iter *i,unsigned int direction,const struct folio_queue *folioq,unsigned int first_slot,unsigned int offset,size_t count);
lib/iov_iter.c +332 -2
407 lines not on this page · raw message
lib/scatterlist.c +65 -2
91 lines not on this page · raw message
lib/tests/kunit_iov_iter.c +260 -0
290 lines not on this page · raw message
David Howells
maintainerPATCH v7 12/29 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 | 768 +++++++++++++++++++++++++++++++++++ fs/netfs/internal.h | 1 + fs/netfs/stats.c | 4 +- include/linux/bvecq.h | 302 ++++++++++++++ include/linux/netfs.h | 1 + include/trace/events/netfs.h | 24 ++ 7 files changed, 1100 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 +768 -0
768 lines not on this page · raw message
fs/netfs/internal.h +1 -0
@@ -170,6 +170,7 @@ 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);
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/bvecq.h +302 -0
306 lines not on this page · raw message
include/linux/netfs.h +1 -0
@@ -17,6 +17,7 @@#include <linux/workqueue.h> #include <linux/fs.h> #include <linux/pagemap.h> +#include <linux/bvecq.h> #include <linux/uio.h> #include <linux/rolling_buffer.h>
include/trace/events/netfs.h +24 -0
@@ -789,6 +789,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
maintainerPATCH v7 13/29 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 | 142 ++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 3 + 2 files changed, 145 insertions(+)
fs/netfs/iterator.c +142 -0
@@ -13,6 +13,148 @@#include <linux/netfs.h> #include "internal.h" +/** +* netfs_extract_iter - Extract virtually contiguous pages from an iterator into a bvecq +* @orig: The original iterator +* @max_len: Maximum number of bytes to extract +* @max_pages: Maximum number of pages to extract +* @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 virtually contiguous page fragments from the source iterator up to +* the given maxima 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 or partial success, the amount of data in the bvec is returned, +* the original iterator will have been advanced by the amount extracted. +* +* If an error occurs and no pages are extracted, an error will be returned and +* any allocated bvecq will be freed. If there is no data to be extracted (or +* @max_len or @max_pages are zero), a single empty bvecq will be returned. +* +* 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 max_len,size_t max_pages, +unsigned long long fpos,struct bvecq **_bvecq_head, +iov_iter_extraction_t extraction_flags) +{ +struct bvecq *bq_tail =NULL , *bq; +ssize_t ret =0 ; +size_t extracted =0 ; + +_enter ("{%u,%zx},%zx" , orig->iter_type, orig->count, max_len); + + *_bvecq_head =NULL ; +if (max_len > orig->count) + max_len = orig->count; +if (WARN_ON_ONCE (!max_len || !max_pages)) + goto alloc_empty; + + max_pages =iov_iter_npages (orig, max_pages); +if (!max_pages) + goto alloc_empty; + +do { + bq =bvecq_alloc_one (max_pages,GFP_NOFS ); +if (!bq) { + ret = -ENOMEM ; +break ; + } +if (user_backed_iter (orig)) + bq->mem_type =iov_iter_extract_will_pin (orig) ? +BVECQ_MEM_GUP :BVECQ_MEM_PAGECACHE ; + bq->fpos = fpos + extracted; + +if (bq_tail) +bvecq_append (bq_tail, bq); +else + *_bvecq_head = bq; + bq_tail = bq; + +if (max_len ==0 ) +break ; + +struct bio_vec *bv = bq->bv; +unsigned int slot =0 ; +do { +struct page **pages; +ssize_t got; +size_t offset; +size_t space = bq->max_slots - slot; +size_t bv_size =array_size (bq->max_slots,sizeof (*bv)); +size_t pg_size =array_size (space,sizeof (*pages)); + +/* 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. +*/ + pages = (void *)bv + bv_size - pg_size; + + got =iov_iter_extract_pages (orig, &pages, max_len, +min (space, max_pages), + extraction_flags, &offset); +if (got <0 ) { + ret = got; + goto out; + } + +if (got ==0 ) { +pr_err ("extract_pages gave nothing from %zu, %zu\n" , + extracted, max_len); + ret = -EIO ; + goto out; + } + +if (WARN (got > max_len, +"%s: extract_pages overrun %zd > %zu bytes\n" , + __func__, got, max_len)) { + ret = -EIO ; + goto out; + } + + extracted += got; + max_len -= got; + +do { +size_t len =umin (got,PAGE_SIZE - offset); + +BUG_ON (slot >= bq->max_slots); + +bvec_set_page (&bq->bv[slot], *pages++, len, offset); + slot++; + max_pages--; + got -= len; + offset =0 ; + }while (got >0 ); + +bvecq_filled_to (bq, slot); + }while (max_len >0 && max_pages >0 && !bvecq_is_full (bq)); + + }while (max_len >0 && max_pages >0 ); + +out: +if (extracted || ret ==0 ) +return extracted; +bvecq_put (*_bvecq_head); + *_bvecq_head =NULL ; +return ret; + +alloc_empty: + bq =bvecq_alloc_one (1 ,GFP_NOFS ); +if (!bq) +return -ENOMEM ; + *_bvecq_head = bq; +return 0 ; + +} +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
@@ -439,6 +439,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 max_len,size_t max_pages, +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
maintainerPATCH v7 14/29 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 | 35 +++++---- fs/afs/dir_edit.c | 42 +++++------ fs/afs/dir_search.c | 33 ++++----- fs/afs/inode.c | 2 +- fs/afs/internal.h | 6 +- fs/afs/symlink.c | 34 ++++----- fs/netfs/write_issue.c | 161 ++++++----------------------------------- 7 files changed, 92 insertions(+), 221 deletions(-)
fs/afs/dir.c +17 -18
@@ -140,9 +140,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); }/*
@@ -203,9 +203,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 ;
@@ -250,15 +250,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, -mapping_gfp_mask (dvnode->netfs.inode.i_mapping)); + ret =bvecq_expand_buffer (&dvnode->directory, &cur_size, i_size, +GFP_KERNEL ); 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
@@ -294,8 +293,8 @@ static 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)
@@ -483,7 +482,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) {
@@ -498,11 +497,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);
@@ -2228,8 +2227,8 @@ static int afs_dir_writepages(struct address_space *mapping, }if (test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags)) { -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);if (ret ==1 ) ret =0 ;/* Skipped write due to lock conflict. */
fs/afs/dir_edit.c +19 -23
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);
@@ -80,36 +79,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->nr_slots; 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 =bvec_kmap_partial (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 +1 -1
@@ -683,7 +683,7 @@ void afs_evict_inode(struct inode *inode)flush_delayed_work (&vnode->lock_work);netfs_wait_for_outstanding_io (inode);truncate_inode_pages_final (&inode->i_data); -netfs_free_folioq_buffer (vnode->directory); +bvecq_put (vnode->directory);if (vnode->symlink)afs_evict_symlink (vnode);
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 afs_symlink __rcu *symlink;/* Symlink content */ struct list_head wb_keys;/* List of keys available for writeback */ struct list_head pending_locks;/* locks waiting to be granted */
@@ -991,9 +991,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/afs/symlink.c +15 -19
@@ -56,7 +56,6 @@ void afs_evict_symlink(struct afs_vnode *vnode)void afs_init_new_symlink (struct afs_vnode *vnode,struct afs_operation *op) {struct afs_symlink *symlink = op->create.symlink; -size_t dsize =0 ;size_t size =strlen (symlink->content) +1 ;char *p;
@@ -66,13 +65,15 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)if (!fscache_cookie_enabled (netfs_i_cookie (&vnode->netfs)))return ; -if (netfs_alloc_folioq_buffer (NULL , &vnode->directory, &dsize, size, -mapping_gfp_mask (vnode->netfs.inode.i_mapping)) <0 ) + vnode->directory =bvecq_alloc_buffer (PAGE_SIZE ,GFP_KERNEL ); +if (!vnode->directory)return ; - vnode->directory_size = dsize; - p =kmap_local_folio (folioq_folio (vnode->directory,0 ),0 ); + vnode->directory_size = size; + p =bvec_kmap_partial (&vnode->directory->bv[0 ],0 );memcpy (p, symlink->content, size); +if (size <PAGE_SIZE ) +memset (p + size,0 ,PAGE_SIZE - size);kunmap_local (p);netfs_single_mark_inode_dirty (&vnode->netfs.inode); }
@@ -94,17 +95,12 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode) }if (!vnode->directory) { -size_t cur_size =0 ; - - ret =netfs_alloc_folioq_buffer (NULL , - &vnode->directory, &cur_size,PAGE_SIZE , -mapping_gfp_mask (vnode->netfs.inode.i_mapping)); - vnode->directory_size =PAGE_SIZE -1 ; -if (ret <0 ) -return ret; + vnode->directory =bvecq_alloc_buffer (PAGE_SIZE ,GFP_KERNEL ); +if (!vnode->directory) +return -ENOMEM ; } -iov_iter_folio_queue (&iter,ITER_DEST , vnode->directory,0 ,0 ,PAGE_SIZE ); +iov_iter_bvec_queue (&iter,ITER_DEST , vnode->directory,0 ,0 ,PAGE_SIZE );/* AFS requires us to perform the read of a symlink as a single unit to * avoid issues with the content being changed between reads.
@@ -127,7 +123,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode)refcount_set (&symlink->ref,1 ); symlink->content[i_size] =0 ; -const char *s =kmap_local_folio (folioq_folio (vnode->directory,0 ),0 ); +const char *s =bvec_kmap_partial (&vnode->directory->bv[0 ],0 );memcpy (symlink->content, s, i_size);kunmap_local (s);
@@ -136,7 +132,7 @@ static ssize_t afs_do_read_symlink(struct afs_vnode *vnode) }if (!fscache_cookie_enabled (netfs_i_cookie (&vnode->netfs))) { -netfs_free_folioq_buffer (vnode->directory); +bvecq_put (vnode->directory); vnode->directory =NULL ; vnode->directory_size =0 ; }
@@ -249,14 +245,14 @@ int afs_symlink_writepages(struct address_space *mapping,if (vnode->directory &&atomic64_read (&vnode->cb_expires_at) !=AFS_NO_CB_PROMISE ) { -iov_iter_folio_queue (&iter,ITER_SOURCE , vnode->directory,0 ,0 , -i_size_read (&vnode->netfs.inode)); +iov_iter_bvec_queue (&iter,ITER_SOURCE , vnode->directory,0 ,0 , +i_size_read (&vnode->netfs.inode)); ret =netfs_writeback_single (mapping, wbc, &iter); }if (ret ==0 ) {netfs_wb_begin (&vnode->netfs, false); -netfs_free_folioq_buffer (vnode->directory); +bvecq_put (vnode->directory); vnode->directory =NULL ; vnode->directory_size =0 ;netfs_wb_end (&vnode->netfs);
fs/netfs/write_issue.c +22 -139
200 lines not on this page · raw message
David Howells
maintainerPATCH v7 15/29 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 | 74 +++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 40 deletions(-)
fs/smb/client/cifsglob.h +1 -1
@@ -289,7 +289,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 +35 -39
162 lines not on this page · raw message
David Howells
maintainerPATCH v7 16/29 smbdirect: Support ITER_BVECQ in smbdirect_map_sges_from_iter()
In reply to David HowellsAdd support for ITER_BVECQ to smbdirect_map_sges_from_iter().
--- fs/smb/smbdirect/connection.c | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
fs/smb/smbdirect/connection.c +67 -0
@@ -5,6 +5,7 @@*/ #include "internal.h" +#include <linux/bvecq.h> #include <linux/folio_queue.h> struct smbdirect_map_sges {
@@ -2006,6 +2007,69 @@ static ssize_t smbdirect_map_sges_from_bvec(struct iov_iter *iter,return ret; } +/* +* Extract memory fragments from a BVECQ-class iterator and add them to an RDMA +* list. The fragments are not pinned. +*/ +static ssize_t smbdirect_map_sges_from_bvecq (struct iov_iter *iter, +struct smbdirect_map_sges *state, +ssize_t maxsize) +{ +const struct bvecq *bq = iter->bvecq, *next; +unsigned int slot = iter->bvecq_slot; +ssize_t extracted =0 ; +size_t offset = iter->iov_offset; + + maxsize =umin (maxsize,iov_iter_count (iter)); + +do { +struct bio_vec *bv; +size_t bsize; + +while (slot >= bq->nr_slots) { + next =bvecq_next (bq); +if (!next) { +if (WARN_ON_ONCE (maxsize >0 )) +return -EIO ; + goto out; + } + bq = next; + slot =0 ; + } + + bv = &bq->bv[slot]; + bsize = bv->bv_len; + +if (offset < bsize) { +size_t part =umin (maxsize, bsize - offset); +bool ok; + + ok =smbdirect_map_sges_single_page (state, + bv->bv_page, + bv->bv_offset + offset, + part); +if (!ok) +return -EIO ; + + offset += part; + extracted += part; + maxsize -= part; + } + +if (offset >= bsize) { + offset =0 ; + slot++; + } + }while (state->num_sge < state->max_sge && maxsize >0 ); + +out: + iter->bvecq = bq; + iter->bvecq_slot = slot; + iter->iov_offset = offset; + iter->count -= extracted; +return extracted; +} +/* * Extract fragments from a KVEC-class iterator and add them to an ib_sge list. * This can deal with vmalloc'd buffers as well as kmalloc'd or static buffers.
@@ -2155,6 +2219,9 @@ static ssize_t smbdirect_map_sges_from_iter(struct iov_iter *iter, size_t len,case ITER_BVEC : ret =smbdirect_map_sges_from_bvec (iter, state, len);break ; +case ITER_BVECQ : + ret =smbdirect_map_sges_from_bvecq (iter, state, len); +break ;case ITER_KVEC : ret =smbdirect_map_sges_from_kvec (iter, state, len);break ;
David Howells
maintainerPATCH v7 17/29 netfs: Remove the writethrough code
In reply to David HowellsRemove the netfs writethrough code as it's very tricky to get the locking right and it will probably deadlock if used in conjunction with Ceph snapshots because it excludes writeback for the duration, but to flush out old snapshots, it does a synchronous flush that invokes writeback.
Instead, O_SYNC writes do a flush after performing the write - which is already there as the callers of netfs_perform_write() all call generic_write_sync().
--- fs/9p/vfs_addr.c | 1 - fs/afs/file.c | 1 - fs/netfs/buffered_write.c | 56 ++----------------- fs/netfs/internal.h | 7 --- fs/netfs/main.c | 1 - fs/netfs/stats.c | 4 +- fs/netfs/write_collect.c | 2 - fs/netfs/write_issue.c | 104 +---------------------------------- include/linux/netfs.h | 1 - include/trace/events/netfs.h | 8 +-- 10 files changed, 9 insertions(+), 176 deletions(-)
fs/9p/vfs_addr.c +0 -1
@@ -124,7 +124,6 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)struct p9_fid *fid;struct dentry *dentry;bool writing = (rreq->origin ==NETFS_READ_FOR_WRITE || - rreq->origin ==NETFS_WRITETHROUGH || rreq->origin ==NETFS_UNBUFFERED_WRITE || rreq->origin ==NETFS_DIO_WRITE );
fs/afs/file.c +0 -1
@@ -400,7 +400,6 @@ static int afs_init_request(struct netfs_io_request *rreq, struct file *file) }break ;case NETFS_WRITEBACK : -case NETFS_WRITETHROUGH :case NETFS_UNBUFFERED_WRITE :case NETFS_DIO_WRITE :if (S_ISREG (rreq->inode->i_mode))
fs/netfs/buffered_write.c +5 -51
79 lines not on this page · raw message
fs/netfs/internal.h +0 -7
@@ -154,7 +154,6 @@ extern atomic_t netfs_n_rh_write_zskip;extern atomic_t netfs_n_rh_retry_read_req;extern atomic_t netfs_n_rh_retry_read_subreq;extern atomic_t netfs_n_wh_buffered_write; -extern atomic_t netfs_n_wh_writethrough;extern atomic_t netfs_n_wh_dio_write;extern atomic_t netfs_n_wh_writepages;extern atomic_t netfs_n_wh_copy_to_cache;
@@ -214,12 +213,6 @@ void netfs_issue_write(struct netfs_io_request *wreq,size_t netfs_advance_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream,loff_t start,size_t len,bool to_eof); -struct netfs_io_request *netfs_begin_writethrough (struct kiocb *iocb,size_t len); -int netfs_advance_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, -struct folio *folio,size_t copied,bool to_page_end, -struct folio **writethrough_cache); -ssize_t netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, -struct folio *writethrough_cache);/* * write_retry.c
fs/netfs/main.c +0 -1
@@ -43,7 +43,6 @@ static const char *netfs_origins[nr__netfs_io_origin] = { [NETFS_DIO_READ] = "DR", [NETFS_WRITEBACK] = "WB", [NETFS_WRITEBACK_SINGLE] = "W1", - [NETFS_WRITETHROUGH] = "WT", [NETFS_UNBUFFERED_WRITE] = "UW", [NETFS_DIO_WRITE] = "DW", [NETFS_PGPRIV2_COPY_TO_CACHE] = "2C",
fs/netfs/stats.c +1 -3
@@ -32,7 +32,6 @@ atomic_t netfs_n_rh_write_zskip;atomic_t netfs_n_rh_retry_read_req;atomic_t netfs_n_rh_retry_read_subreq;atomic_t netfs_n_wh_buffered_write; -atomic_t netfs_n_wh_writethrough;atomic_t netfs_n_wh_dio_write;atomic_t netfs_n_wh_writepages;atomic_t netfs_n_wh_copy_to_cache;
@@ -59,9 +58,8 @@ int netfs_stats_show(struct seq_file *m, void *v)atomic_read (&netfs_n_rh_read_single),atomic_read (&netfs_n_rh_write_begin), atomic_read(&netfs_n_rh_write_zskip)); -seq_printf (m,"Writes : BW=%u WT=%u DW=%u WP=%u 2C=%u\n" , +seq_printf (m,"Writes : BW=%u DW=%u WP=%u 2C=%u\n" ,atomic_read (&netfs_n_wh_buffered_write), -atomic_read (&netfs_n_wh_writethrough),atomic_read (&netfs_n_wh_dio_write),atomic_read (&netfs_n_wh_writepages),atomic_read (&netfs_n_wh_copy_to_cache));
fs/netfs/write_collect.c +0 -2
@@ -214,7 +214,6 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)smp_rmb (); collected_to =ULLONG_MAX ;if (wreq->origin ==NETFS_WRITEBACK || - wreq->origin ==NETFS_WRITETHROUGH || wreq->origin ==NETFS_PGPRIV2_COPY_TO_CACHE ) notes =NEED_UNLOCK ;else
@@ -411,7 +410,6 @@ bool netfs_write_collection(struct netfs_io_request *wreq)switch (wreq->origin) {case NETFS_WRITEBACK :case NETFS_WRITEBACK_SINGLE : -case NETFS_WRITETHROUGH :netfs_wb_end (ictx);break ;default :
fs/netfs/write_issue.c +1 -103
122 lines not on this page · raw message
include/linux/netfs.h +0 -1
@@ -210,7 +210,6 @@ enum netfs_io_origin {NETFS_DIO_READ ,/* This is a direct I/O read */ NETFS_WRITEBACK ,/* This write was triggered by writepages */ NETFS_WRITEBACK_SINGLE ,/* This monolithic write was triggered by writepages */ -NETFS_WRITETHROUGH ,/* This write was made by netfs_perform_write() */ NETFS_UNBUFFERED_WRITE ,/* This is an unbuffered write */ NETFS_DIO_WRITE ,/* This is a direct I/O write */ NETFS_PGPRIV2_COPY_TO_CACHE, /* [DEPRECATED] This is writing read data to the cache */
include/trace/events/netfs.h +2 -6
@@ -30,8 +30,7 @@ EM(netfs_write_trace_dio_write, "DIO-WRITE") \ EM(netfs_write_trace_unbuffered_write, "UNB-WRITE") \ EM(netfs_write_trace_writeback, "WRITEBACK") \ - EM(netfs_write_trace_writeback_single, "WB-SINGLE") \ - E_(netfs_write_trace_writethrough, "WRITETHRU") + E_(netfs_write_trace_writeback_single, "WB-SINGLE")#define netfs_rreq_origins \ EM(NETFS_READAHEAD, "RA") \
@@ -43,7 +42,6 @@ EM(NETFS_DIO_READ, "DR") \ EM(NETFS_WRITEBACK, "WB") \ EM(NETFS_WRITEBACK_SINGLE, "W1") \ - EM(NETFS_WRITETHROUGH, "WT") \ EM(NETFS_UNBUFFERED_WRITE, "UW") \ EM(NETFS_DIO_WRITE, "DW") \E_ (NETFS_PGPRIV2_COPY_TO_CACHE ,"2C" )
@@ -221,9 +219,7 @@ EM(netfs_folio_trace_redirtied, "redirtied") \ EM(netfs_folio_trace_store, "store") \ EM(netfs_folio_trace_store_copy, "store-copy") \ - EM(netfs_folio_trace_store_plus, "store+") \ - EM(netfs_folio_trace_wthru, "wthru") \ - E_(netfs_folio_trace_wthru_plus, "wthru+") + E_(netfs_folio_trace_store_plus, "store+")#define netfs_collect_contig_traces \ EM(netfs_contig_trace_collect, "Collect") \
David Howells
maintainerPATCH v7 18/29 cachefiles,netfs: sunset ondemand mode
In reply to David HowellsFrom: Gao Xiang <[email protected]>
It was an effort to enhance fscache as a kernel cache for lazy pulling (at least according to previous Incremental FS discussion [1]) and EROFS over fscache was the in-tree user of this mode.
fscache has since evolved to be netfslib-oriented, serving network filesystem inodes via the netfs library, but EROFS never acts as a network filesystem and we need to cache golden filesystem images rather than individual EROFS inodes.
Since EROFS over fscache is now removed, clean up netfs/fscache/ cachefiles upstream too.
[1] https://lore.kernel.org/r/CAOQ4uxi4dzxArY24YO=+kBCK2gGoq3Ptb8WkzCqSogPgU_R3dQ@mail.gmail.com
[dh] Fixed up comments on:
https://sashiko.dev/#/patchset/20260716103030.3065561-1-dhowells%40redhat.com
--- .../filesystems/caching/cachefiles.rst | 179 ---- fs/cachefiles/Kconfig | 12 - fs/cachefiles/Makefile | 1 - fs/cachefiles/daemon.c | 76 +- fs/cachefiles/interface.c | 8 - fs/cachefiles/internal.h | 129 --- fs/cachefiles/io.c | 26 +- fs/cachefiles/namei.c | 8 - fs/cachefiles/ondemand.c | 761 ------------------ include/linux/netfs.h | 9 - include/trace/events/cachefiles.h | 178 ---- 11 files changed, 5 insertions(+), 1382 deletions(-) delete mode 100644 fs/cachefiles/ondemand.c
Documentation/filesystems/caching/cachefiles.rst +0 -179
@@ -28,8 +28,6 @@ Cache on Already Mounted Filesystem (*) Debugging. - (*) On-demand Read. - Overview ========
@@ -483,180 +481,3 @@ the control file. For example:: echo $((1|4|8)) >/sys/module/cachefiles/parameters/debug will turn on all function entry debugging. - - -On-demand Read -============== - -When working in its original mode, CacheFiles serves as a local cache for a -remote networking fs - while in on-demand read mode, CacheFiles can boost the -scenario where on-demand read semantics are needed, e.g. container image -distribution. - -The essential difference between these two modes is seen when a cache miss -occurs: In the original mode, the netfs will fetch the data from the remote -server and then write it to the cache file; in on-demand read mode, fetching -the data and writing it into the cache is delegated to a user daemon. - -``CONFIG_CACHEFILES_ONDEMAND`` should be enabled to support on-demand read mode. - - -Protocol Communication ----------------------- - -The on-demand read mode uses a simple protocol for communication between kernel -and user daemon. The protocol can be modeled as:: - - kernel --[request]--> user daemon --[reply]--> kernel - -CacheFiles will send requests to the user daemon when needed. The user daemon -should poll the devnode ('/dev/cachefiles') to check if there's a pending -request to be processed. A POLLIN event will be returned when there's a pending -request. - -The user daemon then reads the devnode to fetch a request to process. It should -be noted that each read only gets one request. When it has finished processing -the request, the user daemon should write the reply to the devnode. - -Each request starts with a message header of the form:: - - struct cachefiles_msg { - __u32 msg_id; - __u32 opcode; - __u32 len; - __u32 object_id; - __u8 data[]; - }; - -where: - - * ``msg_id`` is a unique ID identifying this request among all pending - requests. - - * ``opcode`` indicates the type of this request. - - * ``object_id`` is a unique ID identifying the cache file operated on. - - * ``data`` indicates the payload of this request. - - * ``len`` indicates the whole length of this request, including the - header and following type-specific payload. - - -Turning on On-demand Mode -------------------------- - -An optional parameter becomes available to the "bind" command:: - - bind [ondemand] - -When the "bind" command is given no argument, it defaults to the original mode. -When it is given the "ondemand" argument, i.e. "bind ondemand", on-demand read -mode will be enabled. - - -The OPEN Request ----------------- - -When the netfs opens a cache file for the first time, a request with the -CACHEFILES_OP_OPEN opcode, a.k.a an OPEN request will be sent to the user -daemon. The payload format is of the form:: - - struct cachefiles_open { - __u32 volume_key_size; - __u32 cookie_key_size; - __u32 fd; - __u32 flags; - __u8 data[]; - }; - -where: - - * ``data`` contains the volume_key followed directly by the cookie_key. - The volume key is a NUL-terminated string; the cookie key is binary - data. - - * ``volume_key_size`` indicates the size of the volume key in bytes. - - * ``cookie_key_size`` indicates the size of the cookie key in bytes. - - * ``fd`` indicates an anonymous fd referring to the cache file, through - which the user daemon can perform write/llseek file operations on the - cache file. - - -The user daemon can use the given (volume_key, cookie_key) pair to distinguish -the requested cache file. With the given anonymous fd, the user daemon can -fetch the data and write it to the cache file in the background, even when -kernel has not triggered a cache miss yet. - -Be noted that each cache file has a unique object_id, while it may have multiple -anonymous fds. The user daemon may duplicate anonymous fds from the initial -anonymous fd indicated by the @fd field through dup(). Thus each object_id can -be mapped to multiple anonymous fds, while the usr daemon itself needs to -maintain the mapping. - -When implementing a user daemon, please be careful of RLIMIT_NOFILE, -``/proc/sys/fs/nr_open`` and ``/proc/sys/fs/file-max``. Typically these needn't -be huge since they're related to the number of open device blobs rather than -open files of each individual filesystem. - -The user daemon should reply the OPEN request by issuing a "copen" (complete -open) command on the devnode:: - - copen <msg_id>,<cache_size> - -where: - - * ``msg_id`` must match the msg_id field of the OPEN request. - - * When >= 0, ``cache_size`` indicates the size of the cache file; - when < 0, ``cache_size`` indicates any error code encountered by the - user daemon. - - -The CLOSE Request ------------------ - -When a cookie withdrawn, a CLOSE request (opcode CACHEFILES_OP_CLOSE) will be -sent to the user daemon. This tells the user daemon to close all anonymous fds -associated with the given object_id. The CLOSE request has no extra payload, -and shouldn't be replied. - - -The READ Request ----------------- - -When a cache miss is encountered in on-demand read mode, CacheFiles will send a -READ request (opcode CACHEFILES_OP_READ) to the user daemon. This tells the user -daemon to fetch the contents of the requested file range. The payload is of the -form:: - - struct cachefiles_read { - __u64 off; - __u64 len; - }; - -where: - - * ``off`` indicates the starting offset of the requested file range. - - * ``len`` indicates the length of the requested file range. - - -When it receives a READ request, the user daemon should fetch the requested data -and write it to the cache file identified by object_id. - -When it has finished processing the READ request, the user daemon should reply -by using the CACHEFILES_IOC_READ_COMPLETE ioctl on one of the anonymous fds -associated with the object_id given in the READ request. The ioctl is of the -form:: - - ioctl(fd, CACHEFILES_IOC_READ_COMPLETE, msg_id); - -where: - - * ``fd`` is one of the anonymous fds associated with the object_id - given. - - * ``msg_id`` must match the msg_id field of the READ request.
fs/cachefiles/Kconfig +0 -12
@@ -26,15 +26,3 @@ config CACHEFILES_ERROR_INJECTION help This permits error injection to be enabled in cachefiles whilst a cache is in service. - -config CACHEFILES_ONDEMAND - bool "Support for on-demand read" - depends on CACHEFILES - default n - help - This permits userspace to enable the cachefiles on-demand read mode. - In this mode, when a cache miss occurs, responsibility for fetching - the data lies with the cachefiles backend instead of with the netfs - and is delegated to userspace. - - If unsure, say N.
fs/cachefiles/Makefile +0 -1
@@ -16,6 +16,5 @@ cachefiles-y := \ xattr.o cachefiles-$(CONFIG_CACHEFILES_ERROR_INJECTION) += error_inject.o -cachefiles-$(CONFIG_CACHEFILES_ONDEMAND) += ondemand.o obj-$(CONFIG_CACHEFILES) := cachefiles.o
fs/cachefiles/daemon.c +4 -72
123 lines not on this page · raw message
fs/cachefiles/interface.c +0 -8
@@ -32,11 +32,6 @@ struct cachefiles_object *cachefiles_alloc_object(struct fscache_cookie *cookie)if (!object)return NULL ; -if (cachefiles_ondemand_init_obj_info (object, volume)) { -kmem_cache_free (cachefiles_object_jar, object); -return NULL ; - } -refcount_set (&object->ref,1 );spin_lock_init (&object->lock);
@@ -94,7 +89,6 @@ void cachefiles_put_object(struct cachefiles_object *object, ASSERTCMP(object->file, ==, NULL);kfree (object->d_name); -cachefiles_ondemand_deinit_obj_info (object); cache = object->volume->cache->cache;fscache_put_cookie (object->cookie, fscache_cookie_put_object); object->cookie =NULL ;
@@ -374,8 +368,6 @@ static void cachefiles_withdraw_cookie(struct fscache_cookie *cookie)spin_unlock (&cache->object_list_lock); } -cachefiles_ondemand_clean_object (object); -if (object->file) {cachefiles_begin_secure (cache, &saved_cred);cachefiles_clean_up_object (object, cache);
fs/cachefiles/internal.h +0 -129
174 lines not on this page · raw message
fs/cachefiles/io.c +1 -25
@@ -390,7 +390,6 @@ cachefiles_do_prepare_read(struct netfs_cache_resources *cres,size_t len = *_len;loff_t off, to;ino_t ino = file ?file_inode (file)->i_ino :0 ; -int rc;_enter ("%zx @%llx/%llx" , len, start, i_size);
@@ -403,8 +402,7 @@ cachefiles_do_prepare_read(struct netfs_cache_resources *cres,if (test_bit (FSCACHE_COOKIE_NO_DATA_TO_READ , &cookie->flags)) {__set_bit (NETFS_SREQ_COPY_TO_CACHE , _flags); why = cachefiles_trace_read_no_data; -if (!test_bit (NETFS_SREQ_ONDEMAND , _flags)) - goto out_no_object; + goto out_no_object; }/* The object and the file may be being created in the background. */
@@ -421,7 +419,6 @@ cachefiles_do_prepare_read(struct netfs_cache_resources *cres, object =cachefiles_cres_object (cres); cache = object->volume->cache;cachefiles_begin_secure (cache, &saved_cred); -retry: off =cachefiles_inject_read_error ();if (off ==0 ) off =vfs_llseek (file, start,SEEK_DATA );
@@ -474,14 +471,6 @@ cachefiles_do_prepare_read(struct netfs_cache_resources *cres, download_and_store:__set_bit (NETFS_SREQ_COPY_TO_CACHE , _flags); -if (test_bit (NETFS_SREQ_ONDEMAND , _flags)) { - rc =cachefiles_ondemand_read (object, start, len); -if (!rc) { -__clear_bit (NETFS_SREQ_ONDEMAND , _flags); - goto retry; - } - ret =NETFS_INVALID_READ ; - } out:cachefiles_end_secure (cache, saved_cred); out_no_object:
@@ -501,18 +490,6 @@ static enum netfs_io_source cachefiles_prepare_read(struct netfs_io_subrequest * &subreq->flags, subreq->rreq->inode->i_ino); } -/* -* Prepare an on-demand read operation, shortening it to a cached/uncached -* boundary as appropriate. -*/ -static enum netfs_io_source -cachefiles_prepare_ondemand_read (struct netfs_cache_resources *cres, -loff_t start,size_t *_len,loff_t i_size, -unsigned long *_flags,ino_t ino) -{ -return cachefiles_do_prepare_read (cres, start, _len, i_size, _flags, ino); -} -/* * Prepare for a write to occur. */
@@ -731,7 +708,6 @@ static const struct netfs_cache_ops cachefiles_netfs_cache_ops = { .prepare_read = cachefiles_prepare_read, .prepare_write = cachefiles_prepare_write, .prepare_write_subreq = cachefiles_prepare_write_subreq, - .prepare_ondemand_read = cachefiles_prepare_ondemand_read, .query_occupancy = cachefiles_query_occupancy, };
fs/cachefiles/namei.c +0 -8
@@ -442,10 +442,6 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)if (!cachefiles_mark_inode_in_use (object,file_inode (file)))WARN_ON (1 ); - ret =cachefiles_ondemand_init_object (object); -if (ret <0 ) - goto err_unuse; - ni_size = object->cookie->object_size; ni_size =round_up (ni_size,CACHEFILES_DIO_BLOCK_SIZE );
@@ -546,10 +542,6 @@ static bool cachefiles_open_file(struct cachefiles_object *object, }_debug ("file -> %pd positive" , dentry); - ret =cachefiles_ondemand_init_object (object); -if (ret <0 ) - goto error_fput; - ret =cachefiles_check_auxdata (object, file);if (ret <0 ) goto check_failed;
fs/cachefiles/ondemand.c deleted +0 -761
761 lines not on this page · raw message
include/linux/netfs.h +0 -9
@@ -192,7 +192,6 @@ struct netfs_io_subrequest {#define NETFS_SREQ_COPY_TO_CACHE 0/* Set if should copy the data to the cache */ #define NETFS_SREQ_CLEAR_TAIL 1/* Set if the rest of the read should be cleared */ #define NETFS_SREQ_MADE_PROGRESS 4/* Set if we transferred at least some data */ -#define NETFS_SREQ_ONDEMAND 5/* Set if it's from on-demand read mode */ #define NETFS_SREQ_BOUNDARY 6/* Set if ends on hard boundary (eg. ceph object) */ #define NETFS_SREQ_HIT_EOF 7/* Set if short due to EOF */ #define NETFS_SREQ_IN_PROGRESS 8/* Unlocked when the subrequest completes */
@@ -374,14 +373,6 @@ struct netfs_cache_ops { loff_t *_start, size_t *_len, size_t upper_len, loff_t i_size, bool no_space_allocated_yet); -/* Prepare an on-demand read operation, shortening it to a cached/uncached -* boundary as appropriate. -*/ -enum netfs_io_source (*prepare_ondemand_read)(struct netfs_cache_resources *cres, -loff_t start,size_t *_len, -loff_t i_size, -unsigned long *_flags,ino_t ino); -/* Query the occupancy of the cache in a region, returning where the * next chunk of data starts and how long it is. */
include/trace/events/cachefiles.h +0 -178
196 lines not on this page · raw message
David Howells
maintainerPATCH v7 19/29 cachefiles: Don't rely on backing fs storage map for most use cases
In reply to David HowellsCachefiles currently uses the backing filesystem's idea of what data is held in a backing file and queries this by means of SEEK_DATA and SEEK_HOLE. However, this means it does two seek operations on the backing file for each individual read call it wants to prepare (unless the first returns -ENXIO). Worse, the backing filesystem is at liberty to insert or remove blocks of zeros in order to optimise its layout which may cause false positives and false negatives.
The problem is that keeping track of what is dirty is tricky (if storing info in xattrs, which may have limited capacity and must be read and written as one piece) and expensive (in terms of diskspace at least) and is basically duplicating what a filesystem does.
However, the most common write case, in which the application does { open(O_TRUNC); write(); write(); ... write(); close(); } where each write follows directly on from the previous and leaves no gaps in the file is reasonably easy to detect and can be noted in the primary xattr as CACHEFILES_CONTENT_ALL, indicating we have everything up to the object size stored.
In this specific case, given that it is known that there are no holes in the file, there's no need to call SEEK_DATA/HOLE or use any other mechanism to track the contents. That speeds things up enormously.
Even when it is necessary to use SEEK_DATA/HOLE, it may not be necessary to call it for each cache read subrequest generated.
Implement this by adding support for the CACHEFILES_CONTENT_ALL content type (which is defined, but currently unused), which requires a slight adjustment in how backing files are managed. Specifically, the driver needs to know how much of the tail block is data and whether storing more data will create a hole.
To this end, the way that the size of a backing file is managed is changed. Currently, the backing file is expanded to strictly match the size of the network file, but this can be changed to carry more useful information. This makes two pieces of metadata available: xattr.object_size and the backing file's i_size. Apply the following schema:
(a) i_size is always a multiple of the DIO block size.
(b) i_size is only updated to the end of the highest write stored. This is used to work out if we are following on without leaving a hole.
(c) xattr.object_size is the size of the network filesystem file cached in this backing file.
(d) xattr.object_size must point after the start of the last block (unless both are 0).
(e) If xattr.object_size is at or after the block at the current end of the backing file (ie. i_size), then we have all the contents of the block (if xattr.content == CACHEFILES_CONTENT_ALL).
(f) If xattr.object_size is somewhere in the middle of the last block, then the data following it is invalid and must be ignored.
(g) If data is added to the last block, then that block must be fetched, modified and rewritten (it must be a buffered write through the pagecache and not DIO).
(h) Writes to cache are rounded out to blocks on both sides and the folios used as sources must contain data for any lower gap and must have been cleared for any upper gap, and so will rewrite any non-data area in the tail block.
To implement this, the following changes are made:
(1) cookie->object_size is no longer updated when writes are copied into the pagecache, but rather only updated when a write request completes.
This prevents object size miscomparison when checking the xattr causing the backing file to be invalidated (opening and marking the backing file and modifying the pagecache run in parallel).
(2) The cache's current idea of the amount of data that should be stored
in the backing file is kept track of in object->object_size.
Possibly this is redundant with cookie->object_size, but the latter
gets updated in some addition circumstances. (3) The size of the backing file at the start of a request is now tracked in struct netfs_cache_resources so that the partial EOF block can be located and cleaned.
(4) The cache block size is now used consistently rather than using
CACHEFILES_DIO_BLOCK_SIZE (4096).
(5) The backing file size is no longer adjusted when looking up an object.
(6) When shortening a file, if the new size is not block aligned, the part beyond the new size is cleared. If the file is truncated to zero, the content_info gets reset to CACHEFILES_CONTENT_NO_DATA.
(7) A new struct, fscache_occupancy, is instituted to track the region being read. Netfslib allocates it and fills in the start and end of the region to be read then calls the ->query_occupancy() method to find and fill in the extents. It also indicates whether a recorded extent contains data or just contains a region that's all zeros (FSCACHE_EXTENT_DATA or FSCACHE_EXTENT_ZERO).
(8) The ->prepare_read() cache method is changed such that, if given, it just limits the amount that can be read from the cache in one go. It no longer indicates what source of read should be done; that information is now obtained from ->query_occupancy().
(9) A new cache method, ->collect_write(), is added that is called when a contiguous series of writes have completed and a discontiguity or the end of the request has been hit. It it supplied with the start and length of the write made to the backing file and can use this information to update the cache metadata.
(10) cachefiles_query_occupancy() is altered to find the next two "extents" of data stored in the backing file by doing SEEK_DATA/HOLE between the bounds set - unless it is known that there are no holes, in which case a whole-file first extent can be set.
(11) cachefiles_collect_write() is implemented to take the collated write completion information and use this to update the cache metadata, in particular working out whether there's now a hole in the backing file requiring future use of SEEK_DATA/HOLE instead of just assuming the data is all present.
It also uses fallocate(FALLOC_FL_ZERO_RANGE) to clean the part of a partial block that extended beyond the old object size. It might be better to perform a synchronous DIO write for this purpose, but that would mandate an RMW cycle. Ideally, it should be all zeros anyway, but, unfortunately, shared-writable mmap can interfere.
(12) cachefiles_begin_operation() is updated to note the current backing file size and the cache DIO size.
(13) cachefiles_create_tmpfile() no longer expands the backing file when it creates it.
(14) cachefiles_set_object_xattr() is changed to use object->object_size
rather than cookie->object_size.
(15) cachefiles_check_auxdata() is altered to actually store the content type and to also set object->object_size. The cachefiles_coherency tracepoint is also modified to display xattr.object_size.
(16) netfs_read_to_pagecache() is reworked. The cache ->prepare_read() method is replaced with ->query_occupancy() as the arbiter of what region of the file is read from where, and that retrieves up to two occupied extents of the backing file at once.
The cache ->prepare_read() method is now repurposed to be the same as the equivalent network filesystem method and allows the cache to limit the size of the read before the iterator is prepared.
netfs_single_dispatch_read() is similarly modified.
(17) netfs_update_i_size() and afs_update_i_size() no longer call
fscache_update_cookie() to update cookie->object_size.
(18) Write collection now collates contiguous sequences of writes to the
cache and calls the cache ->collect_write() method.
--- fs/afs/file.c | 1 - fs/cachefiles/interface.c | 90 ++------- fs/cachefiles/internal.h | 13 +- fs/cachefiles/io.c | 312 +++++++++++++++++++++++------- fs/cachefiles/namei.c | 19 +- fs/cachefiles/xattr.c | 24 ++- fs/netfs/buffered_read.c | 176 +++++++++++------ fs/netfs/buffered_write.c | 3 - fs/netfs/internal.h | 2 + fs/netfs/read_retry.c | 2 + fs/netfs/read_single.c | 39 ++-- fs/netfs/write_collect.c | 132 ++++++++++--- fs/netfs/write_issue.c | 18 ++ fs/netfs/write_retry.c | 3 + include/linux/fscache.h | 17 ++ include/linux/netfs.h | 40 +++- include/trace/events/cachefiles.h | 17 +- include/trace/events/netfs.h | 9 +- 18 files changed, 631 insertions(+), 286 deletions(-)
fs/afs/file.c +0 -1
@@ -447,7 +447,6 @@ void afs_set_i_size(struct afs_vnode *vnode, loff_t new_i_size) }spin_unlock (&inode->i_lock);write_sequnlock (&vnode->cb_lock); -fscache_update_cookie (afs_vnode_cache (vnode),NULL , &new_i_size); }static void afs_update_i_size (struct inode *inode,loff_t new_i_size)
fs/cachefiles/interface.c +16 -74
131 lines not on this page · raw message
fs/cachefiles/internal.h +8 -5
@@ -17,8 +17,6 @@#include <linux/security.h> #include <linux/cachefiles.h> -#define CACHEFILES_DIO_BLOCK_SIZE 4096 -struct cachefiles_cache ;struct cachefiles_object ;
@@ -52,12 +50,17 @@ struct cachefiles_object {struct list_head cache_link;/* Link in cache->*_list */ struct file *file;/* The file representing this object */ char *d_name;/* Backing file name */ +unsigned long flags; +#define CACHEFILES_OBJECT_USING_TMPFILE 0/* Have an unlinked tmpfile */ +unsigned long long object_size;/* Size of the object stored +* (independent of cookie->object_size for +* coherency reasons) +*/ +atomic64_t read_limit;/* Point beyond which uncommitted writes */ int debug_id;spinlock_t lock;refcount_t ref; - enum cachefiles_content content_info:8; /* Info about content presence */ -unsigned long flags; -#define CACHEFILES_OBJECT_USING_TMPFILE 0/* Have an unlinked tmpfile */ +enum cachefiles_content content_info;/* Info about content presence */ };/*
fs/cachefiles/io.c +247 -65
412 lines not on this page · raw message
fs/cachefiles/namei.c +1 -18
@@ -414,7 +414,6 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)struct dentry *fan = volume->fanout[(u8 )object->cookie->key_hash];struct file *file;const struct path parentpath = { .mnt = cache->mnt, .dentry = fan }; -uint64_t ni_size;long ret;
@@ -442,23 +441,6 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)if (!cachefiles_mark_inode_in_use (object,file_inode (file)))WARN_ON (1 ); - ni_size = object->cookie->object_size; - ni_size =round_up (ni_size,CACHEFILES_DIO_BLOCK_SIZE ); - -if (ni_size >0 ) { -trace_cachefiles_trunc (object,file_inode (file),0 , ni_size, - cachefiles_trunc_expand_tmpfile); - ret =cachefiles_inject_write_error (); -if (ret ==0 ) - ret =vfs_truncate (&file->f_path, ni_size); -if (ret <0 ) { -trace_cachefiles_vfs_error ( - object,file_inode (file), ret, - cachefiles_trace_trunc_error); - goto err_unuse; - } - } - ret = -EINVAL ;if (unlikely (!file->f_op->read_iter) ||unlikely (!file->f_op->write_iter)) {
@@ -467,6 +449,7 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) } out:cachefiles_end_secure (cache, saved_cred); + object->content_info =CACHEFILES_CONTENT_ALL ;return file; err_unuse:
fs/cachefiles/xattr.c +18 -6
@@ -54,7 +54,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)if (!buf)return -ENOMEM ; - buf->object_size =cpu_to_be64 (object->cookie->object_size); + buf->object_size =cpu_to_be64 (object->object_size); buf->zero_point =0 ; buf->type =CACHEFILES_COOKIE_TYPE_DATA ; buf->content = object->content_info;
@@ -77,6 +77,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)trace_cachefiles_vfs_error (object,file_inode (file), ret, cachefiles_trace_setxattr_error);trace_cachefiles_coherency (object,file_inode (file)->i_ino, + object->object_size,be64_to_cpup ((__be64 *)buf->data), buf->content, cachefiles_coherency_set_fail);
@@ -86,6 +87,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object) "Failed to set xattr with error %d", ret); }else {trace_cachefiles_coherency (object,file_inode (file)->i_ino, + object->object_size,be64_to_cpup ((__be64 *)buf->data), buf->content, cachefiles_coherency_set_ok);
@@ -103,9 +105,11 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file {struct cachefiles_xattr *buf;struct dentry *dentry = file->f_path.dentry; +struct inode *inode =file_inode (file);unsigned int len = object->cookie->aux_len, tlen;const void *p =fscache_get_aux (object->cookie);enum cachefiles_coherency_trace why; +unsigned long long obj_size;ssize_t xlen;int ret = -ESTALE ;
@@ -120,36 +124,41 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *fileif (xlen != tlen) {if (xlen <0 ) { ret = xlen; -trace_cachefiles_vfs_error (object,file_inode (file), xlen, +trace_cachefiles_vfs_error (object, inode, xlen, cachefiles_trace_getxattr_error); }if (xlen == -EIO )cachefiles_io_error_obj ( object,"Failed to read aux with error %zd" , xlen); - why = cachefiles_coherency_check_xattr; +trace_cachefiles_coherency (object, inode->i_ino,0 ,0 ,0 , + cachefiles_coherency_check_xattr); goto out; } + obj_size =be64_to_cpu (buf->object_size);if (buf->type !=CACHEFILES_COOKIE_TYPE_DATA ) { why = cachefiles_coherency_check_type; }else if (memcmp (buf->data, p, len) !=0 ) { why = cachefiles_coherency_check_aux; - }else if (be64_to_cpu (buf->object_size) != object->cookie->object_size) { + }else if (obj_size != object->cookie->object_size) { why = cachefiles_coherency_check_objsize; }else if (buf->content ==CACHEFILES_CONTENT_DIRTY ) {// TODO: Begin conflict resolution pr_warn ("Dirty object in cache\n" ); why = cachefiles_coherency_check_dirty; }else { + object->content_info = buf->content; + object->object_size = obj_size; +atomic64_set (&object->read_limit,i_size_read (inode)); why = cachefiles_coherency_check_ok; ret =0 ; } -out: -trace_cachefiles_coherency (object,file_inode (file)->i_ino, +trace_cachefiles_coherency (object, inode->i_ino, obj_size,be64_to_cpup ((__be64 *)buf->data), buf->content, why); +out:kfree (buf);return ret; }
@@ -163,6 +172,9 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, {int ret; +trace_cachefiles_coherency (object,d_inode (dentry)->i_ino,0 ,0 ,0 , + cachefiles_coherency_remove); + ret =cachefiles_inject_remove_error ();if (ret ==0 ) { ret =mnt_want_write (cache->mnt);
fs/netfs/buffered_read.c +113 -63
224 lines not on this page · raw message
fs/netfs/buffered_write.c +0 -3
@@ -54,9 +54,6 @@ void netfs_update_i_size(struct netfs_inode *ctx, struct inode *inode, i_size =i_size_read (inode);if (end > i_size) {i_size_write (inode, end); -#if IS_ENABLED (CONFIG_FSCACHE ) -fscache_update_cookie (ctx->cache,NULL , &end); -#endif gap =SECTOR_SIZE - (i_size & (SECTOR_SIZE -1 ));if (copied > gap) {
fs/netfs/internal.h +2 -0
@@ -23,6 +23,8 @@/* * buffered_read.c */ +int netfs_read_query_cache (struct netfs_io_request *rreq, +struct fscache_occupancy *occ);void netfs_queue_read (struct netfs_io_request *rreq,struct netfs_io_subrequest *subreq);void netfs_cache_read_terminated (void *priv,ssize_t transferred_or_error);
fs/netfs/read_retry.c +2 -0
@@ -272,6 +272,7 @@ void netfs_retry_reads(struct netfs_io_request *rreq)struct netfs_io_stream *stream = &rreq->io_streams[0 ];netfs_stat (&netfs_n_rh_retry_read_req); +trace_netfs_rreq (rreq, netfs_rreq_trace_retry_begin);/* Wait for all outstanding I/O to quiesce before performing retries as * we may need to renegotiate the I/O sizes.
@@ -282,6 +283,7 @@ void netfs_retry_reads(struct netfs_io_request *rreq)trace_netfs_rreq (rreq, netfs_rreq_trace_resubmit);netfs_retry_read_subrequests (rreq); +trace_netfs_rreq (rreq, netfs_rreq_trace_retry_end); }/*
fs/netfs/read_single.c +23 -16
@@ -58,20 +58,6 @@ static int netfs_single_begin_cache_read(struct netfs_io_request *rreq, struct nreturn fscache_begin_read_operation (&rreq->cache_resources,netfs_i_cookie (ctx)); } -static void netfs_single_cache_prepare_read (struct netfs_io_request *rreq, -struct netfs_io_subrequest *subreq) -{ -struct netfs_cache_resources *cres = &rreq->cache_resources; - -if (!cres->ops) { - subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; -return ; - } - subreq->source = cres->ops->prepare_read (subreq, rreq->i_size); -trace_netfs_sreq (subreq, netfs_sreq_trace_prepare); - -} -static void netfs_single_read_cache (struct netfs_io_request *rreq,struct netfs_io_subrequest *subreq) {
@@ -89,6 +75,14 @@ static void netfs_single_read_cache(struct netfs_io_request *rreq,*/ static int netfs_single_dispatch_read (struct netfs_io_request *rreq) { +struct fscache_occupancy occ = { + .query_from =0 , + .query_to = rreq->len, + .cached_from[0 ] =ULLONG_MAX , + .cached_to[0 ] =ULLONG_MAX , + .cached_from[1 ] =ULLONG_MAX , + .cached_to[1 ] =ULLONG_MAX , + };struct netfs_io_subrequest *subreq;int ret =0 ;
@@ -96,14 +90,21 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)if (!subreq)return -ENOMEM ; - subreq->source =NETFS_SOURCE_UNKNOWN ; + subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->start =0 ; subreq->len = rreq->len; subreq->io_iter = rreq->buffer.iter;netfs_queue_read (rreq, subreq); -netfs_single_cache_prepare_read (rreq, subreq); +/* Try to use the cache if the cache content matches the size of the +* remote file. +*/ +netfs_read_query_cache (rreq, &occ); +if (occ.cached_from[0 ] ==0 && + occ.cached_to[0 ] >= rreq->len) + subreq->source =NETFS_READ_FROM_CACHE ; +switch (subreq->source) {case NETFS_DOWNLOAD_FROM_SERVER :netfs_stat (&netfs_n_rh_download);
@@ -119,6 +120,12 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq) rreq->submitted += subreq->len;break ;case NETFS_READ_FROM_CACHE : +if (rreq->cache_resources.ops->prepare_read) { + ret = rreq->cache_resources.ops->prepare_read (subreq); +if (ret <0 ) + goto cancel; + } +smp_wmb ();/* Write lists before ALL_QUEUED. */ set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags);trace_netfs_sreq (subreq, netfs_sreq_trace_submit);
fs/netfs/write_collect.c +110 -22
194 lines not on this page · raw message
fs/netfs/write_issue.c +18 -0
@@ -111,6 +111,8 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping, goto nomem; wreq->cleaned_to = wreq->start; +if (wreq->cache_resources.dio_size >1 ) + wreq->cache_coll_to =round_down (wreq->start, wreq->cache_resources.dio_size); wreq->io_streams[0 ].stream_nr =0 ; wreq->io_streams[0 ].source =NETFS_UPLOAD_TO_SERVER ;
@@ -230,6 +232,21 @@ static void netfs_do_issue_write(struct netfs_io_stream *stream,_enter ("R=%x[%x],%zx" , wreq->debug_id, subreq->debug_index, subreq->len); +if (stream->source ==NETFS_WRITE_TO_CACHE && +unlikely (test_bit (NETFS_RREQ_CACHE_STOP , &wreq->flags))) { +size_t dio_size = wreq->cache_resources.dio_size; +size_t len, disp; + + disp = subreq->start & (dio_size -1 ); + len =round_up (subreq->len + disp, dio_size); + + subreq->start -= disp; + subreq->len = len; + +__set_bit (NETFS_SREQ_CANCELLED , &subreq->flags); +return netfs_write_subrequest_terminated (subreq, subreq->len); + } +if (test_bit (NETFS_SREQ_FAILED , &subreq->flags))return netfs_write_subrequest_terminated (subreq, subreq->error);
@@ -263,6 +280,7 @@ void netfs_issue_write(struct netfs_io_request *wreq,if (!subreq)return ; + stream->construct =NULL ; subreq->io_iter.count = subreq->len;netfs_do_issue_write (stream, subreq);
fs/netfs/write_retry.c +3 -0
@@ -211,6 +211,7 @@ void netfs_retry_writes(struct netfs_io_request *wreq)int s;netfs_stat (&netfs_n_wh_retry_write_req); +trace_netfs_rreq (wreq, netfs_rreq_trace_retry_begin);/* Wait for all outstanding I/O to quiesce before performing retries as * we may need to renegotiate the I/O sizes.
@@ -235,4 +236,6 @@ void netfs_retry_writes(struct netfs_io_request *wreq)netfs_retry_write_stream (wreq, stream); } } + +trace_netfs_rreq (wreq, netfs_rreq_trace_retry_end); }
include/linux/fscache.h +17 -0
@@ -147,6 +147,23 @@ struct fscache_cookie { }; }; +enum fscache_extent_type { +FSCACHE_EXTENT_DATA , +FSCACHE_EXTENT_ZERO , +}__mode (byte ); + +/* +* Cache occupancy information. +*/ +struct fscache_occupancy { +unsigned long long query_from;/* Point to query from */ +unsigned long long query_to;/* Point to query to */ +unsigned long long cached_from[2 ];/* Point at which cache extents start */ +unsigned long long cached_to[2 ];/* Point at which cache extents end */ +unsigned int granularity;/* Granularity desired */ +enum fscache_extent_type cached_type[2 ];/* Type of cache extent */ +}; +/* * slow-path functions for when there is actually caching available, and the * netfs does actually have a valid token
include/linux/netfs.h +31 -9
@@ -23,6 +23,7 @@enum netfs_sreq_ref_trace ;typedef struct mempool mempool_t ; +struct fscache_occupancy ;struct folio_queue ;/**
@@ -153,6 +154,7 @@ struct netfs_io_stream {bool need_retry;/* T if this stream needs retrying */ bool failed;/* T if this stream failed */ bool transferred_valid;/* T is ->transferred is valid */ +bool cancelled;/* T if stream is cancelled */ };/*
@@ -162,8 +164,10 @@ struct netfs_cache_resources {const struct netfs_cache_ops *ops;void *cache_priv;void *cache_priv2; +unsigned long long cache_i_size;/* Initial size of cache file */ unsigned int debug_id;/* Cookie debug ID */ unsigned int inval_counter;/* object->inval_counter at begin_op */ +unsigned int dio_size;/* DIO block size */ };/*
@@ -197,6 +201,7 @@ struct netfs_io_subrequest {#define NETFS_SREQ_IN_PROGRESS 8/* Unlocked when the subrequest completes */ #define NETFS_SREQ_NEED_RETRY 9/* Set if the filesystem requests a retry */ #define NETFS_SREQ_FAILED 10/* Set if the subreq failed unretryably */ +#define NETFS_SREQ_CANCELLED 11/* Set if the subreq was cancelled by netfslib */ };enum netfs_io_origin {
@@ -251,6 +256,7 @@ struct netfs_io_request {unsigned long long start;/* Start position */ atomic64_t issued_to;/* Write issuer folio cursor */ unsigned long long collected_to;/* Point we've collected to */ +unsigned long long cache_coll_to;/* Point the cache has collected to */ unsigned long long cleaned_to;/* Position we've cleaned folios to */ unsigned long long abandon_to;/* Position to abandon folios to */ const struct folio *no_unlock_folio;/* Don't unlock this folio after read */
@@ -272,11 +278,13 @@ struct netfs_io_request {#define NETFS_RREQ_FAILED 3/* The request failed */ #define NETFS_RREQ_RETRYING 4/* Set if we're in the retry path */ #define NETFS_RREQ_SHORT_TRANSFER 5/* Set if we have a short transfer */ -#define NETFS_RREQ_OFFLOAD_COLLECTION 8/* Offload collection to workqueue */ -#define NETFS_RREQ_NO_UNLOCK_FOLIO 9/* Don't unlock no_unlock_folio on completion */ -#define NETFS_RREQ_FOLIO_COPY_TO_CACHE 10/* Copy current folio to cache from read */ -#define NETFS_RREQ_UPLOAD_TO_SERVER 11/* Need to write to the server */ -#define NETFS_RREQ_USE_IO_ITER 12/* Use ->io_iter rather than ->i_pages */ +#define NETFS_RREQ_CACHE_STOP 8/* Set to stop caching (ENOBUFS or error) */ +#define NETFS_RREQ_CACHE_ERROR 9/* Set if we got an error from the cache */ +#define NETFS_RREQ_OFFLOAD_COLLECTION 12/* Offload collection to workqueue */ +#define NETFS_RREQ_NO_UNLOCK_FOLIO 13/* Don't unlock no_unlock_folio on completion */ +#define NETFS_RREQ_FOLIO_COPY_TO_CACHE 14/* Copy current folio to cache from read */ +#define NETFS_RREQ_UPLOAD_TO_SERVER 15/* Need to write to the server */ +#define NETFS_RREQ_USE_IO_ITER 16/* Use ->io_iter rather than ->i_pages */ #define NETFS_RREQ_NEED_PUT_RA_REFS 17/* Need to put the folio refs RA gave us */ #define NETFS_RREQ_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark * write to cache on read */
@@ -322,6 +330,12 @@ enum netfs_read_from_hole { NETFS_READ_HOLE_FAIL, }; +enum netfs_cache_collect { +NETFS_CACHE_COLLECT_WRITE_DATA , +NETFS_CACHE_COLLECT_WRITE_GAP , +NETFS_CACHE_COLLECT_WRITE_CANCEL , +}; +/* * Table of operations for access to a cache. */
@@ -356,8 +370,7 @@ struct netfs_cache_ops {/* Prepare a read operation, shortening it to a cached/uncached * boundary as appropriate. */ -enum netfs_io_source (*prepare_read)(struct netfs_io_subrequest *subreq, -unsigned long long i_size); +int (*prepare_read)(struct netfs_io_subrequest *subreq);/* Prepare a write subrequest, working out if we're allowed to do it * and finding out the maximum amount of data to gather before
@@ -377,8 +390,17 @@ struct netfs_cache_ops {* next chunk of data starts and how long it is. */ int (*query_occupancy)(struct netfs_cache_resources *cres, -loff_t start,size_t len,size_t granularity, -loff_t *_data_start,size_t *_data_len); +struct fscache_occupancy *occ); + +/* Collect the result of buffered writeback to the cache. This +* includes copying a read to the cache. block_type is one of: +* - NETFS_CACHE_COLLECT_WRITE_DATA for a block of data +* - NETFS_CACHE_COLLECT_WRITE_GAP if a discontiguity was skipped +* - NETFS_CACHE_COLLECT_WRITE_CANCEL for a cancellation gap +*/ +void (*collect_write)(struct netfs_io_request *wreq, +unsigned long long start,size_t len, +enum netfs_cache_collect block_type); };/* High-level read API. */
include/trace/events/cachefiles.h +14 -3
@@ -54,6 +54,8 @@ enum cachefiles_coherency_trace { cachefiles_coherency_check_ok, cachefiles_coherency_check_type, cachefiles_coherency_check_xattr, + cachefiles_coherency_discontiguous, + cachefiles_coherency_remove, cachefiles_coherency_set_fail, cachefiles_coherency_set_ok, cachefiles_coherency_vol_check_cmp,
@@ -65,6 +67,7 @@ enum cachefiles_coherency_trace { };enum cachefiles_trunc_trace { + cachefiles_trunc_clear_padding, cachefiles_trunc_dio_adjust, cachefiles_trunc_expand_tmpfile, cachefiles_trunc_shrink,
@@ -82,6 +85,7 @@ enum cachefiles_prepare_read_trace { };enum cachefiles_error_trace { + cachefiles_trace_alignment_error, cachefiles_trace_fallocate_error, cachefiles_trace_getxattr_error, cachefiles_trace_link_error,
@@ -140,6 +144,8 @@ enum cachefiles_error_trace { EM(cachefiles_coherency_check_ok, "OK ") \ EM(cachefiles_coherency_check_type, "BAD type") \ EM(cachefiles_coherency_check_xattr, "BAD xatt") \ + EM(cachefiles_coherency_discontiguous, "--- gap ") \ + EM(cachefiles_coherency_remove, "REMOVE ") \ EM(cachefiles_coherency_set_fail, "SET fail") \ EM(cachefiles_coherency_set_ok, "SET ok ") \EM (cachefiles_coherency_vol_check_cmp,"VOL BAD cmp " ) \
@@ -150,6 +156,7 @@ enum cachefiles_error_trace { E_(cachefiles_coherency_vol_set_ok, "VOL SET ok ")#define cachefiles_trunc_traces \ + EM(cachefiles_trunc_clear_padding, "CLRPAD") \ EM(cachefiles_trunc_dio_adjust, "DIOADJ") \ EM(cachefiles_trunc_expand_tmpfile, "EXPTMP") \ E_(cachefiles_trunc_shrink, "SHRINK")
@@ -165,6 +172,7 @@ enum cachefiles_error_trace { E_(cachefiles_trace_read_seek_nxio, "seek-enxio")#define cachefiles_error_traces \ + EM(cachefiles_trace_alignment_error, "align") \ EM(cachefiles_trace_fallocate_error, "fallocate") \ EM(cachefiles_trace_getxattr_error, "getxattr") \ EM(cachefiles_trace_link_error, "link") \
@@ -375,12 +383,12 @@ TRACE_EVENT(cachefiles_rename, TRACE_EVENT(cachefiles_coherency, TP_PROTO(struct cachefiles_object *obj, - ino_t ino, + ino_t ino, unsigned long long obj_size, u64 disk_aux, enum cachefiles_content content, enum cachefiles_coherency_trace why), - TP_ARGS(obj, ino, disk_aux, content, why), + TP_ARGS(obj, ino, obj_size, disk_aux, content, why), /* Note that obj may be NULL */ TP_STRUCT__entry(
@@ -388,6 +396,7 @@ TRACE_EVENT(cachefiles_coherency, __field(enum cachefiles_coherency_trace, why) __field(enum cachefiles_content, content) __field(u64, ino) + __field(u64, obj_size) __field(u64, aux) __field(u64, disk_aux) ),
@@ -397,14 +406,16 @@ TRACE_EVENT(cachefiles_coherency, __entry->why = why; __entry->content = content; __entry->ino = ino; + __entry->obj_size = obj_size; __entry->aux =be64_to_cpup ((__be64 *)obj->cookie->inline_aux); __entry->disk_aux = disk_aux; ), -TP_printk ("o=%08x %s B=%llx c=%u aux=%llx dsk=%llx" , +TP_printk ("o=%08x %s B=%llx oz=%llx c=%u aux=%llx dsk=%llx" , __entry->obj,__print_symbolic (__entry->why, cachefiles_coherency_traces), __entry->ino, + __entry->obj_size, __entry->content, __entry->aux, __entry->disk_aux)
include/trace/events/netfs.h +8 -1
@@ -48,6 +48,10 @@#define netfs_rreq_traces \ EM(netfs_rreq_trace_assess, "ASSESS ") \ + EM(netfs_rreq_trace_cache_cancelled, "CA-CNCL") \ + EM(netfs_rreq_trace_cache_failed, "CA-FAIL") \ + EM(netfs_rreq_trace_cache_fail_collect, "CA-F-CO") \ + EM(netfs_rreq_trace_cache_no_space, "CA-NOSP") \ EM(netfs_rreq_trace_collect, "COLLECT") \ EM(netfs_rreq_trace_complete, "COMPLET") \ EM(netfs_rreq_trace_copy, "COPY ") \
@@ -56,11 +60,14 @@ 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_inval_cache, "INVL-CA") \ EM(netfs_rreq_trace_ki_complete, "KI-CMPL") \ EM(netfs_rreq_trace_ra_put_ref, "RA-PUT ") \ EM(netfs_rreq_trace_recollect, "RECLLCT") \ EM(netfs_rreq_trace_redirty, "REDIRTY") \ EM(netfs_rreq_trace_resubmit, "RESUBMT") \ + EM(netfs_rreq_trace_retry_begin, "RETRY-BEGIN") \ + EM(netfs_rreq_trace_retry_end, "RETRY-END") \ EM(netfs_rreq_trace_set_abandon, "S-ABNDN") \ EM(netfs_rreq_trace_set_pause, "PAUSE ") \EM (netfs_rreq_trace_unlock,"UNLOCK " ) \
@@ -132,12 +139,12 @@#define netfs_failures \ EM(netfs_fail_check_write_begin, "check-write-begin") \ - EM(netfs_fail_copy_to_cache, "copy-to-cache") \ EM(netfs_fail_dio_read_short, "dio-read-short") \ EM(netfs_fail_dio_read_zero, "dio-read-zero") \ EM(netfs_fail_read, "read") \ EM(netfs_fail_short_read, "short-read") \ EM(netfs_fail_prepare_write, "prep-write") \ + EM(netfs_fail_upload, "upload") \ E_(netfs_fail_write, "write")#define netfs_rreq_ref_traces \
David Howells
maintainerPATCH v7 20/29 netfs: Add the cache object ID to netfs_read/write tracepoints
In reply to David HowellsAdd the cache object debug ID to netfs_read/write tracepoints to make debugging easier as there's now a direct cross-reference with the cachefiles tracepoints that only log that debug ID.
--- fs/cachefiles/io.c | 1 + fs/netfs/fscache_io.c | 2 +- include/linux/netfs.h | 3 ++- include/trace/events/netfs.h | 27 +++++++++++++++------------ 4 files changed, 19 insertions(+), 14 deletions(-)
fs/cachefiles/io.c +1 -0
@@ -899,6 +899,7 @@ bool cachefiles_begin_operation(struct netfs_cache_resources *cres,if (!cachefiles_cres_file (cres)) { cres->ops = &cachefiles_netfs_cache_ops; + cres->object_id = object->debug_id;if (object->file) {spin_lock (&object->lock); file = object->file;
fs/netfs/fscache_io.c +1 -1
@@ -79,7 +79,7 @@ static int fscache_begin_operation(struct netfs_cache_resources *cres, cres->ops =NULL ; cres->cache_priv = cookie; cres->cache_priv2 =NULL ; - cres->debug_id = cookie->debug_id; + cres->cookie_id = cookie->debug_id; cres->inval_counter = cookie->inval_counter;if (!fscache_begin_cookie_access (cookie, why)) {
include/linux/netfs.h +2 -1
@@ -165,7 +165,8 @@ struct netfs_cache_resources {void *cache_priv;void *cache_priv2;unsigned long long cache_i_size;/* Initial size of cache file */ -unsigned int debug_id;/* Cookie debug ID */ +unsigned int cookie_id;/* Cache cookie debug ID */ +unsigned int object_id;/* Cache object debug ID */ unsigned int inval_counter;/* object->inval_counter at begin_op */ unsigned int dio_size;/* DIO block size */ };
include/trace/events/netfs.h +15 -12
@@ -310,6 +310,7 @@ TRACE_EVENT(netfs_read,TP_STRUCT__entry (__field (unsigned int ,rreq ) __field(unsigned int, cookie) + __field(unsigned int, object)__field (loff_t, i_size)__field (loff_t, start) __field(size_t, len)
@@ -319,7 +320,8 @@ TRACE_EVENT(netfs_read,TP_fast_assign ( __entry->rreq = rreq->debug_id; - __entry->cookie = rreq->cache_resources.debug_id; + __entry->cookie = rreq->cache_resources.cookie_id; + __entry->object = rreq->cache_resources.object_id; __entry->i_size = rreq->i_size; __entry->start = start; __entry->len = len;
@@ -327,10 +329,10 @@ TRACE_EVENT(netfs_read, __entry->netfs_inode = rreq->inode->i_ino; ), -TP_printk ("R=%08x %s c=%08x ni=%llx s=%llx l=%zx sz=%llx" , +TP_printk ("R=%08x %s c=%08x o=%08x ni=%llx s=%llx l=%zx sz=%llx" , __entry->rreq,__print_symbolic (__entry->what, netfs_read_traces), - __entry->cookie, + __entry->cookie, __entry->object, __entry->netfs_inode, __entry->start, __entry->len, __entry->i_size) );
@@ -551,6 +553,7 @@ TRACE_EVENT(netfs_write,TP_STRUCT__entry (__field (unsigned int ,wreq ) __field(unsigned int, cookie) + __field(unsigned int, object) __field(unsigned int, ino) __field(enum netfs_write_trace, what) __field(unsigned long long, start)
@@ -558,20 +561,19 @@ TRACE_EVENT(netfs_write, ), TP_fast_assign( - struct netfs_inode *__ctx = netfs_inode(wreq->inode); -struct fscache_cookie *__cookie =netfs_i_cookie (__ctx); __entry->wreq = wreq->debug_id; - __entry->cookie = __cookie ? __cookie->debug_id :0 ; + __entry->cookie = wreq->cache_resources.cookie_id; + __entry->object = wreq->cache_resources.object_id; __entry->ino = wreq->inode->i_ino; __entry->what = what; __entry->start = wreq->start; __entry->len = wreq->len; ), -TP_printk ("R=%08x %s c=%08x i=%x by=%llx-%llx" , +TP_printk ("R=%08x %s c=%08x o=%08x i=%x by=%llx-%llx" , __entry->wreq,__print_symbolic (__entry->what, netfs_write_traces), - __entry->cookie, + __entry->cookie, __entry->object, __entry->ino, __entry->start, __entry->start + __entry->len -1 ) );
@@ -586,22 +588,23 @@ TRACE_EVENT(netfs_copy2cache, __field(unsigned int, rreq) __field(unsigned int, creq) __field(unsigned int, cookie) + __field(unsigned int, object) __field(unsigned int, ino) ),TP_fast_assign ( - struct netfs_inode *__ctx = netfs_inode(rreq->inode); -struct fscache_cookie *__cookie =netfs_i_cookie (__ctx); __entry->rreq = rreq->debug_id; __entry->creq = creq->debug_id; - __entry->cookie = __cookie ? __cookie->debug_id :0 ; + __entry->cookie = rreq->cache_resources.cookie_id; + __entry->object = rreq->cache_resources.object_id; __entry->ino = rreq->inode->i_ino; ), -TP_printk ("R=%08x CR=%08x c=%08x i=%x " , +TP_printk ("R=%08x CR=%08x c=%08x o=%08x i=%x " , __entry->rreq, __entry->creq, __entry->cookie, + __entry->object, __entry->ino) );
David Howells
maintainerPATCH v7 21/29 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 unbuffered/direct I/O, the iterator is extracted into the queue up front. For buffered I/O, the folios are added to the queue as the operation proceeds, much as it does now with folio_queues. There is one important change for buffered writes: only the relevant part of the folio is included; this is expanded for writes to the cache in a copy of the bvecq segment (it is known that each bio_vec corresponds to part of a folio in this case).
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 | 12 --- fs/netfs/Makefile | 1 - fs/netfs/buffered_read.c | 122 +++++++++++++--------- fs/netfs/direct_read.c | 78 ++++++-------- fs/netfs/direct_write.c | 69 +++++++------ fs/netfs/internal.h | 10 +- fs/netfs/iterator.c | 2 + fs/netfs/misc.c | 20 +--- fs/netfs/objects.c | 17 ++-- fs/netfs/read_collect.c | 98 ++++++++++-------- fs/netfs/read_pgpriv2.c | 93 +++++++++++------ fs/netfs/read_retry.c | 102 +++++++++++-------- fs/netfs/read_single.c | 16 ++- fs/netfs/stats.c | 4 +- fs/netfs/write_collect.c | 60 +++++------ fs/netfs/write_issue.c | 192 ++++++++++++++++++++++++++--------- fs/netfs/write_retry.c | 62 ++++++----- include/linux/netfs.h | 25 ++--- include/trace/events/netfs.h | 46 ++++----- 19 files changed, 591 insertions(+), 438 deletions(-)
fs/cachefiles/io.c +0 -12
@@ -636,7 +636,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;
@@ -661,17 +660,6 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq) }/* We also need to end on the cache granularity boundary */ -if (start + len == wreq->i_size) { -size_t part = len & (cache->bsize -1 ); -size_t need = cache->bsize - part; - -if (part && stream->submit_extendable_to >= need) { - len += need; - subreq->len += need; - subreq->io_iter.count += need; - } - } - post = len & (cache->bsize -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 +73 -49
235 lines not on this page · raw message
fs/netfs/direct_read.c +29 -49
120 lines not on this page · raw message
fs/netfs/direct_write.c +39 -30
133 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>
@@ -69,9 +68,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,
@@ -170,7 +168,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);
@@ -208,8 +205,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
@@ -155,6 +155,7 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pag }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
@@ -448,3 +449,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 +6 -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,10 @@ 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_unset (&rreq->load_cursor); +bvecq_pos_unset (&rreq->dispatch_cursor); +bvecq_pos_unset (&rreq->collect_cursor); +bvecq_put (rreq->spare);if (atomic_dec_and_test (&ictx->io_count))wake_up_var (&ictx->io_count);
@@ -236,6 +229,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_unset (&subreq->dispatch_pos); +bvecq_pos_unset (&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 +53 -45
179 lines not on this page · raw message
fs/netfs/read_pgpriv2.c +63 -30
164 lines not on this page · raw message
fs/netfs/read_retry.c +60 -42
194 lines not on this page · raw message
fs/netfs/read_single.c +14 -2
@@ -93,7 +93,12 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq) subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->start =0 ; subreq->len = rreq->len; - subreq->io_iter = rreq->buffer.iter; + +bvecq_pos_set (&subreq->dispatch_pos, &rreq->dispatch_cursor); +bvecq_pos_set (&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);netfs_queue_read (rreq, subreq);
@@ -177,6 +182,14 @@ 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; +if (ret < rreq->len) { + ret = -EIO ; + goto cleanup_free; + } + ret =netfs_single_begin_cache_read (rreq, ictx);if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) goto cleanup_free;
@@ -184,7 +197,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
@@ -46,7 +46,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)
@@ -89,11 +88,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 +30 -30
103 lines not on this page · raw message
fs/netfs/write_issue.c +145 -47
328 lines not on this page · raw message
fs/netfs/write_retry.c +38 -24
154 lines not on this page · raw message
include/linux/netfs.h +10 -15
@@ -19,12 +19,13 @@#include <linux/pagemap.h> #include <linux/bvecq.h> #include <linux/uio.h> -#include <linux/rolling_buffer.h> enum netfs_sreq_ref_trace ;typedef struct mempool mempool_t ; +struct readahead_control ; +struct netfs_io_request ; +struct netfs_io_subrequest ;struct fscache_occupancy ; -struct folio_queue ;/** * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -139,7 +140,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 */
@@ -182,6 +182,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 */
@@ -242,13 +244,14 @@ 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 *spare;/* Advance allocation of bvecq */ +struct bvecq_pos load_cursor;/* Point at which new folios are loaded in */ +struct bvecq_pos dispatch_cursor;/* Point from which buffers are dispatched */ +struct bvecq_pos collect_cursor;/* Clear-up point of I/O buffer */ 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 */
@@ -261,7 +264,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 */ const struct folio *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) */
@@ -270,7 +272,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) */
@@ -470,12 +471,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
maintainerPATCH v7 22/29 smbdirect: Remove support for ITER_FOLIOQ from smbdirect_map_sges_from_iter()
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 the ITER_FOLIOQ iterator. So remove that code.
Netfslib also won't supply ITER_BVEC/KVEC iterators, though smbdirect might; further in future, it won't supply iterators at all, but rather a bvecq slice (that can be used to construct an iterator).
--- fs/smb/smbdirect/connection.c | 68 ----------------------------------- 1 file changed, 68 deletions(-)
fs/smb/smbdirect/connection.c +0 -68
@@ -6,7 +6,6 @@#include "internal.h" #include <linux/bvecq.h> -#include <linux/folio_queue.h> struct smbdirect_map_sges {struct ib_sge *sge;
@@ -2131,70 +2130,6 @@ static ssize_t smbdirect_map_sges_from_kvec(struct iov_iter *iter,return ret; } -/* -* Extract folio fragments from a FOLIOQ-class iterator and add them to an -* ib_sge list. The folios are not pinned. -*/ -static ssize_t smbdirect_map_sges_from_folioq (struct iov_iter *iter, -struct smbdirect_map_sges *state, -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; - -if (WARN_ON_ONCE (!folioq)) -return -EIO ; - -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); -bool ok; - - ok =smbdirect_map_sges_single_page (state, -folio_page (folio,0 ), - offset, - part); -if (!ok) -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 (state->num_sge < state->max_sge && maxsize >0 ); - - iter->folioq = folioq; - iter->folioq_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 ib_sge list that refers to all of those bits. The ib_sge list
@@ -2225,9 +2160,6 @@ static ssize_t smbdirect_map_sges_from_iter(struct iov_iter *iter, size_t len,case ITER_KVEC : ret =smbdirect_map_sges_from_kvec (iter, state, len);break ; -case ITER_FOLIOQ : - ret =smbdirect_map_sges_from_folioq (iter, state, len); -break ;default :WARN_ONCE (1 ,"iov_iter_type[%u]\n" ,iov_iter_type (iter));return -EIO ;
David Howells
maintainerPATCH v7 23/29 netfs: Remove netfs_alloc/free_folioq_buffer()
In reply to David HowellsRemove netfs_alloc/free_folioq_buffer() as bvecq_alloc_*() and bvecq_put() should now be used instead.
--- fs/afs/dir_edit.c | 1 - fs/netfs/misc.c | 98 ----------------------------------------- fs/smb/client/smb2ops.c | 1 - include/linux/netfs.h | 6 --- 4 files changed, 106 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"
include/linux/netfs.h +0 -6
@@ -471,12 +471,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); -/* 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); -/* Writeback exclusion API. */ bool netfs_wb_begin (struct netfs_inode *ictx,bool nowait);void netfs_wb_end (struct netfs_inode *ictx);
David Howells
maintainerPATCH v7 24/29 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 | 104 ------------------------------------------ include/linux/netfs.h | 3 -- 2 files changed, 107 deletions(-)
fs/netfs/iterator.c +0 -104
@@ -156,110 +156,6 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pagEXPORT_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 be 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 =0 ; -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 (unlikely (ret <=0 )) { - ret = ret ?: -EIO ; -break ; - } - -if (WARN (ret > count, -"%s: extract_pages overrun %zd > %zu bytes\n" , - __func__, ret, count)) { - ret = -EIO ; -break ; - } - - cur_npages =DIV_ROUND_UP (offset + ret,PAGE_SIZE ); -if (WARN (cur_npages > max_pages - npages, -"%s: extract_pages overrun %u > %u pages\n" , - __func__, npages + cur_npages, max_pages)) { - ret = -EIO ; -break ; - } - - count -= ret; - ret += offset; - -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; - } - -/* Note: Don't try to clean up after EIO. Either we got no pages, so -* nothing to clean up, or we got a buffer overrun, memory corruption -* and can't trust the stuff in the buffer (a WARN was emitted). -*/ - -if (ret <0 && (ret == -ENOMEM || npages ==0 )) { -for (i =0 ; i < npages; i++) -unpin_user_page (bv[i].bv_page); -kvfree (bv); -return ret; - } - -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
@@ -456,9 +456,6 @@ void netfs_put_subrequest(struct netfs_io_subrequest *subreq,ssize_t netfs_extract_iter (struct iov_iter *orig,size_t max_len,size_t max_pages,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
maintainerPATCH v7 25/29 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 | 175 +----------------------- lib/scatterlist.c | 69 +--------- lib/tests/kunit_iov_iter.c | 271 ------------------------------------- 5 files changed, 7 insertions(+), 585 deletions(-)
include/linux/iov_iter.h +2 -63
@@ -11,7 +11,6 @@#include <linux/uio.h> #include <linux/bvec.h> #include <linux/bvecq.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);
@@ -207,62 +206,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. */
@@ -374,8 +317,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);
@@ -410,8 +351,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
@@ -440,8 +381,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 ;
@@ -27,7 +26,6 @@ enum iter_type {ITER_BVEC ,ITER_KVEC ,ITER_BVECQ , -ITER_FOLIOQ ,ITER_XARRAY , ITER_DISCARD, };
@@ -70,7 +68,6 @@ struct iov_iter {const struct kvec *kvec;const struct bio_vec *bvec;const struct bvecq *bvecq; -const struct folio_queue *folioq;struct xarray *xarray;void __user *ubuf; };
@@ -80,7 +77,6 @@ struct iov_iter {union {unsigned long nr_segs;u16 bvecq_slot; -u8 folioq_slot;loff_t xarray_start; }; };
@@ -153,11 +149,6 @@ 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_folioq (const struct iov_iter *i) -{ -return iov_iter_type (i) ==ITER_FOLIOQ ; -} -static inline bool iov_iter_is_xarray (const struct iov_iter *i) {return iov_iter_type (i) ==ITER_XARRAY ;
@@ -306,9 +297,6 @@ void iov_iter_discard(struct iov_iter *i, unsigned int direction, 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_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_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 +3 -172
241 lines not on this page · raw message
lib/scatterlist.c +2 -67
93 lines not on this page · raw message
lib/tests/kunit_iov_iter.c +0 -271
309 lines not on this page · raw message
David Howells
maintainerPATCH v7 26/29 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 - Documentation/filesystems/netfs_library.rst | 2 +- fs/netfs/iterator.c | 192 ------------- fs/netfs/rolling_buffer.c | 297 -------------------- include/linux/folio_queue.h | 282 ------------------- include/linux/netfs.h | 2 - include/linux/rolling_buffer.h | 64 ----- kernel/bpf/btf.c | 2 - 9 files changed, 1 insertion(+), 1050 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
Documentation/filesystems/netfs_library.rst +1 -1
@@ -449,7 +449,7 @@ be called from the writeback code to write the data to the cache, if there is one. The inode should be marked ``NETFS_ICTX_SINGLE_NO_UPLOAD`` if this API is to be -used. The writeback function requires the buffer to be of ITER_FOLIOQ type. +used. High-Level VM API ==================
fs/netfs/iterator.c +0 -192
195 lines not on this page · raw message
fs/netfs/rolling_buffer.c deleted +0 -297
297 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/netfs.h +0 -2
@@ -456,8 +456,6 @@ void netfs_put_subrequest(struct netfs_io_subrequest *subreq,ssize_t netfs_extract_iter (struct iov_iter *orig,size_t max_len,size_t max_pages,unsigned long long fpos,struct bvecq **_bvecq_head,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);void netfs_write_subrequest_terminated (void *_op,ssize_t transferred_or_error);
include/linux/rolling_buffer.h deleted +0 -64
64 lines not on this page · raw message
kernel/bpf/btf.c +0 -2
@@ -6749,8 +6749,6 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {/* amdgpu */ { "amdgpu_vm_bo_map", 0x1 }, { "amdgpu_vm_bo_unmap", 0x1 }, -/* netfs */ - { "netfs_folioq", 0x1 },/* xfs from xfs_defer_pending_class */ { "xfs_defer_create_intent", 0x1 }, { "xfs_defer_cancel_list", 0x1 },
David Howells
maintainerPATCH v7 27/29 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. In the event that this happens, abort the rest of the read request on the basis that some of the read buffer may have been corrupted and return -EIO.
--- fs/netfs/read_collect.c | 56 ++++++++++++++++++++++++++++++++++-- include/linux/netfs.h | 1 + include/trace/events/netfs.h | 1 + 3 files changed, 55 insertions(+), 3 deletions(-)
fs/netfs/read_collect.c +53 -3
@@ -19,8 +19,9 @@#define MADE_PROGRESS 0x04/* Made progress cleaning up a stream or the folio set */ #define BUFFERED 0x08/* The pagecache needs cleaning up */ #define NEED_RETRY 0x10/* A front op requests retrying */ -#define COPY_TO_CACHE 0x40/* Need to copy subrequest to cache */ -#define ABANDON_SREQ 0x80/* Need to abandon untransferred part of subrequest */ +#define COPY_TO_CACHE 0x20/* Need to copy subrequest to cache */ +#define ABANDON_SREQ 0x40/* Need to abandon untransferred part of subrequest */ +#define ABANDON_RREQ 0x80/* Need to abandon the rest of a request */ /* * Clear the unread part of an I/O request.
@@ -201,6 +202,8 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) notes =BUFFERED ; else notes =0 ; +if (test_bit (NETFS_RREQ_ABANDON_REQ , &rreq->flags)) + notes |=ABANDON_RREQ ;/* Remove completed subrequests from the front of the stream and * advance the completion point. We stop when we hit something that's
@@ -226,14 +229,43 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)if (netfs_check_subreq_in_progress (front)) notes |=HIT_PENDING ;smp_rmb ();/* Read counters after IN_PROGRESS flag. */ + transferred =READ_ONCE (front->transferred); +if (unlikely (transferred > front->len)) { +/* Ugh... A subreq overran its allotted length. It +* may have corrupted the read buffer. +*/ +set_bit (NETFS_RREQ_FAILED , &rreq->flags); +set_bit (NETFS_RREQ_ABANDON_REQ , &rreq->flags); + notes |=ABANDON_RREQ ; + } + +/* Deal with an abandoned request. Wait for each subreq to +* complete before abandoning them. +*/ +if (unlikely (notes &ABANDON_RREQ )) { +if (notes &HIT_PENDING ) +break ; + +/* The subreq now belongs to us. */ + stream->error = -EIO ; + stream->failed = true; + rreq->abandon_to = front->start + front->len; + rreq->error = -EIO ; + transferred =0 ; +trace_netfs_rreq (rreq, netfs_rreq_trace_set_abandon); + notes |=ABANDON_SREQ ; + goto sreq_complete; + }/* If we can now collect the next folio, do so. We don't want * to defer this as we have to decide whether we need to copy * to the cache or not, and that may differ between adjacent * subreqs. */ -if (notes &BUFFERED ) { +if (notes &ABANDON_SREQ ) { +/* Don't collect anything. */ + }else if (notes &BUFFERED ) {size_t fsize =PAGE_SIZE << rreq->front_folio_order;/* Clear the tail of a short read. */
@@ -295,6 +327,7 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) notes |=MADE_PROGRESS ; } +sreq_complete:/* Remove if completely consumed. */ stream->source = front->source;spin_lock (&rreq->lock);
@@ -319,6 +352,8 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)if (!(notes &BUFFERED )) rreq->cleaned_to = rreq->collected_to; +if (notes &ABANDON_RREQ ) + goto out;if (notes &NEED_RETRY ) goto need_retry;if (notes &MADE_PROGRESS ) {
@@ -543,6 +578,21 @@ void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq)break ; } +/* If the subrequest read more than it was supposed to, abort +* the request with EIO as we may have clobbered other parts +* of the buffer that are already read. +*/ +if (subreq->transferred > subreq->len) { +trace_netfs_sreq (subreq, netfs_sreq_trace_too_much); +__set_bit (NETFS_SREQ_FAILED , &subreq->flags); +__clear_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags); + subreq->error = -EIO ; +trace_netfs_failure (rreq, subreq, subreq->error, netfs_fail_read); +trace_netfs_rreq (rreq, netfs_rreq_trace_set_pause); +set_bit (NETFS_RREQ_PAUSE , &rreq->flags); + goto skip_error_checks; + } +/* Deal with retry requests, short reads and errors. If we retry * but don't make progress, we abandon the attempt. */
include/linux/netfs.h +1 -0
@@ -280,6 +280,7 @@ struct netfs_io_request {#define NETFS_RREQ_FAILED 3/* The request failed */ #define NETFS_RREQ_RETRYING 4/* Set if we're in the retry path */ #define NETFS_RREQ_SHORT_TRANSFER 5/* Set if we have a short transfer */ +#define NETFS_RREQ_ABANDON_REQ 6/* Set if the request is to be abandoned */ #define NETFS_RREQ_CACHE_STOP 8/* Set to stop caching (ENOBUFS or error) */ #define NETFS_RREQ_CACHE_ERROR 9/* Set if we got an error from the cache */ #define NETFS_RREQ_OFFLOAD_COLLECTION 12/* Offload collection to workqueue */
include/trace/events/netfs.h +1 -0
@@ -132,6 +132,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
maintainerPATCH v7 28/29 netfs: Limit the minimum trigger for progress reporting
In reply to David HowellsFor really big read RPC ops that span multiple folios, netfslib allows the filesystem to give progress notifications to wake up the collector thread to do a collection of folios that have now been fetched, even if the RPC is still ongoing, thereby allowing the application to make progress.
The trigger for this is that at least one folio has been downloaded since the clean point. If, however, the folios are small, this means the collector thread is constantly being woken up - which has a negative performance impact on the system.
Set a minimum trigger of 256KiB or the size of the folio at the front of the queue, whichever is larger.
Also, fix the base to be the stream collection point, not the point at which the collector has cleaned up to (which is currently 0 until something has been collected).
--- fs/netfs/read_collect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/netfs/read_collect.c +3 -3
@@ -527,15 +527,15 @@ void netfs_read_collection_worker(struct work_struct *work)void netfs_read_subreq_progress (struct netfs_io_subrequest *subreq) {struct netfs_io_request *rreq = subreq->rreq; -struct netfs_io_stream *stream = &rreq->io_streams[0 ]; -size_t fsize =PAGE_SIZE << rreq->front_folio_order; +struct netfs_io_stream *stream = &rreq->io_streams[subreq->stream_nr]; +size_t fsize =umax (PAGE_SIZE << rreq->front_folio_order,256 *1024 );trace_netfs_sreq (subreq, netfs_sreq_trace_progress);/* If we are at the head of the queue, wake up the collector, * getting a ref to it if we were the ones to do so. */ - if (subreq->start + subreq->transferred > rreq->cleaned_to + fsize && + if (subreq->start + subreq->transferred >= stream->collected_to + fsize && (rreq->origin == NETFS_READAHEAD || rreq->origin == NETFS_READPAGE || rreq->origin == NETFS_READ_FOR_WRITE) &&
David Howells
maintainerPATCH v7 29/29 netfs: Combine prepare and issue ops and grab the buffers on request
In reply to David HowellsModify the way subrequests are generated in netfslib to try and simplify the code. The issue, primarily, is in writeback: the code has to create multiple streams of write requests to disparate targets with different properties (e.g. server and fscache), where not every folio needs to go to every target (e.g. data just read from the server may only need writing to the cache).
The current model in writeback, at least, is to go carefully through every folio, preparing a subrequest for each stream when it was detected that part of the current folio needed to go to that stream, and repeating this within and across contiguous folios; then to issue subrequests as they become full or hit boundaries after first setting up the buffer. However, this is quite difficult to follow - and makes it tricky to handle discontiguous folios in a request.
This is changed such that netfs now accumulates buffers and attaches them to each stream when they become valid for that stream, then flushes the stream when a limit or a boundary is hit. The issuing code in netfs then loops around creating and issuing subrequests without calling a separate prepare stage (though a function is provided to get an estimate of when flushing should occur). The filesystem (or cache) then gets to take a slice of the master bvec chain as its I/O buffer for each subrequest, including discontiguities if it can support a sparse/vectored RPC (as Ceph can).
Similar-ish changes also apply to buffered read and unbuffered read and write, though in each of those cases there is only a single contiguous stream. Though for buffered read this consists of interwoven requests from multiple sources (server or cache).
To this end, netfslib is changed 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/cache 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/cache then dispatches the operation.
(2) Retry buffer tracking is added to the netfs_io_request struct. This is then selected by the subrequest retry counter being non-zero.
(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) If the ->issue_xxx() functions terminate with -ENOMEM, a flag is set on the request to abort further subrequest generation/retrying. If it fails early with any other error, generally the subreq will be extended as much as possible and failed with the error returned.
(5) During writeback, netfslib 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 next generates subrequests on the stream. The filesystem or cache is not required to use up all the data accumulated on a stream at that time unless the end of the pagecache is hit.
(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 read or written as a single stream. The dispatching function just creates subrequests and calls ->issue_xxx() repeatedly to eat through the bufferage.
(8) At the start of buffered read, the entire set of folios allocated by VM readahead is loaded into a bvecq chain, rather than trying to do it piecemeal as-needed. As the pages were already added and locked by the VM, this is slightly more efficient than loading piecemeal as only a single iteration of the xarray is required.
(9) 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.
(10) Cachefiles now provides an estimation function that indicates the standard maxima for doing DIO (MAX_RW_COUNT and BIO_MAX_VECS).
Note that sparse cachefiles still rely on the backing filesystem for content mapping. That will need to be addressed in a future patch and is not trivial to fix.
--- fs/9p/vfs_addr.c | 60 ++- fs/afs/dir.c | 11 +- fs/afs/file.c | 29 +- fs/afs/fsclient.c | 8 +- fs/afs/internal.h | 8 +- fs/afs/symlink.c | 5 +- fs/afs/write.c | 36 +- fs/afs/yfsclient.c | 6 +- fs/cachefiles/io.c | 244 ++++++++--- fs/ceph/Kconfig | 1 + fs/ceph/addr.c | 123 +++--- fs/netfs/Kconfig | 3 + fs/netfs/Makefile | 2 +- fs/netfs/buffered_read.c | 252 ++++++----- fs/netfs/direct_read.c | 87 ++-- fs/netfs/direct_write.c | 135 +++--- fs/netfs/fscache_io.c | 2 +- fs/netfs/internal.h | 92 +++- fs/netfs/iterator.c | 4 +- fs/netfs/misc.c | 35 +- fs/netfs/objects.c | 7 +- fs/netfs/read_collect.c | 43 +- fs/netfs/read_pgpriv2.c | 126 ++++-- fs/netfs/read_retry.c | 208 ++++----- fs/netfs/read_single.c | 158 ++++--- fs/netfs/write_collect.c | 62 ++- fs/netfs/write_issue.c | 809 +++++++++++++++++++++-------------- fs/netfs/write_retry.c | 159 +++---- fs/nfs/Kconfig | 1 + fs/nfs/fscache.c | 24 +- fs/smb/client/cifssmb.c | 13 +- fs/smb/client/file.c | 145 +++---- fs/smb/client/smb2ops.c | 9 +- fs/smb/client/smb2pdu.c | 28 +- fs/smb/client/transport.c | 15 +- include/linux/netfs.h | 97 +++-- include/trace/events/netfs.h | 51 ++- net/9p/client.c | 8 +- 38 files changed, 1891 insertions(+), 1215 deletions(-)
fs/9p/vfs_addr.c +51 -9
@@ -48,31 +48,70 @@ static void v9fs_begin_writeback(struct netfs_io_request *wreq) wreq->io_streams[0 ].avail = true; } +/* +* Estimate how much data should be accumulated before we start issuing +* write subrequests. +*/ +static int v9fs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate) +{ +struct p9_fid *fid = wreq->netfs_priv; +unsigned long long limit =ULLONG_MAX - stream->issue_from; +unsigned long long max_len = fid->clnt->msize -P9_IOHDRSZ ; + + estimate->issue_at = stream->issue_from +umin (max_len, limit); +return 0 ; +} +/* * 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 iov_iter iter;struct p9_fid *fid = subreq->rreq->netfs_priv; -int err, len; +int err, len =0 ; + + subreq->len =umin (subreq->len, fid->clnt->msize -P9_IOHDRSZ ); - len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); + err =netfs_prepare_write_buffer (subreq,INT_MAX ); +if (err <0 ) +return err; +/* After this point, must fail by termination. */ + +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 0 ; }/** * v9fs_issue_read - Issue a read from 9P * @subreq: The read to make */ -static void v9fs_issue_read (struct netfs_io_subrequest *subreq) +static int v9fs_issue_read (struct netfs_io_subrequest *subreq) {struct netfs_io_request *rreq = subreq->rreq; +struct iov_iter iter;struct p9_fid *fid = rreq->netfs_priv;char *target;unsigned long long pos = subreq->start + subreq->transferred; -int total =0 , err, len, n; +size_t len; +int total =0 , err; + + err =netfs_prepare_read_buffer (subreq,INT_MAX ); +if (err <0 ) +return err; +/* After this point, must fail by termination. */ + +iov_iter_bvec_queue (&iter,ITER_DEST , subreq->content.bvecq, + subreq->content.slot, subreq->content.offset, subreq->len);if (S_ISLNK (rreq->inode->i_mode)) {/* p9_client_readlink() must not be called for legacy protocols
@@ -89,12 +128,13 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) err =p9_client_readlink (fid, &target);if (err !=0 ) goto fill_subreq; - len =strlen (target); - n =copy_to_iter (target, len, &subreq->io_iter); + len =min (strlen (target), subreq->len); + total =copy_to_iter (target, len, &iter);kfree (target); - total = n; }else { - total =p9_client_read (fid, pos, &subreq->io_iter, &err); +trace_netfs_sreq (subreq, netfs_sreq_trace_submit); + + total =p9_client_read (fid, pos, &iter, &err); } fill_subreq:
@@ -112,6 +152,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) subreq->error = err;netfs_read_subreq_terminated (subreq); +return 0 ; }/**
@@ -185,6 +226,7 @@ const struct netfs_request_ops v9fs_req_ops = { .free_request = v9fs_free_request, .issue_read = v9fs_issue_read, .begin_writeback = v9fs_begin_writeback, + .estimate_write = v9fs_estimate_write, .issue_write = v9fs_issue_write, };
fs/afs/dir.c +5 -6
@@ -250,8 +250,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 =bvecq_expand_buffer (&dvnode->directory, &cur_size, i_size, -GFP_KERNEL ); + ret =bvecq_expand_buffer (&dvnode->directory, &cur_size, +round_up (i_size,PAGE_SIZE ),GFP_KERNEL ); dvnode->directory_size = cur_size;if (ret <0 )return ret;
@@ -2227,11 +2227,10 @@ static int afs_dir_writepages(struct address_space *mapping, }if (test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags)) { +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); -if (ret ==1 ) - ret =0 ;/* Skipped write due to lock conflict. */ +round_up (len,PAGE_SIZE )); + ret =netfs_writeback_single (mapping, wbc, &iter, len); }up_read (&dvnode->validate_lock);
fs/afs/file.c +19 -10
@@ -332,11 +332,12 @@ 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 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,
@@ -345,11 +346,15 @@ static void afs_issue_read(struct netfs_io_subrequest *subreq) vnode->fid.unique, key_serial(key)); + ret =netfs_prepare_read_buffer (subreq,INT_MAX ); +if (ret <0 ) +return ret; +/* After this point, must fail by termination. */ + op =afs_alloc_operation (key, vnode->volume);if (IS_ERR (op)) { - subreq->error =PTR_ERR (op); -netfs_read_subreq_terminated (subreq); -return ; + ret =PTR_ERR (op); + goto failed; }afs_op_set_vnode (op,0 , vnode);
@@ -364,20 +369,24 @@ static void afs_issue_read(struct netfs_io_subrequest *subreq) op->flags |=AFS_OPERATION_ASYNC ;if (!afs_begin_vnode_operation (op)) { - subreq->error =afs_put_operation (op); -netfs_read_subreq_terminated (subreq); -return ; + ret =afs_put_operation (op); + goto failed; }if (!afs_select_fileserver (op)) { -afs_end_read (op); -return ; +afs_end_read (op);/* Error recorded here. */ +return 0 ; }afs_issue_read_call (op); }else {afs_do_sync_operation (op); } +return 0 ; +failed: + subreq->error = ret; +netfs_read_subreq_terminated (subreq); +return 0 ; }static int afs_init_request (struct netfs_io_request *rreq,struct file *file)
@@ -469,7 +478,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 +5 -3
@@ -914,7 +914,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;
@@ -1705,8 +1705,10 @@ 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, +struct netfs_write_estimate *estimate); +int afs_issue_write (struct netfs_io_subrequest *subreq);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/symlink.c +3 -2
@@ -245,9 +245,10 @@ int afs_symlink_writepages(struct address_space *mapping,if (vnode->directory &&atomic64_read (&vnode->cb_expires_at) !=AFS_NO_CB_PROMISE ) { +size_t len =i_size_read (&vnode->netfs.inode);iov_iter_bvec_queue (&iter,ITER_SOURCE , vnode->directory,0 ,0 , -i_size_read (&vnode->netfs.inode)); - ret =netfs_writeback_single (mapping, wbc, &iter); +round_up (len,PAGE_SIZE )); + ret =netfs_writeback_single (mapping, wbc, &iter, len); }if (ret ==0 ) {
fs/afs/write.c +27 -9
@@ -83,17 +83,20 @@ 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, +struct netfs_write_estimate *estimate) { -struct netfs_io_stream *stream = &subreq->rreq->io_streams[subreq->stream_nr]; +unsigned long long limit =ULLONG_MAX - stream->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 = stream->issue_from +umin (max_len, limit); +return 0 ; }/*
@@ -139,12 +142,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,netfs_read_remote_i_size (&vnode->netfs.inode)); 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) {
@@ -168,11 +174,21 @@ 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) { +int ret; + +if (subreq->len >256 *1024 *1024 ) + subreq->len =256 *1024 *1024 ; + ret =netfs_prepare_write_buffer (subreq,INT_MAX ); +if (ret <0 ) +return ret; +/* After this point, must fail by termination. */ + subreq->work.func = afs_issue_write_worker;if (!queue_work (system_dfl_wq, &subreq->work))WARN_ON_ONCE (1 ); +return 0 ; }/*
@@ -183,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 +181 -63
326 lines not on this page · raw message
fs/ceph/Kconfig +1 -0
@@ -4,6 +4,7 @@ config CEPH_FS depends on INET select CEPH_LIB select NETFS_SUPPORT + select NETFS_PGPRIV2 select FS_ENCRYPTION_ALGS if FS_ENCRYPTION default n help
fs/ceph/addr.c +71 -52
244 lines not on this page · raw message
fs/netfs/Kconfig +3 -0
@@ -22,6 +22,9 @@ config NETFS_STATS between CPUs. On the other hand, the stats are very useful for debugging purposes. Saying 'Y' here is recommended. +config NETFS_PGPRIV2 + bool + config NETFS_DEBUG bool "Enable dynamic debugging netfslib and FS-Cache" depends on NETFS_SUPPORT
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 +141 -111
449 lines not on this page · raw message
fs/netfs/direct_read.c +47 -40
142 lines not on this page · raw message
fs/netfs/direct_write.c +71 -64
220 lines not on this page · raw message
fs/netfs/fscache_io.c +1 -1
@@ -239,7 +239,7 @@ 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); + ret = cres->ops->prepare_write_old (cres, &start, &len, len, i_size, false);if (ret <0 ) goto abandon_end;
fs/netfs/internal.h +78 -14
146 lines not on this page · raw message
fs/netfs/iterator.c +2 -2
@@ -105,14 +105,14 @@ ssize_t netfs_extract_iter(struct iov_iter *orig, size_t max_len, size_t max_pag }if (got ==0 ) { -pr_err ("extract_pages gave nothing from %zu, %zu\n" , +pr_err ("extract_pages gave nothing from %zx, %zx\n" , extracted, max_len); ret = -EIO ; goto out; }if (WARN (got > max_len, -"%s: extract_pages overrun %zd > %zu bytes\n" , +"%s: extract_pages overrun %zx > %zx bytes\n" , __func__, got, max_len)) { ret = -EIO ; goto out;
fs/netfs/misc.c +33 -2
@@ -250,6 +250,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. */
@@ -310,7 +341,7 @@ static int netfs_collect_in_app(struct netfs_io_request *rreq, need_collect = true;break ; } -if (subreq || !test_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags)) +if (subreq || !netfs_are_all_subreqs_queued (rreq)) done = false; }
@@ -380,7 +411,7 @@ static ssize_t netfs_wait_for_in_progress(struct netfs_io_request *rreq,case NETFS_UNBUFFERED_WRITE :break ;default : -if (rreq->submitted < rreq->len) { +if (rreq->transferred < rreq->len) {trace_netfs_failure (rreq,NULL , ret, netfs_fail_short_read); ret = -EIO ; }
fs/netfs/objects.c +4 -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,9 +132,11 @@ 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_unset (&rreq->load_cursor); -bvecq_pos_unset (&rreq->dispatch_cursor);bvecq_pos_unset (&rreq->collect_cursor); +bvecq_pos_unset (&rreq->retry_cursor);bvecq_put (rreq->spare); +for (int i =0 ; i <NR_IO_STREAMS ; i++) +bvecq_pos_unset (&rreq->io_streams[i].dispatch_cursor);if (atomic_dec_and_test (&ictx->io_count))wake_up_var (&ictx->io_count);
@@ -227,6 +227,7 @@ static void netfs_free_subrequest(struct netfs_io_subrequest *subreq)struct netfs_io_request *rreq = subreq->rreq;trace_netfs_sreq (subreq, netfs_sreq_trace_free); +WARN_ON_ONCE (!list_empty (&subreq->rreq_link));if (rreq->netfs_ops->free_subrequest) rreq->netfs_ops->free_subrequest (subreq);bvecq_pos_unset (&subreq->dispatch_pos);
fs/netfs/read_collect.c +12 -31
92 lines not on this page · raw message
fs/netfs/read_pgpriv2.c +81 -45
188 lines not on this page · raw message
fs/netfs/read_retry.c +93 -115
317 lines not on this page · raw message
fs/netfs/read_single.c +97 -61
209 lines not on this page · raw message
fs/netfs/write_collect.c +43 -19
139 lines not on this page · raw message
fs/netfs/write_issue.c +485 -324
47 lines not on this page · raw message
fs/netfs/write_retry.c +83 -76
159 lines not on this page · raw message
fs/smb/client/file.c +73 -72
145 lines not on this page · raw message
include/linux/netfs.h +56 -41
97 lines not on this page · raw message
include/trace/events/netfs.h +41 -10
51 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.