netfs: Keep track of folios in a segmented bio_vec[] chain
Subsystems (19)
David Howells
maintainerv11 cover netfs: Keep track of folios in a segmented bio_vec[] chain
Hi Paulo,
Could you look these patches over please?
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;
refcount_t ref;
u32 priv;
u16 nr_slots;
u16 max_slots;
enum bvecq_mem mem_type:2;
bool inline_bv:1;
bool from_pool: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) ref - Refcount. Each bvecq keeps a ref on the next. I'm not sure this is entirely necessary, but it makes sharing slices easier.
(3) priv - Private data for the owner. Dispensible; currently only used for storing a debug ID for tracing in a patch not included here.
(4) 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).
(5) 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).
(6) 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.
(7) from_pool. Set if the bvecq is allocated from netfslib's mempool and should be freed to it.
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 one folio. A bvecq may hold folios that are not contiguous during writeback.
(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 into 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. This also allows the filesystem to reduce the size of the slice of buffer a subrequest gets (e.g. for cifs credits or RDMA limits).
(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) 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).
(2) 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.
(3) 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).
(4) Preset the xattr on a cachefile to try to avoid having to deal with ENOSPC from setxattr when committing the object.
Two further things that I'm working on (but not in this branch) are:
(1) Make it so that a filesystem can get a copy of part of a chain 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) 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.
(2) 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 #11)
- Rebased on Christian's vfs/vfs.fixes branch, pending fixes being taken upsteam.
- Split out fixing readahead producer/consumer issues by preloading the rolling buffer out into its own patch and bumped to netfs-fixes.
- Added a patch to fix mark folios for copy-to-cache earlier and bumped to netfs-fixes.
- Added a patch with Willy's idea of an end-writeback iteration tool.
- Added a patch to create a list of regions by file position that are involved in the writeback.
- Added a patch to use the end-writeback iteration tool to clean up the folios involved, using the region list to specify where to look.
- Split out read abandonment simplification into its own patch.
- Split out the addition of the ->estimate_write() method into its own patch.
- Split out the reworking of the writeback algorithm to better handle bounce buffering in the future into its own patch.
- Added a patch to preset the subrequest source so that it's correct in traces.
- Split out the removal of now-unused code into its own patch.
ver #10)
- Rebased on v7.2
- Pushed the cachefiles ondemand sunset patch separately.
- Pushed the patch to fix read progress handling separately.
- Changed some umin() to min().
- Changed netfs writeback to hold the list of regions that need unlocking separately from the bvecq holding the folios to write.
- Added a patch to convert unsigned long long to uoff_t throughout netfslib, fscache and cachefiles and to convert loff_t where appropriate.
- Split some bits out of the larger patches into smaller patches, including:
- Made some minor adjustments to tracepoints.
- Provided helper functions to handle the barriering around setting NETFS_RREQ_ALL_QUEUED.
- Made the use of the PG_private_2 flag optional, requiring anything wanting to use it (NFS, Ceph) to select it in Kconfig.
- Added a new function to estimate the amount to write.
- Fixed a number of issues reported by Sashiko[8]:
- Fixed initialisation of ->progress_at to be 0, not ULONG_MAX, when request is allocated otherwise netfs_prepare_read_iterator() won't set it.
- Pass gfp into rolling_buffer_bulk_load_from_ra().
- Fixes iter_get_kernel_pages() to use folio_test_large_kmalloc() as well as folio_test_slab() when deciding to take a ref.
- Fixed iter_count_bvecq_pages() and iov_iter_extract_bvecq_pages() to
assume that bio_vecs with bv_page==NULL and bv_len>0 are not allowed.
- Fixed iov_iter_extract_bvecq_pages() to check if the result of
iter_count_bvecq_pages() is zero, not less than zero.
- Fixed bvecq_pos_advance(), bvecq_zero(), bvecq_slice(),
bvecq_extract(), bvecq_pos_step() and bvecq_pos_nudge() to recheck the
slot count of the current bvecq after reading the next pointer in order
to advance to the next bvecq.
- Made bvecq_delete_spent() retain spent->next and instead take a ref on
what spend->next points to (so that putting spent doesn't delete the
entire chain) thereby avoiding breaking the chain.
- Fixed bvecq_alloc_one() to strip off __GFP_THISNODE as well as
GFP_ZONEMASK when turning a gfp for allocating folios into a gfp for
allocating bvecq objects.
- Change cachefiles_collect_write() to set CACHEFILES_CONTENT_NO_DATA if
a cache write fails and the cache content is truncated away.
- Fixed stream->cancelled boolean to be a 3-state enum instead for
tracking gap, data or cancelled writes to the cache.
- Fixed netfs_writeback_single() to take two lengths: one for the whole
buffer and one for the data content in that buffer to allow DIO
rounding to use extra buffer.
- Fixed netfs_collect_read_results() to set -EIO on the request when
abandoning it due to subreq over-read
- Fixed netfs_writeback_single() to pre-expand the buffer to include all
available buffer space, even beyond the data, and fixed
netfs_prepare_write_single_buffer() to do no rounding.
- Fixed netfs_alloc_read_subrequest() to not set stream->collected_to as
that's set when the object is initialised and subreq->start isn't set
yet. - Fixed netfs_unbuffered_write() to not skip cleanup if it fails to allocate a subreq.
- Fixed netfs_unbuffered_write() to fail immediately if ->issue_write() returns an error rather than going for a retry.
- Changed netfs_unbuffered_write() to not get subreq->error if netfs_wait_for_in_progress_subreq() fails as it returns that.
- Added a comment to netfs_writeback_single() to indicate that it doesn't normally write to the server.
- Split the cachefiles_trace_write_nospace to distinguish the two users.
- Fixed the cachefiles file xattr set/get functions to make sure that the storage for the cachefiles_xattr::data is at least 8 bytes and that it's initialised to 0 so that the tracepoint doesn't cause a KASAN error.
- Fixed missing export of the netfs_rreq tracepoint.
ver #9)
- Fixed a number of issues reported by Sashiko[7]:
- Fixed netfs_unlock_abandoned_read_pages() to make sure the refs are dropped before unlocking.
- Fixed iov_iter_extract_bvecq_pages() to immediately return 0 if there are no pages to be extracted from the iterator (e.g. if maxpages is 0).
- Pass a flag into bvecq_alloc_one() to indicate if we can access writeback memory pools rather than trying to divine this from gfp.
- Fixed bvecq_alloc_one() to use the same gfp adjustments as mempool_alloc() when prospectively allocating what the caller asked for during writeback.
- Simplified the bvecq-based rolling buffer in writeback by always adding whole folios and then setting the offset appropriately. The offset and length of the part added can then be aligned at that point when tracking the new folio in the cache stream rather than copying and rounding out later.
- Changed the writeback loop to ignore ENOMEM. There are now backup memory pools for writeback.
- Simplified the writeback loop to update stream tracking as folios are added and to flush at that point too if needed.
- Removed the warning given by netfs_extract_iter() if max_len or max_pages is 0.
- Made netfs_extract_iter() set the fpos on the blank bvecq it allocates in the alloc_empty path.
- Fixed netfs_writeback_single() to test NETFS_RREQ_UPLOAD_TO_SERVER rather than test-and-setting it (nothing currently wants to writeback-single to the server anyway, only to the cache).
- Removed cachefiles ondemand pincount.
- Fixed netfs_collect_write_results() to get the cancel/data flags to netfs_collect_write_results() the right way round.
- Fixed netfs_writeback_unlock_folios() to just warn and oops in the unlikely event that it sees a NULL (ie. already unlocked) folio pointer.
- Moved some common initialisation of fields to rreq->start to netfs_alloc_request().
- Fixed bvecq_load_from_ra() to set bq->fpos.
- Fixed read progress reporting to use an offset from rreq->start
(unchanging) rather than trying to use rreq->clean_to (tearable) as a
base.ver #8)
- Removed the fix patches to their own branches and posted separately.
- Rebased on v7.2-rc6 as a number of fixes went in.
- Fixed cachefiles_collect_write() to handle cres->cache_priv2 (file) being NULL due to failure to create an object (e.g. due to ENOSPC).
- Added a patch to cachefiles to preset the xattr on a cachefiles to avoid dealing with ENOSPC from setxattr when committing an object.
- Fixed a number of bugs reported by Sashiko[6]:
- Fixed bvecq_alloc_buffer2() to break out of the loop if pre_slots > 0
and size == 0.
- Made netfs_extract_iter() limit max_pages to protect iov_iter_npages().
- Remove include/uapi/linux/cachefiles.h when ondemand mode is removed.
- Remove more ondemand-related trace bits.
- Remove ondemand-related BPF bits.
- Fixed a missing ENOMEM check in netfs_pgpriv2_begin_copy_to_cache().
- Fixed netfs_retry_read_subrequests() to unset dispatch_cursor on the "abandon_after" error path.
- Fixed netfs_issue_write() to clear stream->construct if a subreq is terminated due to ENOMEM.
- Fixed netfs_collect_read_results() to unpause the app if it decides to abandon the read.
- Fixed cachefiles_issue_read() to not wait for the object state to match FSCACHE_WANT_READ as cachefiles_query_occupancy() should have done that already.
- Fixed netfs_retry_write_stream() to handle superfluous subreqs correctly (borrowing from read retry).
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
[6] https://sashiko.dev/#/patchset/20260722130218.78958-1-dhowells%40redhat.com
[7] https://sashiko.dev/#/patchset/20260804100224.2748935-1-dhowells%40redhat.com
[8] https://sashiko.dev/#/patchset/20260810144746.574036-1-dhowells%40redhat.com
David Howells (36):
block: Fix start and length check added to iov_iter_extract_bvecs()
mm: Make readahead store folio count in readahead_control
mm: Add a bulk end-writeback tool
netfs: Use uoff_t instead of unsigned long long and loff_t 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: Make mempool available for bvecq
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
netfs: trace: Change the "clear" folio traces to "endwb"
netfs: trace: Rejig a couple of the tracepoints
netfs: Add some functions to wrap the all-queued handling
netfs: Make deprecated PG_private_2 support optional
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: Build a list of regions undergoing writeback
netfs: Simplify writeback cleanup
netfs: Simplify read abandonment
netfs: Check for too much data being read
netfs: Add a method to get an estimate of the amount that can be
written
netfs: Rework writeback to estimate
netfs: Set subrequest->source at alloc before trace emission
netfs: Combine prepare and issue ops
netfs: Clean up now-unused code
cachefiles: Preset the state xattr when creating a new file
Documentation/core-api/folio_queue.rst | 209 ---- Documentation/core-api/index.rst | 1 - Documentation/filesystems/netfs_library.rst | 2 +- fs/9p/vfs_addr.c | 61 +- fs/afs/dir.c | 38 +- fs/afs/dir_edit.c | 43 +- fs/afs/dir_search.c | 33 +- fs/afs/file.c | 35 +- fs/afs/fsclient.c | 8 +- fs/afs/inode.c | 2 +- fs/afs/internal.h | 14 +- fs/afs/symlink.c | 36 +- fs/afs/write.c | 36 +- fs/afs/yfsclient.c | 6 +- fs/cachefiles/interface.c | 96 +- fs/cachefiles/internal.h | 18 +- fs/cachefiles/io.c | 594 ++++++++--- fs/cachefiles/namei.c | 34 +- fs/cachefiles/xattr.c | 82 +- fs/ceph/Kconfig | 1 + fs/ceph/addr.c | 127 ++- fs/netfs/Kconfig | 3 + fs/netfs/Makefile | 4 +- fs/netfs/buffered_read.c | 545 ++++++---- fs/netfs/buffered_write.c | 69 +- fs/netfs/bvecq.c | 857 ++++++++++++++++ fs/netfs/direct_read.c | 116 +-- fs/netfs/direct_write.c | 179 ++-- fs/netfs/fscache_cookie.c | 8 +- fs/netfs/fscache_io.c | 12 +- fs/netfs/internal.h | 121 ++- fs/netfs/iterator.c | 391 +++---- fs/netfs/main.c | 21 +- fs/netfs/misc.c | 157 +-- fs/netfs/objects.c | 36 +- fs/netfs/read_collect.c | 371 ++++--- fs/netfs/read_pgpriv2.c | 211 ++-- fs/netfs/read_retry.c | 253 +++-- fs/netfs/read_single.c | 180 ++-- fs/netfs/rolling_buffer.c | 249 ----- fs/netfs/stats.c | 10 +- fs/netfs/write_collect.c | 319 ++++-- fs/netfs/write_issue.c | 1027 +++++++++---------- fs/netfs/write_retry.c | 192 ++-- 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 | 148 +-- fs/smb/client/smb2ops.c | 84 +- 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 | 361 +++++++ include/linux/folio_queue.h | 282 ----- include/linux/fscache-cache.h | 2 +- include/linux/fscache.h | 53 +- include/linux/iov_iter.h | 87 +- include/linux/netfs.h | 247 +++-- include/linux/pagemap.h | 10 + include/linux/rolling_buffer.h | 61 -- include/linux/uio.h | 17 +- include/linux/writeback.h | 10 + include/trace/events/cachefiles.h | 81 +- include/trace/events/fscache.h | 10 +- include/trace/events/netfs.h | 281 +++-- kernel/bpf/btf.c | 2 - lib/iov_iter.c | 567 +++++----- lib/scatterlist.c | 82 +- lib/tests/kunit_iov_iter.c | 131 ++- mm/page-writeback.c | 45 + mm/readahead.c | 5 + net/9p/client.c | 8 +- 74 files changed, 5523 insertions(+), 4094 deletions(-) delete mode 100644 Documentation/core-api/folio_queue.rst create mode 100644 fs/netfs/bvecq.c delete mode 100644 fs/netfs/rolling_buffer.c 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 v11 1/36 block: Fix start and length check added to iov_iter_extract_bvecs()
Commit 14b007e17881 added an address check using iter_iov_addr() and a length check using iter_iov_len() to iov_iter_extract_bvecs(), but these cannot be used so and are unsafe in this circumstance as the functions have hardwired assumptions about the iterator type. They should only be used with ITER_UBUF or ITER_IOVEC-type iterators; they shouldn't be used with ITER_BVEC, ITER_KVEC, ITER_FOLIOQ, ITER_XARRAY or ITER_DISCARD iterators.
This proves to be a problem for cachefiles as an iterator of type ITER_FOLIOQ is passed and iter_iov_addr() and iter_iov_len() both malfunction because iter->__iov in iter_iov() is not pointing to an iovec array.
Fix this by using iov_iter_alignment() instead.
--- lib/iov_iter.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
lib/iov_iter.c +9 -2
@@ -1921,15 +1921,22 @@ ssize_t iov_iter_extract_bvecs(struct iov_iter *iter, struct bio_vec *bv, unsigned short max_vecs, unsigned mem_align_mask, iov_iter_extraction_t extraction_flags) { - unsigned long start = (unsigned long)iter_iov_addr(iter); unsigned short entries_left = max_vecs - *nr_vecs;unsigned short nr_pages, i =0 ;size_t left, offset, len;struct page **pages;ssize_t size; -if ((start |iter_iov_len (iter)) & mem_align_mask) +if (likely (iter_is_ubuf (iter) || +iter_is_iovec (iter) || +iov_iter_is_kvec (iter))) { +unsigned long start = (unsigned long )iter_iov_addr (iter); + +if ((start |iter_iov_len (iter)) & mem_align_mask) +return -EINVAL ; + }else if (iov_iter_alignment (iter) & mem_align_mask) {return -EINVAL ; + }/* * Move page array up in the allocated memory for the bio vecs as far as
David Howells
maintainerPATCH v11 2/36 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
@@ -1377,6 +1377,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;
@@ -1556,6 +1557,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 v11 3/36 mm: Add a bulk end-writeback tool
In reply to David HowellsAdd a tool to perform bulk folio_end_writeback() across a series of contiguous folios. The function takes a beginning and an end file position and ends any folio that lies wholly in the range, leaving the end position of the last folio it considered in the iterator state for the filesystem to use as a hint for when to call again.
As folio_end_writeback() has to access the xarray to clear the marks set on the entries for the folios involved, this tool provides the opportunity to merge the two xarray accesses (the iteration and the unmarking) and also do statistics update in bulk.
--- fs/netfs/write_collect.c | 51 +++++++++++++++++++++++++++++++++++++++ include/linux/writeback.h | 10 ++++++++ mm/page-writeback.c | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+)
fs/netfs/write_collect.c +51 -0
@@ -21,6 +21,57 @@#define NEED_RETRY 0x10/* A front op requests retrying */ #define SAW_FAILURE 0x20/* One stream or hit a permanent failure */ +struct end_writeback_ctrl { +struct xa_state xas; +uoff_t fend; +}; + +/** +* end_writeback_iter - End writeback for the folios within the range +* @mapping: The pagecache to modify +* @from: Pointer to the starting position +* @to: The end position (exclusive) +* @ctrl: Iterator state +* @folio: The last return from this function or NULL if first call +* +* Remove the writeback mark on folios that are entirely within in the given +* range, where @from is included in the range, but @to is excluded from the +* range. +* +* Return: The folio to end writeback upon or NULL if the next folio isn't +* wholly within the range. Note that this does not necessarily imply that the +* ending is complete. @ctrl->fend is updated to point directly beyond the +* folio that was considered and may be negative if cast to loff_t. +*/ +static +struct folio *end_writeback_iter (struct address_space *mapping, +uoff_t from,uoff_t to, +struct end_writeback_ctrl *ctrl, +struct folio *folio) +{ +if (!folio) { +lockdep_assert_in_rcu_read_lock (); + ctrl->xas = (struct xa_state ) +__XA_STATE (&mapping->i_pages, from /PAGE_SIZE ,0 ,0 ); + folio =xas_find (&ctrl->xas, (to -1 ) /PAGE_SIZE ); + }else { +folio_end_writeback (folio); + retry: + folio =xas_next_entry (&ctrl->xas, (to -1 ) /PAGE_SIZE ); + } + +if (xas_retry (&ctrl->xas, folio)) + goto retry; + +if (!folio) +return NULL ; + + ctrl->fend =folio_next_pos (folio); +if (ctrl->fend > to) + folio =NULL ; +return folio; +} +static void netfs_dump_request (const struct netfs_io_request *rreq) { pr_err("Request R=%08x r=%d fl=%lx or=%x e=%ld\n",
include/linux/writeback.h +10 -0
@@ -358,6 +358,16 @@ bool wb_over_bg_thresh(struct bdi_writeback *wb);struct folio *writeback_iter (struct address_space *mapping,struct writeback_control *wbc,struct folio *folio,int *error); +/* end_writeback_iter() state. */ +struct end_writeback_ctrl { +struct xa_state xas;/* The xarray walker */ +uoff_t fend;/* The next file pos after the folio last considered. */ +}; + +struct folio *end_writeback_iter (struct address_space *mapping, +struct end_writeback_ctrl *ctrl, +uoff_t from,uoff_t to,struct folio *folio); +int do_writepages (struct address_space *mapping,struct writeback_control *wbc);void writeback_set_ratelimit (void ); void tag_pages_for_writeback(struct address_space *mapping,
mm/page-writeback.c +45 -0
51 lines not on this page · raw message
David Howells
maintainerPATCH v11 4/36 netfs: Use uoff_t instead of unsigned long long and loff_t
In reply to David HowellsUse uoff_t instead of unsigned long long and loff_t for file positions that can't be negative.
--- fs/afs/file.c | 4 +- fs/cachefiles/interface.c | 10 ++-- fs/cachefiles/internal.h | 4 +- fs/cachefiles/io.c | 24 +++++----- fs/ceph/addr.c | 4 +- fs/netfs/buffered_read.c | 22 ++++----- fs/netfs/buffered_write.c | 10 ++-- fs/netfs/direct_read.c | 2 +- fs/netfs/direct_write.c | 8 ++-- fs/netfs/fscache_cookie.c | 8 ++-- fs/netfs/fscache_io.c | 8 ++-- fs/netfs/internal.h | 10 ++-- fs/netfs/iterator.c | 2 +- fs/netfs/misc.c | 8 ++-- fs/netfs/objects.c | 2 +- fs/netfs/read_collect.c | 4 +- fs/netfs/read_pgpriv2.c | 8 ++-- fs/netfs/read_retry.c | 2 +- fs/netfs/write_collect.c | 10 ++-- fs/netfs/write_issue.c | 10 ++-- fs/netfs/write_retry.c | 2 +- include/linux/fscache-cache.h | 2 +- include/linux/fscache.h | 36 +++++++-------- include/linux/netfs.h | 74 ++++++++++++++--------------- include/trace/events/cachefiles.h | 30 ++++++------ include/trace/events/fscache.h | 10 ++-- include/trace/events/netfs.h | 77 +++++++++++++++---------------- 27 files changed, 195 insertions(+), 196 deletions(-)
fs/afs/file.c +2 -2
@@ -413,7 +413,7 @@ static int afs_init_request(struct netfs_io_request *rreq, struct file *file)return 0 ; } -static int afs_check_write_begin (struct file *file,loff_t pos,unsigned len, +static int afs_check_write_begin (struct file *file,uoff_t pos,unsigned len,struct folio **foliop,void **_fsdata) {struct afs_vnode *vnode =AFS_FS_I (file_inode (file));
@@ -451,7 +451,7 @@ void afs_set_i_size(struct afs_vnode *vnode, loff_t new_i_size)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) +static void afs_update_i_size (struct inode *inode,uoff_t new_i_size) {afs_set_i_size (AFS_FS_I (inode), new_i_size); }
fs/cachefiles/interface.c +5 -5
@@ -111,7 +111,7 @@ static int cachefiles_adjust_size(struct cachefiles_object *object)struct iattr newattrs;struct file *file = object->file;uint64_t ni_size; -loff_t oi_size; +uoff_t oi_size;int ret; ni_size = object->cookie->object_size;
@@ -225,11 +225,11 @@ static bool cachefiles_lookup_cookie(struct fscache_cookie *cookie)* any unused granules. */ static bool cachefiles_shorten_object (struct cachefiles_object *object, -struct file *file,loff_t new_size) +struct file *file,uoff_t new_size) {struct cachefiles_cache *cache = object->volume->cache;struct inode *inode =file_inode (file); -loff_t i_size, dio_size; +uoff_t i_size, dio_size;int ret; dio_size =round_up (new_size,CACHEFILES_DIO_BLOCK_SIZE );
@@ -271,14 +271,14 @@ static bool cachefiles_shorten_object(struct cachefiles_object *object,* Resize the backing object. */ static void cachefiles_resize_cookie (struct netfs_cache_resources *cres, -loff_t new_size) +uoff_t new_size) {struct cachefiles_object *object =cachefiles_cres_object (cres);struct cachefiles_cache *cache = object->volume->cache;struct fscache_cookie *cookie = object->cookie;const struct cred *saved_cred;struct file *file =cachefiles_cres_file (cres); -loff_t old_size = cookie->object_size; +uoff_t old_size = cookie->object_size;_enter ("%llu->%llu" , old_size, new_size);
fs/cachefiles/internal.h +2 -2
@@ -203,11 +203,11 @@ extern bool cachefiles_begin_operation(struct netfs_cache_resources *cres, enum fscache_want_state want_state);extern int __cachefiles_prepare_write (struct cachefiles_object *object,struct file *file, -loff_t *_start,size_t *_len,size_t upper_len, +uoff_t *_start,size_t *_len,size_t upper_len,bool no_space_allocated_yet);extern int __cachefiles_write (struct cachefiles_object *object,struct file *file, -loff_t start_pos, +uoff_t start_pos,struct iov_iter *iter,netfs_io_terminated_t term_func,void *term_func_priv);
fs/cachefiles/io.c +12 -12
@@ -19,7 +19,7 @@struct cachefiles_kiocb {struct kiocb iocb;refcount_t ki_refcnt; -loff_t start; +uoff_t start;union {size_t skipped;size_t len;
@@ -73,7 +73,7 @@ static void cachefiles_read_complete(struct kiocb *iocb, long ret)* Initiate a read from the cache. */ static int cachefiles_read(struct netfs_cache_resources *cres, - loff_t start_pos, + uoff_t start_pos, struct iov_iter *iter, enum netfs_read_from_hole read_hole, netfs_io_terminated_t term_func,
@@ -197,8 +197,8 @@ static int cachefiles_read(struct netfs_cache_resources *cres,* of data starts and how long it is. */ static int cachefiles_query_occupancy (struct netfs_cache_resources *cres, -loff_t start,size_t len,size_t granularity, -loff_t *_data_start,size_t *_data_len) +uoff_t start,size_t len,size_t granularity, +uoff_t *_data_start,size_t *_data_len) {struct cachefiles_object *object;struct file *file;
@@ -280,7 +280,7 @@ static void cachefiles_write_complete(struct kiocb *iocb, long ret)*/ int __cachefiles_write (struct cachefiles_object *object,struct file *file, -loff_t start_pos, +uoff_t start_pos,struct iov_iter *iter,netfs_io_terminated_t term_func,void *term_func_priv)
@@ -357,7 +357,7 @@ int __cachefiles_write(struct cachefiles_object *object, }static int cachefiles_write (struct netfs_cache_resources *cres, -loff_t start_pos, +uoff_t start_pos,struct iov_iter *iter,netfs_io_terminated_t term_func,void *term_func_priv)
@@ -377,7 +377,7 @@ static int cachefiles_write(struct netfs_cache_resources *cres,static inline enum netfs_io_source cachefiles_do_prepare_read (struct netfs_cache_resources *cres, -loff_t start,size_t *_len,loff_t i_size, +uoff_t start,size_t *_len,loff_t i_size,unsigned long *_flags,ino_t netfs_ino) {enum cachefiles_prepare_read_trace why;
@@ -483,7 +483,7 @@ cachefiles_do_prepare_read(struct netfs_cache_resources *cres,* boundary as appropriate. */ static enum netfs_io_source cachefiles_prepare_read (struct netfs_io_subrequest *subreq, -unsigned long long i_size) +uoff_t i_size) { return cachefiles_do_prepare_read(&subreq->rreq->cache_resources, subreq->start, &subreq->len, i_size,
@@ -495,7 +495,7 @@ static enum netfs_io_source cachefiles_prepare_read(struct netfs_io_subrequest **/ int __cachefiles_prepare_write (struct cachefiles_object *object,struct file *file, -loff_t *_start,size_t *_len,size_t upper_len, +uoff_t *_start,size_t *_len,size_t upper_len,bool no_space_allocated_yet) {struct cachefiles_cache *cache = object->volume->cache;
@@ -577,8 +577,8 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, }static int cachefiles_prepare_write (struct netfs_cache_resources *cres, -loff_t *_start,size_t *_len,size_t upper_len, -loff_t i_size,bool no_space_allocated_yet) +uoff_t *_start,size_t *_len,size_t upper_len, +uoff_t i_size,bool no_space_allocated_yet) {struct cachefiles_object *object =cachefiles_cres_object (cres);struct cachefiles_cache *cache = object->volume->cache;
@@ -628,7 +628,7 @@ static void cachefiles_issue_write(struct netfs_io_subrequest *subreq)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; +uoff_t start = subreq->start;int ret; _enter("W=%x[%x] %llx-%llx",
fs/ceph/addr.c +2 -2
@@ -65,7 +65,7 @@ (CONGESTION_ON_THRESH (congestion_kb) - \ (CONGESTION_ON_THRESH(congestion_kb) >> 2)) -static int ceph_netfs_check_write_begin (struct file *file,loff_t pos,unsigned int len, +static int ceph_netfs_check_write_begin (struct file *file,uoff_t pos,unsigned int len,struct folio **foliop,void **_fsdata);static inline struct ceph_snap_context *page_snap_context (struct page *page)
@@ -1854,7 +1854,7 @@ ceph_find_incompatible(struct folio *folio)return NULL ; } -static int ceph_netfs_check_write_begin (struct file *file,loff_t pos,unsigned int len, +static int ceph_netfs_check_write_begin (struct file *file,uoff_t pos,unsigned int len,struct folio **foliop,void **_fsdata) {struct inode *inode =file_inode (file);
fs/netfs/buffered_read.c +11 -11
@@ -10,9 +10,9 @@#include "internal.h" static void netfs_cache_expand_readahead (struct netfs_io_request *rreq, -unsigned long long *_start, -unsigned long long *_len, -unsigned long long i_size) +uoff_t *_start, +uoff_t *_len, +uoff_t i_size) {struct netfs_cache_resources *cres = &rreq->cache_resources;
@@ -139,7 +139,7 @@ static ssize_t netfs_prepare_read_iterator(struct netfs_io_subrequest *subreq)static enum netfs_io_source netfs_cache_prepare_read (struct netfs_io_request *rreq,struct netfs_io_subrequest *subreq, -loff_t i_size) +uoff_t i_size) {struct netfs_cache_resources *cres = &rreq->cache_resources;enum netfs_io_source source;
@@ -269,9 +269,9 @@ static void netfs_mark_copy_to_cache(struct netfs_io_request *rreq,static void netfs_read_to_pagecache (struct netfs_io_request *rreq) {struct folio_queue *fq = rreq->buffer.tail; -unsigned long long start = rreq->start;unsigned int offset =0 ;ssize_t size = rreq->len; +uoff_t start = rreq->start;int ret =0 , slot =0 ; do {
@@ -293,8 +293,8 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) source =netfs_cache_prepare_read (rreq, subreq, rreq->i_size); subreq->source = source;if (source ==NETFS_DOWNLOAD_FROM_SERVER ) { -unsigned long long zero_point =netfs_read_zero_point (rreq->inode); -unsigned long long zp =umin (zero_point, rreq->i_size); +uoff_t zero_point =netfs_read_zero_point (rreq->inode); +uoff_t zp =umin (zero_point, rreq->i_size);size_t len = subreq->len;if (unlikely (rreq->origin ==NETFS_READ_SINGLE ))
@@ -642,11 +642,11 @@ EXPORT_SYMBOL(netfs_read_folio);* If any of these criteria are met, then zero out the unwritten parts * of the folio and return true. Otherwise, return false. */ -static bool netfs_skip_folio_read (struct folio *folio,loff_t pos,size_t len, +static bool netfs_skip_folio_read (struct folio *folio,uoff_t pos,size_t len,bool always_fill) {struct inode *inode =folio_inode (folio); -loff_t i_size =i_size_read (inode); +uoff_t i_size =i_size_read (inode);size_t offset =offset_in_folio (folio, pos);size_t plen =folio_size (folio);
@@ -711,7 +711,7 @@ static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len,*/ int netfs_write_begin (struct netfs_inode *ctx,struct file *file,struct address_space *mapping, -loff_t pos,unsigned int len,struct folio **_folio, +uoff_t pos,unsigned int len,struct folio **_folio,void **_fsdata) {struct netfs_io_request *rreq;
@@ -807,7 +807,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,struct netfs_io_request *rreq;struct address_space *mapping = folio->mapping;struct netfs_inode *ctx =netfs_inode (mapping->host); -unsigned long long start =folio_pos (folio); +uoff_t start =folio_pos (folio);size_t flen =folio_size (folio);int ret;
fs/netfs/buffered_write.c +5 -5
@@ -17,7 +17,7 @@* as possible to hold as much of the remaining length as possible in one go. */ static struct folio *netfs_grab_folio_for_write (struct address_space *mapping, -loff_t pos,size_t part) +uoff_t pos,size_t part) {pgoff_t index = pos /PAGE_SIZE ;fgf_t fgp_flags =FGP_WRITEBEGIN ;
@@ -35,9 +35,9 @@ static struct folio *netfs_grab_folio_for_write(struct address_space *mapping,* the values actually are. */ void netfs_update_i_size (struct netfs_inode *ctx,struct inode *inode, -loff_t pos,size_t copied) +uoff_t pos,size_t copied) { -loff_t i_size, end = pos + copied; +uoff_t i_size, end = pos + copied;blkcnt_t add;size_t gap;
@@ -102,7 +102,7 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,struct folio *folio =NULL , *writethrough =NULL ;unsigned int bdp_flags = (iocb->ki_flags &IOCB_NOWAIT ) ?BDP_ASYNC :0 ;ssize_t written =0 , ret, ret2; -loff_t pos = iocb->ki_pos; +uoff_t pos = iocb->ki_pos;size_t max_chunk =mapping_max_folio_size (mapping);bool maybe_trouble = false;
@@ -134,7 +134,7 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,enum netfs_folio_trace trace;struct netfs_folio *finfo;struct netfs_group *group; -unsigned long long fpos; +uoff_t fpos;size_t flen;size_t offset;/* Offset into pagecache folio */ size_t part;/* Bytes to write to folio */
fs/netfs/direct_read.c +1 -1
@@ -47,8 +47,8 @@ static void netfs_prepare_dio_read_iterator(struct netfs_io_subrequest *subreq)*/ static void netfs_dispatch_unbuffered_reads (struct netfs_io_request *rreq) { -unsigned long long start = rreq->start;ssize_t size = rreq->len; +uoff_t start = rreq->start;int ret; do {
fs/netfs/direct_write.c +4 -4
@@ -225,9 +225,9 @@ ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter * struct netfs_group *netfs_group) {struct netfs_io_request *wreq; -unsigned long long start = iocb->ki_pos; -unsigned long long end = start +iov_iter_count (iter);ssize_t ret, n; +uoff_t start = iocb->ki_pos; +uoff_t end = start +iov_iter_count (iter);size_t len =iov_iter_count (iter);bool async = !is_sync_kiocb (iocb);
@@ -336,8 +336,8 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)struct inode *inode = mapping->host;struct netfs_inode *ictx =netfs_inode (inode);ssize_t ret; -loff_t pos = iocb->ki_pos; -unsigned long long end = pos +iov_iter_count (from) -1 ; +uoff_t pos = iocb->ki_pos; +uoff_t end = pos +iov_iter_count (from) -1 ;_enter ("%llx,%zx,%llx" , pos,iov_iter_count (from),i_size_read (inode));
fs/netfs/fscache_cookie.c +4 -4
@@ -327,7 +327,7 @@ static struct fscache_cookie *fscache_alloc_cookie(u8 advice, const void *index_key, size_t index_key_len, const void *aux_data, size_t aux_data_len, - loff_t object_size) + uoff_t object_size) { struct fscache_cookie *cookie;
@@ -452,7 +452,7 @@ struct fscache_cookie *__fscache_acquire_cookie(u8 advice, const void *index_key, size_t index_key_len, const void *aux_data, size_t aux_data_len, - loff_t object_size) + uoff_t object_size) { struct fscache_cookie *cookie;
@@ -663,7 +663,7 @@ static void fscache_unuse_cookie_locked(struct fscache_cookie *cookie)* Stop using the cookie for I/O. */ void __fscache_unuse_cookie (struct fscache_cookie *cookie, -const void *aux_data,const loff_t *object_size) +const void *aux_data,const uoff_t *object_size) {unsigned int debug_id = cookie->debug_id;unsigned int r =refcount_read (&cookie->ref);
@@ -1049,7 +1049,7 @@ static void fscache_perform_invalidation(struct fscache_cookie *cookie)* Invalidate an object. */ void __fscache_invalidate (struct fscache_cookie *cookie, -const void *aux_data,loff_t new_size, +const void *aux_data,uoff_t new_size,unsigned int flags) {bool is_caching;
fs/netfs/fscache_io.c +4 -4
@@ -162,7 +162,7 @@ EXPORT_SYMBOL(__fscache_begin_write_operation);struct fscache_write_request {struct netfs_cache_resources cache_resources;struct address_space *mapping; -loff_t start; +uoff_t start;size_t len;bool set_bits;bool using_pgpriv2;
@@ -171,7 +171,7 @@ struct fscache_write_request { };void __fscache_clear_page_bits (struct address_space *mapping, -loff_t start,size_t len) +uoff_t start,size_t len) {pgoff_t first = start /PAGE_SIZE ;pgoff_t last = (start + len -1 ) /PAGE_SIZE ;
@@ -208,7 +208,7 @@ static void fscache_wreq_done(void *priv, ssize_t transferred_or_error)void __fscache_write_to_cache (struct fscache_cookie *cookie,struct address_space *mapping, -loff_t start,size_t len,loff_t i_size, +uoff_t start,size_t len,uoff_t i_size,netfs_io_terminated_t term_func,void *term_func_priv,bool using_pgpriv2,bool cond)
@@ -267,7 +267,7 @@ EXPORT_SYMBOL(__fscache_write_to_cache);/* * Change the size of a backing object. */ -void __fscache_resize_cookie (struct fscache_cookie *cookie,loff_t new_size) +void __fscache_resize_cookie (struct fscache_cookie *cookie,uoff_t new_size) {struct netfs_cache_resources cres;
fs/netfs/internal.h +5 -5
@@ -33,7 +33,7 @@ int netfs_prefetch_for_write(struct file *file, struct folio *folio,* buffered_write.c */ void netfs_update_i_size (struct netfs_inode *ctx,struct inode *inode, -loff_t pos,size_t copied); +uoff_t pos,size_t copied);/* * main.c
@@ -86,7 +86,7 @@ void netfs_wait_for_put_ra_refs(struct netfs_io_request *rreq);*/ struct netfs_io_request *netfs_alloc_request (struct address_space *mapping,struct file *file, -loff_t start,size_t len, +uoff_t start,size_t len,enum netfs_io_origin origin);void netfs_get_request (struct netfs_io_request *rreq,enum netfs_rreq_ref_trace what);void netfs_clear_subrequests (struct netfs_io_request *rreq);
@@ -203,11 +203,11 @@ void netfs_write_collection_worker(struct work_struct *work);*/ struct netfs_io_request *netfs_create_write_req (struct address_space *mapping,struct file *file, -loff_t start, +uoff_t start,enum netfs_io_origin origin);void netfs_prepare_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream, -loff_t start); +uoff_t start);void netfs_reissue_write (struct netfs_io_stream *stream,struct netfs_io_subrequest *subreq,struct iov_iter *source);
@@ -215,7 +215,7 @@ void netfs_issue_write(struct netfs_io_request *wreq, struct netfs_io_stream *stream);size_t netfs_advance_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream, -loff_t start,size_t len,bool to_eof); +uoff_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,
fs/netfs/iterator.c +1 -1
@@ -209,7 +209,7 @@ static size_t netfs_limit_xarray(const struct iov_iter *iter, size_t start_offse {struct folio *folio;unsigned int nsegs =0 ; -loff_t pos = iter->xarray_start + iter->iov_offset; +uoff_t pos = iter->xarray_start + iter->iov_offset;pgoff_t index = pos /PAGE_SIZE ;size_t span =0 , n = iter->count;
fs/netfs/misc.c +4 -4
@@ -193,7 +193,7 @@ void netfs_clear_inode_writeback(struct inode *inode, const void *aux)struct fscache_cookie *cookie =netfs_i_cookie (netfs_inode (inode));if (inode_state_read_once (inode) &I_PINNING_NETFS_WB ) { -loff_t i_size =i_size_read (inode); +uoff_t i_size =i_size_read (inode);fscache_unuse_cookie (cookie, aux, &i_size); } }
@@ -218,8 +218,8 @@ void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length)_enter ("{%lx},%zx,%zx" , folio->index, offset, length);if (offset ==0 && length == flen) { -unsigned long long i_size, remote_i_size, zero_point; -unsigned long long fpos =folio_pos (folio), end; +uoff_t i_size, remote_i_size, zero_point; +uoff_t fpos =folio_pos (folio), end;netfs_read_sizes (inode, &i_size, &remote_i_size, &zero_point); end =umin (fpos + flen, i_size);
@@ -305,7 +305,7 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp) {struct inode *inode =folio_inode (folio);struct netfs_inode *ctx =netfs_inode (inode); -unsigned long long i_size, remote_i_size, zero_point, end; +uoff_t i_size, remote_i_size, zero_point, end;if (folio_test_dirty (folio))return false;
fs/netfs/objects.c +1 -1
@@ -16,7 +16,7 @@ static void netfs_free_request(struct work_struct *work);*/ struct netfs_io_request *netfs_alloc_request (struct address_space *mapping,struct file *file, -loff_t start,size_t len, +uoff_t start,size_t len,enum netfs_io_origin origin) {static atomic_t debug_ids;
fs/netfs/read_collect.c +2 -2
@@ -153,8 +153,8 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq, unsigned int *notes) {struct folio_queue *folioq = rreq->buffer.tail; -unsigned long long collected_to = rreq->collected_to;unsigned int slot = rreq->buffer.first_tail_slot; +uoff_t collected_to = rreq->collected_to;if (rreq->cleaned_to >= rreq->collected_to)return ;
@@ -179,7 +179,7 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,for (;;) {struct folio *folio; -unsigned long long fpos, fend; +uoff_t fpos, fend;size_t fsize; folio =folioq_folio (folioq, slot);
fs/netfs/read_pgpriv2.c +4 -4
@@ -20,7 +20,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio {struct netfs_io_stream *cache = &creq->io_streams[1 ];size_t fsize =folio_size (folio), flen = fsize; -loff_t fpos =folio_pos (folio), i_size; +uoff_t fpos =folio_pos (folio), i_size;bool to_eof = false;_enter ("" );
@@ -175,8 +175,8 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)bool netfs_pgpriv2_unlock_copied_folios (struct netfs_io_request *creq) {struct folio_queue *folioq = creq->buffer.tail; -unsigned long long collected_to = creq->collected_to;unsigned int slot = creq->buffer.first_tail_slot; +uoff_t collected_to = creq->collected_to;bool made_progress = false;if (slot >=folioq_nr_slots (folioq)) {
@@ -186,7 +186,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq)for (;;) {struct folio *folio; -unsigned long long fpos, fend; +uoff_t fpos, fend;size_t fsize, flen; folio =folioq_folio (folioq, slot);
@@ -199,7 +199,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq) fsize =folio_size (folio); flen = fsize; - fend = min_t(unsigned long long, fpos + flen, creq->i_size); + fend =min_t (uoff_t, fpos + flen, creq->i_size);trace_netfs_collect_folio (creq, folio, fend, collected_to);
fs/netfs/read_retry.c +1 -1
@@ -75,7 +75,7 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq) do { struct netfs_io_subrequest *from, *to, *tmp; struct iov_iter source; - unsigned long long start, len; + uoff_t start, len; size_t part; bool boundary = false, subreq_superfluous = false;
fs/netfs/write_collect.c +5 -5
@@ -118,7 +118,7 @@ int netfs_folio_written_back(struct folio *folio)/* Streaming writes cannot be redirtied whilst under writeback, * so discard the streaming record. */ -unsigned long long fend; +uoff_t fend; fend =folio_pos (folio) + finfo->dirty_offset + finfo->dirty_len;spin_lock (&ictx->inode.i_lock);
@@ -166,8 +166,8 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq, unsigned int *notes) {struct folio_queue *folioq = wreq->buffer.tail; -unsigned long long collected_to = wreq->collected_to;unsigned int slot = wreq->buffer.first_tail_slot; +uoff_t collected_to = wreq->collected_to;if (WARN_ON_ONCE (!folioq)) {pr_err ("[!] Writeback unlock found empty rolling buffer!\n" );
@@ -191,7 +191,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq,for (;;) {struct folio *folio;struct netfs_folio *finfo; -unsigned long long fpos, fend; +uoff_t fpos, fend;size_t fsize, flen; folio =folioq_folio (folioq, slot);
@@ -205,7 +205,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq, finfo =netfs_folio_info (folio); flen = finfo ? finfo->dirty_offset + finfo->dirty_len : fsize; - fend = min_t(unsigned long long, fpos + flen, wreq->i_size); + fend =min_t (uoff_t, fpos + flen, wreq->i_size);trace_netfs_collect_folio (wreq, folio, fend, collected_to);
@@ -252,8 +252,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq) {struct netfs_io_subrequest *front, *remove;struct netfs_io_stream *stream; -unsigned long long collected_to, issued_to;unsigned int notes; +uoff_t collected_to, issued_to;int s;_enter ("%llx-%llx" , wreq->start, wreq->start + wreq->len);
fs/netfs/write_issue.c +5 -5
@@ -89,7 +89,7 @@ static void netfs_kill_dirty_pages(struct address_space *mapping,*/ struct netfs_io_request *netfs_create_write_req (struct address_space *mapping,struct file *file, -loff_t start, +uoff_t start,enum netfs_io_origin origin) {struct netfs_io_request *wreq;
@@ -156,7 +156,7 @@ EXPORT_SYMBOL(netfs_prepare_write_failed);*/ void netfs_prepare_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream, -loff_t start) +uoff_t start) {struct netfs_io_subrequest *subreq;struct iov_iter *wreq_iter = &wreq->buffer.iter;
@@ -279,7 +279,7 @@ 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) +uoff_t start,size_t len,bool to_eof) {struct netfs_io_subrequest *subreq = stream->construct;size_t part;
@@ -330,7 +330,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,struct netfs_folio *finfo;size_t iter_off =0 ;size_t fsize =folio_size (folio), flen = fsize, foff =0 ; -loff_t fpos =folio_pos (folio), i_size; +uoff_t fpos =folio_pos (folio), i_size;bool to_eof = false, streamw = false;bool debug = false;
@@ -721,7 +721,7 @@ static int netfs_write_folio_single(struct netfs_io_request *wreq,struct netfs_io_stream *stream;size_t iter_off =0 ;size_t fsize =folio_size (folio), flen; -loff_t fpos =folio_pos (folio); +uoff_t fpos =folio_pos (folio);ssize_t ret;bool to_eof = false;bool no_debug = false;
fs/netfs/write_retry.c +1 -1
@@ -55,7 +55,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, do { struct netfs_io_subrequest *subreq = NULL, *from, *to, *tmp; struct iov_iter source; - unsigned long long start, len; + uoff_t start, len; size_t part; bool boundary = false;
include/linux/fscache-cache.h +1 -1
@@ -67,7 +67,7 @@ struct fscache_cache_ops {/* Change the size of a data object */ void (*resize_cookie)(struct netfs_cache_resources *cres, -loff_t new_size); +uoff_t new_size);/* Invalidate an object */ bool (*invalidate_cookie)(struct fscache_cookie *cookie);
include/linux/fscache.h +18 -18
@@ -112,7 +112,7 @@ struct fscache_cookie {struct list_head proc_link;/* Link in proc list */ struct list_head commit_link;/* Link in commit queue */ struct work_struct work;/* Commit/relinq/withdraw work */ -loff_t object_size;/* Size of the netfs object */ +uoff_t object_size;/* Size of the netfs object */ unsigned long unused_at;/* Time at which unused (jiffies) */ unsigned long flags;#define FSCACHE_COOKIE_RELINQUISHED 0/* T if cookie has been relinquished */
@@ -163,22 +163,22 @@ extern struct fscache_cookie *__fscache_acquire_cookie( u8, const void *, size_t, const void *, size_t, - loff_t); + uoff_t);extern void __fscache_use_cookie (struct fscache_cookie *,bool ); -extern void __fscache_unuse_cookie (struct fscache_cookie *,const void *,const loff_t *); +extern void __fscache_unuse_cookie (struct fscache_cookie *,const void *,const uoff_t *);extern void __fscache_relinquish_cookie (struct fscache_cookie *,bool ); -extern void __fscache_resize_cookie (struct fscache_cookie *,loff_t ); -extern void __fscache_invalidate (struct fscache_cookie *,const void *,loff_t ,unsigned int ); +extern void __fscache_resize_cookie (struct fscache_cookie *,uoff_t ); +extern void __fscache_invalidate (struct fscache_cookie *,const void *,uoff_t ,unsigned int );extern int __fscache_begin_read_operation (struct netfs_cache_resources *,struct fscache_cookie *);extern int __fscache_begin_write_operation (struct netfs_cache_resources *,struct fscache_cookie *);void __fscache_write_to_cache (struct fscache_cookie *cookie,struct address_space *mapping, -loff_t start,size_t len,loff_t i_size, +uoff_t start,size_t len,uoff_t i_size,netfs_io_terminated_t term_func,void *term_func_priv,bool using_pgpriv2,bool cond); -extern void __fscache_clear_page_bits (struct address_space *,loff_t ,size_t ); +extern void __fscache_clear_page_bits (struct address_space *,uoff_t ,size_t );/** * fscache_acquire_volume - Register a volume as desiring caching services
@@ -249,7 +249,7 @@ struct fscache_cookie *fscache_acquire_cookie(struct fscache_volume *volume, size_t index_key_len, const void *aux_data, size_t aux_data_len, - loff_t object_size) + uoff_t object_size) { if (!fscache_volume_valid(volume)) return NULL;
@@ -286,7 +286,7 @@ static inline void fscache_use_cookie(struct fscache_cookie *cookie,*/ static inline void fscache_unuse_cookie (struct fscache_cookie *cookie,const void *aux_data, -const loff_t *object_size) +const uoff_t *object_size) {if (fscache_cookie_valid (cookie))__fscache_unuse_cookie (cookie, aux_data, object_size);
@@ -327,7 +327,7 @@ static inline void *fscache_get_aux(struct fscache_cookie *cookie)*/ static inline void fscache_update_aux (struct fscache_cookie *cookie, -const void *aux_data,const loff_t *object_size) +const void *aux_data,const uoff_t *object_size) {void *p =fscache_get_aux (cookie);
@@ -343,7 +343,7 @@ extern atomic_t fscache_n_updates;static inline void __fscache_update_cookie (struct fscache_cookie *cookie,const void *aux_data, -const loff_t *object_size) +const uoff_t *object_size) {#ifdef CONFIG_FSCACHE_STATS atomic_inc (&fscache_n_updates);
@@ -369,7 +369,7 @@ void __fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data*/ static inline void fscache_update_cookie (struct fscache_cookie *cookie,const void *aux_data, -const loff_t *object_size) +const uoff_t *object_size) {if (fscache_cookie_enabled (cookie))__fscache_update_cookie (cookie, aux_data, object_size);
@@ -386,7 +386,7 @@ void fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data,* description. */ static inline -void fscache_resize_cookie (struct fscache_cookie *cookie,loff_t new_size) +void fscache_resize_cookie (struct fscache_cookie *cookie,uoff_t new_size) {if (fscache_cookie_enabled (cookie))__fscache_resize_cookie (cookie, new_size);
@@ -413,7 +413,7 @@ void fscache_resize_cookie(struct fscache_cookie *cookie, loff_t new_size)*/ static inline void fscache_invalidate (struct fscache_cookie *cookie, -const void *aux_data,loff_t size,unsigned int flags) +const void *aux_data,uoff_t size,unsigned int flags) {if (fscache_cookie_enabled (cookie))__fscache_invalidate (cookie, aux_data, size, flags);
@@ -502,7 +502,7 @@ static inline void fscache_end_operation(struct netfs_cache_resources *cres)*/ static inline int fscache_read(struct netfs_cache_resources *cres, - loff_t start_pos, + uoff_t start_pos, struct iov_iter *iter, enum netfs_read_from_hole read_hole, netfs_io_terminated_t term_func,
@@ -561,7 +561,7 @@ int fscache_begin_write_operation(struct netfs_cache_resources *cres,*/ static inline int fscache_write (struct netfs_cache_resources *cres, -loff_t start_pos, +uoff_t start_pos,struct iov_iter *iter,netfs_io_terminated_t term_func,void *term_func_priv)
@@ -581,7 +581,7 @@ int fscache_write(struct netfs_cache_resources *cres,* waiting. */ static inline void fscache_clear_page_bits (struct address_space *mapping, -loff_t start,size_t len, +uoff_t start,size_t len,bool caching) {if (caching)
@@ -615,7 +615,7 @@ static inline void fscache_clear_page_bits(struct address_space *mapping,*/ static inline void fscache_write_to_cache (struct fscache_cookie *cookie,struct address_space *mapping, -loff_t start,size_t len,loff_t i_size, +uoff_t start,size_t len,uoff_t i_size,netfs_io_terminated_t term_func,void *term_func_priv,bool using_pgpriv2,bool caching)
include/linux/netfs.h +37 -37
198 lines not on this page · raw message
include/trace/events/cachefiles.h +15 -15
@@ -449,7 +449,7 @@ TRACE_EVENT(cachefiles_vol_coherency, TRACE_EVENT(cachefiles_prep_read, TP_PROTO(struct cachefiles_object *obj, - loff_t start, + uoff_t start, size_t len, unsigned short flags, enum netfs_io_source source,
@@ -464,7 +464,7 @@ TRACE_EVENT(cachefiles_prep_read, __field(enum netfs_io_source, source) __field(enum cachefiles_prepare_read_trace, why) __field(size_t, len) - __field(loff_t, start) + __field(uoff_t, start) __field(unsigned int, netfs_inode) __field(unsigned int, cache_inode) ),
@@ -492,16 +492,16 @@ TRACE_EVENT(cachefiles_prep_read, TRACE_EVENT(cachefiles_read, TP_PROTO(struct cachefiles_object *obj, struct inode *backer, - loff_t start, + uoff_t start, size_t len), TP_ARGS(obj, backer, start, len), TP_STRUCT__entry( - __field(unsigned int, obj) - __field(unsigned int, backer) - __field(size_t, len) - __field(loff_t, start) + __field(unsigned int, obj) + __field(unsigned int, backer) + __field(size_t, len) + __field(uoff_t, start) ), TP_fast_assign(
@@ -521,16 +521,16 @@ TRACE_EVENT(cachefiles_read, TRACE_EVENT(cachefiles_write, TP_PROTO(struct cachefiles_object *obj, struct inode *backer, - loff_t start, + uoff_t start, size_t len), TP_ARGS(obj, backer, start, len), TP_STRUCT__entry( - __field(unsigned int, obj) - __field(unsigned int, backer) - __field(size_t, len) - __field(loff_t, start) + __field(unsigned int, obj) + __field(unsigned int, backer) + __field(size_t, len) + __field(uoff_t, start) ), TP_fast_assign(
@@ -549,7 +549,7 @@ TRACE_EVENT(cachefiles_write, TRACE_EVENT(cachefiles_trunc, TP_PROTO(struct cachefiles_object *obj, struct inode *backer, - loff_t from, loff_t to, enum cachefiles_trunc_trace why), + uoff_t from, uoff_t to, enum cachefiles_trunc_trace why), TP_ARGS(obj, backer, from, to, why),
@@ -557,8 +557,8 @@ TRACE_EVENT(cachefiles_trunc, __field(unsigned int, obj) __field(unsigned int, backer) __field(enum cachefiles_trunc_trace, why) - __field(loff_t, from) - __field(loff_t, to) + __field(uoff_t, from) + __field(uoff_t, to) ), TP_fast_assign(
include/trace/events/fscache.h +5 -5
@@ -460,13 +460,13 @@ TRACE_EVENT(fscache_relinquish, ); TRACE_EVENT(fscache_invalidate, - TP_PROTO(struct fscache_cookie *cookie, loff_t new_size), + TP_PROTO(struct fscache_cookie *cookie, uoff_t new_size), TP_ARGS(cookie, new_size), TP_STRUCT__entry( __field(unsigned int, cookie ) - __field(loff_t, new_size ) + __field(uoff_t, new_size ) ), TP_fast_assign(
@@ -479,14 +479,14 @@ TRACE_EVENT(fscache_invalidate, ); TRACE_EVENT(fscache_resize, - TP_PROTO(struct fscache_cookie *cookie, loff_t new_size), + TP_PROTO(struct fscache_cookie *cookie, uoff_t new_size), TP_ARGS(cookie, new_size), TP_STRUCT__entry( __field(unsigned int, cookie ) - __field(loff_t, old_size ) - __field(loff_t, new_size ) + __field(uoff_t, old_size ) + __field(uoff_t, new_size ) ), TP_fast_assign(
include/trace/events/netfs.h +38 -39
178 lines not on this page · raw message
David Howells
maintainerPATCH v11 5/36 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 v11 6/36 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_test_large_kmalloc (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 v11 7/36 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. 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 | 50 ++++++ include/linux/iov_iter.h | 74 ++++++++- include/linux/uio.h | 11 ++ lib/iov_iter.c | 333 ++++++++++++++++++++++++++++++++++++- lib/scatterlist.c | 67 +++++++- lib/tests/kunit_iov_iter.c | 260 +++++++++++++++++++++++++++++ 6 files changed, 789 insertions(+), 6 deletions(-) create mode 100644 include/linux/bvecq.h
include/linux/bvecq.h new file +50 -0
@@ -0,0 +1,50 @@ +/* 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). +*/ +struct bvecq { +struct bvecq *next;/* Next bvec in the list or NULL */ +struct bvecq *prev;/* Prev bvec in the list or NULL */ +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 */ +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 +331 -2
406 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 v11 8/36 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 | 830 +++++++++++++++++++++++++++++++++++ fs/netfs/internal.h | 1 + fs/netfs/stats.c | 4 +- include/linux/bvecq.h | 308 +++++++++++++ include/linux/netfs.h | 1 + include/trace/events/netfs.h | 24 + 7 files changed, 1168 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 +830 -0
830 lines not on this page · raw message
fs/netfs/internal.h +1 -0
@@ -173,6 +173,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 +308 -0
312 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
@@ -811,6 +811,30 @@ TRACE_EVENT(netfs_read_progress_at, __entry->rreq, __entry->cleaned_to, __entry->progress_at) ); +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 v11 9/36 netfs: Make mempool available for bvecq
In reply to David HowellsMake a mempool available for allocating bvecq structs. Use it automatically if anything other than GFP_KERNEL (with GFP_ZONEMASK flags masked off) is specified. Reading from a file can use GFP_KERNEL as the failure mode is straightforward and the same for DIO reads and writes. When it comes to writeback, however, the writeback_iter() API does not permit temporary failure, including ENOMEM, if WB_SYNC_ALL is set and the caller must process all folios to completion. (I'm not sure if EINTR constitutes an acceptable failure).
--- fs/netfs/bvecq.c | 39 +++++++++++++++++++++++++++++++++------ fs/netfs/internal.h | 1 + fs/netfs/main.c | 7 +++++++ include/linux/bvecq.h | 3 +++ 4 files changed, 44 insertions(+), 6 deletions(-)
fs/netfs/bvecq.c +33 -6
@@ -44,8 +44,9 @@ EXPORT_SYMBOL(bvecq_dump);* * Allocate a single bvecq node and initialise the header. A number of inline * slots are also allocated, rounded up to fit after the header in a power-of-2 -* slab object of up to 512 bytes (up to 29 slots on a 64-bit cpu). The slot -* array is not initialised. +* slab object of up to 512 bytes (up to 29 slots on a 64-bit cpu). The caller +* should be aware that the number of slots allocated may be more or less than +* the number requested. The slot array is not initialised. * * Return: The node pointer or NULL on allocation failure. */
@@ -56,16 +57,39 @@ struct bvecq *bvecq_alloc_one(size_t nr_slots, gfp_t gfp, bool for_writeback)const size_t max_slots = (max_size -sizeof (*bq)) /sizeof (bq->__bv[0 ]);size_t part =min (nr_slots, max_slots);size_t size =roundup_pow_of_two (struct_size (bq, __bv, part)); +bool from_pool = false; - bq =kmalloc (size, gfp & ~GFP_ZONEMASK ); -if (!bq) -return bq; + gfp &= ~(GFP_ZONEMASK | __GFP_THISNODE); + +if (for_writeback) { +if (size !=BVECQ_STD_SIZE ) { +gfp_t gfp_temp = gfp; + gfp_temp |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN; + gfp_temp &= ~(__GFP_DIRECT_RECLAIM | __GFP_IO); + bq =kmalloc (size, gfp_temp); +if (bq) + goto success; + } + + bq =mempool_alloc (&netfs_bvecq_pool, gfp); +if (!bq) +return bq; + from_pool = true; + size =BVECQ_STD_SIZE ; + }else { + bq =kmalloc (size, gfp); +if (!bq) +return bq; + } + +success: *bq = (struct bvecq ) { .ref =REFCOUNT_INIT (1 ), .bv = bq->__bv, .inline_bv = true, .max_slots = (size -sizeof (*bq)) /sizeof (bq->__bv[0 ]), + .from_pool = from_pool, };netfs_stat (&netfs_n_bvecq);return bq;
@@ -245,7 +269,10 @@ void bvecq_put(struct bvecq *bq)bvecq_free_slot (bq, slot); next = bq->next;netfs_stat_d (&netfs_n_bvecq); -kfree (bq); +if (bq->from_pool) +mempool_free (bq, &netfs_bvecq_pool); +else +kfree (bq); } }EXPORT_SYMBOL (bvecq_put);
fs/netfs/internal.h +1 -0
@@ -43,6 +43,7 @@ extern struct list_head netfs_io_requests;extern spinlock_t netfs_proc_lock;extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool; +extern mempool_t netfs_bvecq_pool;extern mempool_t netfs_folioq_pool;#ifdef CONFIG_PROC_FS
fs/netfs/main.c +7 -0
@@ -28,6 +28,7 @@ static struct kmem_cache *netfs_request_slab;static struct kmem_cache *netfs_subrequest_slab;mempool_t netfs_request_pool;mempool_t netfs_subrequest_pool; +mempool_t netfs_bvecq_pool;mempool_t netfs_folioq_pool;#ifdef CONFIG_PROC_FS
@@ -112,6 +113,9 @@ static int __init netfs_init(void)if (mempool_init_kmalloc_pool (&netfs_folioq_pool,100 ,sizeof (struct folio_queue )) <0 ) goto error_folioq_pool; +if (mempool_init_kmalloc_pool (&netfs_bvecq_pool,100 ,BVECQ_STD_SIZE ) <0 ) + goto error_bvecq_pool; + netfs_request_slab = kmem_cache_create("netfs_request", sizeof(struct netfs_io_request), 0, SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
@@ -164,6 +168,8 @@ static int __init netfs_init(void) error_reqpool:kmem_cache_destroy (netfs_request_slab); error_req: +mempool_exit (&netfs_bvecq_pool); +error_bvecq_pool:mempool_exit (&netfs_folioq_pool); error_folioq_pool:return ret;
@@ -178,6 +184,7 @@ static void __exit netfs_exit(void)kmem_cache_destroy (netfs_subrequest_slab);mempool_exit (&netfs_request_pool);kmem_cache_destroy (netfs_request_slab); +mempool_exit (&netfs_bvecq_pool);mempool_exit (&netfs_folioq_pool); }module_exit (netfs_exit);
include/linux/bvecq.h +3 -0
@@ -43,15 +43,18 @@ struct bvecq {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 from_pool:1; /* T if bvecq from mempool */struct bio_vec *bv;/* Pointer to array of page fragments */ struct bio_vec __bv[];/* Default array (if ->inline_bv) */ };#if BITS_PER_LONG ==64 /* Number of slots in __bv[] for a bvecq in a 512-byte kmalloc block. */ +#define BVECQ_STD_SIZE 512#define BVECQ_STD_SLOTS 29/* 2 words/slot; 32 slots; bvecq is 6 words (3 slots) */ #elif BITS_PER_LONG ==32 /* Number of slots in __bv[] for a bvecq in a 256-byte kmalloc block. */ +#define BVECQ_STD_SIZE 256#define BVECQ_STD_SLOTS 18/* 3 words/slot; 21 slots; bvecq is 9 words (3 slots) */ #else #error BVECQ_STD_SLOTS undetermined
David Howells
maintainerPATCH v11 10/36 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 | 143 ++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 3 + 2 files changed, 146 insertions(+)
fs/netfs/iterator.c +143 -0
@@ -13,6 +13,149 @@#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 +* @_bvecq_head: Where to cache the bvec queue +* @extraction_flags: Flags to qualify the request +* @gfp: Allocation mode for bvecq structs. +* +* 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, +struct bvecq **_bvecq_head, +iov_iter_extraction_t extraction_flags,gfp_t gfp) +{ +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 (!max_len || !max_pages) + goto alloc_empty; +if (WARN_ON_ONCE (max_pages >INT_MAX )) + max_pages =INT_MAX ;/* Protect iov_iter_npages(). */ + + max_pages =iov_iter_npages (orig, max_pages); +if (!max_pages) + goto alloc_empty; + +do { + bq =bvecq_alloc_one (max_pages, gfp, false); +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 ; + +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 %zx, %zx\n" , + extracted, max_len); + ret = -EIO ; + goto out; + } + +if (WARN (got > max_len, +"%s: extract_pages overrun %zx > %zx 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, false); +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
@@ -431,6 +431,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, +struct bvecq **_bvecq_head, +iov_iter_extraction_t extraction_flags,gfp_t gfp);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 v11 11/36 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 | 163 ++++++----------------------------------- 7 files changed, 93 insertions(+), 222 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, +round_up (i_size,PAGE_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);
@@ -83,36 +82,34 @@ union afs_xdr_dir_block *afs_dir_find_block(struct afs_dir_iter *iter, size_t blif (dvnode->directory_size < blend) goto fail; -if (!fq || blpos < fpos) { - fq = dvnode->directory; +if (!bq || blpos < fpos) { + bq = dvnode->directory; slot =0 ; fpos =0 ; }/* Search the folio queue for the folio containing the block... */ -for (; fq; fq = fq->next) { -for (; slot <folioq_count (fq); slot++) { -size_t fsize =folioq_folio_size (fq, slot); +for (; bq; bq = bq->next) { +for (; slot < bq->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 , false); +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 , false); +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 +23 -140
202 lines not on this page · raw message
David Howells
maintainerPATCH v11 12/36 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 | 76 +++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 41 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 +36 -40
163 lines not on this page · raw message
David Howells
maintainerPATCH v11 13/36 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 v11 14/36 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
@@ -158,7 +158,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;
@@ -218,12 +217,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,uoff_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
@@ -45,7 +45,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
@@ -265,7 +265,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
@@ -462,7 +461,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
@@ -209,7 +209,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" )
@@ -223,9 +221,7 @@ EM(netfs_folio_trace_sched_copy, "sched-copy") \ 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 v11 15/36 netfs: trace: Change the "clear" folio traces to "endwb"
In reply to David HowellsChange the "clear" folio traces to "endwb" as it's more obvious what it means.
--- fs/netfs/write_collect.c | 8 ++++---- include/trace/events/netfs.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
fs/netfs/write_collect.c +4 -4
@@ -107,7 +107,7 @@ static void netfs_dump_request(const struct netfs_io_request *rreq)*/ int netfs_folio_written_back (struct folio *folio) { -enum netfs_folio_trace why = netfs_folio_trace_clear; +enum netfs_folio_trace why = netfs_folio_trace_endwb;struct inode *inode =folio_inode (folio);struct netfs_inode *ictx =netfs_inode (inode);struct netfs_folio *finfo;
@@ -130,13 +130,13 @@ int netfs_folio_written_back(struct folio *folio) group = finfo->netfs_group; gcount++;kfree (finfo); - why = netfs_folio_trace_clear_s; + why = netfs_folio_trace_endwb_s; goto end_wb; }if ((group =netfs_folio_group (folio))) {if (group ==NETFS_FOLIO_COPY_TO_CACHE ) { - why = netfs_folio_trace_clear_cc; + why = netfs_folio_trace_endwb_cc;folio_detach_private (folio); goto end_wb; }
@@ -149,7 +149,7 @@ int netfs_folio_written_back(struct folio *folio)if (!folio_test_dirty (folio)) {folio_detach_private (folio); gcount++; - why = netfs_folio_trace_clear_g; + why = netfs_folio_trace_endwb_g; } }
include/trace/events/netfs.h +4 -4
@@ -192,11 +192,11 @@ EM(netfs_folio_trace_alloc_buffer, "alloc-buf") \ EM(netfs_folio_trace_cancel_copy, "cancel-copy") \ EM(netfs_folio_trace_cancel_store, "cancel-store") \ - EM(netfs_folio_trace_clear, "clear") \ - EM(netfs_folio_trace_clear_cc, "clear-cc") \ - EM(netfs_folio_trace_clear_g, "clear-g") \ - EM(netfs_folio_trace_clear_s, "clear-s") \ EM(netfs_folio_trace_end_copy, "end-copy") \ + EM(netfs_folio_trace_endwb, "endwb") \ + EM(netfs_folio_trace_endwb_cc, "endwb-cc") \ + EM(netfs_folio_trace_endwb_g, "endwb-g") \ + EM(netfs_folio_trace_endwb_s, "endwb-s") \ EM(netfs_folio_trace_filled_gaps, "filled-gaps") \ EM(netfs_folio_trace_invalidate_all, "inval-all") \EM (netfs_folio_trace_invalidate_front,"inval-front" ) \
David Howells
maintainerPATCH v11 16/36 netfs: trace: Rejig a couple of the tracepoints
In reply to David HowellsRejig the following tracepoints:
(1) Change netfs_folio to show the pfn.
(2) Change netfs_collect_folio to show a folio index range rather than file position range and don't show the cleaned_to or collected_to points.
--- fs/netfs/read_collect.c | 2 +- fs/netfs/read_pgpriv2.c | 2 +- fs/netfs/write_collect.c | 2 +- include/trace/events/netfs.h | 23 ++++++++++------------- 4 files changed, 13 insertions(+), 16 deletions(-)
fs/netfs/read_collect.c +1 -1
@@ -192,7 +192,7 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq, fpos =folio_pos (folio); fend = fpos + fsize; -trace_netfs_collect_folio (rreq, folio, fend, collected_to); +trace_netfs_collect_folio (rreq, folio);/* Unlock any folio we've transferred all of. */ if (collected_to < fend)
fs/netfs/read_pgpriv2.c +1 -1
@@ -201,7 +201,7 @@ bool netfs_pgpriv2_unlock_copied_folios(struct netfs_io_request *creq) fend =min_t (uoff_t, fpos + flen, creq->i_size); -trace_netfs_collect_folio (creq, folio, fend, collected_to); +trace_netfs_collect_folio (creq, folio);/* Unlock any folio we've transferred all of. */ if (collected_to < fend)
fs/netfs/write_collect.c +1 -1
@@ -207,7 +207,7 @@ static void netfs_writeback_unlock_folios(struct netfs_io_request *wreq, fend =min_t (uoff_t, fpos + flen, wreq->i_size); -trace_netfs_collect_folio (wreq, folio, fend, collected_to); +trace_netfs_collect_folio (wreq, folio);/* Unlock any folio we've transferred all of. */ if (collected_to < fend)
include/trace/events/netfs.h +10 -13
@@ -497,6 +497,7 @@ TRACE_EVENT(netfs_folio,TP_STRUCT__entry (__field (u64 ,ino )__field (pgoff_t, index) + __field(unsigned long, pfn) __field(unsigned int, nr) __field(enum netfs_folio_trace, why) ),
@@ -507,9 +508,11 @@ TRACE_EVENT(netfs_folio, __entry->why = why; __entry->index = folio->index; __entry->nr =folio_nr_pages (folio); + __entry->pfn =folio_pfn (folio); ), -TP_printk ("i=%05llx ix=%05lx-%05lx %s" , +TP_printk ("p=%lx i=%05llx ix=%05lx-%05lx %s" , + __entry->pfn, __entry->ino, __entry->index, __entry->index + __entry->nr -1 ,__print_symbolic (__entry->why, netfs_folio_traces)) );
@@ -656,31 +659,25 @@ TRACE_EVENT(netfs_collect_sreq,TRACE_EVENT (netfs_collect_folio, TP_PROTO(const struct netfs_io_request *wreq, - const struct folio *folio, - uoff_t fend, uoff_t collected_to), + const struct folio *folio), -TP_ARGS (wreq, folio, fend, collected_to), +TP_ARGS (wreq, folio),TP_STRUCT__entry ( __field(unsigned int, wreq) __field(unsigned long, index) - __field(uoff_t, fend) - __field(uoff_t, cleaned_to) -__field (uoff_t, collected_to) + __field(unsigned int, nr) ),TP_fast_assign ( __entry->wreq = wreq->debug_id; __entry->index = folio->index; - __entry->fend = fend; - __entry->cleaned_to = wreq->cleaned_to; - __entry->collected_to = collected_to; + __entry->nr = folio_nr_pages(folio); ), -TP_printk ("R=%08x ix=%05lx r=%llx-%llx t=%llx/%llx" , +TP_printk ("R=%08x ix=%05lx-%05lx" , __entry->wreq, __entry->index, - (uoff_t )__entry->index *PAGE_SIZE , __entry->fend, - __entry->cleaned_to, __entry->collected_to) + __entry->index + __entry->nr -1 ) ); TRACE_EVENT(netfs_collect_state,
David Howells
maintainerPATCH v11 17/36 netfs: Add some functions to wrap the all-queued handling
In reply to David HowellsAdd some helper functions to wrap the handling of the NETFS_RREQ_ALL_QUEUED flag and to insert the appropriate barriers.
--- fs/netfs/buffered_read.c | 9 +++------ fs/netfs/direct_read.c | 9 +++------ fs/netfs/internal.h | 19 +++++++++++++++++++ fs/netfs/misc.c | 2 +- fs/netfs/read_collect.c | 4 +--- fs/netfs/read_pgpriv2.c | 3 +-- fs/netfs/read_single.c | 9 +++------ fs/netfs/write_collect.c | 3 +-- fs/netfs/write_issue.c | 7 ++----- include/trace/events/netfs.h | 1 + 10 files changed, 35 insertions(+), 31 deletions(-)
fs/netfs/buffered_read.c +3 -6
@@ -355,10 +355,8 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) } start += slice; size -= slice; -if (size <=0 ) { -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); - } +if (size <=0 ) +netfs_all_subreqs_queued (rreq);if (fq) {/* See if the cache indicated this should be cached. */
@@ -378,8 +376,7 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) }while (size >0 );if (unlikely (size >0 )) { -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +netfs_all_subreqs_queued (rreq);netfs_wake_collector (rreq); }
fs/netfs/direct_read.c +3 -6
@@ -84,10 +84,8 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq) size -= slice; start += slice; rreq->submitted += slice; -if (size <=0 ) { -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); - } +if (size <=0 ) +netfs_all_subreqs_queued (rreq); rreq->netfs_ops->issue_read (subreq);
@@ -99,8 +97,7 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq) }while (size >0 );if (unlikely (size >0 )) { -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +netfs_all_subreqs_queued (rreq);netfs_wake_collector (rreq); } }
fs/netfs/internal.h +19 -0
@@ -315,6 +315,25 @@ static inline bool netfs_check_subreq_in_progress(const struct netfs_io_subrequereturn test_bit_acquire (NETFS_SREQ_IN_PROGRESS , &subreq->flags); } +/* +* Indicate that we've generated and queued all the subrequests we're going to. +*/ +static inline void netfs_all_subreqs_queued (struct netfs_io_request *rreq) +{ +smp_wmb ();/* Write lists before ALL_QUEUED. */ +set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +trace_netfs_rreq (rreq, netfs_rreq_trace_all_queued); +} + +/* +* Query if all subrequests are queued. +*/ +static inline bool netfs_are_all_subreqs_queued (const struct netfs_io_request *rreq) +{ +/* Read lists after ALL_QUEUED. */ +return test_bit_acquire (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +} +/* * fscache-cache.c */
fs/netfs/misc.c +1 -1
@@ -424,7 +424,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; }
fs/netfs/read_collect.c +1 -3
@@ -462,10 +462,8 @@ bool netfs_read_collection(struct netfs_io_request *rreq)/* We're done when the app thread has finished posting subreqs and the * queue is empty. */ -if (!test_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags)) +if (!netfs_are_all_subreqs_queued (rreq))return false; -smp_rmb ();/* Read ALL_QUEUED before subreq lists. */ -if (!list_empty (&stream->subrequests))return false;
fs/netfs/read_pgpriv2.c +1 -2
@@ -158,8 +158,7 @@ void netfs_pgpriv2_end_copy_to_cache(struct netfs_io_request *rreq)return ;netfs_issue_write (creq, &creq->io_streams[1 ]); -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &creq->flags); +netfs_all_subreqs_queued (creq);trace_netfs_rreq (rreq, netfs_rreq_trace_end_copy_to_cache);if (list_empty_careful (&creq->io_streams[1 ].subrequests))netfs_wake_collector (creq);
fs/netfs/read_single.c +3 -6
@@ -113,14 +113,12 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq) goto cancel; } -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +netfs_all_subreqs_queued (rreq); rreq->netfs_ops->issue_read (subreq); rreq->submitted += subreq->len;break ;case NETFS_READ_FROM_CACHE : -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +netfs_all_subreqs_queued (rreq);trace_netfs_sreq (subreq, netfs_sreq_trace_submit);netfs_single_read_cache (rreq, subreq); rreq->submitted += subreq->len;
@@ -136,8 +134,7 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)return ret; cancel:netfs_cancel_read (subreq, ret); -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &rreq->flags); +netfs_all_subreqs_queued (rreq);netfs_wake_collector (rreq);return ret; }
fs/netfs/write_collect.c +1 -2
@@ -422,9 +422,8 @@ bool netfs_write_collection(struct netfs_io_request *wreq)/* We're done when the app thread has finished posting subreqs and all * the queues in all the streams are empty. */ -if (!test_bit (NETFS_RREQ_ALL_QUEUED , &wreq->flags)) +if (!netfs_are_all_subreqs_queued (wreq))return false; -smp_rmb ();/* Read ALL_QUEUED before lists. */ transferred =LONG_MAX ;for (s =0 ; s <NR_IO_STREAMS ; s++) {
fs/netfs/write_issue.c +2 -5
@@ -520,8 +520,7 @@ static void netfs_end_issue_write(struct netfs_io_request *wreq) {bool needs_poke = true; -smp_wmb ();/* Write subreq lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &wreq->flags); +netfs_all_subreqs_queued (wreq);for (int s =0 ; s <NR_IO_STREAMS ; s++) {struct netfs_io_stream *stream = &wreq->io_streams[s];
@@ -667,9 +666,7 @@ int netfs_writeback_single(struct address_space *mapping,netfs_issue_write (wreq, stream); } -smp_wmb ();/* Write lists before ALL_QUEUED. */ -set_bit (NETFS_RREQ_ALL_QUEUED , &wreq->flags); - +netfs_all_subreqs_queued (wreq);netfs_wake_collector (wreq);/* TODO: Might want to be async here if WB_SYNC_NONE, but then need to
include/trace/events/netfs.h +1 -0
@@ -47,6 +47,7 @@ E_(NETFS_PGPRIV2_COPY_TO_CACHE, "2C")#define netfs_rreq_traces \ + EM(netfs_rreq_trace_all_queued, "ALL-Q ") \ EM(netfs_rreq_trace_assess, "ASSESS ") \ EM(netfs_rreq_trace_collect, "COLLECT") \ EM(netfs_rreq_trace_complete, "COMPLET") \
David Howells
maintainerPATCH v11 18/36 netfs: Make deprecated PG_private_2 support optional
In reply to David HowellsMake the deprecated PG_private_2 support optional, requiring it to be selected by the filesystems that might want to use it.
--- fs/ceph/Kconfig | 1 + fs/netfs/Kconfig | 3 +++ fs/netfs/Makefile | 2 +- fs/netfs/internal.h | 28 ++++++++++++++++++++++++++++ fs/netfs/read_collect.c | 4 ++-- fs/nfs/Kconfig | 1 + include/linux/netfs.h | 2 ++ 7 files changed, 38 insertions(+), 3 deletions(-)
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/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,7 +12,6 @@ netfs-y := \ misc.o \ objects.o \ read_collect.o \ - read_pgpriv2.o \ read_retry.o \ read_single.o \ rolling_buffer.o \
@@ -20,6 +19,7 @@ netfs-y := \ write_issue.o \ write_retry.o +netfs-$(CONFIG_NETFS_PGPRIV2) += read_pgpriv2.o netfs-$(CONFIG_NETFS_STATS) += stats.o netfs-$(CONFIG_FSCACHE) += \
fs/netfs/internal.h +28 -0
@@ -121,9 +121,37 @@ void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error);/* * read_pgpriv2.c */ +#ifdef CONFIG_NETFS_PGPRIV2 +int netfs_prepare_pgpriv2_write_buffer (struct netfs_io_subrequest *subreq, +unsigned int max_segs);void netfs_pgpriv2_copy_to_cache (struct netfs_io_request *rreq,struct folio *folio);void netfs_pgpriv2_end_copy_to_cache (struct netfs_io_request *rreq);bool netfs_pgpriv2_unlock_copied_folios (struct netfs_io_request *wreq); +static inline bool netfs_using_pgpriv2 (const struct netfs_io_request *rreq) +{ +return test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags); +} +#else +static inline int netfs_prepare_pgpriv2_write_buffer (struct netfs_io_subrequest *subreq, +unsigned int max_segs) +{ +return -EIO ; +} +static inline void netfs_pgpriv2_copy_to_cache (struct netfs_io_request *rreq,struct folio *folio) +{ +} +static inline void netfs_pgpriv2_end_copy_to_cache (struct netfs_io_request *rreq) +{ +} +static inline bool netfs_pgpriv2_unlock_copied_folios (struct netfs_io_request *wreq) +{ +return true; +} +static inline bool netfs_using_pgpriv2 (const struct netfs_io_request *rreq) +{ +return false; +} +#endif /* * read_retry.c
fs/netfs/read_collect.c +2 -2
@@ -38,7 +38,7 @@ static void netfs_clear_unread(struct netfs_io_subrequest *subreq)*/ void netfs_cancel_copy_to_cache (struct netfs_io_request *rreq,struct folio *folio) { -if (!test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags)) { +if (!netfs_using_pgpriv2 (rreq)) {if (folio_get_private (folio) ==NETFS_FOLIO_COPY_TO_CACHE ) {folio_detach_private (folio);trace_netfs_folio (folio, netfs_folio_trace_cancel_copy);
@@ -81,7 +81,7 @@ static void netfs_unlock_read_folio(struct netfs_io_request *rreq,if (unlikely (test_bit (NETFS_RREQ_CANCEL_CACHING , &rreq->flags)))netfs_cancel_copy_to_cache (rreq, folio); -if (!test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags)) { +if (!netfs_using_pgpriv2 (rreq)) {if (netfs_folio_group (folio) ==NETFS_FOLIO_COPY_TO_CACHE ) {trace_netfs_folio (folio, netfs_folio_trace_sched_copy);folio_mark_dirty (folio);
fs/nfs/Kconfig +1 -0
@@ -174,6 +174,7 @@ config NFS_FSCACHE bool "Provide NFS client caching support" depends on NFS_FS select NETFS_SUPPORT + select NETFS_PGPRIV2 select FSCACHE help Say Y here if you want NFS data to be cached locally on disc through
include/linux/netfs.h +2 -0
@@ -279,8 +279,10 @@ struct netfs_io_request {#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 */ +#ifdef CONFIG_NETFS_PGPRIV2 #define NETFS_RREQ_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark * write to cache on read */ +#endif const struct netfs_request_ops *netfs_ops; };
David Howells
maintainerPATCH v11 19/36 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 | 341 ++++++++++++++++++++++++------ fs/cachefiles/namei.c | 19 +- fs/cachefiles/xattr.c | 23 +- fs/netfs/buffered_read.c | 176 +++++++++------ fs/netfs/buffered_write.c | 3 - fs/netfs/internal.h | 2 + fs/netfs/objects.c | 1 + 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 | 38 +++- include/trace/events/cachefiles.h | 21 +- include/trace/events/netfs.h | 9 +- 19 files changed, 661 insertions(+), 287 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,uoff_t new_i_size)
fs/cachefiles/interface.c +16 -74
131 lines not on this page · raw message
fs/cachefiles/internal.h +8 -5
@@ -16,8 +16,6 @@#include <linux/cred.h> #include <linux/security.h> -#define CACHEFILES_DIO_BLOCK_SIZE 4096 -struct cachefiles_cache ;struct cachefiles_object ;
@@ -51,12 +49,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 */ +uoff_t 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 +275 -66
447 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 +17 -6
@@ -43,6 +43,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)struct dentry *dentry;struct file *file = object->file;unsigned int len = object->cookie->aux_len; +uoff_t object_size = object->cookie->object_size;int ret;if (!file)
@@ -55,7 +56,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_size); buf->zero_point =0 ; buf->type =CACHEFILES_COOKIE_TYPE_DATA ; buf->content = object->content_info;
@@ -79,7 +80,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, - buf->data, buf->content, + object_size, buf->data, buf->content, cachefiles_coherency_set_fail);if (ret != -ENOMEM ) cachefiles_io_error_obj(
@@ -87,7 +88,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, - buf->data, buf->content, + object_size, buf->data, buf->content, cachefiles_coherency_set_ok); }
@@ -103,10 +104,12 @@ 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;ssize_t xlen; +uoff_t obj_size;int ret = -ESTALE ; tlen =sizeof (struct cachefiles_xattr ) + len;
@@ -121,34 +124,39 @@ 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); + obj_size =0 ; why = 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, buf->data, buf->content, why);kfree (buf);return ret;
@@ -163,6 +171,9 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, {int ret; +trace_cachefiles_coherency (object,d_inode (dentry)->i_ino,0 ,NULL ,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/objects.c +1 -0
@@ -44,6 +44,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq->gfp = gfp; rreq->start = start; rreq->collected_to = start; + rreq->cache_coll_to = start; rreq->cleaned_to = start; rreq->len = len; rreq->progress_at =0 ;
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);
@@ -118,6 +119,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; + } +netfs_all_subreqs_queued (rreq);trace_netfs_sreq (subreq, netfs_sreq_trace_submit);netfs_single_read_cache (rreq, subreq);
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 ;
@@ -232,6 +234,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);
@@ -265,6 +282,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 +30 -8
@@ -23,6 +23,7 @@enum netfs_sreq_ref_trace ;typedef struct mempool mempool_t ; +struct fscache_occupancy ;struct folio_queue ;/**
@@ -126,6 +127,12 @@ static inline struct netfs_group *netfs_folio_group(struct folio *folio)return priv; } +enum netfs_cache_collect { +NETFS_CACHE_COLLECT_WRITE_GAP ,/* Gap in collection, no state either way */ +NETFS_CACHE_COLLECT_WRITE_DATA ,/* Currently collecting good writes */ +NETFS_CACHE_COLLECT_WRITE_CANCEL ,/* Currently collecting cancelled writes */ +}; +/* * Stream of I/O subrequests going to a particular destination, such as the * server or the local cache. This is mainly intended for writing where we may
@@ -153,6 +160,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 */ +enum netfs_cache_collect cache_collect;/* Current writeback cache collect state */ };/*
@@ -162,8 +170,10 @@ struct netfs_cache_resources {const struct netfs_cache_ops *ops;void *cache_priv;void *cache_priv2; +uoff_t 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 +207,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 {
@@ -252,6 +263,7 @@ struct netfs_io_request {uoff_t start;/* Start position */ atomic64_t issued_to;/* Write issuer folio cursor */ uoff_t collected_to;/* Point we've collected to */ +uoff_t cache_coll_to;/* Point the cache has collected to */ uoff_t cleaned_to;/* Position we've cleaned folios to */ uoff_t abandon_to;/* Position to abandon folios to */ const struct folio *no_unlock_folio;/* Don't unlock this folio after read */
@@ -273,11 +285,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_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_CANCEL_CACHING 10/* Set to cancel caching */ -#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_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_UPLOAD_TO_SERVER 14/* Need to write to the server */ +#define NETFS_RREQ_USE_IO_ITER 15/* Use ->io_iter rather than ->i_pages */ #define NETFS_RREQ_NEED_PUT_RA_REFS 17/* Need to put the folio refs RA gave us */ #ifdef CONFIG_NETFS_PGPRIV2 #define NETFS_RREQ_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark
@@ -359,8 +373,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, -uoff_t 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
@@ -380,8 +393,17 @@ struct netfs_cache_ops {* next chunk of data starts and how long it is. */ int (*query_occupancy)(struct netfs_cache_resources *cres, -uoff_t start,size_t len,size_t granularity, -uoff_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, +uoff_t start,size_t len, +enum netfs_cache_collect block_type); };/* High-level read API. */
include/trace/events/cachefiles.h +17 -4
@@ -52,6 +52,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,
@@ -63,9 +65,11 @@ enum cachefiles_coherency_trace { };enum cachefiles_trunc_trace { + cachefiles_trunc_clear_padding, cachefiles_trunc_dio_adjust, cachefiles_trunc_expand_tmpfile, cachefiles_trunc_shrink, + cachefiles_trunc_zap, };enum cachefiles_prepare_read_trace {
@@ -80,6 +84,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,
@@ -136,6 +141,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 " ) \
@@ -146,9 +153,11 @@ 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") + EM(cachefiles_trunc_shrink, "SHRINK") \ + E_(cachefiles_trunc_zap, "ZAP ")#define cachefiles_prepare_read_traces \ EM(cachefiles_trace_read_after_eof, "after-eof ") \
@@ -161,6 +170,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") \
@@ -371,12 +381,12 @@ TRACE_EVENT(cachefiles_rename, TRACE_EVENT(cachefiles_coherency, TP_PROTO(struct cachefiles_object *obj, - ino_t ino, + ino_t ino, uoff_t obj_size, const void *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(
@@ -384,6 +394,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) ),
@@ -398,6 +409,7 @@ 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);/* cachefiles_xattr::data is 2-byte aligned but not 8-byte aligned. */
@@ -412,10 +424,11 @@ TRACE_EVENT(cachefiles_coherency, } ), -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
@@ -49,6 +49,10 @@#define netfs_rreq_traces \ EM(netfs_rreq_trace_all_queued, "ALL-Q ") \ 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 ") \
@@ -57,11 +61,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 " ) \
@@ -133,12 +140,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 v11 20/36 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
@@ -927,6 +927,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
@@ -171,7 +171,8 @@ struct netfs_cache_resources {void *cache_priv;void *cache_priv2;uoff_t 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
@@ -313,6 +313,7 @@ TRACE_EVENT(netfs_read,TP_STRUCT__entry (__field (unsigned int ,rreq ) __field(unsigned int, cookie) + __field(unsigned int, object)__field (uoff_t, i_size)__field (uoff_t, start) __field(size_t, len)
@@ -322,7 +323,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;
@@ -330,10 +332,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) );
@@ -557,6 +559,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(uoff_t, start)
@@ -564,20 +567,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 ) );
@@ -592,22 +594,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 v11 21/36 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.
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. For buffered reads and writes through the pagecache, bv_len is set to the length of the entire folio and then slices of the relevant parts are passed to subrequests.
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. The filesystem may modify ->content, but not
->dispatch_pos. (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 ends of the slice will be rounded up/down to the backing file's DIO block alignment.
(6) bvecq_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 a specific slice 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) 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.
(4) 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.
(5) 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/afs/dir.c | 5 +- fs/afs/symlink.c | 6 +- fs/cachefiles/io.c | 12 --- fs/netfs/Makefile | 1 - fs/netfs/buffered_read.c | 177 ++++++++++++++++++++--------------- fs/netfs/direct_read.c | 78 ++++++--------- fs/netfs/direct_write.c | 71 ++++++++------ fs/netfs/internal.h | 10 +- fs/netfs/iterator.c | 2 + fs/netfs/main.c | 6 -- fs/netfs/misc.c | 20 +--- fs/netfs/objects.c | 17 ++-- fs/netfs/read_collect.c | 116 ++++++++++++----------- fs/netfs/read_pgpriv2.c | 91 ++++++++++++------ fs/netfs/read_retry.c | 100 +++++++++++--------- fs/netfs/read_single.c | 17 +++- fs/netfs/stats.c | 4 +- fs/netfs/write_collect.c | 60 ++++++------ fs/netfs/write_issue.c | 163 ++++++++++++++++++++++---------- fs/netfs/write_retry.c | 62 +++++++----- include/linux/netfs.h | 27 +++--- include/trace/events/netfs.h | 46 ++++----- 22 files changed, 604 insertions(+), 487 deletions(-)
fs/afs/dir.c +3 -2
@@ -2228,8 +2228,9 @@ static int afs_dir_writepages(struct address_space *mapping,if (test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags)) {iov_iter_bvec_queue (&iter,ITER_SOURCE , dvnode->directory,0 ,0 , -i_size_read (&dvnode->netfs.inode)); - ret =netfs_writeback_single (mapping, wbc, &iter); + dvnode->directory_size); + ret =netfs_writeback_single (mapping, wbc, &iter, +i_size_read (&dvnode->netfs.inode));if (ret ==1 ) ret =0 ;/* Skipped write due to lock conflict. */ }
fs/afs/symlink.c +3 -3
@@ -245,9 +245,9 @@ int afs_symlink_writepages(struct address_space *mapping,if (vnode->directory &&atomic64_read (&vnode->cb_expires_at) !=AFS_NO_CB_PROMISE ) { -iov_iter_bvec_queue (&iter,ITER_SOURCE , vnode->directory,0 ,0 , -i_size_read (&vnode->netfs.inode)); - ret =netfs_writeback_single (mapping, wbc, &iter); +iov_iter_bvec_queue (&iter,ITER_SOURCE , vnode->directory,0 ,0 ,PAGE_SIZE ); + ret =netfs_writeback_single (mapping, wbc, &iter, +i_size_read (&vnode->netfs.inode)); }if (ret ==0 ) {
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;uoff_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
@@ -14,7 +14,6 @@ netfs-y := \ read_collect.o \ read_retry.o \ read_single.o \ - rolling_buffer.o \ write_collect.o \ write_issue.o \ write_retry.o
fs/netfs/buffered_read.c +104 -73
326 lines not on this page · raw message
fs/netfs/direct_read.c +29 -49
118 lines not on this page · raw message
fs/netfs/direct_write.c +40 -31
137 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>
@@ -71,9 +70,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,
@@ -202,7 +200,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);
@@ -240,8 +237,7 @@ void netfs_prepare_write(struct netfs_io_request *wreq,struct netfs_io_stream *stream, uoff_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
@@ -156,6 +156,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
@@ -449,3 +450,4 @@ size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset, BUG(); }EXPORT_SYMBOL (netfs_limit_iter); +#endif
fs/netfs/main.c +0 -6
@@ -109,9 +109,6 @@ static int __init netfs_init(void) {int ret = -ENOMEM ; -if (mempool_init_kmalloc_pool (&netfs_folioq_pool,100 ,sizeof (struct folio_queue )) <0 ) - goto error_folioq_pool; -if (mempool_init_kmalloc_pool (&netfs_bvecq_pool,100 ,BVECQ_STD_SIZE ) <0 ) goto error_bvecq_pool;
@@ -169,8 +166,6 @@ static int __init netfs_init(void) error_req:mempool_exit (&netfs_bvecq_pool); error_bvecq_pool: -mempool_exit (&netfs_folioq_pool); -error_folioq_pool:return ret; }fs_initcall (netfs_init);
@@ -184,6 +179,5 @@ static void __exit netfs_exit(void)mempool_exit (&netfs_request_pool);kmem_cache_destroy (netfs_request_slab);mempool_exit (&netfs_bvecq_pool); -mempool_exit (&netfs_folioq_pool); }module_exit (netfs_exit);
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
@@ -133,7 +133,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);
@@ -148,16 +147,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);
@@ -249,6 +242,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 +61 -55
207 lines not on this page · raw message
fs/netfs/read_pgpriv2.c +61 -30
162 lines not on this page · raw message
fs/netfs/read_retry.c +58 -42
207 lines not on this page · raw message
fs/netfs/read_single.c +15 -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);
@@ -174,6 +179,15 @@ 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 , &rreq->dispatch_cursor.bvecq, +0 , rreq->gfp); +if (ret <0 ) + goto cleanup_free; +if (ret < rreq->len) { + ret = -EIO ; + goto cleanup_free; + } + rreq->progress_at = rreq->len; ret =netfs_single_begin_cache_read (rreq, ictx);
@@ -183,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 +114 -49
313 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 +11 -16
@@ -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]
@@ -145,7 +146,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 */
@@ -188,6 +188,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 */ uoff_t start;/* Where to start the I/O */ size_t len;/* Size of the I/O */
@@ -248,13 +250,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) */ +uoff_t last_end;/* End pos of last folio submitted */ uoff_t submitted;/* Amount submitted for I/O so far */ uoff_t len;/* Length of the request */ size_t transferred;/* Amount to be indicated as transferred */
@@ -269,7 +272,6 @@ struct netfs_io_request {uoff_t abandon_to;/* Position to abandon folios to */ const struct folio *no_unlock_folio;/* Don't unlock this folio after read */ gfp_t gfp;/* GFP flags to use */ -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) */
@@ -277,7 +279,6 @@ struct netfs_io_request {unsigned int nr_group_rel;/* Number of refs to release on ->group */ spinlock_t lock;/* Lock for queuing subreqs */ 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) */
@@ -428,7 +429,7 @@ void netfs_single_mark_inode_dirty(struct inode *inode);ssize_t netfs_read_single (struct inode *inode,struct file *file,struct iov_iter *iter);int netfs_writeback_single (struct address_space *mapping,struct writeback_control *wbc, -struct iov_iter *iter); +struct iov_iter *iter,size_t len);/* Address operations API */ struct readahead_control ;
@@ -473,12 +474,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 v11 22/36 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 v11 23/36 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
@@ -474,12 +474,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 v11 24/36 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
@@ -157,110 +157,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
@@ -459,9 +459,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,struct bvecq **_bvecq_head,iov_iter_extraction_t extraction_flags,gfp_t gfp); -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 v11 25/36 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 v11 26/36 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/internal.h | 1 - fs/netfs/iterator.c | 192 ------------- fs/netfs/main.c | 1 - fs/netfs/rolling_buffer.c | 249 ----------------- include/linux/folio_queue.h | 282 -------------------- include/linux/netfs.h | 2 - include/linux/rolling_buffer.h | 61 ----- kernel/bpf/btf.c | 2 - 11 files changed, 1 insertion(+), 1001 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/internal.h +0 -1
@@ -45,7 +45,6 @@ extern spinlock_t netfs_proc_lock;extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool;extern mempool_t netfs_bvecq_pool; -extern mempool_t netfs_folioq_pool;#ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq (struct netfs_io_request *rreq)
fs/netfs/iterator.c +0 -192
195 lines not on this page · raw message
fs/netfs/main.c +0 -1
@@ -29,7 +29,6 @@ static struct kmem_cache *netfs_subrequest_slab;mempool_t netfs_request_pool;mempool_t netfs_subrequest_pool;mempool_t netfs_bvecq_pool; -mempool_t netfs_folioq_pool;#ifdef CONFIG_PROC_FS LIST_HEAD (netfs_io_requests);
fs/netfs/rolling_buffer.c deleted +0 -249
249 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
@@ -459,8 +459,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,struct bvecq **_bvecq_head,iov_iter_extraction_t extraction_flags,gfp_t gfp); -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 -61
61 lines not on this page · raw message
kernel/bpf/btf.c +0 -2
@@ -6743,8 +6743,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 v11 27/36 netfs: Build a list of regions undergoing writeback
In reply to David HowellsBuild a linked list of the regions of file position that are involved in a writeback whilst processing the folios to be written back. These will be used in a subsequent patch to work out which folios need unlocking rather than walking the bvecq list of folios.
This will mean that the folio list need not be maintained as a single list of folios, but can instead be made into multiple lists and have various roundings applied to it - and can be ignored by the collector, except when various pins are pulled out of it by subrequest cleanup.
--- fs/netfs/internal.h | 1 + fs/netfs/main.c | 7 +++++++ fs/netfs/objects.c | 7 +++++++ fs/netfs/write_issue.c | 20 ++++++++++++++++++++ include/linux/netfs.h | 12 ++++++++++++ 5 files changed, 47 insertions(+)
fs/netfs/internal.h +1 -0
@@ -44,6 +44,7 @@ extern struct list_head netfs_io_requests;extern spinlock_t netfs_proc_lock;extern mempool_t netfs_request_pool;extern mempool_t netfs_subrequest_pool; +extern mempool_t netfs_writeback_pool;extern mempool_t netfs_bvecq_pool;#ifdef CONFIG_PROC_FS
fs/netfs/main.c +7 -0
@@ -28,6 +28,7 @@ static struct kmem_cache *netfs_request_slab;static struct kmem_cache *netfs_subrequest_slab;mempool_t netfs_request_pool;mempool_t netfs_subrequest_pool; +mempool_t netfs_writeback_pool;mempool_t netfs_bvecq_pool;#ifdef CONFIG_PROC_FS
@@ -110,6 +111,9 @@ static int __init netfs_init(void)if (mempool_init_kmalloc_pool (&netfs_bvecq_pool,100 ,BVECQ_STD_SIZE ) <0 ) goto error_bvecq_pool; +if (mempool_init_kmalloc_pool (&netfs_writeback_pool,100 , +sizeof (struct netfs_writeback )) <0 ) + goto error_writeback_pool; netfs_request_slab = kmem_cache_create("netfs_request", sizeof(struct netfs_io_request), 0,
@@ -163,6 +167,8 @@ static int __init netfs_init(void) error_reqpool:kmem_cache_destroy (netfs_request_slab); error_req: +mempool_exit (&netfs_writeback_pool); +error_writeback_pool:mempool_exit (&netfs_bvecq_pool); error_bvecq_pool:return ret;
@@ -177,6 +183,7 @@ static void __exit netfs_exit(void)kmem_cache_destroy (netfs_subrequest_slab);mempool_exit (&netfs_request_pool);kmem_cache_destroy (netfs_request_slab); +mempool_exit (&netfs_writeback_pool);mempool_exit (&netfs_bvecq_pool); }module_exit (netfs_exit);
fs/netfs/objects.c +7 -0
@@ -151,6 +151,13 @@ static void netfs_deinit_request(struct netfs_io_request *rreq)bvecq_pos_unset (&rreq->dispatch_cursor);bvecq_pos_unset (&rreq->collect_cursor);bvecq_put (rreq->spare); +while (rreq->writebacks) { +struct netfs_writeback *wback = rreq->writebacks; + + rreq->writebacks = wback->next; +mempool_free (wback, &netfs_bvecq_pool); + + }if (atomic_dec_and_test (&ictx->io_count))wake_up_var (&ictx->io_count);
fs/netfs/write_issue.c +20 -0
@@ -335,6 +335,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,struct netfs_io_stream *upload = &wreq->io_streams[0 ];struct netfs_io_stream *cache = &wreq->io_streams[1 ];struct netfs_io_stream *stream; +struct netfs_writeback *wback;struct netfs_group *fgroup;/* TODO: Use this with ceph */ struct netfs_folio *finfo;struct bvecq *queue = wreq->load_cursor.bvecq;
@@ -433,6 +434,25 @@ static int netfs_write_folio(struct netfs_io_request *wreq,folio_start_writeback (folio);folio_unlock (folio); +/* Keep track of what we will need to unlock. */ + wback = wreq->writebacks_tail; +if (!wback || fpos != wback->start + wback->len || wback->len >LONG_MAX ) { + wback =mempool_alloc (&netfs_writeback_pool, wreq->gfp); + wback->next =NULL ; + wback->start = fpos; + wback->len = fsize; + +if (wreq->writebacks) +/* Order write of next after last write of len in old tail. */ +smp_store_release (&wreq->writebacks_tail->next, wback); +else + wreq->writebacks = wback; + wreq->writebacks_tail = wback; + }else { +/* Order update of len after setting pointer. */ +smp_store_release (&wback->len, wback->len + fsize); + } +if (fgroup ==NETFS_FOLIO_COPY_TO_CACHE ) {if (!cache->avail) {trace_netfs_folio (folio, netfs_folio_trace_cancel_copy);
include/linux/netfs.h +12 -0
@@ -134,6 +134,16 @@ enum netfs_cache_collect { NETFS_CACHE_COLLECT_WRITE_CANCEL, /* Currently collecting cancelled writes */ }; +/* +* Record of a contiguous region undergoing writeback. The tail region (ie. if +* next is NULL) may be extended dynamically. +*/ +struct netfs_writeback { +struct netfs_writeback *next;/* Next extent in list */ +uoff_t start;/* Start position */ +size_t len;/* Total size (can increase) */ +}; +/* * Stream of I/O subrequests going to a particular destination, such as the * server or the local cache. This is mainly intended for writing where we may
@@ -249,6 +259,8 @@ struct netfs_io_request {#endif struct netfs_io_stream io_streams[2 ];/* Streams of parallel I/O operations */ #define NR_IO_STREAMS 2 //wreq->nr_io_streams +struct netfs_writeback *writebacks;/* List of regions undergoing writeback */ +struct netfs_writeback *writebacks_tail;/* Tail of region list */ struct netfs_group *group;/* Writeback group being written back */ struct bvecq *spare;/* Advance allocation of bvecq */ struct bvecq_pos load_cursor;/* Point at which new folios are loaded in */
David Howells
maintainerPATCH v11 28/36 netfs: Simplify writeback cleanup
In reply to David HowellsCurrently, the netfslib buffered writeback algorithm walks the list of folios, using that to determine the folios that need to be unlocked. This is tricky, however, as different streams really want different folios or different parts of folios (e.g. data that's read from the server will be written to the cache, but not written back to the server, and a small region that can be written to the server may need to be rounded out for DIO write to the cache).
Further, the collector thread may be walking the folio list at the same time that the application thread is filling it - and at the same time as things are doing I/O to or from it.
Finally, it requires careful cleanup during collection, such that there's always at least one link remaining in the bvecq chain so that the consumer never gets disconnected from the producer.
Instead, use the end-writeback iteration tool to simplify the cleanup of writeback by walking the inode's pagecache xarray to find the folios that will be unmarked rather than looking in the list of bio_vecs that refer to those folios.
This makes use of the list of file sections under writeback to keep track of what needs to be dealt with.
Using the end-writeback iterator affords the possibility of improving efficiency of the process by doing bulk access and bulk modification of the xarray and stats.
--- fs/netfs/internal.h | 2 +- fs/netfs/write_collect.c | 170 +++++++++++++---------------------- fs/netfs/write_issue.c | 6 +- include/trace/events/netfs.h | 30 +++++++ 4 files changed, 97 insertions(+), 111 deletions(-)
fs/netfs/internal.h +1 -1
@@ -222,7 +222,7 @@ static inline void netfs_stat_d(atomic_t *stat)/* * write_collect.c */ -int netfs_folio_written_back (struct folio *folio); +void netfs_folio_written_back (struct netfs_io_request *wreq,struct folio *folio);bool netfs_write_collection (struct netfs_io_request *wreq);void netfs_write_collection_worker (struct work_struct *work);
fs/netfs/write_collect.c +63 -107
228 lines not on this page · raw message
fs/netfs/write_issue.c +3 -3
@@ -369,7 +369,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,_debug ("beyond eof" );folio_start_writeback (folio);folio_unlock (folio); - wreq->nr_group_rel +=netfs_folio_written_back (folio); +netfs_folio_written_back (wreq, folio);netfs_put_group_many (wreq->group, wreq->nr_group_rel); wreq->nr_group_rel =0 ;return 0 ;
@@ -457,13 +457,13 @@ static int netfs_write_folio(struct netfs_io_request *wreq,if (!cache->avail) {trace_netfs_folio (folio, netfs_folio_trace_cancel_copy);netfs_issue_write (wreq, upload); -netfs_folio_written_back (folio); +netfs_folio_written_back (wreq, folio);return 0 ; }trace_netfs_folio (folio, netfs_folio_trace_store_copy); }else if (!upload->avail && !cache->avail) {trace_netfs_folio (folio, netfs_folio_trace_cancel_store); -netfs_folio_written_back (folio); +netfs_folio_written_back (wreq, folio);return 0 ; }else if (!upload->construct) {trace_netfs_folio (folio, netfs_folio_trace_store);
include/trace/events/netfs.h +30 -0
@@ -773,6 +773,36 @@ TRACE_EVENT(netfs_collect_stream, __entry->collected_to, __entry->issued_to) ); +TRACE_EVENT (netfs_collect_folios, + TP_PROTO(const struct netfs_io_request *wreq, + uoff_t range_start, size_t range_len), + +TP_ARGS (wreq, range_start, range_len), + +TP_STRUCT__entry ( + __field(unsigned int, wreq) + __field(size_t, range_len) + __field(uoff_t, range_start) + __field(uoff_t, cleaned_to) +__field (uoff_t, collected_to) + ), + +TP_fast_assign ( + __entry->wreq = wreq->debug_id; + __entry->range_len = range_len; + __entry->range_start = range_start; + __entry->cleaned_to = wreq->cleaned_to; + __entry->collected_to = wreq->collected_to; + ), + +TP_printk ("R=%08x r=%llx-%llx cln=%llx col=%llx" , + __entry->wreq, + __entry->range_start, + __entry->range_start + __entry->range_len, + __entry->cleaned_to, + __entry->collected_to) + ); + TRACE_EVENT(netfs_bvecq, TP_PROTO(const struct bvecq *bq, enum netfs_bvecq_trace trace),
David Howells
maintainerPATCH v11 29/36 netfs: Simplify read abandonment
In reply to David HowellsCurrently, if one or more of the subrequests in a read request fails, the read collection algorithm will attempt to salvage folios that are fully downloaded but that span multiple subreqs, provided all of the contributory subreqs succeeded, but this makes the algorithm quite complicated as a subreq can contribute to multiple folios and a folio can be contributed to by multiple subreqs.
Simplify this by just abandoning the rest of a read request once a permanently failed subreq is hit. This is what read_folio, DIO/unbuffered read, gap filling, RMW and write preload all need to do; readahead is the odd one out as it doesn't have any return other than unlocking folios.
With this change, even for readahead, the rest of the read is simply abandoned; read() and suchlike will call ->read_folio() on each non-uptodate folio to retry and retrieve the error.
Note that retryable failures still get retried by netfslib as part of the request as before.
--- fs/netfs/read_collect.c | 183 ++++++++++++++++++++++++++++------------ include/linux/netfs.h | 1 + 2 files changed, 132 insertions(+), 52 deletions(-)
fs/netfs/read_collect.c +131 -52
@@ -19,7 +19,7 @@#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 ABANDON_SREQ 0x80/* Need to abandon untransferred part of subrequest */ +#define ABANDON_RREQ 0x40/* Need to abandon the rest of a request */ /* * Clear the unread part of an I/O request.
@@ -220,6 +220,78 @@ static void netfs_read_unlock_folios(struct netfs_io_request *rreq,netfs_read_set_unlock_at (rreq); } +/* +* Abandon all remaining read results. Once we've hit a permanent failure, we +* assume that the file is probably unusable. In the event of readahead, in +* theory we might manage to read some data later in the file, that we could +* still unlock, but ->read_folio() will be called again. +*/ +static void netfs_abandon_read_results (struct netfs_io_request *rreq) +{ +struct netfs_io_stream *stream = &rreq->io_streams[0 ]; +unsigned int notes =ABANDON_RREQ ; + +_enter ("%llx-%llx" , rreq->start, rreq->start + rreq->len); +trace_netfs_rreq (rreq, netfs_rreq_trace_collect); +trace_netfs_collect (rreq); + +if (rreq->origin ==NETFS_READAHEAD || + rreq->origin ==NETFS_READPAGE || + rreq->origin ==NETFS_READ_FOR_WRITE ) + notes |=BUFFERED ; + +/* Remove completed subrequests from the front of the stream and +* advance the completion point. We stop when we hit something that's +* in progress. The issuer thread may be adding stuff to the tail +* whilst we're doing this. +*/ +for (;;) { +struct netfs_io_subrequest *front; +unsigned long front_flags; + + front =list_first_entry_or_null_acquire (&stream->subrequests, + struct netfs_io_subrequest, rreq_link); +/* Read first subreq pointer before IN_PROGRESS flag. */ +if (!front) +break ; + + front_flags =smp_load_acquire (&front->flags); +/* Order read of flags before read of anything else, such as error. */ + +/* Wait for each subreq to complete. */ +if (test_bit (NETFS_SREQ_IN_PROGRESS , &front_flags)) { + notes |=HIT_PENDING ; +break ; + } + +/* The subreq now belongs to us. */ +if (!stream->failed) { + stream->failed = true; + stream->error = front->error; + rreq->error = front->error; +trace_netfs_rreq (rreq, netfs_rreq_trace_set_abandon); + } + + stream->collected_to = front->start + front->len; +trace_netfs_sreq (front, netfs_sreq_trace_abandoned); + +spin_lock (&rreq->lock); +list_del_init (&front->rreq_link); +spin_unlock (&rreq->lock); +netfs_put_subrequest (front, netfs_sreq_trace_put_abandon); + } + + rreq->collected_to = stream->collected_to; + rreq->abandon_to = rreq->collected_to; +if (notes &BUFFERED ) +netfs_read_unlock_folios (rreq, ¬es); +else + rreq->cleaned_to = rreq->collected_to; + +trace_netfs_collect_stream (rreq, stream); +trace_netfs_collect_state (rreq, rreq->collected_to, notes); +} +/* * Collect and assess the results of various read subrequests. We may need to * retry some of the results.
@@ -239,6 +311,9 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)trace_netfs_collect (rreq); reassess: +if (test_bit (NETFS_RREQ_ABANDON_REQ , &rreq->flags)) + goto abandon_request; +if (rreq->origin ==NETFS_READAHEAD || rreq->origin ==NETFS_READPAGE || rreq->origin ==NETFS_READ_FOR_WRITE )
@@ -256,7 +331,9 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)/* Read first subreq pointer before IN_PROGRESS flag. */ while (front) { +unsigned long front_flags;size_t transferred; +uoff_t unlock_at = rreq->start + rreq->progress_at;trace_netfs_collect_sreq (rreq, front); _debug("sreq [%x] %llx %zx/%zx",
@@ -267,25 +344,60 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) stream->collected_to = front->start; } -if (netfs_check_subreq_in_progress (front)) + front_flags =smp_load_acquire (&front->flags); +/* Order read of flags before read of anything else, such as error. */ + +if (test_bit (NETFS_SREQ_FAILED , &front_flags)) + goto abandon_request; +if (test_bit (NETFS_SREQ_IN_PROGRESS , &front_flags)) notes |=HIT_PENDING ; -smp_rmb ();/* Read counters after IN_PROGRESS flag. */ + transferred =READ_ONCE (front->transferred); +/* If we can collect the next folio from a pending op, do so, +* but we should only do it if we don't otherwise need to wait +* for completion. +*/ +if ((notes &HIT_PENDING ) && + (notes &BUFFERED ) && + !test_bit (NETFS_SREQ_HIT_EOF , &front_flags) && + front->error ==0 && + transferred < front->len + ) { + stream->collected_to = front->start + transferred; + rreq->collected_to = stream->collected_to; +if (front->start + transferred >= unlock_at) +netfs_read_unlock_folios (rreq, ¬es); + } + +/* Stall if the front is still undergoing I/O. */ +if (notes &HIT_PENDING ) +break ; + +if (test_bit (NETFS_SREQ_NEED_RETRY , &front_flags)) { + stream->need_retry = true; + notes |=NEED_RETRY |MADE_PROGRESS ; +break ; + }else if (test_bit (NETFS_RREQ_SHORT_TRANSFER , &rreq->flags)) { + notes |=MADE_PROGRESS ; + }else { + stream->transferred += transferred; + stream->transferred_valid = true; +if (front->transferred < front->len) +set_bit (NETFS_RREQ_SHORT_TRANSFER , &rreq->flags); + notes |=MADE_PROGRESS ; + } +/* 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 ) { -uoff_t unlock_at = rreq->start + rreq->progress_at; -/* Clear the tail of a short read. */ -if (!(notes &HIT_PENDING ) && - front->error ==0 && - transferred < front->len && - (test_bit (NETFS_SREQ_HIT_EOF , &front->flags) || -test_bit (NETFS_SREQ_CLEAR_TAIL , &front->flags))) { +if (transferred < front->len && + (test_bit (NETFS_SREQ_HIT_EOF , &front_flags) || +test_bit (NETFS_SREQ_CLEAR_TAIL , &front_flags))) {netfs_clear_unread (front); transferred = front->transferred = front->len;trace_netfs_sreq (front, netfs_sreq_trace_clear);
@@ -294,64 +406,25 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) stream->collected_to = front->start + transferred; rreq->collected_to = stream->collected_to; -if (test_bit (NETFS_SREQ_FAILED , &front->flags)) { - rreq->abandon_to = front->start + front->len; - front->transferred = front->len; - transferred = front->len; -trace_netfs_rreq (rreq, netfs_rreq_trace_set_abandon); - }if (front->start + transferred >= unlock_at || -test_bit (NETFS_SREQ_HIT_EOF , &front->flags)) +test_bit (NETFS_SREQ_HIT_EOF , &front_flags))netfs_read_unlock_folios (rreq, ¬es); }else { stream->collected_to = front->start + transferred; rreq->collected_to = stream->collected_to; } -/* Stall if the front is still undergoing I/O. */ -if (notes &HIT_PENDING ) -break ; - -if (test_bit (NETFS_SREQ_FAILED , &front->flags)) { -if (!stream->failed) { - stream->error = front->error; - rreq->error = front->error; -set_bit (NETFS_RREQ_FAILED , &rreq->flags); - stream->failed = true; - } - notes |=MADE_PROGRESS |ABANDON_SREQ ; - }else if (test_bit (NETFS_SREQ_NEED_RETRY , &front->flags)) { - stream->need_retry = true; - notes |=NEED_RETRY |MADE_PROGRESS ; -break ; - }else if (test_bit (NETFS_RREQ_SHORT_TRANSFER , &rreq->flags)) { - notes |=MADE_PROGRESS ; - }else { -if (!stream->failed) { - stream->transferred += transferred; - stream->transferred_valid = true; - } -if (front->transferred < front->len) -set_bit (NETFS_RREQ_SHORT_TRANSFER , &rreq->flags); - notes |=MADE_PROGRESS ; - } -/* Remove if completely consumed. */ stream->source = front->source;spin_lock (&rreq->lock); remove = front; -trace_netfs_sreq (front, - notes &ABANDON_SREQ ? - netfs_sreq_trace_abandoned : netfs_sreq_trace_consumed); +trace_netfs_sreq (front, netfs_sreq_trace_consumed);list_del_init (&front->rreq_link); front =list_first_entry_or_null (&stream->subrequests, struct netfs_io_subrequest, rreq_link);spin_unlock (&rreq->lock); -netfs_put_subrequest (remove, - notes &ABANDON_SREQ ? - netfs_sreq_trace_put_abandon : - netfs_sreq_trace_put_done); +netfs_put_subrequest (remove, netfs_sreq_trace_put_done); }trace_netfs_collect_stream (rreq, stream);
@@ -380,6 +453,12 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)_debug ("retry" );netfs_retry_reads (rreq); goto out; + +abandon_request: +set_bit (NETFS_RREQ_FAILED , &rreq->flags); +set_bit (NETFS_RREQ_ABANDON_REQ , &rreq->flags); +netfs_wake_rreq_flag (rreq,NETFS_RREQ_PAUSE , netfs_rreq_trace_unpause); +return netfs_abandon_read_results (rreq); }/*
include/linux/netfs.h +1 -0
@@ -299,6 +299,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_CANCEL_CACHING 10/* Set to cancel caching */
David Howells
maintainerPATCH v11 30/36 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 | 24 ++++++++++++++++++++++++ include/trace/events/netfs.h | 1 + 2 files changed, 25 insertions(+)
fs/netfs/read_collect.c +24 -0
@@ -353,6 +353,15 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) notes |=HIT_PENDING ; transferred =READ_ONCE (front->transferred); +if (unlikely (transferred > front->len)) { +/* Ugh... A subreq overran its allotted length. It +* may have corrupted the read buffer. +*/ + stream->failed = true; + stream->error = -EIO ; + rreq->error = -EIO ; + goto abandon_request; + }/* If we can collect the next folio from a pending op, do so, * but we should only do it if we don't otherwise need to wait
@@ -663,6 +672,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/trace/events/netfs.h +1 -0
@@ -133,6 +133,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 v11 31/36 netfs: Add a method to get an estimate of the amount that can be written
In reply to David HowellsAdd a method, both to the netfs cache API and the netfs filesystem API, that allows netfslib to query how much can be written to a stream in one go. A filesystem like Ceph can use this to limit writes to object boundaries.
This is part of the replacement for ->prepare_write() and will be made use of in a later patch.
--- fs/9p/vfs_addr.c | 17 +++++++++++++++++ fs/afs/file.c | 2 +- fs/afs/internal.h | 3 +++ fs/afs/write.c | 17 +++++++++++++++++ fs/cachefiles/io.c | 15 ++++++++++++++- fs/netfs/write_issue.c | 2 ++ fs/smb/client/file.c | 14 ++++++++++++++ include/linux/netfs.h | 22 ++++++++++++++++++++++ 8 files changed, 90 insertions(+), 2 deletions(-)
fs/9p/vfs_addr.c +17 -0
@@ -48,6 +48,22 @@ 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. */
@@ -185,6 +201,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/file.c +1 -1
@@ -469,7 +469,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/internal.h +3 -0
@@ -1698,6 +1698,9 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);/* * write.c */ +int afs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate);void afs_prepare_write (struct netfs_io_subrequest *subreq);void afs_issue_write (struct netfs_io_subrequest *subreq);void afs_begin_writeback (struct netfs_io_request *wreq);
fs/afs/write.c +17 -0
@@ -82,6 +82,23 @@ static const struct afs_operation_ops afs_store_data_operation = { .success = afs_store_data_success, }; +/* +* Estimate the maximum size of a write we can send to the server. +*/ +int afs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate) +{ +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)) +// max_len = 512 * 1024; + + estimate->issue_at = stream->issue_from +umin (max_len, limit); +return 0 ; +} +/* * Prepare a subrequest to write to the server. This sets the max_len * parameter.
fs/cachefiles/io.c +14 -1
@@ -26,7 +26,10 @@ struct cachefiles_kiocb { };struct cachefiles_object *object;netfs_io_terminated_t term_func; -void *term_func_priv; +union { +struct netfs_io_subrequest *subreq; +void *term_func_priv; + };bool was_async;unsigned int inval_counter;/* Copy of cookie->inval_counter */ u64 b_writing;
@@ -611,6 +614,15 @@ static int cachefiles_prepare_write(struct netfs_cache_resources *cres,return ret; } +static int cachefiles_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate) +{ + estimate->issue_at = stream->issue_from +MAX_RW_COUNT ; + estimate->max_segs =BIO_MAX_VECS ; +return 0 ; +} +static void cachefiles_prepare_write_subreq (struct netfs_io_subrequest *subreq) {struct netfs_io_request *wreq = subreq->rreq;
@@ -898,6 +910,7 @@ static const struct netfs_cache_ops cachefiles_netfs_cache_ops = { .issue_write = cachefiles_issue_write, .prepare_write = cachefiles_prepare_write, .prepare_write_subreq = cachefiles_prepare_write_subreq, + .estimate_write = cachefiles_estimate_write, .query_occupancy = cachefiles_query_occupancy, .collect_write = cachefiles_collect_write, };
fs/netfs/write_issue.c +2 -0
@@ -114,6 +114,7 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping, wreq->io_streams[0 ].stream_nr =0 ; wreq->io_streams[0 ].source =NETFS_UPLOAD_TO_SERVER ; + wreq->io_streams[0 ].estimate_write = ictx->ops->estimate_write; wreq->io_streams[0 ].prepare_write = ictx->ops->prepare_write; wreq->io_streams[0 ].issue_write = ictx->ops->issue_write; wreq->io_streams[0 ].collected_to = start;
@@ -126,6 +127,7 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,if (fscache_resources_valid (&wreq->cache_resources)) { wreq->io_streams[1 ].avail = true; wreq->io_streams[1 ].active = true; + wreq->io_streams[1 ].estimate_write = wreq->cache_resources.ops->estimate_write; wreq->io_streams[1 ].prepare_write = wreq->cache_resources.ops->prepare_write_subreq; wreq->io_streams[1 ].issue_write = wreq->cache_resources.ops->issue_write; }
fs/smb/client/file.c +14 -0
@@ -39,6 +39,19 @@static int cifs_reopen_file (struct cifsFileInfo *cfile,bool can_flush); +/* +* Estimate the amount of data that can be written in one RPC op. +*/ +static int cifs_estimate_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate) +{ +struct cifs_sb_info *cifs_sb =CIFS_SB (wreq->inode->i_sb); + + estimate->issue_at = stream->issue_from + cifs_sb->ctx->wsize; +return 0 ; +} +/* * Prepare a subrequest to upload to the server. We need to allocate credits * so that we know the maximum amount of data that we can include in it.
@@ -362,6 +375,7 @@ const struct netfs_request_ops cifs_req_ops = { .issue_read = cifs_issue_read, .done = cifs_rreq_done, .begin_writeback = cifs_begin_writeback, + .estimate_write = cifs_estimate_write, .prepare_write = cifs_prepare_write, .issue_write = cifs_issue_write, .invalidate_cache = cifs_netfs_invalidate_cache,
include/linux/netfs.h +22 -0
@@ -144,6 +144,16 @@ struct netfs_writeback {size_t len;/* Total size (can increase) */ }; +/* +* Estimate of maximum write subrequest for writeback. The filesystem is +* responsible for filling this in when called from ->estimate_write(), though +* netfslib will preset infinite defaults. +*/ +struct netfs_write_estimate { +uoff_t issue_at;/* Point at which we must submit */ +int max_segs;/* Max number of segments in a single RPC */ +}; +/* * Stream of I/O subrequests going to a particular destination, such as the * server or the local cache. This is mainly intended for writing where we may
@@ -152,10 +162,14 @@ struct netfs_writeback {struct netfs_io_stream {/* Submission tracking */ struct netfs_io_subrequest *construct;/* Op being constructed */ +uoff_t issue_from;/* Current issue point */ size_t sreq_max_len;/* Maximum size of a subrequest */ 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 */ +int (*estimate_write)(struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate);void (*prepare_write)(struct netfs_io_subrequest *subreq);void (*issue_write)(struct netfs_io_subrequest *subreq);/* Collection tracking */
@@ -340,6 +354,9 @@ struct netfs_request_ops {/* Write request handling */ void (*begin_writeback)(struct netfs_io_request *wreq); +int (*estimate_write)(struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate);void (*prepare_write)(struct netfs_io_subrequest *subreq);void (*issue_write)(struct netfs_io_subrequest *subreq);void (*retry_request)(struct netfs_io_request *wreq,struct netfs_io_stream *stream);
@@ -376,6 +393,11 @@ struct netfs_cache_ops {netfs_io_terminated_t term_func, void *term_func_priv); +/* Estimate the amount of data that can be written in an op. */ +int (*estimate_write)(struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +struct netfs_write_estimate *estimate); +/* Write data to the cache from a netfs subrequest. */ void (*issue_write)(struct netfs_io_subrequest *subreq);
David Howells
maintainerPATCH v11 32/36 netfs: Rework writeback to estimate
In reply to David HowellsThe current netfslib writeback algorithm goes through every folio, preparing a subrequest for each stream when it has been determined that part of the current folio needs to go to that stream, and repeating this within and across contiguous folios; then issues subrequests as they become full or hit boundaries after first setting up the buffer.
However, the way this is implemented becomes a problem when content encryption is added as we may not have enough memory to encrypt a large folio to a bounce buffer in one go, but have to use a bunch of smaller bounce buffers and wait for them to become available again.
Fix this by changing how netfs writeback builds buffers and creates and dispatches subrequests. With this patch, it 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 up to an estimate supplied by the filesystem. The filesystem (or cache) then gets to take a slice of the master bvecq chain as its I/O buffer for each subrequest.
This will make it easier to feed small bounce buffers into the list and pull the flush if we hit ENOMEM. This will be dealt with in a later patch series.
Also, as ->estimate_write is now being used to work out how much bufferage can be accumulated before a flush is required, the { ->prepare_write(), buffer selection, ->issue_write() } combination are now moved into one place, preparatory to combining those in the filesystem in a subsequent patch.
--- fs/netfs/buffered_read.c | 1 + fs/netfs/internal.h | 2 + fs/netfs/objects.c | 5 + fs/netfs/read_pgpriv2.c | 4 +- fs/netfs/write_collect.c | 49 ++- fs/netfs/write_issue.c | 626 +++++++++++++++++++++++++---------- include/linux/netfs.h | 17 +- include/trace/events/netfs.h | 9 +- 8 files changed, 513 insertions(+), 200 deletions(-)
fs/netfs/buffered_read.c +1 -0
@@ -531,6 +531,7 @@ static int netfs_create_singular_buffer(struct netfs_io_request *rreq, struct fobvecq_filled_to (bq,1 ); rreq->submitted = rreq->start + fsize; rreq->progress_at = fsize; +bvecq_pos_set (&rreq->collect_cursor, &rreq->load_cursor);return 0 ; }
fs/netfs/internal.h +2 -0
@@ -233,6 +233,8 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping,struct file *file, uoff_t start, enum netfs_io_origin origin); +struct netfs_io_subrequest *netfs_alloc_write_subreq (struct netfs_io_request *wreq, +struct netfs_io_stream *stream);void netfs_prepare_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream,uoff_t start);
fs/netfs/objects.c +5 -0
@@ -66,6 +66,8 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,INIT_LIST_HEAD (&stream->subrequests); stream->collected_to = rreq->start; + stream->issue_from = rreq->start; + stream->alignment =1 ; } if (origin == NETFS_READAHEAD ||
@@ -159,6 +161,9 @@ static void netfs_deinit_request(struct netfs_io_request *rreq) } +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); }
fs/netfs/read_pgpriv2.c +2 -2
@@ -95,7 +95,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio creq->dispatch_cursor.offset = cache->submit_off; -atomic64_set (&creq->issued_to, fpos + cache->submit_off); +atomic64_set (&cache->issued_to, fpos + cache->submit_off); part =netfs_advance_write (creq, cache, fpos + cache->submit_off, cache->submit_len, to_eof); cache->submit_off += part;
@@ -106,7 +106,7 @@ static void netfs_pgpriv2_copy_folio(struct netfs_io_request *creq, struct folio }while (cache->submit_len >0 );bvecq_pos_step (&creq->dispatch_cursor); -atomic64_set (&creq->issued_to, fpos + fsize); +atomic64_set (&cache->issued_to, fpos + fsize);if (flen < fsize)netfs_issue_write (creq, cache);
fs/netfs/write_collect.c +34 -15
97 lines not on this page · raw message
fs/netfs/write_issue.c +450 -176
771 lines not on this page · raw message
include/linux/netfs.h +13 -4
@@ -160,23 +160,32 @@ struct netfs_write_estimate {* have to write to multiple destinations concurrently. */ struct netfs_io_stream { -/* Submission tracking */ +/* Submission tracking (main dispatch only; not retry) */ +struct bvecq_pos dispatch_cursor;/* Point from which buffers are dispatched */ struct netfs_io_subrequest *construct;/* Op being constructed */ uoff_t issue_from;/* Current issue point */ +uoff_t last_end;/* End file pos of last folio added */ +size_t buffered;/* Amount in buffer */ +size_t post_gap;/* Length of partial folio tail */ size_t sreq_max_len;/* Maximum size of a subrequest */ 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 alignment;/* Required alignment */ +u8 applicable;/* What sources are applicable (NOTE_* mask) */ +bool buffering;/* T if buffering on this stream */ int (*estimate_write)(struct netfs_io_request *wreq,struct netfs_io_stream *stream,struct netfs_write_estimate *estimate);void (*prepare_write)(struct netfs_io_subrequest *subreq);void (*issue_write)(struct netfs_io_subrequest *subreq); +atomic64_t issued_to;/* Point to which can be considered issued */ +/* Collection tracking */ struct list_head subrequests;/* Contributory I/O operations */ uoff_t collected_to;/* Position we've collected results to */ size_t transferred;/* The amount transferred from this stream */ -unsigned short error;/* Aggregate error for the stream */ +short error;/* Aggregate error for the stream */ enum netfs_io_source source;/* Where to read from/write to */ unsigned char stream_nr;/* Index of stream in parent table */ bool avail;/* T if stream is available */
@@ -217,11 +226,12 @@ struct netfs_io_subrequest {struct iov_iter io_iter;/* Iterator for this subrequest */ uoff_t start;/* Where to start the I/O */ size_t len;/* Size of the I/O */ +size_t post_gap;/* Length of partial folio tail */ size_t transferred;/* Amount of data transferred */ refcount_t ref;short error;/* 0 or error that occurred */ unsigned short debug_index;/* Index in list (for debugging output) */ -unsigned int nr_segs;/* Number of segs in io_iter */ +unsigned int nr_segs;/* Number of segments in content */ u8 retry_count;/* The number of retries (0 on initial pass) */ enum netfs_io_source source;/* Where to read from/write to */ unsigned char stream_nr;/* I/O stream this belongs to */
@@ -291,7 +301,6 @@ struct netfs_io_request {long error;/* 0 or error that occurred */ uoff_t i_size;/* Size of the file */ uoff_t start;/* Start position */ -atomic64_t issued_to;/* Write issuer folio cursor */ uoff_t collected_to;/* Point we've collected to */ uoff_t cache_coll_to;/* Point the cache has collected to */ uoff_t cleaned_to;/* Position we've cleaned folios to */
include/trace/events/netfs.h +6 -3
@@ -654,6 +654,7 @@ TRACE_EVENT(netfs_collect_sreq, __field(unsigned int, stream) __field(unsigned int, len) __field(unsigned int, transferred) + __field(unsigned int, post_gap) __field(uoff_t, start) ),
@@ -663,12 +664,14 @@ TRACE_EVENT(netfs_collect_sreq, __entry->stream = subreq->stream_nr; __entry->start = subreq->start; __entry->len = subreq->len; + __entry->post_gap = subreq->post_gap; __entry->transferred = subreq->transferred; ), -TP_printk ("R=%08x[%u:%02x] s=%llx t=%x/%x" , +TP_printk ("R=%08x[%u:%02x] s=%llx t=%x/%x gap=%x" , __entry->wreq, __entry->stream, __entry->subreq, - __entry->start, __entry->transferred, __entry->len) + __entry->start, __entry->transferred, __entry->len, + __entry->post_gap) ); TRACE_EVENT(netfs_collect_folio,
@@ -766,7 +769,7 @@ TRACE_EVENT(netfs_collect_stream, __entry->wreq = wreq->debug_id; __entry->stream = stream->stream_nr; __entry->collected_to = stream->collected_to; - __entry->issued_to =atomic64_read (&wreq->issued_to); + __entry->issued_to =atomic64_read (&stream->issued_to); ), TP_printk("R=%08x[%x:] cto=%llx ito=%llx",
David Howells
maintainerPATCH v11 33/36 netfs: Set subrequest->source at alloc before trace emission
In reply to David HowellsSet subrequest->source in netfs_alloc_subrequest() before we emit the trace line indicating we allocated the subrequest. Note that this requires the allocation of the subreq in netfs_read_to_pagecache() to be pushed to after the decision about what sort of subreq it should be.
--- fs/netfs/buffered_read.c | 69 ++++++++++++++++++++-------------------- fs/netfs/direct_read.c | 3 +- fs/netfs/internal.h | 3 +- fs/netfs/objects.c | 4 ++- fs/netfs/read_retry.c | 3 +- fs/netfs/read_single.c | 2 +- fs/netfs/write_issue.c | 6 ++-- fs/netfs/write_retry.c | 3 +- 8 files changed, 45 insertions(+), 48 deletions(-)
fs/netfs/buffered_read.c +34 -35
@@ -295,8 +295,11 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq) do { int (*prepare_read)(struct netfs_io_subrequest *subreq) = NULL; struct netfs_io_subrequest *subreq; + enum netfs_io_source source; ssize_t slice; uoff_t hole_to, cache_to; + size_t len = size; + bool copy = false; /* If we don't have any, find out the next couple of data * extents from the cache, containing of following the
@@ -327,48 +330,34 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)continue ; } - subreq =netfs_alloc_subrequest (rreq); -if (!subreq) { - ret = -ENOMEM ; -break ; - } - - subreq->start = start; - subreq->len = size; - -netfs_queue_read (rreq, subreq); -uoff_t zero_point =netfs_read_zero_point (rreq->inode);uoff_t zlimit =umin (zero_point, rreq->i_size); -_debug ("rsub %llx %llx-%llx" , subreq->start, hole_to, cache_to); +_debug ("rsub %llx %llx-%llx" , start, hole_to, cache_to);if (start >= hole_to && start < cache_to) {/* Overlap with a cached region, where the cache may * record a block of zeroes. */ _debug ("cached s=%llx c=%llx l=%zx" , start, cache_to, size); - subreq->len =umin (cache_to - start, size); - subreq->len =round_up (subreq->len, occ->granularity); + len =umin (cache_to - start, size); + len =round_up (len, occ->granularity);if (occ->cached_type[0 ] ==FSCACHE_EXTENT_ZERO ) { - subreq->source =NETFS_FILL_WITH_ZEROES ; + source =NETFS_FILL_WITH_ZEROES ;netfs_stat (&netfs_n_rh_zero); }else { - subreq->source =NETFS_READ_FROM_CACHE ; + source =NETFS_READ_FROM_CACHE ; prepare_read = rreq->cache_resources.ops->prepare_read; } - -trace_netfs_sreq (subreq, netfs_sreq_trace_prepare); - - }else if (subreq->start >= zlimit && size >0 ) { + }else if (start >= zlimit && size >0 ) {/* If this range lies beyond the zero-point, that part * can just be cleared locally. */ _debug ("zero %llx-%llx" , start, start + size); - subreq->len = size; - subreq->source =NETFS_FILL_WITH_ZEROES ; + len = size; + source =NETFS_FILL_WITH_ZEROES ;if (rreq->cache_resources.ops) -__set_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags); + copy = true;netfs_stat (&netfs_n_rh_zero); }else {/* Read a cache hole from the server. If any part of
@@ -379,22 +368,33 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)_debug ("limit %llx %llx" , rreq->i_size, zero_point);_debug ("download %llx-%llx" , start, start + size); - subreq->len =umin (limit - subreq->start,ULONG_MAX ); - subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; + len =umin (limit - start,ULONG_MAX ); + source =NETFS_DOWNLOAD_FROM_SERVER ;if (rreq->cache_resources.ops) -__set_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags); + copy = true;netfs_stat (&netfs_n_rh_download); } -if (size ==0 ) { -pr_err ("ZERO-LEN READ: R=%08x[%x] l=%zx/%zx s=%llx z=%llx i=%llx" , - rreq->debug_id, subreq->debug_index, - subreq->len, size, - subreq->start, zero_point, rreq->i_size); -netfs_cancel_read (subreq, ret); +if (len ==0 ) { +pr_err ("ZERO-LEN READ: R=%08x l=%zx/%zx s=%llx z=%llx i=%llx" , + rreq->debug_id, len, size, + start, zero_point, rreq->i_size); +break ; + } + + subreq =netfs_alloc_subrequest (rreq, source); +if (!subreq) { + ret = -ENOMEM ;break ; } + subreq->start = start; + subreq->len = size; +if (copy) +__set_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags); + +netfs_queue_read (rreq, subreq); + rreq->io_streams[0 ].sreq_max_len =MAX_RW_COUNT ; rreq->io_streams[0 ].sreq_max_segs =INT_MAX ;
@@ -418,10 +418,9 @@ static void netfs_read_to_pagecache(struct netfs_io_request *rreq)if (size <=0 )netfs_all_subreqs_queued (rreq); +/* See if the cache indicated this should be cached. */ if (mark_cursor.bvecq) { -/* See if the cache indicated this should be cached. */ -bool copy =test_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags); - + copy =test_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags);netfs_mark_copy_to_cache (rreq, &mark_cursor, slice, copy); }
fs/netfs/direct_read.c +1 -2
@@ -33,7 +33,7 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq) do { struct netfs_io_subrequest *subreq; - subreq = netfs_alloc_subrequest(rreq); + subreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER); if (!subreq) { /* Stash the error in the request if there's not * already an error set.
@@ -42,7 +42,6 @@ static void netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)break ; } - subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->start = start; subreq->len = size;
fs/netfs/internal.h +2 -1
@@ -93,7 +93,8 @@ void netfs_get_request(struct netfs_io_request *rreq, enum netfs_rreq_ref_tracevoid netfs_clear_subrequests (struct netfs_io_request *rreq);void netfs_put_request (struct netfs_io_request *rreq,enum netfs_rreq_ref_trace what);void netfs_put_failed_request (struct netfs_io_request *rreq); -struct netfs_io_subrequest *netfs_alloc_subrequest (struct netfs_io_request *rreq); +struct netfs_io_subrequest *netfs_alloc_subrequest (struct netfs_io_request *rreq, +enum netfs_io_source source);static inline void netfs_see_request (struct netfs_io_request *rreq,enum netfs_rreq_ref_trace what)
fs/netfs/objects.c +3 -1
@@ -213,7 +213,8 @@ void netfs_put_failed_request(struct netfs_io_request *rreq)/* * Allocate and partially initialise an I/O request structure. */ -struct netfs_io_subrequest *netfs_alloc_subrequest (struct netfs_io_request *rreq) +struct netfs_io_subrequest *netfs_alloc_subrequest (struct netfs_io_request *rreq, +enum netfs_io_source source) {struct netfs_io_subrequest *subreq;mempool_t *mempool = rreq->netfs_ops->subrequest_pool ?: &netfs_subrequest_pool;
@@ -230,6 +231,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreqINIT_WORK (&subreq->work,NULL );INIT_LIST_HEAD (&subreq->rreq_link);refcount_set (&subreq->ref,2 ); + subreq->source = source; subreq->rreq = rreq; subreq->debug_index =atomic_inc_return (&rreq->subreq_counter);netfs_get_request (rreq, netfs_rreq_trace_get_subreq);
fs/netfs/read_retry.c +1 -2
@@ -210,12 +210,11 @@ static void netfs_retry_read_subrequests(struct netfs_io_request *rreq)* and insert them after. */ do { - subreq = netfs_alloc_subrequest(rreq); + subreq = netfs_alloc_subrequest(rreq, NETFS_DOWNLOAD_FROM_SERVER); if (!subreq) { subreq = to; goto abandon_after; } - subreq->source = NETFS_DOWNLOAD_FROM_SERVER; subreq->start = start; subreq->len = len; subreq->stream_nr = stream->stream_nr;
fs/netfs/read_single.c +1 -1
@@ -86,7 +86,7 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)struct netfs_io_subrequest *subreq;int ret =0 ; - subreq =netfs_alloc_subrequest (rreq); + subreq =netfs_alloc_subrequest (rreq,NETFS_DOWNLOAD_FROM_SERVER );if (!subreq)return -ENOMEM ;
fs/netfs/write_issue.c +2 -4
@@ -193,11 +193,10 @@ struct netfs_io_subrequest *netfs_alloc_write_subreq(struct netfs_io_request *wr {struct netfs_io_subrequest *subreq; - subreq =netfs_alloc_subrequest (wreq); + subreq =netfs_alloc_subrequest (wreq, stream->source);if (!subreq)return subreq; - subreq->source = stream->source; subreq->start = stream->issue_from; subreq->len = stream->buffered; subreq->stream_nr = stream->stream_nr;
@@ -245,10 +244,9 @@ void netfs_prepare_write(struct netfs_io_request *wreq, {struct netfs_io_subrequest *subreq; - subreq =netfs_alloc_subrequest (wreq); + subreq =netfs_alloc_subrequest (wreq, stream->source);if (!subreq)return ; - subreq->source = stream->source; subreq->start = start; subreq->stream_nr = stream->stream_nr;
fs/netfs/write_retry.c +1 -2
@@ -158,8 +158,7 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,* and insert them after. */ do { - subreq = netfs_alloc_subrequest(wreq); - subreq->source = to->source; + subreq = netfs_alloc_subrequest(wreq, stream->source); subreq->start = start; subreq->stream_nr = to->stream_nr; subreq->retry_count = 1;
David Howells
maintainerPATCH v11 34/36 netfs: Combine prepare and issue ops
In reply to David HowellsModify the way subrequests are generated in netfslib to simplify the way things work. Currently, netfslib creates a subrequest and then calls ->prepare_xxx() to prepare it and to enquire about how big it can be and to which source it sends a request (server or cache), then it progressively loads up the buffer and some time later finally issues it.
This delay between prepare and issue, however, presents a couple of issues:
firstly, it may hold server resources for a significant length of time (e.g. cifs SMB2+ credits), blocking other users; and secondly it holds memory or other local resources that could otherwise be used to perform some other task under low-memory conditions.
Fix this by accumulating buffers to be involved in the I/O and then calling ->issue_xxx() to do all the preparation work and issuing, including calling back into netfslib to grab a slice of the so-far accumulated buffers.
For buffered reads, instead of ->prepare_read() setting limits on the amount of bufferage to be accumulated, all read requests (including readahead) build the buffer list up front and then just go through dispatching slices of it. Each subreq bites off the slice it can handle. In a previous patch, the cache acquired a ->query_occupancy() method that allows netfs to find out where extents of holes or data are rather than sending each subreq to the cache first.
For unbuffered/DIO read and writes, as for buffered reads, the buffer list is built up front and then slices of it are dispatched.
For buffered writeback, ->estimate_write() is used to set a need-flush-by point for each stream, and then buffers are added into the list until enough is accumulated to flush a stream or a discontiguity is reached - at which point ->issue_write() is called and the estimate refreshed repeatedly until the remaining amount of accumulated buffers is less than the estimate.
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 duplicated 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.
--- fs/9p/vfs_addr.c | 43 ++++-- fs/afs/file.c | 27 ++-- fs/afs/fsclient.c | 8 +- fs/afs/internal.h | 5 +- fs/afs/write.c | 33 ++-- fs/afs/yfsclient.c | 6 +- fs/cachefiles/io.c | 230 ++++++++++++++++++++-------- fs/ceph/addr.c | 123 ++++++++------- fs/netfs/buffered_read.c | 281 ++++++++++++++++++++--------------- fs/netfs/direct_read.c | 84 ++++++----- fs/netfs/direct_write.c | 144 +++++++++--------- fs/netfs/fscache_io.c | 2 +- fs/netfs/internal.h | 44 ++++-- fs/netfs/main.c | 1 + fs/netfs/misc.c | 33 +++- fs/netfs/objects.c | 4 +- fs/netfs/read_collect.c | 38 ++--- fs/netfs/read_pgpriv2.c | 125 ++++++++++------ fs/netfs/read_retry.c | 208 ++++++++++++-------------- fs/netfs/read_single.c | 151 ++++++++++++------- fs/netfs/write_collect.c | 2 + fs/netfs/write_issue.c | 157 ++++++++++++------- fs/netfs/write_retry.c | 168 +++++++++++---------- fs/nfs/fscache.c | 24 ++- fs/smb/client/cifssmb.c | 13 +- fs/smb/client/file.c | 134 ++++++++--------- fs/smb/client/smb2ops.c | 9 +- fs/smb/client/smb2pdu.c | 28 +++- fs/smb/client/transport.c | 15 +- include/linux/netfs.h | 55 +++---- include/trace/events/netfs.h | 30 +++- net/9p/client.c | 8 +- 32 files changed, 1320 insertions(+), 913 deletions(-)
fs/9p/vfs_addr.c +34 -9
@@ -67,28 +67,51 @@ static int v9fs_estimate_write(struct netfs_io_request *wreq,/* * Issue a subrequest to write to the server. */ -static void v9fs_issue_write (struct netfs_io_subrequest *subreq) +static int v9fs_issue_write (struct netfs_io_subrequest *subreq) { +struct iov_iter iter;struct p9_fid *fid = subreq->rreq->netfs_priv; -int err, len; +int err, len =0 ; - len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); + subreq->len =umin (subreq->len, fid->clnt->msize -P9_IOHDRSZ ); + + err =netfs_prepare_write_buffer (subreq,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
@@ -105,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:
@@ -128,6 +152,7 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) subreq->error = err;netfs_read_subreq_terminated (subreq); +return 0 ; }/**
fs/afs/file.c +18 -9
@@ -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)
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;
@@ -1088,7 +1090,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;
@@ -1142,7 +1144,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 +2 -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;
@@ -1701,8 +1701,7 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);int afs_estimate_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream,struct netfs_write_estimate *estimate); -void afs_prepare_write (struct netfs_io_subrequest *subreq); -void afs_issue_write (struct netfs_io_subrequest *subreq); +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/write.c +17 -16
@@ -99,20 +99,6 @@ int afs_estimate_write(struct netfs_io_request *wreq,return 0 ; } -/* -* Prepare a subrequest to write to the server. This sets the max_len -* parameter. -*/ -void afs_prepare_write (struct netfs_io_subrequest *subreq) -{ -struct netfs_io_stream *stream = &subreq->rreq->io_streams[subreq->stream_nr]; - -//if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) -// subreq->max_len = 512 * 1024; -//else - stream->sreq_max_len =256 *1024 *1024 ; -} -/* * Issue a subrequest to write to the server. */
@@ -156,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) {
@@ -185,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 ; }/*
@@ -200,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 +166 -64
311 lines not on this page · raw message
fs/ceph/addr.c +71 -52
244 lines not on this page · raw message
fs/netfs/buffered_read.c +162 -119
494 lines not on this page · raw message
fs/netfs/direct_read.c +47 -37
139 lines not on this page · raw message
fs/netfs/direct_write.c +74 -70
231 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 +30 -14
87 lines not on this page · raw message
fs/netfs/main.c +1 -0
@@ -18,6 +18,7 @@ MODULE_DESCRIPTION("Network fs support");MODULE_AUTHOR ("Red Hat, Inc." );MODULE_LICENSE ("GPL" ); +EXPORT_TRACEPOINT_SYMBOL (netfs_rreq);EXPORT_TRACEPOINT_SYMBOL (netfs_sreq);unsigned netfs_debug;
fs/netfs/misc.c +32 -1
@@ -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. */
@@ -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 +1 -3
@@ -55,8 +55,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_waitqueue_head (&rreq->waitq);refcount_set (&rreq->ref,2 );
@@ -150,8 +148,8 @@ 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);while (rreq->writebacks) {struct netfs_writeback *wback = rreq->writebacks;
fs/netfs/read_collect.c +10 -28
@@ -35,6 +35,7 @@ static void netfs_clear_unread(struct netfs_io_subrequest *subreq)if (subreq->start + subreq->transferred >= subreq->rreq->i_size)__set_bit (NETFS_SREQ_HIT_EOF , &subreq->flags); +trace_netfs_rreq (subreq->rreq, netfs_rreq_trace_zero_unread); }/*
@@ -415,8 +416,7 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq) stream->collected_to = front->start + transferred; rreq->collected_to = stream->collected_to; -if (front->start + transferred >= unlock_at || -test_bit (NETFS_SREQ_HIT_EOF , &front_flags)) +if (front->start + transferred >= unlock_at)netfs_read_unlock_folios (rreq, ¬es); }else { stream->collected_to = front->start + transferred;
@@ -508,31 +508,6 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)inode_dio_end (rreq->inode); } -/* -* Do processing after reading a monolithic single object. -*/ -static void netfs_rreq_assess_single (struct netfs_io_request *rreq) -{ -struct netfs_io_stream *stream = &rreq->io_streams[0 ]; - -if (!rreq->error && stream->source ==NETFS_DOWNLOAD_FROM_SERVER && -fscache_resources_valid (&rreq->cache_resources)) { -trace_netfs_rreq (rreq, netfs_rreq_trace_dirty); -netfs_single_mark_inode_dirty (rreq->inode); - } - -if (rreq->iocb) { - rreq->iocb->ki_pos += rreq->transferred; -if (rreq->iocb->ki_complete) { -trace_netfs_rreq (rreq, netfs_rreq_trace_ki_complete); - rreq->iocb->ki_complete ( - rreq->iocb, rreq->error ? rreq->error : rreq->transferred); - } - } -if (rreq->netfs_ops->done) - rreq->netfs_ops->done (rreq); -} -/* * Perform the collection of subrequests and folios. *
@@ -566,7 +541,7 @@ bool netfs_read_collection(struct netfs_io_request *rreq)netfs_rreq_assess_dio (rreq);break ;case NETFS_READ_SINGLE : -netfs_rreq_assess_single (rreq); +WARN_ON_ONCE (1 );break ;default :break ;
@@ -700,6 +675,11 @@ void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq) }else if (test_bit (NETFS_SREQ_MADE_PROGRESS , &subreq->flags)) {__set_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags);trace_netfs_sreq (subreq, netfs_sreq_trace_partial_read); + }else if (subreq->source ==NETFS_READ_FROM_CACHE ) { +netfs_stat (&netfs_n_rh_read_failed); +__set_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags); + subreq->error = -ENODATA ; +trace_netfs_sreq (subreq, netfs_sreq_trace_short); }else {__set_bit (NETFS_SREQ_FAILED , &subreq->flags); subreq->error = -ENODATA ;
@@ -718,6 +698,8 @@ void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq)if (unlikely (subreq->error <0 )) {trace_netfs_failure (rreq, subreq, subreq->error, netfs_fail_read); +if (subreq->error == -ENOMEM ) +set_bit (NETFS_RREQ_SAW_ENOMEM , &rreq->flags);if (subreq->source ==NETFS_READ_FROM_CACHE ) {netfs_stat (&netfs_n_rh_read_failed);__set_bit (NETFS_SREQ_NEED_RETRY , &subreq->flags);
fs/netfs/read_pgpriv2.c +80 -45
195 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 +95 -56
204 lines not on this page · raw message
fs/netfs/write_collect.c +2 -0
@@ -566,6 +566,8 @@ void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error)if (IS_ERR_VALUE (transferred_or_error)) { subreq->error = transferred_or_error; +if (transferred_or_error == -ENOMEM ) +set_bit (NETFS_RREQ_SAW_ENOMEM , &wreq->flags);switch (subreq->source) {case NETFS_WRITE_TO_CACHE :
fs/netfs/write_issue.c +104 -53
279 lines not on this page · raw message
fs/netfs/write_retry.c +90 -78
73 lines not on this page · raw message
fs/smb/client/file.c +60 -74
134 lines not on this page · raw message
include/linux/netfs.h +19 -36
55 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.
David Howells
maintainerPATCH v11 35/36 netfs: Clean up now-unused code
In reply to David HowellsDelete now-unused code from netfslib, given the changes to the writeback dispatch code and the combination of ->prepare_xxx() and ->issue_xxx() methods.
--- fs/netfs/write_issue.c | 217 ----------------------------------------- 1 file changed, 217 deletions(-)
fs/netfs/write_issue.c +0 -217
@@ -222,70 +222,6 @@ struct netfs_io_subrequest *netfs_alloc_write_subreq(struct netfs_io_request *wrreturn subreq; } -#if 0 // TODO: Remove old stuff -/* -* Prepare a write subrequest. We need to allocate a new subrequest -* if we don't have one. -*/ -void netfs_prepare_write (struct netfs_io_request *wreq, -struct netfs_io_stream *stream, -uoff_t start) -{ -struct netfs_io_subrequest *subreq; - - subreq =netfs_alloc_subrequest (wreq, stream->source); -if (!subreq) -return ; - subreq->start = start; - subreq->stream_nr = stream->stream_nr; - -bvecq_pos_set (&subreq->dispatch_pos, &wreq->dispatch_cursor); - -_enter ("R=%x[%x]" , wreq->debug_id, subreq->debug_index); - -trace_netfs_sreq (subreq, netfs_sreq_trace_prepare); - - stream->sreq_max_len =UINT_MAX ; - stream->sreq_max_segs =INT_MAX ; -switch (stream->source) { -case NETFS_UPLOAD_TO_SERVER : -netfs_stat (&netfs_n_wh_upload); - stream->sreq_max_len = wreq->wsize; -break ; -case NETFS_WRITE_TO_CACHE : -netfs_stat (&netfs_n_wh_write); -break ; -default : -WARN_ON_ONCE (1 ); -break ; - } - -if (stream->prepare_write) - stream->prepare_write (subreq); - -__set_bit (NETFS_SREQ_IN_PROGRESS , &subreq->flags); - -/* We add to the end of the list whilst the collector may be walking -* the list. The collector only goes nextwards and uses the lock to -* remove entries off of the front. -*/ -spin_lock (&wreq->lock); -/* Write IN_PROGRESS before pointer to new subreq */ -list_add_tail_release (&subreq->rreq_link, &stream->subrequests); -if (list_is_first (&subreq->rreq_link, &stream->subrequests)) { -if (!stream->active) { - stream->collected_to = subreq->start; -/* Write list pointers before active flag */ -smp_store_release (&stream->active, true); - } - } - -spin_unlock (&wreq->lock); - - stream->construct = subreq; -} -#endif -/* * Advance the state of the amount of data buffered on a stream. */
@@ -368,159 +304,6 @@ int netfs_prepare_write_buffer(struct netfs_io_subrequest *subreq, }EXPORT_SYMBOL (netfs_prepare_write_buffer); -#if 0 // TODO: Remove old stuff -/* -* Set the I/O iterator for the filesystem/cache to use and dispatch the I/O -* operation. The operation may be asynchronous and should call -* netfs_write_subrequest_terminated() when complete. -*/ -static void netfs_do_issue_write (struct netfs_io_stream *stream, -struct netfs_io_subrequest *subreq) -{ -struct netfs_io_request *wreq = subreq->rreq; - -_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); - -trace_netfs_sreq (subreq, netfs_sreq_trace_submit); - stream->issue_write (subreq); -} - -void netfs_reissue_write (struct netfs_io_stream *stream, -struct netfs_io_subrequest *subreq) -{ -// TODO: Use encrypted buffer -bvecq_pos_unset (&subreq->content); -bvecq_pos_set (&subreq->content, &subreq->dispatch_pos); -iov_iter_bvec_queue (&subreq->io_iter,ITER_SOURCE , - subreq->content.bvecq, subreq->content.slot, - subreq->content.offset, - subreq->len); -iov_iter_advance (&subreq->io_iter, subreq->transferred); - - subreq->retry_count++; - subreq->error =0 ; -__clear_bit (NETFS_SREQ_MADE_PROGRESS , &subreq->flags); -__set_bit (NETFS_SREQ_IN_PROGRESS , &subreq->flags); -netfs_stat (&netfs_n_wh_retry_write_subreq); -netfs_do_issue_write (stream, subreq); -} - -static void netfs_issue_write (struct netfs_io_request *wreq, -struct netfs_io_stream *stream) -{ -struct netfs_io_subrequest *subreq = stream->construct; - -if (!subreq) -return ; - -bvecq_pos_set (&subreq->content, &subreq->dispatch_pos); -iov_iter_bvec_queue (&subreq->io_iter,ITER_SOURCE , - subreq->content.bvecq, subreq->content.slot, - subreq->content.offset, - subreq->len); - - stream->construct =NULL ; -netfs_do_issue_write (stream, subreq); -} - -/* -* Add data to the write subrequest, dispatching each as we fill it up or if it -* is discontiguous with the previous. We only fill one part at a time so that -* we can avoid overrunning the credits obtained (cifs) and try to parallelise -* content-crypto preparation with network writes. -*/ -size_t netfs_advance_write (struct netfs_io_request *wreq, -struct netfs_io_stream *stream, -uoff_t start,size_t len,bool to_eof) -{ -struct netfs_io_subrequest *subreq = stream->construct; -size_t part; - -if (!stream->avail) { -_leave ("no write" ); -return len; - } - -_enter ("R=%x[%x]" , wreq->debug_id, subreq ? subreq->debug_index :0 ); - -if (subreq && start != subreq->start + subreq->len) { -netfs_issue_write (wreq, stream); - subreq =NULL ; - } - -if (!stream->construct) -netfs_prepare_write (wreq, stream, start); - subreq = stream->construct; - - part =umin (stream->sreq_max_len - subreq->len, len); -_debug ("part %zx/%zx %zx/%zx" , subreq->len, stream->sreq_max_len, part, len); - subreq->len += part; - subreq->nr_segs++; - -if (subreq->len >= stream->sreq_max_len || - subreq->nr_segs >= stream->sreq_max_segs || - to_eof) { -netfs_issue_write (wreq, stream); - subreq =NULL ; - } - -return part; -} - -/* -* Prepare and issue a subrequest. -* TODO: Replace with combined ->prepare/->issue call(). -*/ -static int netfs_prep_and_issue_subreq (struct netfs_io_request *wreq, -struct netfs_io_stream *stream, -struct netfs_io_subrequest *subreq) -{ - stream->sreq_max_len =UINT_MAX ; - stream->sreq_max_segs =INT_MAX ; -switch (stream->source) { -case NETFS_UPLOAD_TO_SERVER : -netfs_stat (&netfs_n_wh_upload); - stream->sreq_max_len = wreq->wsize; -break ; -case NETFS_WRITE_TO_CACHE : -netfs_stat (&netfs_n_wh_write); -break ; -default : -WARN_ON_ONCE (1 ); -break ; - } - -if (stream->prepare_write) - stream->prepare_write (subreq); -netfs_prepare_buffered_write_buffer (subreq, stream->sreq_max_segs); -iov_iter_bvec_queue (&subreq->io_iter,ITER_SOURCE , - subreq->content.bvecq, subreq->content.slot, - subreq->content.offset, - subreq->len); -trace_netfs_sreq (subreq, netfs_sreq_trace_submit); - stream->issue_write (subreq); -return 0 ; -} -#endif -/* * Issue writes for a stream. */
David Howells
maintainerPATCH v11 36/36 cachefiles: Preset the state xattr when creating a new file
In reply to David HowellsWith a really small cache, cachefiles is likely to see a lot of writes hitting ENOSPC - and this can include setxattr that sets the state xattr on a cachefile - but we don't really want to successfully fill a cache file only to have to scrap it because we can't set the xattr.
Instead, preset the xattr when we create the tmpfile we're going to use, and scrap the file at that point if we get ENOSPC. Only if setxattr succeeds do we allow data to be written to the file.
Note that there is a potential performance loss in that writes to the cache have to be delayed until this is completed - but we do the tmpfile/setxattr in parallel, starting when the file is opened and only have to wait once writeback occurs.
Further, a new tracepoint, cachefiles_no_space, has been added to log ENOSPC events, along with a couple of subreq traces to log failure detection in netfslib.
--- fs/cachefiles/internal.h | 1 + fs/cachefiles/io.c | 23 ++++++++---- fs/cachefiles/namei.c | 15 ++++++-- fs/cachefiles/xattr.c | 59 ++++++++++++++++++++++++++++++- include/trace/events/cachefiles.h | 30 +++++++++++++++- include/trace/events/netfs.h | 2 ++ 6 files changed, 120 insertions(+), 10 deletions(-)
fs/cachefiles/internal.h +1 -0
@@ -283,6 +283,7 @@ void cachefiles_withdraw_volume(struct cachefiles_volume *volume);/* * xattr.c */ +int cachefiles_preset_object_xattr (struct cachefiles_object *object,struct file *file);extern int cachefiles_set_object_xattr (struct cachefiles_object *object);extern int cachefiles_check_auxdata (struct cachefiles_object *object,struct file *file);
fs/cachefiles/io.c +17 -6
@@ -672,10 +672,14 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,* space, we need to see if it's fully allocated. If it's not, we may * want to cull it. */ -if (cachefiles_has_space (cache,0 , *_len / cache->bsize, - cachefiles_has_space_check) ==0 ) + ret =cachefiles_has_space (cache,0 , *_len / cache->bsize, + cachefiles_has_space_check); +if (ret ==0 )return 0 ;/* Enough space to simply overwrite the whole block */ +if (ret == -ENOBUFS ) +trace_cachefiles_no_space (object, cachefiles_trace_write_nospace_2); + pos =cachefiles_inject_read_error ();if (pos ==0 ) pos =vfs_llseek (file, start,SEEK_HOLE );
@@ -704,8 +708,11 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,return ret; check_space: -return cachefiles_has_space (cache,0 , *_len / cache->bsize, - cachefiles_has_space_for_write); + ret =cachefiles_has_space (cache,0 , *_len / cache->bsize, + cachefiles_has_space_for_write); +if (ret == -ENOBUFS ) +trace_cachefiles_no_space (object, cachefiles_trace_write_nospace); +return ret; } static int cachefiles_prepare_write_old(struct netfs_cache_resources *cres,
@@ -757,10 +764,14 @@ static int cachefiles_issue_write(struct netfs_io_subrequest *subreq) wreq->debug_id, subreq->debug_index, start, start + len - 1);if (!cachefiles_cres_file (cres)) { -if (!fscache_wait_for_operation (cres,FSCACHE_WANT_WRITE )) +if (!fscache_wait_for_operation (cres,FSCACHE_WANT_WRITE )) { +trace_netfs_sreq (subreq, netfs_sreq_trace_cache_waitfail);return -ENOBUFS ; -if (!cachefiles_cres_file (cres)) + } +if (!cachefiles_cres_file (cres)) { +trace_netfs_sreq (subreq, netfs_sreq_trace_cache_nofile);return -ENOBUFS ; + } } ret =netfs_prepare_write_buffer (subreq,BIO_MAX_VECS );
fs/cachefiles/namei.c +13 -2
@@ -117,8 +117,11 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,if (d_is_negative (subdir)) { ret =cachefiles_has_space (cache,1 ,0 , cachefiles_has_space_for_create); -if (ret <0 ) +if (ret <0 ) { +if (ret == -ENOBUFS ) +trace_cachefiles_no_space (NULL , cachefiles_trace_mkdir_nospace); goto mkdir_error; + }_debug ("attempt mkdir" );
@@ -447,6 +450,11 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)pr_notice ("Cache does not support read_iter and write_iter\n" ); goto err_unuse; } + +/* Preallocate space for the xattr. */ + ret =cachefiles_preset_object_xattr (object, file); +if (ret <0 ) + goto err_unuse; out:cachefiles_end_secure (cache, saved_cred); object->content_info =CACHEFILES_CONTENT_ALL ;
@@ -470,8 +478,11 @@ static bool cachefiles_create_file(struct cachefiles_object *object) ret =cachefiles_has_space (object->volume->cache,1 ,0 , cachefiles_has_space_for_create); -if (ret <0 ) +if (ret <0 ) { +if (ret == -ENOBUFS ) +trace_cachefiles_no_space (object, cachefiles_trace_create_nospace);return false; + } file =cachefiles_create_tmpfile (object);if (IS_ERR (file))
fs/cachefiles/xattr.c +58 -1
74 lines not on this page · raw message
include/trace/events/cachefiles.h +29 -1
@@ -85,11 +85,13 @@ enum cachefiles_prepare_read_trace {enum cachefiles_error_trace { cachefiles_trace_alignment_error, + cachefiles_trace_create_nospace, cachefiles_trace_fallocate_error, cachefiles_trace_getxattr_error, cachefiles_trace_link_error, cachefiles_trace_lookup_error, cachefiles_trace_mkdir_error, + cachefiles_trace_mkdir_nospace, cachefiles_trace_notify_change_error, cachefiles_trace_open_error, cachefiles_trace_read_error,
@@ -102,6 +104,8 @@ enum cachefiles_error_trace { cachefiles_trace_trunc_error, cachefiles_trace_unlink_error, cachefiles_trace_write_error, + cachefiles_trace_write_nospace, + cachefiles_trace_write_nospace_2, };#endif
@@ -171,11 +175,13 @@ enum cachefiles_error_trace {#define cachefiles_error_traces \ EM(cachefiles_trace_alignment_error, "align") \ + EM(cachefiles_trace_create_nospace, "create-nospace") \ EM(cachefiles_trace_fallocate_error, "fallocate") \ EM(cachefiles_trace_getxattr_error, "getxattr") \ EM(cachefiles_trace_link_error, "link") \ EM(cachefiles_trace_lookup_error, "lookup") \ EM(cachefiles_trace_mkdir_error, "mkdir") \ + EM(cachefiles_trace_mkdir_nospace, "mkdir-nospace") \ EM(cachefiles_trace_notify_change_error, "notify_change") \ EM(cachefiles_trace_open_error, "open") \ EM(cachefiles_trace_read_error, "read") \
@@ -187,7 +193,9 @@ enum cachefiles_error_trace { EM(cachefiles_trace_tmpfile_error, "tmpfile") \ EM(cachefiles_trace_trunc_error, "trunc") \ EM(cachefiles_trace_unlink_error, "unlink") \ -E_ (cachefiles_trace_write_error,"write" ) + EM(cachefiles_trace_write_error, "write") \ + EM(cachefiles_trace_write_nospace, "write-nospace") \ +E_ (cachefiles_trace_write_nospace_2,"write-nospace-2" )/*
@@ -707,6 +715,26 @@ TRACE_EVENT(cachefiles_io_error, __entry->error) ); +TRACE_EVENT (cachefiles_no_space, + TP_PROTO(struct cachefiles_object *obj, enum cachefiles_error_trace trace), + +TP_ARGS (obj, trace), + +TP_STRUCT__entry ( + __field(unsigned int, obj) + __field(enum cachefiles_error_trace, trace) + ), + +TP_fast_assign ( + __entry->obj = obj ? obj->debug_id : 0; + __entry->trace = trace; + ), + +TP_printk ("o=%08x %s" , + __entry->obj, +__print_symbolic (__entry->trace, cachefiles_error_traces)) + ); +#endif /* _TRACE_CACHEFILES_H */ /* This part must be outside protection */
include/trace/events/netfs.h +2 -0
@@ -102,8 +102,10 @@ EM(netfs_sreq_trace_abandoned, "ABNDN") \ EM(netfs_sreq_trace_add_donations, "+DON ") \ EM(netfs_sreq_trace_added, "ADD ") \ + EM(netfs_sreq_trace_cache_nofile, "CA-!F") \ EM(netfs_sreq_trace_cache_nowrite, "CA-NW") \ EM(netfs_sreq_trace_cache_prepare, "CA-PR") \ + EM(netfs_sreq_trace_cache_waitfail, "CA-!W") \ EM(netfs_sreq_trace_cache_write, "CA-WR") \ EM(netfs_sreq_trace_cancel, "CANCL") \EM (netfs_sreq_trace_clear,"CLEAR" ) \
<broken record mode>
Please split out changes to core infrastructure. Make sure they are also useful and used outside of your little corner. Ensure they can be an are properly tested by either having common test exercise them or adding new easy to run test in common testsuites like xfstests or blktests. And make sure the changes to the core code are relatively self-contained and reviewable.
</broken record mode>