netfs, afs, 9p, cifs: Rework netfs to use ->writepages() to copy to cache
Subsystems (15)
David Howells
maintainerv2 cover netfs, afs, 9p, cifs: Rework netfs to use ->writepages() to copy to cache
Hi Christian, Willy,
Here's an updated version of my netfs writeback rewrite. There haven't been any major fixes. So far...
The primary purpose of these patches is to rework the netfslib writeback implementation such that pages read from the cache are written to the cache through ->writepages(), thereby allowing the fscache page flag to be retired.
The reworking also:
(1) builds on top of the new writeback_iter() infrastructure;
(2) makes it possible to use vectored write RPCs as discontiguous streams
of pages can be accommodated;
(3) makes it easier to do simultaneous content crypto and stream division.
(4) provides support for retrying writes and re-dividing a stream;
(5) replaces the ->launder_folio() op, so that ->writepages() is used
instead;
(6) uses mempools to allocate the netfs_io_request and netfs_io_subrequest structs to avoid allocation failure in the writeback path.
Some code that uses the fscache page flag is retained for compatibility purposes with nfs and ceph. The code is switched to using the synonymous private_2 label instead and marked with deprecation comments. I have a separate set of patches that convert cifs to use this code.
-~-
In this new implementation, writeback_iter() is used to pump folios, progressively creating two parallel, but separate streams. Either or both streams can contain gaps, and the subrequests in each stream can be of variable size, don't need to align with each other and don't need to align with the folios. (Note that more streams can be added if we have multiple servers to duplicate data to).
Indeed, subrequests can cross folio boundaries, may cover several folios or a folio may be spanned by multiple subrequests, e.g.:
+---+---+-----+-----+---+----------+
Folios: | | | | | | |
+---+---+-----+-----+---+----------+ +------+------+ +----+----+
Upload: | | |.....| | |
+------+------+ +----+----+ +------+------+------+------+------+
Cache: | | | | | |
+------+------+------+------+------+Data that got read from the server that needs copying to the cache is stored in folios that are marked dirty and have folio->private set to a special value.
The progressive subrequest construction permits the algorithm to be preparing both the next upload to the server and the next write to the cache whilst the previous ones are already in progress. Throttling can be applied to control the rate of production of subrequests - and, in any case, we probably want to write them to the server in ascending order, particularly if the file will be extended.
Content crypto can also be prepared at the same time as the subrequests and run asynchronously, with the prepped requests being stalled until the crypto catches up with them. This might also be useful for transport crypto, but that happens at a lower layer, so probably would be harder to pull off.
The algorithm is split into three parts:
(1) The issuer. This walks through the data, packaging it up, encrypting it and creating subrequests. The part of this that generates subrequests only deals with file positions and spans and so is usable for DIO/unbuffered writes as well as buffered writes.
(2) The collector. This asynchronously collects completed subrequests, unlocks folios, frees crypto buffers and performs any retries. This runs in a work queue so that the issuer can return to the caller for writeback (so that the VM can have its kswapd thread back) or async writes.
Collection is slightly complex as the collector has to work out where discontiguities happen in the folio list so that it doesn't try and collect folios that weren't included in the write out.
(3) The retryer. This pauses the issuer, waits for all outstanding subrequests to complete and then goes through the failed subrequests to reissue them. This may involve reprepping them (with cifs, the credits must be renegotiated and a subrequest may need splitting), and doing RMW for content crypto if there's a conflicting change on the server.
The patches can be found here also:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-writeback
David
Changes
=======
ver #2)
- Rebase on v6.9-rc6 to accommodate some fixes that went upstream.
- Make netfs_begin_writethrough() actually return an error.
- Move the cifs invalidation patch to the cifs-netfs branch.
- Mark writeback_iter() EXPORT_SYMBOL_GPL.
- In p9_client_write_subreq(), use 'int len' rather than 'size_t len' because of the varargs packet formatter.
- In netfs_perform_write(), don't wait for writeback if we don't need to.
- Don't do the AFS StoreData RPC inline, but keep doing it from a workqueue.
- Remove a couple of redundant checks where the second used to be inside a lock.
- Add missing linux/bio.h for BIO_MAX_VECS in cachefiles.
- Change a comma ending a statement to a semicolon.
- Make filemap_invalidate_inode() take a range.
- Make netfs_unbuffered_write_iter() use filemap_invalidate_inode().
David Howells (22):
netfs: Update i_blocks when write committed to pagecache
netfs: Replace PG_fscache by setting folio->private and marking dirty
mm: Remove the PG_fscache alias for PG_private_2
netfs: Remove deprecated use of PG_private_2 as a second writeback
flag
netfs: Make netfs_io_request::subreq_counter an atomic_t
netfs: Use subreq_counter to allocate subreq debug_index values
mm: Provide a means of invalidation without using launder_folio 9p: Use alternative invalidation to using launder_folio
afs: Use alternative invalidation to using launder_folio
netfs: Remove ->launder_folio() support
netfs: Use mempools for allocating requests and subrequests
mm: Export writeback_iter()
netfs: Switch to using unsigned long long rather than loff_t
netfs: New writeback implementation
netfs: Add some write-side stats and clean up some stat names netfs, afs: Implement helpers for new write code
netfs, 9p: Implement helpers for new write code
netfs, cachefiles: Implement helpers for new write code
netfs: Cut over to using new writeback code
netfs: Remove the old writeback code
netfs: Miscellaneous tidy ups
netfs, afs: Use writeback retry to deal with alternate keys
fs/9p/vfs_addr.c | 60 +-- fs/afs/file.c | 8 +- fs/afs/internal.h | 6 +- fs/afs/validation.c | 4 +- fs/afs/write.c | 189 ++++---- fs/cachefiles/io.c | 76 +++- fs/ceph/addr.c | 24 +- fs/ceph/inode.c | 2 + fs/netfs/Makefile | 3 +- fs/netfs/buffered_read.c | 40 +- fs/netfs/buffered_write.c | 825 +++-------------------------------- fs/netfs/direct_write.c | 56 ++- fs/netfs/fscache_io.c | 14 +- fs/netfs/internal.h | 55 ++- fs/netfs/io.c | 155 +------ fs/netfs/main.c | 55 ++- fs/netfs/misc.c | 10 +- fs/netfs/objects.c | 81 +++- fs/netfs/output.c | 478 -------------------- fs/netfs/stats.c | 17 +- fs/netfs/write_collect.c | 808 ++++++++++++++++++++++++++++++++++ fs/netfs/write_issue.c | 675 ++++++++++++++++++++++++++++ fs/nfs/file.c | 8 +- fs/nfs/fscache.h | 6 +- fs/nfs/write.c | 4 +- fs/smb/client/file.c | 16 +- include/linux/fscache.h | 22 +- include/linux/netfs.h | 196 +++++---- include/linux/pagemap.h | 2 + include/net/9p/client.h | 2 + include/trace/events/netfs.h | 249 ++++++++++- mm/filemap.c | 60 ++- mm/page-writeback.c | 1 + net/9p/Kconfig | 1 + net/9p/client.c | 49 +++ 35 files changed, 2502 insertions(+), 1755 deletions(-) delete mode 100644 fs/netfs/output.c create mode 100644 fs/netfs/write_collect.c create mode 100644 fs/netfs/write_issue.c
David Howells
maintainerPATCH v2 1/22 netfs: Update i_blocks when write committed to pagecache
Update i_blocks when i_size is updated when we finish making a write to the pagecache to reflect the amount of space we think will be consumed.
This maintains cifs commit dbfdff402d89854126658376cbcb08363194d3cd ("smb3:
update allocation size more accurately on write completion") which would otherwise be removed by the cifs part of the netfs writeback rewrite.
--- fs/netfs/buffered_write.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-)
fs/netfs/buffered_write.c +34 -11
@@ -130,6 +130,37 @@ static struct folio *netfs_grab_folio_for_write(struct address_space *mapping, mapping_gfp_mask(mapping)); } +/* +* Update i_size and estimate the update to i_blocks to reflect the additional +* data written into the pagecache until we can find out from the server what +* the values actually are. +*/ +static void netfs_update_i_size (struct netfs_inode *ctx,struct inode *inode, +loff_t i_size,loff_t pos,size_t copied) +{ +blkcnt_t add; +size_t gap; + +if (ctx->ops->update_i_size) { + ctx->ops->update_i_size (inode, pos); +return ; + } + +i_size_write (inode, pos); +#if IS_ENABLED (CONFIG_FSCACHE ) +fscache_update_cookie (ctx->cache,NULL , &pos); +#endif + + gap =SECTOR_SIZE - (i_size & (SECTOR_SIZE -1 )); +if (copied > gap) { + add =DIV_ROUND_UP (copied - gap,SECTOR_SIZE ); + + inode->i_blocks =min_t (blkcnt_t, +DIV_ROUND_UP (pos,SECTOR_SIZE ), + inode->i_blocks + add); + } +} +/** * netfs_perform_write - Copy data into the pagecache. * @iocb: The operation parameters
@@ -351,18 +382,10 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,trace_netfs_folio (folio, trace);/* Update the inode size if we moved the EOF marker */ - i_size =i_size_read (inode); pos += copied; -if (pos > i_size) { -if (ctx->ops->update_i_size) { - ctx->ops->update_i_size (inode, pos); - }else { -i_size_write (inode, pos); -#if IS_ENABLED (CONFIG_FSCACHE ) -fscache_update_cookie (ctx->cache,NULL , &pos); -#endif - } - } + i_size =i_size_read (inode); +if (pos > i_size) +netfs_update_i_size (ctx, inode, i_size, pos, copied); written += copied;if (likely (!wreq)) {
David Howells
maintainerPATCH v2 2/22 netfs: Replace PG_fscache by setting folio->private and marking dirty
In reply to David HowellsWhen dirty data is being written to the cache, setting/waiting on/clearing the fscache flag is always done in tandem with setting/waiting on/clearing the writeback flag. The netfslib buffered write routines wait on and set both flags and the write request cleanup clears both flags, so the fscache flag is almost superfluous.
The reason it isn't superfluous is because the fscache flag is also used to indicate that data just read from the server is being written to the cache. The flag is used to prevent a race involving overlapping direct-I/O writes to the cache.
Change this to indicate that a page is in need of being copied to the cache by placing a magic value in folio->private and marking the folios dirty. Then when the writeback code sees a folio marked in this way, it only writes it to the cache and not to the server.
If a folio that has this magic value set is modified, the value is just replaced and the folio will then be uplodaded too.
With this, PG_fscache is no longer required by the netfslib core, 9p and afs.
Ceph and nfs, however, still need to use the old PG_fscache-based tracking. To deal with this, a flag, NETFS_ICTX_USE_PGPRIV2, now has to be set on the flags in the netfs_inode struct for those filesystems. This reenables the use of PG_fscache in that inode. 9p and afs use the netfslib write helpers so get switched over; cifs, for the moment, does page-by-page manual access to the cache, so doesn't use PG_fscache and is unaffected.
--- fs/ceph/addr.c | 2 +- fs/ceph/inode.c | 2 + fs/netfs/buffered_read.c | 36 ++++++++++---- fs/netfs/buffered_write.c | 93 +++++++++++++++++------------------- fs/netfs/fscache_io.c | 12 +++-- fs/netfs/internal.h | 10 ++-- fs/netfs/io.c | 18 +++---- fs/netfs/main.c | 1 + fs/netfs/misc.c | 10 +--- fs/netfs/objects.c | 6 ++- fs/nfs/fscache.h | 2 + include/linux/fscache.h | 22 +++++---- include/linux/netfs.h | 20 ++++++-- include/trace/events/netfs.h | 6 ++- 14 files changed, 143 insertions(+), 97 deletions(-)
fs/ceph/addr.c +1 -1
@@ -517,7 +517,7 @@ static void ceph_fscache_write_to_cache(struct inode *inode, u64 off, u64 len, bstruct fscache_cookie *cookie =ceph_fscache_cookie (ci);fscache_write_to_cache (cookie, inode->i_mapping, off, len,i_size_read (inode), - ceph_fscache_write_terminated, inode, caching); + ceph_fscache_write_terminated, inode, true, caching); }#else static inline void ceph_set_page_fscache (struct page *page)
fs/ceph/inode.c +2 -0
@@ -577,6 +577,8 @@ struct inode *ceph_alloc_inode(struct super_block *sb)/* Set parameters for the netfs library */ netfs_inode_init (&ci->netfs, &ceph_netfs_ops, false); +/* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */ +__set_bit (NETFS_ICTX_USE_PGPRIV2 , &ci->netfs.flags);spin_lock_init (&ci->i_ceph_lock);
fs/netfs/buffered_read.c +26 -10
@@ -10,8 +10,11 @@#include "internal.h" /* -* Unlock the folios in a read operation. We need to set PG_fscache on any +* Unlock the folios in a read operation. We need to set PG_writeback on any * folios we're going to write back before we unlock them. +* +* Note that if the deprecated NETFS_RREQ_USE_PGPRIV2 is set then we use +* PG_private_2 and do a direct write to the cache from here instead. */ void netfs_rreq_unlock_folios (struct netfs_io_request *rreq) {
@@ -48,14 +51,14 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *rreq)xas_for_each (&xas, folio, last_page) {loff_t pg_end;bool pg_failed = false; -bool folio_started; +bool wback_to_cache = false; +bool folio_started = false;if (xas_retry (&xas, folio))continue ; pg_end =folio_pos (folio) +folio_size (folio) -1 ; - folio_started = false;for (;;) {loff_t sreq_end;
@@ -63,10 +66,16 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *rreq) pg_failed = true;break ; } -if (!folio_started &&test_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags)) { -trace_netfs_folio (folio, netfs_folio_trace_copy_to_cache); -folio_start_fscache (folio); - folio_started = true; +if (test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags)) { +if (!folio_started &&test_bit (NETFS_SREQ_COPY_TO_CACHE , + &subreq->flags)) { +trace_netfs_folio (folio, netfs_folio_trace_copy_to_cache); +folio_start_fscache (folio); + folio_started = true; + } + }else { + wback_to_cache |= +test_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags); } pg_failed |= subreq_failed; sreq_end = subreq->start + subreq->len -1 ;
@@ -98,6 +107,11 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *rreq)kfree (finfo); }folio_mark_uptodate (folio); +if (wback_to_cache && !WARN_ON_ONCE (folio_get_private (folio) !=NULL )) { +trace_netfs_folio (folio, netfs_folio_trace_copy_to_cache); +folio_attach_private (folio,NETFS_FOLIO_COPY_TO_CACHE ); +filemap_dirty_folio (folio->mapping, folio); + } }if (!test_bit (NETFS_RREQ_DONT_UNLOCK_FOLIOS , &rreq->flags)) {
@@ -491,9 +505,11 @@ int netfs_write_begin(struct netfs_inode *ctx,netfs_put_request (rreq, false, netfs_rreq_trace_put_return); have_folio: - ret =folio_wait_fscache_killable (folio); -if (ret <0 ) - goto error; +if (test_bit (NETFS_ICTX_USE_PGPRIV2 , &ctx->flags)) { + ret =folio_wait_fscache_killable (folio); +if (ret <0 ) + goto error; + } have_folio_no_wait: *_folio = folio;_leave (" = 0" );
fs/netfs/buffered_write.c +44 -49
250 lines not on this page · raw message
fs/netfs/fscache_io.c +8 -4
@@ -166,6 +166,7 @@ struct fscache_write_request {loff_t start;size_t len;bool set_bits; +bool using_pgpriv2;netfs_io_terminated_t term_func;void *term_func_priv; };
@@ -197,8 +198,9 @@ static void fscache_wreq_done(void *priv, ssize_t transferred_or_error, {struct fscache_write_request *wreq = priv; -fscache_clear_page_bits (wreq->mapping, wreq->start, wreq->len, - wreq->set_bits); +if (wreq->using_pgpriv2) +fscache_clear_page_bits (wreq->mapping, wreq->start, wreq->len, + wreq->set_bits);if (wreq->term_func) wreq->term_func(wreq->term_func_priv, transferred_or_error,
@@ -212,7 +214,7 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie, loff_t start, size_t len, loff_t i_size, netfs_io_terminated_t term_func, void *term_func_priv, - bool cond) + bool using_pgpriv2, bool cond) { struct fscache_write_request *wreq;struct netfs_cache_resources *cres;
@@ -230,6 +232,7 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie, wreq->mapping = mapping; wreq->start = start; wreq->len = len; + wreq->using_pgpriv2 = using_pgpriv2; wreq->set_bits = cond; wreq->term_func = term_func; wreq->term_func_priv = term_func_priv;
@@ -257,7 +260,8 @@ void __fscache_write_to_cache(struct fscache_cookie *cookie, abandon_free:kfree (wreq); abandon: -fscache_clear_page_bits (mapping, start, len, cond); +if (using_pgpriv2) +fscache_clear_page_bits (mapping, start, len, cond);if (term_func)term_func (term_func_priv, ret, false); }
fs/netfs/internal.h +7 -3
@@ -168,7 +168,7 @@ static inline bool netfs_is_cache_enabled(struct netfs_inode *ctx)*/ static inline struct netfs_group *netfs_get_group (struct netfs_group *netfs_group) { -if (netfs_group) +if (netfs_group && netfs_group !=NETFS_FOLIO_COPY_TO_CACHE )refcount_inc (&netfs_group->ref);return netfs_group; }
@@ -178,7 +178,9 @@ static inline struct netfs_group *netfs_get_group(struct netfs_group *netfs_grou*/ static inline void netfs_put_group (struct netfs_group *netfs_group) { -if (netfs_group &&refcount_dec_and_test (&netfs_group->ref)) +if (netfs_group && + netfs_group !=NETFS_FOLIO_COPY_TO_CACHE && +refcount_dec_and_test (&netfs_group->ref)) netfs_group->free (netfs_group); }
@@ -187,7 +189,9 @@ static inline void netfs_put_group(struct netfs_group *netfs_group)*/ static inline void netfs_put_group_many (struct netfs_group *netfs_group,int nr) { -if (netfs_group &&refcount_sub_and_test (nr, &netfs_group->ref)) +if (netfs_group && + netfs_group !=NETFS_FOLIO_COPY_TO_CACHE && +refcount_sub_and_test (nr, &netfs_group->ref)) netfs_group->free (netfs_group); }
fs/netfs/io.c +10 -8
@@ -99,8 +99,9 @@ static void netfs_rreq_completed(struct netfs_io_request *rreq, bool was_async) }/* -* Deal with the completion of writing the data to the cache. We have to clear -* the PG_fscache bits on the folios involved and release the caller's ref. +* [DEPRECATED] Deal with the completion of writing the data to the cache. We +* have to clear the PG_fscache bits on the folios involved and release the +* caller's ref. * * May be called in softirq mode and we inherit a ref from the caller. */
@@ -138,7 +139,7 @@ static void netfs_rreq_unmark_after_write(struct netfs_io_request *rreq, }static void netfs_rreq_copy_terminated (void *priv,ssize_t transferred_or_error, -bool was_async) +bool was_async)/* [DEPRECATED] */ {struct netfs_io_subrequest *subreq = priv;struct netfs_io_request *rreq = subreq->rreq;
@@ -161,8 +162,8 @@ static void netfs_rreq_copy_terminated(void *priv, ssize_t transferred_or_error, }/* -* Perform any outstanding writes to the cache. We inherit a ref from the -* caller. +* [DEPRECATED] Perform any outstanding writes to the cache. We inherit a ref +* from the caller. */ static void netfs_rreq_do_write_to_cache (struct netfs_io_request *rreq) {
@@ -222,7 +223,7 @@ static void netfs_rreq_do_write_to_cache(struct netfs_io_request *rreq)netfs_rreq_unmark_after_write (rreq, false); } -static void netfs_rreq_write_to_cache_work (struct work_struct *work) +static void netfs_rreq_write_to_cache_work (struct work_struct *work)/* [DEPRECATED] */ {struct netfs_io_request *rreq = container_of(work, struct netfs_io_request, work);
@@ -230,7 +231,7 @@ static void netfs_rreq_write_to_cache_work(struct work_struct *work)netfs_rreq_do_write_to_cache (rreq); } -static void netfs_rreq_write_to_cache (struct netfs_io_request *rreq) +static void netfs_rreq_write_to_cache (struct netfs_io_request *rreq)/* [DEPRECATED] */ { rreq->work.func = netfs_rreq_write_to_cache_work;if (!queue_work (system_unbound_wq, &rreq->work))
@@ -409,7 +410,8 @@ static void netfs_rreq_assess(struct netfs_io_request *rreq, bool was_async)clear_bit_unlock (NETFS_RREQ_IN_PROGRESS , &rreq->flags);wake_up_bit (&rreq->flags,NETFS_RREQ_IN_PROGRESS ); -if (test_bit (NETFS_RREQ_COPY_TO_CACHE , &rreq->flags)) +if (test_bit (NETFS_RREQ_COPY_TO_CACHE , &rreq->flags) && +test_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags))return netfs_rreq_write_to_cache (rreq);netfs_rreq_completed (rreq, was_async);
fs/netfs/main.c +1 -0
@@ -31,6 +31,7 @@ static const char *netfs_origins[nr__netfs_io_origin] = { [NETFS_READAHEAD] = "RA", [NETFS_READPAGE] = "RP", [NETFS_READ_FOR_WRITE] = "RW", + [NETFS_COPY_TO_CACHE] = "CC", [NETFS_WRITEBACK] = "WB", [NETFS_WRITETHROUGH] = "WT", [NETFS_LAUNDER_WRITE] = "LW",
fs/netfs/misc.c +1 -9
@@ -177,13 +177,11 @@ EXPORT_SYMBOL(netfs_clear_inode_writeback);*/ void netfs_invalidate_folio (struct folio *folio,size_t offset,size_t length) { -struct netfs_folio *finfo =NULL ; +struct netfs_folio *finfo;size_t flen =folio_size (folio);_enter ("{%lx},%zx,%zx" , folio->index, offset, length); -folio_wait_fscache (folio); -if (!folio_test_private (folio))return ;
@@ -248,12 +246,6 @@ bool netfs_release_folio(struct folio *folio, gfp_t gfp)if (folio_test_private (folio))return false; -if (folio_test_fscache (folio)) { -if (current_is_kswapd () || !(gfp & __GFP_FS)) -return false; -folio_wait_fscache (folio); - } -fscache_note_page_release (netfs_i_cookie (ctx));return true; }
fs/netfs/objects.c +5 -1
@@ -45,8 +45,12 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,refcount_set (&rreq->ref,1 );__set_bit (NETFS_RREQ_IN_PROGRESS , &rreq->flags); -if (cached) +if (cached) {__set_bit (NETFS_RREQ_WRITE_TO_CACHE , &rreq->flags); +if (test_bit (NETFS_ICTX_USE_PGPRIV2 , &ctx->flags)) +/* Filesystem uses deprecated PG_private_2 marking. */ +__set_bit (NETFS_RREQ_USE_PGPRIV2 , &rreq->flags); + }if (file && file->f_flags &O_NONBLOCK )__set_bit (NETFS_RREQ_NONBLOCK , &rreq->flags);if (rreq->netfs_ops->init_request) {
fs/nfs/fscache.h +2 -0
@@ -81,6 +81,8 @@ static inline void nfs_netfs_put(struct nfs_netfs_io_data *netfs)static inline void nfs_netfs_inode_init (struct nfs_inode *nfsi) {netfs_inode_init (&nfsi->netfs, &nfs_netfs_ops, false); +/* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */ +__set_bit (NETFS_ICTX_USE_PGPRIV2 , &nfsi->netfs.flags); }extern void nfs_netfs_initiate_read (struct nfs_pgio_header *hdr);extern void nfs_netfs_read_completion (struct nfs_pgio_header *hdr);
include/linux/fscache.h +14 -8
@@ -172,9 +172,12 @@ extern void __fscache_invalidate(struct fscache_cookie *, const void *, loff_t,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 *); -extern void __fscache_write_to_cache (struct fscache_cookie *,struct address_space *, -loff_t ,size_t ,loff_t ,netfs_io_terminated_t ,void *, -bool ); +void __fscache_write_to_cache (struct fscache_cookie *cookie, +struct address_space *mapping, +loff_t start,size_t len,loff_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 );/**
@@ -597,7 +600,8 @@ static inline void fscache_clear_page_bits(struct address_space *mapping,* @i_size: The new size of the inode * @term_func: The function to call upon completion * @term_func_priv: The private data for @term_func -* @caching: If PG_fscache has been set +* @using_pgpriv2: If we're using PG_private_2 to mark in-progress write +* @caching: If we actually want to do the caching * * Helper function for a netfs to write dirty data from an inode into the cache * object that's backing it.
@@ -608,19 +612,21 @@ static inline void fscache_clear_page_bits(struct address_space *mapping,* marked with PG_fscache. * * If given, @term_func will be called upon completion and supplied with -* @term_func_priv. Note that the PG_fscache flags will have been cleared by -* this point, so the netfs must retain its own pin on the mapping. +* @term_func_priv. Note that if @using_pgpriv2 is set, the PG_private_2 flags +* will have been cleared by this point, so the netfs must retain its own pin +* on the 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,netfs_io_terminated_t term_func,void *term_func_priv, -bool caching) +bool using_pgpriv2,bool caching) {if (caching)__fscache_write_to_cache (cookie, mapping, start, len, i_size, - term_func, term_func_priv, caching); + term_func, term_func_priv, + using_pgpriv2, caching);else if (term_func)term_func (term_func_priv, -ENOBUFS , false);
include/linux/netfs.h +17 -3
@@ -143,6 +143,8 @@ struct netfs_inode {#define NETFS_ICTX_UNBUFFERED 1/* I/O should not use the pagecache */ #define NETFS_ICTX_WRITETHROUGH 2/* Write-through caching */ #define NETFS_ICTX_NO_WRITE_STREAMING 3/* Don't engage in write-streaming */ +#define NETFS_ICTX_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark +* write to cache on read */ };/*
@@ -165,16 +167,25 @@ struct netfs_folio {unsigned int dirty_len;/* Write-streaming dirty data length */ };#define NETFS_FOLIO_INFO 0x1UL/* OR'd with folio->private. */ +#define NETFS_FOLIO_COPY_TO_CACHE ((struct netfs_group *)0x356UL)/* Write to the cache only */ -static inline struct netfs_folio *netfs_folio_info (struct folio *folio) +static inline bool netfs_is_folio_info (const void *priv) { -void *priv =folio_get_private (folio); +return (unsigned long )priv &NETFS_FOLIO_INFO ; +} -if ((unsigned long )priv &NETFS_FOLIO_INFO ) +static inline struct netfs_folio *__netfs_folio_info (const void *priv) +{ +if (netfs_is_folio_info (priv))return (struct netfs_folio *)((unsigned long )priv & ~NETFS_FOLIO_INFO );return NULL ; } +static inline struct netfs_folio *netfs_folio_info (struct folio *folio) +{ +return __netfs_folio_info (folio_get_private (folio)); +} +static inline struct netfs_group *netfs_folio_group (struct folio *folio) {struct netfs_folio *finfo;
@@ -230,6 +241,7 @@ enum netfs_io_origin {NETFS_READAHEAD ,/* This read was triggered by readahead */ NETFS_READPAGE ,/* This read is a synchronous read */ NETFS_READ_FOR_WRITE ,/* This read is to prepare a write */ +NETFS_COPY_TO_CACHE ,/* This write is to copy a read to the cache */ NETFS_WRITEBACK ,/* This write was triggered by writepages */ NETFS_WRITETHROUGH ,/* This write was made by netfs_perform_write() */ NETFS_LAUNDER_WRITE, /* This is triggered by ->launder_folio() */
@@ -287,6 +299,8 @@ struct netfs_io_request {#define NETFS_RREQ_UPLOAD_TO_SERVER 8/* Need to write to the server */ #define NETFS_RREQ_NONBLOCK 9/* Don't block if possible (O_NONBLOCK) */ #define NETFS_RREQ_BLOCKED 10/* We blocked */ +#define NETFS_RREQ_USE_PGPRIV2 31/* [DEPRECATED] Use PG_private_2 to mark +* write to cache on read */ const struct netfs_request_ops *netfs_ops;void (*cleanup)(struct netfs_io_request *req); };
include/trace/events/netfs.h +5 -1
@@ -24,6 +24,7 @@ E_(netfs_read_trace_write_begin, "WRITEBEGN")#define netfs_write_traces \ + EM(netfs_write_trace_copy_to_cache, "COPY2CACH") \ EM(netfs_write_trace_dio_write, "DIO-WRITE") \ EM(netfs_write_trace_launder, "LAUNDER ") \ EM(netfs_write_trace_unbuffered_write, "UNB-WRITE") \
@@ -34,6 +35,7 @@ EM(NETFS_READAHEAD, "RA") \ EM(NETFS_READPAGE, "RP") \ EM(NETFS_READ_FOR_WRITE, "RW") \ + EM(NETFS_COPY_TO_CACHE, "CC") \ EM(NETFS_WRITEBACK, "WB") \ EM(NETFS_WRITETHROUGH, "WT") \EM (NETFS_LAUNDER_WRITE ,"LW" ) \
@@ -127,7 +129,9 @@ EM(netfs_folio_trace_clear, "clear") \ EM(netfs_folio_trace_clear_s, "clear-s") \ EM(netfs_folio_trace_clear_g, "clear-g") \ - EM(netfs_folio_trace_copy_to_cache, "copy") \ + EM(netfs_folio_trace_copy, "copy") \ + EM(netfs_folio_trace_copy_plus, "copy+") \ + EM(netfs_folio_trace_copy_to_cache, "mark-copy") \ EM(netfs_folio_trace_end_copy, "end-copy") \ EM(netfs_folio_trace_filled_gaps, "filled-gaps") \EM (netfs_folio_trace_kill,"kill" ) \
David Howells
maintainerPATCH v2 3/22 mm: Remove the PG_fscache alias for PG_private_2
In reply to David HowellsRemove the PG_fscache alias for PG_private_2 and use the latter directly. Use of this flag for marking pages undergoing writing to the cache should be considered deprecated and the folios should be marked dirty instead and the write done in ->writepages().
Note that PG_private_2 itself should be considered deprecated and up for future removal by the MM folks too.
--- fs/ceph/addr.c | 11 +++--- fs/netfs/buffered_read.c | 4 +- fs/netfs/fscache_io.c | 2 +- fs/netfs/io.c | 2 +- fs/nfs/file.c | 8 ++-- fs/nfs/fscache.h | 4 +- fs/nfs/write.c | 4 +- fs/smb/client/file.c | 16 ++++---- include/linux/netfs.h | 80 ++-------------------------------------- mm/filemap.c | 6 +-- 10 files changed, 33 insertions(+), 104 deletions(-)
fs/ceph/addr.c +6 -5
@@ -500,7 +500,7 @@ const struct netfs_request_ops ceph_netfs_ops = {#ifdef CONFIG_CEPH_FSCACHE static void ceph_set_page_fscache (struct page *page) { -set_page_fscache (page); +folio_start_private_2 (page_folio (page));/* [DEPRECATED] */ }static void ceph_fscache_write_terminated (void *priv,ssize_t error,bool was_async)
@@ -800,7 +800,7 @@ static int ceph_writepage(struct page *page, struct writeback_control *wbc)return AOP_WRITEPAGE_ACTIVATE ; } -wait_on_page_fscache (page); +folio_wait_private_2 (page_folio (page));/* [DEPRECATED] */ err =writepage_nounlock (page, wbc);if (err == -ERESTARTSYS ) {
@@ -1075,7 +1075,8 @@ static int ceph_writepages_start(struct address_space *mapping,unlock_page (page);break ; } -if (PageWriteback (page) ||PageFsCache (page)) { +if (PageWriteback (page) || +PagePrivate2 (page)/* [DEPRECATED] */ ) {if (wbc->sync_mode ==WB_SYNC_NONE ) {doutc (cl,"%p under writeback\n" , page);unlock_page (page);
@@ -1083,7 +1084,7 @@ static int ceph_writepages_start(struct address_space *mapping, }doutc (cl,"waiting on writeback %p\n" , page);wait_on_page_writeback (page); -wait_on_page_fscache (page); +folio_wait_private_2 (page_folio (page));/* [DEPRECATED] */ }if (!clear_page_dirty_for_io (page)) {
@@ -1513,7 +1514,7 @@ static int ceph_write_begin(struct file *file, struct address_space *mapping,if (r <0 )return r; -folio_wait_fscache (folio); +folio_wait_private_2 (folio);/* [DEPRECATED] */ WARN_ON_ONCE (!folio_test_locked (folio)); *pagep = &folio->page;return 0 ;
fs/netfs/buffered_read.c +2 -2
@@ -70,7 +70,7 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *rreq)if (!folio_started &&test_bit (NETFS_SREQ_COPY_TO_CACHE , &subreq->flags)) {trace_netfs_folio (folio, netfs_folio_trace_copy_to_cache); -folio_start_fscache (folio); +folio_start_private_2 (folio); folio_started = true; } }else {
@@ -506,7 +506,7 @@ int netfs_write_begin(struct netfs_inode *ctx, have_folio:if (test_bit (NETFS_ICTX_USE_PGPRIV2 , &ctx->flags)) { - ret =folio_wait_fscache_killable (folio); + ret =folio_wait_private_2_killable (folio);if (ret <0 ) goto error; }
fs/netfs/fscache_io.c +1 -1
@@ -183,7 +183,7 @@ void __fscache_clear_page_bits(struct address_space *mapping,rcu_read_lock ();xas_for_each (&xas, page, last) { -end_page_fscache (page); +folio_end_private_2 (page_folio (page)); }rcu_read_unlock (); }
fs/netfs/io.c +1 -1
@@ -129,7 +129,7 @@ static void netfs_rreq_unmark_after_write(struct netfs_io_request *rreq,continue ; unlocked =folio_next_index (folio) -1 ;trace_netfs_folio (folio, netfs_folio_trace_end_copy); -folio_end_fscache (folio); +folio_end_private_2 (folio); have_unlocked = true; } }
fs/nfs/file.c +4 -4
@@ -433,7 +433,7 @@ static void nfs_invalidate_folio(struct folio *folio, size_t offset,return ;/* Cancel any unstarted writes on this page */ nfs_wb_folio_cancel (inode, folio); -folio_wait_fscache (folio); +folio_wait_private_2 (folio);/* [DEPRECATED] */ trace_nfs_invalidate_folio (inode, folio); }
@@ -500,7 +500,7 @@ static int nfs_launder_folio(struct folio *folio)dfprintk (PAGECACHE ,"NFS: launder_folio(%ld, %llu)\n" , inode->i_ino,folio_pos (folio)); -folio_wait_fscache (folio); +folio_wait_private_2 (folio);/* [DEPRECATED] */ ret =nfs_wb_folio (inode, folio);trace_nfs_launder_folio_done (inode, folio, ret);return ret;
@@ -593,8 +593,8 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)sb_start_pagefault (inode->i_sb);/* make sure the cache has finished storing the page */ -if (folio_test_fscache (folio) && -folio_wait_fscache_killable (folio) <0 ) { +if (folio_test_private_2 (folio) &&/* [DEPRECATED] */ +folio_wait_private_2_killable (folio) <0 ) { ret =VM_FAULT_RETRY ; goto out; }
fs/nfs/fscache.h +2 -2
@@ -103,10 +103,10 @@ extern int nfs_netfs_read_folio(struct file *file, struct folio *folio);static inline bool nfs_fscache_release_folio (struct folio *folio,gfp_t gfp) { -if (folio_test_fscache (folio)) { +if (folio_test_private_2 (folio)) {/* [DEPRECATED] */ if (current_is_kswapd () || !(gfp & __GFP_FS))return false; -folio_wait_fscache (folio); +folio_wait_private_2 (folio); }fscache_note_page_release (netfs_i_cookie (netfs_inode (folio->mapping->host)));return true;
fs/nfs/write.c +2 -2
@@ -2120,10 +2120,10 @@ int nfs_migrate_folio(struct address_space *mapping, struct folio *dst,if (folio_test_private (src))return -EBUSY ; -if (folio_test_fscache (src)) { +if (folio_test_private_2 (src)) {/* [DEPRECATED] */ if (mode ==MIGRATE_ASYNC )return -EBUSY ; -folio_wait_fscache (src); +folio_wait_private_2 (src); }return migrate_folio (mapping, dst, src, mode);
fs/smb/client/file.c +8 -8
@@ -3032,12 +3032,12 @@ static ssize_t cifs_writepages_begin(struct address_space *mapping, }if (folio_test_writeback (folio) || -folio_test_fscache (folio)) { +folio_test_private_2 (folio)) {/* [DEPRECATED] */ folio_unlock (folio);if (wbc->sync_mode !=WB_SYNC_NONE ) {folio_wait_writeback (folio);#ifdef CONFIG_CIFS_FSCACHE -folio_wait_fscache (folio); +folio_wait_private_2 (folio);#endif goto lock_again; }
@@ -4510,8 +4510,8 @@ static vm_fault_t cifs_page_mkwrite(struct vm_fault *vmf)* be modified. We then assume the entire folio will need writing back. */ #ifdef CONFIG_CIFS_FSCACHE -if (folio_test_fscache (folio) && -folio_wait_fscache_killable (folio) <0 ) +if (folio_test_private_2 (folio) &&/* [DEPRECATED] */ +folio_wait_private_2_killable (folio) <0 )return VM_FAULT_RETRY ;#endif
@@ -4977,10 +4977,10 @@ static bool cifs_release_folio(struct folio *folio, gfp_t gfp) {if (folio_test_private (folio))return 0 ; -if (folio_test_fscache (folio)) { +if (folio_test_private_2 (folio)) {/* [DEPRECATED] */ if (current_is_kswapd () || !(gfp & __GFP_FS))return false; -folio_wait_fscache (folio); +folio_wait_private_2 (folio); }fscache_note_page_release (cifs_inode_cookie (folio->mapping->host));return true;
@@ -4989,7 +4989,7 @@ static bool cifs_release_folio(struct folio *folio, gfp_t gfp)static void cifs_invalidate_folio (struct folio *folio,size_t offset,size_t length) { -folio_wait_fscache (folio); +folio_wait_private_2 (folio);/* [DEPRECATED] */ }static int cifs_launder_folio (struct folio *folio)
@@ -5009,7 +5009,7 @@ static int cifs_launder_folio(struct folio *folio)if (folio_clear_dirty_for_io (folio)) rc =cifs_writepage_locked (&folio->page, &wbc); -folio_wait_fscache (folio); +folio_wait_private_2 (folio);/* [DEPRECATED] */ return rc; }
include/linux/netfs.h +4 -76
98 lines not on this page · raw message
mm/filemap.c +3 -3
@@ -1540,7 +1540,7 @@ EXPORT_SYMBOL(folio_end_private_2);* folio_wait_private_2 - Wait for PG_private_2 to be cleared on a folio. * @folio: The folio to wait on. * -* Wait for PG_private_2 (aka PG_fscache) to be cleared on a folio. +* Wait for PG_private_2 to be cleared on a folio. */ void folio_wait_private_2 (struct folio *folio) {
@@ -1553,8 +1553,8 @@ EXPORT_SYMBOL(folio_wait_private_2);* folio_wait_private_2_killable - Wait for PG_private_2 to be cleared on a folio. * @folio: The folio to wait on. * -* Wait for PG_private_2 (aka PG_fscache) to be cleared on a folio or until a -* fatal signal is received by the calling task. +* Wait for PG_private_2 to be cleared on a folio or until a fatal signal is +* received by the calling task. * * Return: * - 0 if successful.
David Howells
maintainerPATCH v2 4/22 netfs: Remove deprecated use of PG_private_2 as a second writeback flag
In reply to David HowellsRemove the deprecated use of PG_private_2 in netfslib.
--- fs/ceph/addr.c | 19 +----- fs/netfs/buffered_read.c | 8 +-- fs/netfs/io.c | 144 --------------------------------------- 3 files changed, 2 insertions(+), 169 deletions(-)
fs/ceph/addr.c +1 -18
@@ -498,11 +498,6 @@ const struct netfs_request_ops ceph_netfs_ops = { };#ifdef CONFIG_CEPH_FSCACHE -static void ceph_set_page_fscache (struct page *page) -{ -folio_start_private_2 (page_folio (page));/* [DEPRECATED] */ -} -static void ceph_fscache_write_terminated (void *priv,ssize_t error,bool was_async) {struct inode *inode = priv;
@@ -520,10 +515,6 @@ static void ceph_fscache_write_to_cache(struct inode *inode, u64 off, u64 len, b ceph_fscache_write_terminated, inode, true, caching); }#else -static inline void ceph_set_page_fscache (struct page *page) -{ -} -static inline void ceph_fscache_write_to_cache (struct inode *inode,u64 off,u64 len,bool caching) { }
@@ -715,8 +706,6 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) len = wlen;set_page_writeback (page); -if (caching) -ceph_set_page_fscache (page);ceph_fscache_write_to_cache (inode, page_off, len, caching);if (IS_ENCRYPTED (inode)) {
@@ -800,8 +789,6 @@ static int ceph_writepage(struct page *page, struct writeback_control *wbc)return AOP_WRITEPAGE_ACTIVATE ; } -folio_wait_private_2 (page_folio (page));/* [DEPRECATED] */ - err =writepage_nounlock (page, wbc);if (err == -ERESTARTSYS ) {/* direct memory reclaimer was killed by SIGKILL. return 0
@@ -1075,8 +1062,7 @@ static int ceph_writepages_start(struct address_space *mapping,unlock_page (page);break ; } -if (PageWriteback (page) || -PagePrivate2 (page)/* [DEPRECATED] */ ) { +if (PageWriteback (page)) {if (wbc->sync_mode ==WB_SYNC_NONE ) {doutc (cl,"%p under writeback\n" , page);unlock_page (page);
@@ -1084,7 +1070,6 @@ static int ceph_writepages_start(struct address_space *mapping, }doutc (cl,"waiting on writeback %p\n" , page);wait_on_page_writeback (page); -folio_wait_private_2 (page_folio (page));/* [DEPRECATED] */ }if (!clear_page_dirty_for_io (page)) {
@@ -1269,8 +1254,6 @@ static int ceph_writepages_start(struct address_space *mapping, }set_page_writeback (page); -if (caching) -ceph_set_page_fscache (page); len +=thp_size (page); }ceph_fscache_write_to_cache (inode, offset, len, caching);
fs/netfs/buffered_read.c +1 -7
@@ -464,7 +464,7 @@ int netfs_write_begin(struct netfs_inode *ctx,if (!netfs_is_cache_enabled (ctx) &&netfs_skip_folio_read (folio, pos, len, false)) {netfs_stat (&netfs_n_rh_write_zskip); - goto have_folio_no_wait; + goto have_folio; } rreq = netfs_alloc_request(mapping, file,
@@ -505,12 +505,6 @@ int netfs_write_begin(struct netfs_inode *ctx,netfs_put_request (rreq, false, netfs_rreq_trace_put_return); have_folio: -if (test_bit (NETFS_ICTX_USE_PGPRIV2 , &ctx->flags)) { - ret =folio_wait_private_2_killable (folio); -if (ret <0 ) - goto error; - } -have_folio_no_wait: *_folio = folio;_leave (" = 0" );return 0 ;
fs/netfs/io.c +0 -144
156 lines not on this page · raw message
David Howells
maintainerPATCH v2 5/22 netfs: Make netfs_io_request::subreq_counter an atomic_t
In reply to David HowellsMake the netfs_io_request::subreq_counter, used to generate values for netfs_io_subrequest::debug_index, into an atomic_t so that it can be called from the retry thread at the same time as the app thread issuing writes.
--- fs/netfs/output.c | 2 +- include/linux/netfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/netfs/output.c +1 -1
@@ -37,7 +37,7 @@ struct netfs_io_subrequest *netfs_create_write_request(struct netfs_io_request * subreq->source = dest; subreq->start = start; subreq->len = len; - subreq->debug_index = wreq->subreq_counter++; + subreq->debug_index =atomic_inc_return (&wreq->subreq_counter);switch (subreq->source) {case NETFS_UPLOAD_TO_SERVER :
include/linux/netfs.h +1 -1
@@ -202,7 +202,7 @@ struct netfs_io_request {unsigned int debug_id;unsigned int rsize;/* Maximum read size (0 for none) */ unsigned int wsize;/* Maximum write size (0 for none) */ -unsigned int subreq_counter;/* Next subreq->debug_index */ +atomic_t subreq_counter;/* Next subreq->debug_index */ atomic_t nr_outstanding;/* Number of ops in progress */ atomic_t nr_copy_ops;/* Number of copy-to-cache ops in progress */ size_t submitted;/* Amount submitted for I/O so far */
David Howells
maintainerPATCH v2 6/22 netfs: Use subreq_counter to allocate subreq debug_index values
In reply to David HowellsUse the subreq_counter in netfs_io_request to allocate subrequest debug_index values in read ops as well as write ops.
--- fs/netfs/io.c | 7 ++----- fs/netfs/objects.c | 1 + fs/netfs/output.c | 1 - 3 files changed, 3 insertions(+), 6 deletions(-)
fs/netfs/io.c +2 -5
@@ -501,8 +501,7 @@ netfs_rreq_prepare_read(struct netfs_io_request *rreq,* Slice off a piece of a read request and submit an I/O request for it. */ static bool netfs_rreq_submit_slice (struct netfs_io_request *rreq, -struct iov_iter *io_iter, -unsigned int *_debug_index) +struct iov_iter *io_iter) {struct netfs_io_subrequest *subreq;enum netfs_io_source source;
@@ -511,7 +510,6 @@ static bool netfs_rreq_submit_slice(struct netfs_io_request *rreq,if (!subreq)return false; - subreq->debug_index = (*_debug_index)++; subreq->start = rreq->start + rreq->submitted; subreq->len = io_iter->count;
@@ -565,7 +563,6 @@ static bool netfs_rreq_submit_slice(struct netfs_io_request *rreq,int netfs_begin_read (struct netfs_io_request *rreq,bool sync) {struct iov_iter io_iter; -unsigned int debug_index =0 ;int ret; _enter("R=%x %llx-%llx",
@@ -596,7 +593,7 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync)if (rreq->origin ==NETFS_DIO_READ && rreq->start + rreq->submitted >= rreq->i_size)break ; -if (!netfs_rreq_submit_slice (rreq, &io_iter, &debug_index)) +if (!netfs_rreq_submit_slice (rreq, &io_iter))break ;if (test_bit (NETFS_RREQ_BLOCKED , &rreq->flags) &&test_bit (NETFS_RREQ_NONBLOCK , &rreq->flags))
fs/netfs/objects.c +1 -0
@@ -152,6 +152,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreqINIT_LIST_HEAD (&subreq->rreq_link);refcount_set (&subreq->ref,2 ); subreq->rreq = rreq; + subreq->debug_index =atomic_inc_return (&rreq->subreq_counter);netfs_get_request (rreq, netfs_rreq_trace_get_subreq);netfs_stat (&netfs_n_rh_sreq); }
fs/netfs/output.c +0 -1
@@ -37,7 +37,6 @@ struct netfs_io_subrequest *netfs_create_write_request(struct netfs_io_request * subreq->source = dest; subreq->start = start; subreq->len = len; - subreq->debug_index =atomic_inc_return (&wreq->subreq_counter);switch (subreq->source) {case NETFS_UPLOAD_TO_SERVER :
David Howells
maintainerPATCH v2 7/22 mm: Provide a means of invalidation without using launder_folio
In reply to David HowellsImplement a replacement for launder_folio. The key feature of invalidate_inode_pages2() is that it locks each folio individually, unmaps it to prevent mmap'd accesses interfering and calls the ->launder_folio() address_space op to flush it. This has problems: firstly, each folio is written individually as one or more small writes; secondly, adjacent folios cannot be added so easily into the laundry; thirdly, it's yet another op to implement.
Instead, use the invalidate lock to cause anyone wanting to add a folio to the inode to wait, then unmap all the folios if we have mmaps, then, conditionally, use ->writepages() to flush any dirty data back and then discard all pages.
The invalidate lock prevents ->read_iter(), ->write_iter() and faulting through mmap all from adding pages for the duration.
This is then used from netfslib to handle the flusing in unbuffered and direct writes.
---
Notes:
Changes
=======
ver #2)
- Make filemap_invalidate_inode() take a range.
- Make netfs_unbuffered_write_iter() use filemap_invalidate_inode().
fs/netfs/direct_write.c | 28 ++++++++++++++++++--- include/linux/pagemap.h | 2 ++ mm/filemap.c | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-)
fs/netfs/direct_write.c +24 -4
@@ -132,12 +132,14 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iovssize_t netfs_unbuffered_write_iter (struct kiocb *iocb,struct iov_iter *from) {struct file *file = iocb->ki_filp; -struct inode *inode = file->f_mapping->host; +struct address_space *mapping = file->f_mapping; +struct inode *inode = mapping->host;struct netfs_inode *ictx =netfs_inode (inode); -unsigned long long end;ssize_t ret; +loff_t pos = iocb->ki_pos; +unsigned long long end = pos +iov_iter_count (from) -1 ; -_enter ("%llx,%zx,%llx" , iocb->ki_pos,iov_iter_count (from),i_size_read (inode)); +_enter ("%llx,%zx,%llx" , pos,iov_iter_count (from),i_size_read (inode));if (!iov_iter_count (from))return 0 ;
@@ -157,7 +159,25 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from) ret =file_update_time (file);if (ret <0 ) goto out; - ret =kiocb_invalidate_pages (iocb,iov_iter_count (from)); +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* We could block if there are any pages in the range. */ + ret = -EAGAIN ; +if (filemap_range_has_page (mapping, pos, end)) +if (filemap_invalidate_inode (inode, true, pos, end)) + goto out; + }else { + ret =filemap_write_and_wait_range (mapping, pos, end); +if (ret <0 ) + goto out; + } + +/* +* After a write we want buffered reads to be sure to go to disk to get +* the new data. We invalidate clean cached page from the region we're +* about to write. We do this *before* the write so that we can return +* without clobbering -EIOCBQUEUED from ->direct_IO(). +*/ + ret =filemap_invalidate_inode (inode, true, pos, end);if (ret <0 ) goto out; end = iocb->ki_pos +iov_iter_count (from);
include/linux/pagemap.h +2 -0
@@ -40,6 +40,8 @@ int filemap_fdatawait_keep_errors(struct address_space *mapping);int filemap_fdatawait_range (struct address_space *,loff_t lstart,loff_t lend);int filemap_fdatawait_range_keep_errors (struct address_space *mapping,loff_t start_byte,loff_t end_byte); +int filemap_invalidate_inode (struct inode *inode,bool flush, +loff_t start,loff_t end);static inline int filemap_fdatawait (struct address_space *mapping) {
mm/filemap.c +54 -0
60 lines not on this page · raw message
Re: [PATCH v2 07/22] mm: Provide a means of invalidation without using launder_folio
mm/filemap.c bool filemap_release_folio(struct folio *folio, gfp_t gfp) · line 4189
Quoted 4 lines
mm/filemap.c +3
-0+unmap_mapping_pages (mapping, first, nr, false); +} +EXPORT_SYMBOL (filemap_invalidate_inode);
unmap_mapping_pages is an EXPORT_SYMBOL_GPL, pleas keep that in this in thin wrapper.
David Howells
maintainerRe: [PATCH v2 07/22] mm: Provide a means of invalidation without using launder_folio
In reply to David HowellsReview
Quoted 4 lines · David Howells
(quoted diff) +3
-0+ .range_start = first, + .range_end = last, + truncate_inode_pages_range(mapping, first, last);
These actually take file offsets and not page ranges and so the attached change is needed. Without this, the generic/412 xfstest fails.
David
---
mm/filemap.c +3 -3
@@ -4171,15 +4171,15 @@ int filemap_invalidate_inode(struct inode *inode, bool flush,struct writeback_control wbc = { .sync_mode =WB_SYNC_ALL , .nr_to_write =LONG_MAX , - .range_start = first, - .range_end = last, + .range_start = start, + .range_end = end, };filemap_fdatawrite_wbc (mapping, &wbc); }/* Wait for writeback to complete on all folios and discard. */ -truncate_inode_pages_range (mapping, first, last); +truncate_inode_pages_range (mapping, start, end); unlock:filemap_invalidate_unlock (mapping);
David Howells
maintainerPATCH v2 8/22 9p: Use alternative invalidation to using launder_folio
In reply to David HowellsUse writepages-based flushing invalidation instead of invalidate_inode_pages2() and ->launder_folio(). This will allow ->launder_folio() to be removed eventually.
--- fs/9p/vfs_addr.c | 2 -- 1 file changed, 2 deletions(-)
fs/9p/vfs_addr.c +0 -2
@@ -89,7 +89,6 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)bool writing = (rreq->origin ==NETFS_READ_FOR_WRITE || rreq->origin ==NETFS_WRITEBACK || rreq->origin ==NETFS_WRITETHROUGH || - rreq->origin ==NETFS_LAUNDER_WRITE || rreq->origin ==NETFS_UNBUFFERED_WRITE || rreq->origin ==NETFS_DIO_WRITE );
@@ -141,7 +140,6 @@ const struct address_space_operations v9fs_addr_operations = { .dirty_folio = netfs_dirty_folio, .release_folio = netfs_release_folio, .invalidate_folio = netfs_invalidate_folio, - .launder_folio = netfs_launder_folio, .direct_IO = noop_direct_IO, .writepages = netfs_writepages, };
David Howells
maintainerPATCH v2 9/22 afs: Use alternative invalidation to using launder_folio
In reply to David HowellsUse writepages-based flushing invalidation instead of invalidate_inode_pages2() and ->launder_folio(). This will allow ->launder_folio() to be removed eventually.
--- fs/afs/file.c | 1 - fs/afs/internal.h | 1 - fs/afs/validation.c | 4 ++-- fs/afs/write.c | 10 +++------- 4 files changed, 5 insertions(+), 11 deletions(-)
fs/afs/file.c +0 -1
@@ -54,7 +54,6 @@ const struct address_space_operations afs_file_aops = { .read_folio = netfs_read_folio, .readahead = netfs_readahead, .dirty_folio = netfs_dirty_folio, - .launder_folio = netfs_launder_folio, .release_folio = netfs_release_folio, .invalidate_folio = netfs_invalidate_folio, .migrate_folio = filemap_migrate_folio,
fs/afs/internal.h +0 -1
@@ -916,7 +916,6 @@ struct afs_operation {loff_t pos;loff_t size;loff_t i_size; -bool laundering;/* Laundering page, PG_writeback not set */ } store;struct {struct iattr *attr;
fs/afs/validation.c +2 -2
@@ -365,9 +365,9 @@ static void afs_zap_data(struct afs_vnode *vnode)* written back in a regular file and completely discard the pages in a * directory or symlink */ if (S_ISREG (vnode->netfs.inode.i_mode)) -invalidate_remote_inode (&vnode->netfs.inode); +filemap_invalidate_inode (&vnode->netfs.inode, true,0 ,LLONG_MAX );else -invalidate_inode_pages2 (vnode->netfs.inode.i_mapping); +filemap_invalidate_inode (&vnode->netfs.inode, false,0 ,LLONG_MAX ); }/*
fs/afs/write.c +3 -7
@@ -75,8 +75,7 @@ static void afs_store_data_success(struct afs_operation *op) op->ctime = op->file[0 ].scb.status.mtime_client;afs_vnode_commit_status (op, &op->file[0 ]);if (!afs_op_error (op)) { -if (!op->store.laundering) -afs_pages_written_back (vnode, op->store.pos, op->store.size); +afs_pages_written_back (vnode, op->store.pos, op->store.size);afs_stat_v (vnode, n_stores);atomic_long_add (op->store.size, &afs_v2net (vnode)->n_store_bytes); }
@@ -91,8 +90,7 @@ static const struct afs_operation_ops afs_store_data_operation = {/* * write to a file */ -static int afs_store_data (struct afs_vnode *vnode,struct iov_iter *iter,loff_t pos, -bool laundering) +static int afs_store_data (struct afs_vnode *vnode,struct iov_iter *iter,loff_t pos) {struct afs_operation *op;struct afs_wb_key *wbk =NULL ;
@@ -123,7 +121,6 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_t op->file[0 ].modification = true; op->store.pos = pos; op->store.size = size; - op->store.laundering = laundering; op->flags |=AFS_OPERATION_UNINTR ; op->ops = &afs_store_data_operation;
@@ -168,8 +165,7 @@ static void afs_upload_to_server(struct netfs_io_subrequest *subreq) subreq->rreq->debug_id, subreq->debug_index, subreq->io_iter.count);trace_netfs_sreq (subreq, netfs_sreq_trace_submit); - ret =afs_store_data (vnode, &subreq->io_iter, subreq->start, - subreq->rreq->origin ==NETFS_LAUNDER_WRITE ); + ret =afs_store_data (vnode, &subreq->io_iter, subreq->start);netfs_write_subrequest_terminated (subreq, ret <0 ? ret : subreq->len, false); }
David Howells
maintainerPATCH v2 10/22 netfs: Remove ->launder_folio() support
In reply to David HowellsRemove support for ->launder_folio() from netfslib and expect filesystems to use filemap_invalidate_inode() instead. netfs_launder_folio() can then be got rid of.
--- fs/netfs/buffered_write.c | 74 ------------------------------------ fs/netfs/main.c | 1 - include/linux/netfs.h | 2 - include/trace/events/netfs.h | 3 -- 4 files changed, 80 deletions(-)
fs/netfs/buffered_write.c +0 -74
@@ -1200,77 +1200,3 @@ int netfs_writepages(struct address_space *mapping,return ret; }EXPORT_SYMBOL (netfs_writepages); - -/* -* Deal with the disposition of a laundered folio. -*/ -static void netfs_cleanup_launder_folio (struct netfs_io_request *wreq) -{ -if (wreq->error) { -pr_notice ("R=%08x Laundering error %d\n" , wreq->debug_id, wreq->error); -mapping_set_error (wreq->mapping, wreq->error); - } -} - -/** -* netfs_launder_folio - Clean up a dirty folio that's being invalidated -* @folio: The folio to clean -* -* This is called to write back a folio that's being invalidated when an inode -* is getting torn down. Ideally, writepages would be used instead. -*/ -int netfs_launder_folio (struct folio *folio) -{ -struct netfs_io_request *wreq; -struct address_space *mapping = folio->mapping; -struct netfs_folio *finfo =netfs_folio_info (folio); -struct netfs_group *group =netfs_folio_group (folio); -struct bio_vec bvec; -unsigned long long i_size =i_size_read (mapping->host); -unsigned long long start =folio_pos (folio); -size_t offset =0 , len; -int ret =0 ; - -if (finfo) { - offset = finfo->dirty_offset; - start += offset; - len = finfo->dirty_len; - }else { - len =folio_size (folio); - } - len = min_t(unsigned long long, len, i_size - start); - - wreq =netfs_alloc_request (mapping,NULL , start, len,NETFS_LAUNDER_WRITE ); -if (IS_ERR (wreq)) { - ret =PTR_ERR (wreq); - goto out; - } - -if (!folio_clear_dirty_for_io (folio)) - goto out_put; - -trace_netfs_folio (folio, netfs_folio_trace_launder); - -_debug ("launder %llx-%llx" , start, start + len -1 ); - -/* Speculatively write to the cache. We have to fix this up later if -* the store fails. -*/ - wreq->cleanup = netfs_cleanup_launder_folio; - -bvec_set_folio (&bvec, folio, len, offset); -iov_iter_bvec (&wreq->iter,ITER_SOURCE , &bvec,1 , len); -if (group !=NETFS_FOLIO_COPY_TO_CACHE ) -__set_bit (NETFS_RREQ_UPLOAD_TO_SERVER , &wreq->flags); - ret =netfs_begin_write (wreq, true, netfs_write_trace_launder); - -out_put: -folio_detach_private (folio); -netfs_put_group (group); -kfree (finfo); -netfs_put_request (wreq, false, netfs_rreq_trace_put_return); -out: -_leave (" = %d" , ret); -return ret; -} -EXPORT_SYMBOL (netfs_launder_folio);
fs/netfs/main.c +0 -1
@@ -34,7 +34,6 @@ static const char *netfs_origins[nr__netfs_io_origin] = { [NETFS_COPY_TO_CACHE] = "CC", [NETFS_WRITEBACK] = "WB", [NETFS_WRITETHROUGH] = "WT", - [NETFS_LAUNDER_WRITE] = "LW", [NETFS_UNBUFFERED_WRITE] = "UW", [NETFS_DIO_READ] = "DR", [NETFS_DIO_WRITE] = "DW",
include/linux/netfs.h +0 -2
@@ -172,7 +172,6 @@ enum netfs_io_origin {NETFS_COPY_TO_CACHE ,/* This write is to copy a read to the cache */ NETFS_WRITEBACK ,/* This write was triggered by writepages */ NETFS_WRITETHROUGH ,/* This write was made by netfs_perform_write() */ -NETFS_LAUNDER_WRITE ,/* This is triggered by ->launder_folio() */ NETFS_UNBUFFERED_WRITE ,/* This is an unbuffered write */ NETFS_DIO_READ ,/* This is a direct I/O read */ NETFS_DIO_WRITE, /* This is a direct I/O write */
@@ -352,7 +351,6 @@ int netfs_unpin_writeback(struct inode *inode, struct writeback_control *wbc);void netfs_clear_inode_writeback (struct inode *inode,const void *aux);void netfs_invalidate_folio (struct folio *folio,size_t offset,size_t length);bool netfs_release_folio (struct folio *folio,gfp_t gfp); -int netfs_launder_folio (struct folio *folio);/* VMA operations API. */ vm_fault_t netfs_page_mkwrite (struct vm_fault *vmf,struct netfs_group *netfs_group);
include/trace/events/netfs.h +0 -3
@@ -26,7 +26,6 @@#define netfs_write_traces \ EM(netfs_write_trace_copy_to_cache, "COPY2CACH") \ EM(netfs_write_trace_dio_write, "DIO-WRITE") \ - EM(netfs_write_trace_launder, "LAUNDER ") \ EM(netfs_write_trace_unbuffered_write, "UNB-WRITE") \ EM(netfs_write_trace_writeback, "WRITEBACK") \ E_(netfs_write_trace_writethrough, "WRITETHRU")
@@ -38,7 +37,6 @@ EM(NETFS_COPY_TO_CACHE, "CC") \ EM(NETFS_WRITEBACK, "WB") \ EM(NETFS_WRITETHROUGH, "WT") \ - EM(NETFS_LAUNDER_WRITE, "LW") \ EM(NETFS_UNBUFFERED_WRITE, "UW") \ EM(NETFS_DIO_READ, "DR") \E_ (NETFS_DIO_WRITE ,"DW" )
@@ -135,7 +133,6 @@ EM(netfs_folio_trace_end_copy, "end-copy") \ EM(netfs_folio_trace_filled_gaps, "filled-gaps") \ EM(netfs_folio_trace_kill, "kill") \ - EM(netfs_folio_trace_launder, "launder") \ EM(netfs_folio_trace_mkwrite, "mkwrite") \ EM(netfs_folio_trace_mkwrite_plus, "mkwrite+") \EM (netfs_folio_trace_read_gaps,"read-gaps" ) \
David Howells
maintainerPATCH v2 11/22 netfs: Use mempools for allocating requests and subrequests
In reply to David HowellsUse mempools for allocating requests and subrequests in an effort to make sure that allocation always succeeds so that when performing writeback we can always make progress.
--- fs/netfs/internal.h | 2 ++ fs/netfs/main.c | 51 ++++++++++++++++++++++++++++++++----- fs/netfs/objects.c | 59 ++++++++++++++++++++++++++++--------------- include/linux/netfs.h | 5 ++-- 4 files changed, 89 insertions(+), 28 deletions(-)
fs/netfs/internal.h +2 -0
@@ -37,6 +37,8 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync);extern unsigned int netfs_debug;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;#ifdef CONFIG_PROC_FS static inline void netfs_proc_add_rreq (struct netfs_io_request *rreq)
fs/netfs/main.c +45 -6
87 lines not on this page · raw message
fs/netfs/objects.c +39 -20
110 lines not on this page · raw message
include/linux/netfs.h +3 -2
@@ -20,6 +20,7 @@#include <linux/uio.h> enum netfs_sreq_ref_trace ; +typedef struct mempool_s mempool_t ;/** * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED]
@@ -236,8 +237,8 @@ struct netfs_io_request {* Operations the network filesystem can/must provide to the helpers. */ struct netfs_request_ops { -unsigned int io_request_size;/* Alloc size for netfs_io_request struct */ -unsigned int io_subrequest_size;/* Alloc size for netfs_io_subrequest struct */ +mempool_t *request_pool; +mempool_t *subrequest_pool;int (*init_request)(struct netfs_io_request *rreq,struct file *file);void (*free_request)(struct netfs_io_request *rreq);void (*free_subrequest)(struct netfs_io_subrequest *rreq);
David Howells
maintainerPATCH v2 12/22 mm: Export writeback_iter()
In reply to David HowellsExport writeback_iter() so that it can be used by netfslib as a module.
---
Notes:
Changes
=======
ver #2)
- Mark the symbol _GPL.mm/page-writeback.c | 1 + 1 file changed, 1 insertion(+)
mm/page-writeback.c +1 -0
@@ -2546,6 +2546,7 @@ struct folio *writeback_iter(struct address_space *mapping,folio_batch_release (&wbc->fbatch);return NULL ; } +EXPORT_SYMBOL_GPL (writeback_iter);/** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them.
David Howells
maintainerPATCH v2 13/22 netfs: Switch to using unsigned long long rather than loff_t
In reply to David HowellsSwitch to using unsigned long long rather than loff_t in netfslib to avoid problems with the sign flipping in the maths when we're dealing with the byte at position 0x7fffffffffffffff.
--- fs/cachefiles/io.c | 2 +- fs/ceph/addr.c | 2 +- fs/netfs/buffered_read.c | 4 +++- fs/netfs/buffered_write.c | 2 +- fs/netfs/io.c | 6 +++--- fs/netfs/main.c | 2 +- fs/netfs/output.c | 4 ++-- include/linux/netfs.h | 16 +++++++++------- include/trace/events/netfs.h | 6 +++--- 9 files changed, 24 insertions(+), 20 deletions(-)
fs/cachefiles/io.c +1 -1
@@ -493,7 +493,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, -loff_t i_size) +unsigned long long i_size) { return cachefiles_do_prepare_read(&subreq->rreq->cache_resources, subreq->start, &subreq->len, i_size,
fs/ceph/addr.c +1 -1
@@ -193,7 +193,7 @@ static void ceph_netfs_expand_readahead(struct netfs_io_request *rreq)* block, but do not exceed the file size, unless the original * request already exceeds it. */ - new_end =min (round_up (end, lo->stripe_unit), rreq->i_size); + new_end =umin (round_up (end, lo->stripe_unit), rreq->i_size);if (new_end > end && new_end <= rreq->start + max_len) rreq->len = new_end - rreq->start;
fs/netfs/buffered_read.c +3 -1
@@ -130,7 +130,9 @@ void netfs_rreq_unlock_folios(struct netfs_io_request *rreq) }static void netfs_cache_expand_readahead (struct netfs_io_request *rreq, -loff_t *_start,size_t *_len,loff_t i_size) +unsigned long long *_start, +unsigned long long *_len, +unsigned long long i_size) {struct netfs_cache_resources *cres = &rreq->cache_resources;
fs/netfs/buffered_write.c +1 -1
@@ -664,7 +664,7 @@ static void netfs_pages_written_back(struct netfs_io_request *wreq) last = (wreq->start + wreq->len -1 ) /PAGE_SIZE ;xas_for_each (&xas, folio, last) {WARN (!folio_test_writeback (folio), -"bad %zx @%llx page %lx %lx\n" , +"bad %llx @%llx page %lx %lx\n" , wreq->len, wreq->start, folio->index, last);if ((finfo =netfs_folio_info (folio))) {
fs/netfs/io.c +3 -3
@@ -476,7 +476,7 @@ netfs_rreq_prepare_read(struct netfs_io_request *rreq, set:if (subreq->len > rreq->len) -pr_warn ("R=%08x[%u] SREQ>RREQ %zx > %zx\n" , +pr_warn ("R=%08x[%u] SREQ>RREQ %zx > %llx\n" , rreq->debug_id, subreq->debug_index, subreq->len, rreq->len);
@@ -513,7 +513,7 @@ static bool netfs_rreq_submit_slice(struct netfs_io_request *rreq, subreq->start = rreq->start + rreq->submitted; subreq->len = io_iter->count; -_debug ("slice %llx,%zx,%zx" , subreq->start, subreq->len, rreq->submitted); +_debug ("slice %llx,%zx,%llx" , subreq->start, subreq->len, rreq->submitted);list_add_tail (&subreq->rreq_link, &rreq->subrequests);/* Call out to the cache to find out what it can do with the remaining
@@ -588,7 +588,7 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync)atomic_set (&rreq->nr_outstanding,1 ); io_iter = rreq->io_iter; do { - _debug("submit %llx + %zx >= %llx", + _debug("submit %llx + %llx >= %llx", rreq->start, rreq->submitted, rreq->i_size); if (rreq->origin == NETFS_DIO_READ && rreq->start + rreq->submitted >= rreq->i_size)
fs/netfs/main.c +1 -1
@@ -62,7 +62,7 @@ static int netfs_requests_seq_show(struct seq_file *m, void *v) rreq = list_entry(v, struct netfs_io_request, proc_link); seq_printf(m, - "%08x %s %3d %2lx %4d %3d @%04llx %zx/%zx", + "%08x %s %3d %2lx %4d %3d @%04llx %llx/%llx", rreq->debug_id, netfs_origins[rreq->origin], refcount_read(&rreq->ref),
fs/netfs/output.c +2 -2
@@ -439,7 +439,7 @@ static void netfs_submit_writethrough(struct netfs_io_request *wreq, bool final)*/ int netfs_advance_writethrough (struct netfs_io_request *wreq,size_t copied,bool to_page_end) { -_enter ("ic=%zu sb=%zu ws=%u cp=%zu tp=%u" , +_enter ("ic=%zu sb=%llu ws=%u cp=%zu tp=%u" , wreq->iter.count, wreq->submitted, wreq->wsize, copied, to_page_end); wreq->iter.count += copied;
@@ -457,7 +457,7 @@ int netfs_end_writethrough(struct netfs_io_request *wreq, struct kiocb *iocb) {int ret = -EIOCBQUEUED ; -_enter ("ic=%zu sb=%zu ws=%u" , +_enter ("ic=%zu sb=%llu ws=%u" , wreq->iter.count, wreq->submitted, wreq->wsize);if (wreq->submitted < wreq->io_iter.count)
include/linux/netfs.h +9 -7
@@ -149,7 +149,7 @@ struct netfs_io_subrequest {struct work_struct work;struct list_head rreq_link;/* Link in rreq->subrequests */ struct iov_iter io_iter;/* Iterator for this subrequest */ -loff_t start;/* Where to start the I/O */ +unsigned long long start;/* Where to start the I/O */ size_t len;/* Size of the I/O */ size_t transferred;/* Amount of data transferred */ refcount_t ref;
@@ -205,15 +205,15 @@ struct netfs_io_request {atomic_t subreq_counter;/* Next subreq->debug_index */ atomic_t nr_outstanding;/* Number of ops in progress */ atomic_t nr_copy_ops;/* Number of copy-to-cache ops in progress */ -size_t submitted;/* Amount submitted for I/O so far */ -size_t len;/* Length of the request */ size_t upper_len;/* Length can be extended to here */ +unsigned long long submitted;/* Amount submitted for I/O so far */ +unsigned long long len;/* Length of the request */ size_t transferred;/* Amount to be indicated as transferred */ short error;/* 0 or error that occurred */ enum netfs_io_origin origin;/* Origin of the request */ bool direct_bv_unpin;/* T if direct_bv[] must be unpinned */ -loff_t i_size;/* Size of the file */ -loff_t start;/* Start position */ +unsigned long long i_size;/* Size of the file */ +unsigned long long start;/* Start position */ pgoff_t no_unlock_folio;/* Don't unlock this folio after read */ refcount_t ref;unsigned long flags;
@@ -294,13 +294,15 @@ struct netfs_cache_ops {/* Expand readahead request */ void (*expand_readahead)(struct netfs_cache_resources *cres, -loff_t *_start,size_t *_len,loff_t i_size); +unsigned long long *_start, +unsigned long long *_len, +unsigned long long i_size);/* Prepare a read operation, shortening it to a cached/uncached * boundary as appropriate. */ enum netfs_io_source (*prepare_read)(struct netfs_io_subrequest *subreq, -loff_t i_size); +unsigned long long i_size);/* Prepare a write operation, working out what part of the write we can * actually do.
include/trace/events/netfs.h +3 -3
@@ -280,7 +280,7 @@ TRACE_EVENT(netfs_sreq, __entry->start = sreq->start; ), - TP_printk("R=%08x[%u] %s %s f=%02x s=%llx %zx/%zx e=%d", + TP_printk("R=%08x[%x] %s %s f=%02x s=%llx %zx/%zx e=%d", __entry->rreq, __entry->index, __print_symbolic(__entry->source, netfs_sreq_sources), __print_symbolic(__entry->what, netfs_sreq_traces),
@@ -320,7 +320,7 @@ TRACE_EVENT(netfs_failure, __entry->start = sreq ? sreq->start :0 ; ), - TP_printk("R=%08x[%d] %s f=%02x s=%llx %zx/%zx %s e=%d", + TP_printk("R=%08x[%x] %s f=%02x s=%llx %zx/%zx %s e=%d", __entry->rreq, __entry->index, __print_symbolic(__entry->source, netfs_sreq_sources), __entry->flags,
@@ -436,7 +436,7 @@ TRACE_EVENT(netfs_write, __field(unsigned int, cookie ) __field(enum netfs_write_trace, what ) __field(unsigned long long, start ) -__field (size_t , len ) +__field (unsigned long long , len ) ), TP_fast_assign(
David Howells
maintainerPATCH v2 14/22 netfs: New writeback implementation
In reply to David HowellsThe current netfslib writeback implementation creates writeback requests of contiguous folio data and then separately tiles subrequests over the space twice, once for the server and once for the cache. This creates a few issues:
(1) Every time there's a discontiguity or a change between writing to only one destination or writing to both, it must create a new request. This makes it harder to do vectored writes.
(2) The folios don't have the writeback mark removed until the end of the request - and a request could be hundreds of megabytes.
(3) In future, I want to support a larger cache granularity, which will require aggregation of some folios that contain unmodified data (which only need to go to the cache) and some which contain modifications (which need to be uploaded and stored to the cache) - but, currently, these are treated as discontiguous.
There's also a move to get everyone to use writeback_iter() to extract writable folios from the pagecache. That said, currently writeback_iter() has some issues that make it less than ideal:
(1) there's no way to cancel the iteration, even if you find a "temporary" error that means the current folio and all subsequent folios are going to fail;
(2) there's no way to filter the folios being written back - something
that will impact Ceph with it's ordered snap system;
(3) and if you get a folio you can't immediately deal with (say you need to flush the preceding writes), you are left with a folio hanging in the locked state for the duration, when really we should unlock it and relock it later.
In this new implementation, I use writeback_iter() to pump folios, progressively creating two parallel, but separate streams and cleaning up the finished folios as the subrequests complete. Either or both streams can contain gaps, and the subrequests in each stream can be of variable size, don't need to align with each other and don't need to align with the folios.
Indeed, subrequests can cross folio boundaries, may cover several folios or a folio may be spanned by multiple folios, e.g.:
+---+---+-----+-----+---+----------+
Folios: | | | | | | |
+---+---+-----+-----+---+----------+ +------+------+ +----+----+
Upload: | | |.....| | |
+------+------+ +----+----+ +------+------+------+------+------+
Cache: | | | | | |
+------+------+------+------+------+The progressive subrequest construction permits the algorithm to be preparing both the next upload to the server and the next write to the cache whilst the previous ones are already in progress. Throttling can be applied to control the rate of production of subrequests - and, in any case, we probably want to write them to the server in ascending order, particularly if the file will be extended.
Content crypto can also be prepared at the same time as the subrequests and run asynchronously, with the prepped requests being stalled until the crypto catches up with them. This might also be useful for transport crypto, but that happens at a lower layer, so probably would be harder to pull off.
The algorithm is split into three parts:
(1) The issuer. This walks through the data, packaging it up, encrypting it and creating subrequests. The part of this that generates subrequests only deals with file positions and spans and so is usable for DIO/unbuffered writes as well as buffered writes.
(2) The collector. This asynchronously collects completed subrequests, unlocks folios, frees crypto buffers and performs any retries. This runs in a work queue so that the issuer can return to the caller for writeback (so that the VM can have its kswapd thread back) or async writes.
(3) The retryer. This pauses the issuer, waits for all outstanding subrequests to complete and then goes through the failed subrequests to reissue them. This may involve reprepping them (with cifs, the credits must be renegotiated, and a subrequest may need splitting), and doing RMW for content crypto if there's a conflicting change on the server.
[!] Note that some of the functions are prefixed with "new_" to avoid clashes with existing functions. These will be renamed in a later patch that cuts over to the new algorithm.
---
Notes:
Changes
=======
ver #2)
- Make netfs_begin_writethrough() actually return an error.
- Remove a couple of redundant checks where the second used to be inside a lock.
fs/netfs/Makefile | 4 +- fs/netfs/buffered_write.c | 4 - fs/netfs/internal.h | 27 ++ fs/netfs/objects.c | 17 + fs/netfs/write_collect.c | 803 +++++++++++++++++++++++++++++++++++ fs/netfs/write_issue.c | 674 +++++++++++++++++++++++++++++ include/linux/netfs.h | 68 ++- include/trace/events/netfs.h | 232 +++++++++- 8 files changed, 1820 insertions(+), 9 deletions(-) create mode 100644 fs/netfs/write_collect.c create mode 100644 fs/netfs/write_issue.c
fs/netfs/Makefile +3 -1
@@ -11,7 +11,9 @@ netfs-y := \ main.o \ misc.o \ objects.o \ - output.o + output.o \ + write_collect.o \ + write_issue.o netfs-$(CONFIG_NETFS_STATS) += stats.o
fs/netfs/buffered_write.c +0 -4
@@ -74,16 +74,12 @@ static enum netfs_how_to_modify netfs_how_to_modify(struct netfs_inode *ctx,if (file->f_mode &FMODE_READ ) goto no_write_streaming; -if (test_bit (NETFS_ICTX_NO_WRITE_STREAMING , &ctx->flags)) - goto no_write_streaming;if (netfs_is_cache_enabled (ctx)) {/* We don't want to get a streaming write on a file that loses * caching service temporarily because the backing store got * culled. */ -if (!test_bit (NETFS_ICTX_NO_WRITE_STREAMING , &ctx->flags)) -set_bit (NETFS_ICTX_NO_WRITE_STREAMING , &ctx->flags); goto no_write_streaming; }
fs/netfs/internal.h +27 -0
@@ -150,6 +150,33 @@ static inline void netfs_stat_d(atomic_t *stat)#define netfs_stat_d (x) do {} while(0)#endif +/* +* write_collect.c +*/ +int netfs_folio_written_back (struct folio *folio); +void netfs_write_collection_worker (struct work_struct *work); +void netfs_wake_write_collector (struct netfs_io_request *wreq,bool was_async); + +/* +* write_issue.c +*/ +struct netfs_io_request *netfs_create_write_req (struct address_space *mapping, +struct file *file, +loff_t start, +enum netfs_io_origin origin); +void netfs_reissue_write (struct netfs_io_stream *stream, +struct netfs_io_subrequest *subreq); +int netfs_advance_write (struct netfs_io_request *wreq, +struct netfs_io_stream *stream, +loff_t start,size_t len,bool to_eof); +struct netfs_io_request *new_netfs_begin_writethrough (struct kiocb *iocb,size_t len); +int new_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); +int new_netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, +struct folio *writethrough_cache); +int netfs_unbuffered_write (struct netfs_io_request *wreq,bool may_wait,size_t len); +/* * Miscellaneous functions. */
fs/netfs/objects.c +17 -0
@@ -47,6 +47,10 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, rreq->inode = inode; rreq->i_size =i_size_read (inode); rreq->debug_id =atomic_inc_return (&debug_ids); + rreq->wsize =INT_MAX ; +spin_lock_init (&rreq->lock); +INIT_LIST_HEAD (&rreq->io_streams[0 ].subrequests); +INIT_LIST_HEAD (&rreq->io_streams[1 ].subrequests);INIT_LIST_HEAD (&rreq->subrequests);INIT_WORK (&rreq->work,NULL );refcount_set (&rreq->ref,1 );
@@ -85,6 +89,8 @@ void netfs_get_request(struct netfs_io_request *rreq, enum netfs_rreq_ref_tracevoid netfs_clear_subrequests (struct netfs_io_request *rreq,bool was_async) {struct netfs_io_subrequest *subreq; +struct netfs_io_stream *stream; +int s;while (!list_empty (&rreq->subrequests)) { subreq = list_first_entry(&rreq->subrequests,
@@ -93,6 +99,17 @@ void netfs_clear_subrequests(struct netfs_io_request *rreq, bool was_async)netfs_put_subrequest (subreq, was_async, netfs_sreq_trace_put_clear); } + +for (s =0 ; s <ARRAY_SIZE (rreq->io_streams); s++) { + stream = &rreq->io_streams[s]; +while (!list_empty (&stream->subrequests)) { + subreq =list_first_entry (&stream->subrequests, + struct netfs_io_subrequest, rreq_link); +list_del (&subreq->rreq_link); +netfs_put_subrequest (subreq, was_async, + netfs_sreq_trace_put_clear); + } + } }static void netfs_free_request_rcu (struct rcu_head *rcu)
fs/netfs/write_collect.c new file +803 -0
803 lines not on this page · raw message
fs/netfs/write_issue.c new file +674 -0
674 lines not on this page · raw message
include/linux/netfs.h +67 -1
167 lines not on this page · raw message
include/trace/events/netfs.h +229 -3
352 lines not on this page · raw message
David Howells
maintainerRe: [PATCH v2 14/22] netfs: New writeback implementation
This needs the attached change. It needs to allow for netfs_perform_write() changing i_size whilst we're doing writeback. The issue is that i_size is cached in the netfs_io_request struct (as that's what we're going to tell the server the new i_size should be), but we're not updating this properly if i_size moves between us creating the request and us deciding to write out the folio in which i_size was when we created the request.
This can lead to the folio_zero_segment() that can be seen in the patch below clearing the wrong amount of the final page - assuming it's still the final page.
David
---
fs/netfs/write_issue.c +16 -7
@@ -315,13 +315,19 @@ static int netfs_write_folio(struct netfs_io_request *wreq,struct netfs_group *fgroup;/* TODO: Use this with ceph */ struct netfs_folio *finfo;size_t fsize =folio_size (folio), flen = fsize, foff =0 ; -loff_t fpos =folio_pos (folio); +loff_t fpos =folio_pos (folio), i_size;bool to_eof = false, streamw = false;bool debug = false;_enter ("" ); -if (fpos >= wreq->i_size) { +/* netfs_perform_write() may shift i_size around the page or from out +* of the page to beyond it, but cannot move i_size into or through the +* page since we have it locked. +*/ + i_size =i_size_read (wreq->inode); + +if (fpos >= i_size) {/* mmap beyond eof. */ _debug ("beyond eof" );folio_start_writeback (folio);
@@ -332,6 +338,9 @@ static int netfs_write_folio(struct netfs_io_request *wreq,return 0 ; } +if (fpos + fsize > wreq->i_size) + wreq->i_size = i_size; + fgroup =netfs_folio_group (folio); finfo =netfs_folio_info (folio);if (finfo) {
@@ -342,14 +351,14 @@ static int netfs_write_folio(struct netfs_io_request *wreq,if (wreq->origin ==NETFS_WRITETHROUGH ) { to_eof = false; -if (flen > wreq->i_size - fpos) - flen = wreq->i_size - fpos; - }else if (flen > wreq->i_size - fpos) { - flen = wreq->i_size - fpos; +if (flen > i_size - fpos) + flen = i_size - fpos; + }else if (flen > i_size - fpos) { + flen = i_size - fpos;if (!streamw)folio_zero_segment (folio, flen, fsize); to_eof = true; - }else if (flen == wreq->i_size - fpos) { + }else if (flen == i_size - fpos) { to_eof = true; } flen -= foff;
David Howells
maintainerPATCH v2 15/22 netfs: Add some write-side stats and clean up some stat names
In reply to David HowellsAdd some write-side stats to count buffered writes, buffered writethrough, and writepages calls.
Whilst we're at it, clean up the naming on some of the existing stats counters and organise the output into two sets.
--- fs/netfs/buffered_read.c | 2 +- fs/netfs/buffered_write.c | 3 +++ fs/netfs/direct_write.c | 2 +- fs/netfs/internal.h | 7 +++++-- fs/netfs/stats.c | 17 ++++++++++++----- fs/netfs/write_issue.c | 1 + 6 files changed, 23 insertions(+), 9 deletions(-)
fs/netfs/buffered_read.c +1 -1
@@ -282,7 +282,7 @@ int netfs_read_folio(struct file *file, struct folio *folio)if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) goto discard; -netfs_stat (&netfs_n_rh_readpage); +netfs_stat (&netfs_n_rh_read_folio);trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage);/* Set up the output buffer */
fs/netfs/buffered_write.c +3 -0
@@ -210,6 +210,9 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,if (!is_sync_kiocb (iocb)) wreq->iocb = iocb; wreq->cleanup = netfs_cleanup_buffered_write; +netfs_stat (&netfs_n_wh_writethrough); + }else { +netfs_stat (&netfs_n_wh_buffered_write); } do {
fs/netfs/direct_write.c +1 -1
@@ -145,7 +145,7 @@ ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from)return 0 ;trace_netfs_write_iter (iocb, from); -netfs_stat (&netfs_n_rh_dio_write); +netfs_stat (&netfs_n_wh_dio_write); ret =netfs_start_io_direct (inode);if (ret <0 )
fs/netfs/internal.h +5 -2
@@ -106,9 +106,8 @@ int netfs_end_writethrough(struct netfs_io_request *wreq, struct kiocb *iocb);*/ #ifdef CONFIG_NETFS_STATS extern atomic_t netfs_n_rh_dio_read; -extern atomic_t netfs_n_rh_dio_write;extern atomic_t netfs_n_rh_readahead; -extern atomic_t netfs_n_rh_readpage; +extern atomic_t netfs_n_rh_read_folio;extern atomic_t netfs_n_rh_rreq;extern atomic_t netfs_n_rh_sreq;extern atomic_t netfs_n_rh_download;
@@ -125,6 +124,10 @@ extern atomic_t netfs_n_rh_write_begin;extern atomic_t netfs_n_rh_write_done;extern atomic_t netfs_n_rh_write_failed;extern atomic_t netfs_n_rh_write_zskip; +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_wstream_conflict;extern atomic_t netfs_n_wh_upload;extern atomic_t netfs_n_wh_upload_done;
fs/netfs/stats.c +12 -5
@@ -10,9 +10,8 @@#include "internal.h" atomic_t netfs_n_rh_dio_read; -atomic_t netfs_n_rh_dio_write;atomic_t netfs_n_rh_readahead; -atomic_t netfs_n_rh_readpage; +atomic_t netfs_n_rh_read_folio;atomic_t netfs_n_rh_rreq;atomic_t netfs_n_rh_sreq;atomic_t netfs_n_rh_download;
@@ -29,6 +28,10 @@ atomic_t netfs_n_rh_write_begin;atomic_t netfs_n_rh_write_done;atomic_t netfs_n_rh_write_failed;atomic_t netfs_n_rh_write_zskip; +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_wstream_conflict;atomic_t netfs_n_wh_upload;atomic_t netfs_n_wh_upload_done;
@@ -39,13 +42,17 @@ atomic_t netfs_n_wh_write_failed;int netfs_stats_show (struct seq_file *m,void *v) { -seq_printf (m,"Netfs : DR=%u DW=%u RA=%u RP=%u WB=%u WBZ=%u\n" , +seq_printf (m,"Netfs : DR=%u RA=%u RF=%u WB=%u WBZ=%u\n" ,atomic_read (&netfs_n_rh_dio_read), -atomic_read (&netfs_n_rh_dio_write),atomic_read (&netfs_n_rh_readahead), -atomic_read (&netfs_n_rh_readpage), +atomic_read (&netfs_n_rh_read_folio),atomic_read (&netfs_n_rh_write_begin),atomic_read (&netfs_n_rh_write_zskip)); +seq_printf (m,"Netfs : BW=%u WT=%u DW=%u WP=%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)); seq_printf(m, "Netfs : ZR=%u sh=%u sk=%u\n", atomic_read(&netfs_n_rh_zero), atomic_read(&netfs_n_rh_short_read),
fs/netfs/write_issue.c +1 -0
@@ -510,6 +510,7 @@ int new_netfs_writepages(struct address_space *mapping, }trace_netfs_write (wreq, netfs_write_trace_writeback); +netfs_stat (&netfs_n_wh_writepages); do { _debug("wbiter %lx %llx", folio->index, wreq->start + wreq->submitted);
David Howells
maintainerPATCH v2 16/22 netfs, afs: Implement helpers for new write code
In reply to David HowellsImplement the helpers for the new write code in afs. There's now an optional ->prepare_write() that allows the filesystem to set the parameters for the next write, such as maximum size and maximum segment count, and an ->issue_write() that is called to initiate an (asynchronous) write operation.
---
Notes:
Changes
=======
ver #2)
- Don't do the StoreData RPC inline, but keep doing it from a workqueue.fs/afs/file.c | 3 +++ fs/afs/internal.h | 3 +++ fs/afs/write.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)
fs/afs/file.c +3 -0
@@ -400,6 +400,9 @@ const struct netfs_request_ops afs_req_ops = { .update_i_size = afs_update_i_size, .invalidate_cache = afs_netfs_invalidate_cache, .create_write_requests = afs_create_write_requests, + .begin_writeback = afs_begin_writeback, + .prepare_write = afs_prepare_write, + .issue_write = afs_issue_write, };static void afs_add_open_mmap (struct afs_vnode *vnode)
fs/afs/internal.h +3 -0
@@ -1598,6 +1598,9 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);/* * write.c */ +void afs_prepare_write (struct netfs_io_subrequest *subreq); +void afs_issue_write (struct netfs_io_subrequest *subreq); +void afs_begin_writeback (struct netfs_io_request *wreq);extern int afs_writepages (struct address_space *,struct writeback_control *);extern int afs_fsync (struct file *,loff_t ,loff_t ,int );extern vm_fault_t afs_page_mkwrite (struct vm_fault *vmf);
fs/afs/write.c +54 -0
60 lines not on this page · raw message
David Howells
maintainerPATCH v2 17/22 netfs, 9p: Implement helpers for new write code
In reply to David HowellsImplement the helpers for the new write code in 9p. There's now an optional ->prepare_write() that allows the filesystem to set the parameters for the next write, such as maximum size and maximum segment count, and an ->issue_write() that is called to initiate an (asynchronous) write operation.
---
Notes:
Changes
=======
ver #2)
- Use 'int len' rather than 'size_t len' because of the varargs packet
formatter.fs/9p/vfs_addr.c | 48 ++++++++++++++++++++++++++++++++++++++++ include/net/9p/client.h | 2 ++ net/9p/Kconfig | 1 + net/9p/client.c | 49 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+)
fs/9p/vfs_addr.c +48 -0
@@ -26,6 +26,40 @@#include "cache.h" #include "fid.h" +/* +* Writeback calls this when it finds a folio that needs uploading. This isn't +* called if writeback only has copy-to-cache to deal with. +*/ +static void v9fs_begin_writeback (struct netfs_io_request *wreq) +{ +struct p9_fid *fid; + + fid =v9fs_fid_find_inode (wreq->inode, true,INVALID_UID , true); +if (!fid) { +WARN_ONCE (1 ,"folio expected an open fid inode->i_ino=%lx\n" , + wreq->inode->i_ino); +return ; + } + + wreq->wsize = fid->clnt->msize -P9_IOHDRSZ ; +if (fid->iounit) + wreq->wsize =min (wreq->wsize, fid->iounit); + wreq->netfs_priv = fid; + wreq->io_streams[0 ].avail = true; +} + +/* +* Issue a subrequest to write to the server. +*/ +static void v9fs_issue_write (struct netfs_io_subrequest *subreq) +{ +struct p9_fid *fid = subreq->rreq->netfs_priv; +int err, len; + + len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); +netfs_write_subrequest_terminated (subreq, len ?: err, false); +} +static void v9fs_upload_to_server (struct netfs_io_subrequest *subreq) {struct p9_fid *fid = subreq->rreq->netfs_priv;
@@ -92,6 +126,14 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) rreq->origin ==NETFS_UNBUFFERED_WRITE || rreq->origin == NETFS_DIO_WRITE); +#if 0 // TODO: Cut over +if (rreq->origin ==NETFS_WRITEBACK ) +return 0 ;/* We don't get the write handle until we find we +* have actually dirty data and not just +* copy-to-cache data. +*/ +#endif +if (file) { fid = file->private_data;if (!fid)
@@ -103,6 +145,10 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) goto no_fid; } + rreq->wsize = fid->clnt->msize -P9_IOHDRSZ ; +if (fid->iounit) + rreq->wsize =min (rreq->wsize, fid->iounit); +/* we might need to read from a fid that was opened write-only * for read-modify-write of page cache, use the writeback fid * for that */
@@ -131,6 +177,8 @@ const struct netfs_request_ops v9fs_req_ops = { .init_request = v9fs_init_request, .free_request = v9fs_free_request, .issue_read = v9fs_issue_read, + .begin_writeback = v9fs_begin_writeback, + .issue_write = v9fs_issue_write, .create_write_requests = v9fs_create_write_requests, };
include/net/9p/client.h +2 -0
@@ -207,6 +207,8 @@ int p9_client_read(struct p9_fid *fid, u64 offset, struct iov_iter *to, int *errint p9_client_read_once (struct p9_fid *fid,u64 offset,struct iov_iter *to,int *err);int p9_client_write (struct p9_fid *fid,u64 offset,struct iov_iter *from,int *err); +struct netfs_io_subrequest ; +void p9_client_write_subreq (struct netfs_io_subrequest *subreq);int p9_client_readdir (struct p9_fid *fid,char *data,u32 count,u64 offset);int p9dirent_read (struct p9_client *clnt,char *buf,int len,struct p9_dirent *dirent);
net/9p/Kconfig +1 -0
@@ -5,6 +5,7 @@ menuconfig NET_9P tristate "Plan 9 Resource Sharing Support (9P2000)" + select NETFS_SUPPORT help If you say Y here, you will get experimental support for Plan 9 resource sharing via the 9P2000 protocol.
net/9p/client.c +49 -0
61 lines not on this page · raw message
David Howells
maintainerPATCH v2 18/22 netfs, cachefiles: Implement helpers for new write code
In reply to David HowellsImplement the helpers for the new write code in cachefiles. There's now an optional ->prepare_write() that allows the filesystem to set the parameters for the next write, such as maximum size and maximum segment count, and an ->issue_write() that is called to initiate an (asynchronous) write operation.
---
Notes:
Changes
=======
ver #2)
- Add missing linux/bio.h for BIO_MAX_VECS.fs/cachefiles/io.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
fs/cachefiles/io.c +74 -0
@@ -9,6 +9,7 @@#include <linux/slab.h> #include <linux/file.h> #include <linux/uio.h> +#include <linux/bio.h> #include <linux/falloc.h> #include <linux/sched/mm.h> #include <trace/events/fscache.h>
@@ -622,6 +623,77 @@ static int cachefiles_prepare_write(struct netfs_cache_resources *cres,return ret; } +static void cachefiles_prepare_write_subreq (struct netfs_io_subrequest *subreq) +{ +struct netfs_io_request *wreq = subreq->rreq; +struct netfs_cache_resources *cres = &wreq->cache_resources; + +_enter ("W=%x[%x] %llx" , wreq->debug_id, subreq->debug_index, subreq->start); + + subreq->max_len =ULONG_MAX ; + subreq->max_nr_segs =BIO_MAX_VECS ; + +if (!cachefiles_cres_file (cres)) { +if (!fscache_wait_for_operation (cres,FSCACHE_WANT_WRITE )) +return netfs_prepare_write_failed (subreq); +if (!cachefiles_cres_file (cres)) +return netfs_prepare_write_failed (subreq); + } +} + +static void cachefiles_issue_write (struct netfs_io_subrequest *subreq) +{ +struct netfs_io_request *wreq = subreq->rreq; +struct netfs_cache_resources *cres = &wreq->cache_resources; +struct cachefiles_object *object =cachefiles_cres_object (cres); +struct cachefiles_cache *cache = object->volume->cache; +const struct cred *saved_cred; +size_t off, pre, post, len = subreq->len; +loff_t start = subreq->start; +int ret; + +_enter ("W=%x[%x] %llx-%llx" , + wreq->debug_id, subreq->debug_index, start, start + len -1 ); + +/* We need to start on the cache granularity boundary */ + off = start & (CACHEFILES_DIO_BLOCK_SIZE -1 ); +if (off) { + pre =CACHEFILES_DIO_BLOCK_SIZE - off; +if (pre >= len) { +netfs_write_subrequest_terminated (subreq, len, false); +return ; + } + subreq->transferred += pre; + start += pre; + len -= pre; +iov_iter_advance (&subreq->io_iter, pre); + } + +/* We also need to end on the cache granularity boundary */ + post = len & (CACHEFILES_DIO_BLOCK_SIZE -1 ); +if (post) { + len -= post; +if (len ==0 ) { +netfs_write_subrequest_terminated (subreq, post, false); +return ; + } +iov_iter_truncate (&subreq->io_iter, len); + } + +cachefiles_begin_secure (cache, &saved_cred); + ret =__cachefiles_prepare_write (object,cachefiles_cres_file (cres), + &start, &len, len, true); +cachefiles_end_secure (cache, saved_cred); +if (ret <0 ) { +netfs_write_subrequest_terminated (subreq, ret, false); +return ; + } + +cachefiles_write (&subreq->rreq->cache_resources, + subreq->start, &subreq->io_iter, + netfs_write_subrequest_terminated, subreq); +} +/* * Clean up an operation. */
@@ -638,8 +710,10 @@ static const struct netfs_cache_ops cachefiles_netfs_cache_ops = { .end_operation = cachefiles_end_operation, .read = cachefiles_read, .write = cachefiles_write, + .issue_write = cachefiles_issue_write, .prepare_read = cachefiles_prepare_read, .prepare_write = cachefiles_prepare_write, + .prepare_write_subreq = cachefiles_prepare_write_subreq, .prepare_ondemand_read = cachefiles_prepare_ondemand_read, .query_occupancy = cachefiles_query_occupancy, };
David Howells
maintainerPATCH v2 19/22 netfs: Cut over to using new writeback code
In reply to David HowellsCut over to using the new writeback code. The old code is #ifdef'd out or otherwise removed from compilation to avoid conflicts and will be removed in a future patch.
---
Notes:
Changes
=======
ver #2)
- In netfs_perform_write(), don't wait for writeback if we don't need to.fs/9p/vfs_addr.c | 6 ++--- fs/afs/file.c | 3 +-- fs/afs/internal.h | 1 - fs/afs/write.c | 2 ++ fs/netfs/Makefile | 1 - fs/netfs/buffered_write.c | 47 ++++++++++++++++++++++----------------- fs/netfs/direct_write.c | 26 ++++++++++++---------- fs/netfs/internal.h | 21 +++++------------ fs/netfs/write_collect.c | 8 +++---- fs/netfs/write_issue.c | 18 +++++++-------- include/linux/netfs.h | 9 -------- 11 files changed, 64 insertions(+), 78 deletions(-)
fs/9p/vfs_addr.c +2 -4
@@ -60,6 +60,7 @@ static void v9fs_issue_write(struct netfs_io_subrequest *subreq)netfs_write_subrequest_terminated (subreq, len ?: err, false); } +#if 0 // TODO: Remove static void v9fs_upload_to_server (struct netfs_io_subrequest *subreq) {struct p9_fid *fid = subreq->rreq->netfs_priv;
@@ -91,6 +92,7 @@ static void v9fs_create_write_requests(struct netfs_io_request *wreq, loff_t staif (subreq) netfs_queue_write_request(subreq); } +#endif /** * v9fs_issue_read - Issue a read from 9P
@@ -121,18 +123,15 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) {struct p9_fid *fid;bool writing = (rreq->origin ==NETFS_READ_FOR_WRITE || - rreq->origin ==NETFS_WRITEBACK || rreq->origin ==NETFS_WRITETHROUGH || rreq->origin ==NETFS_UNBUFFERED_WRITE || rreq->origin ==NETFS_DIO_WRITE ); -#if 0 // TODO: Cut over if (rreq->origin ==NETFS_WRITEBACK )return 0 ;/* We don't get the write handle until we find we * have actually dirty data and not just * copy-to-cache data. */ -#endif if (file) { fid = file->private_data;
@@ -179,7 +178,6 @@ const struct netfs_request_ops v9fs_req_ops = { .issue_read = v9fs_issue_read, .begin_writeback = v9fs_begin_writeback, .issue_write = v9fs_issue_write, - .create_write_requests = v9fs_create_write_requests, };const struct address_space_operations v9fs_addr_operations = {
fs/afs/file.c +1 -2
@@ -353,7 +353,7 @@ static int afs_init_request(struct netfs_io_request *rreq, struct file *file)if (file) rreq->netfs_priv =key_get (afs_file_key (file)); rreq->rsize =256 *1024 ; - rreq->wsize =256 *1024 ; + rreq->wsize =256 *1024 *1024 ;return 0 ; }
@@ -399,7 +399,6 @@ const struct netfs_request_ops afs_req_ops = { .issue_read = afs_issue_read, .update_i_size = afs_update_i_size, .invalidate_cache = afs_netfs_invalidate_cache, - .create_write_requests = afs_create_write_requests, .begin_writeback = afs_begin_writeback, .prepare_write = afs_prepare_write, .issue_write = afs_issue_write,
fs/afs/internal.h +0 -1
@@ -1605,7 +1605,6 @@ extern int afs_writepages(struct address_space *, struct writeback_control *);extern int afs_fsync (struct file *,loff_t ,loff_t ,int );extern vm_fault_t afs_page_mkwrite (struct vm_fault *vmf);extern void afs_prune_wb_keys (struct afs_vnode *); -void afs_create_write_requests (struct netfs_io_request *wreq,loff_t start,size_t len);/* * xattr.c
fs/afs/write.c +2 -0
@@ -156,6 +156,7 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_treturn afs_put_operation (op); } +#if 0 // TODO: Remove static void afs_upload_to_server (struct netfs_io_subrequest *subreq) {struct afs_vnode *vnode =AFS_FS_I (subreq->rreq->inode);
@@ -193,6 +194,7 @@ void afs_create_write_requests(struct netfs_io_request *wreq, loff_t start, sizeif (subreq) netfs_queue_write_request(subreq); } +#endif /* * Writeback calls this when it finds a folio that needs uploading. This isn't
fs/netfs/Makefile +0 -1
@@ -11,7 +11,6 @@ netfs-y := \ main.o \ misc.o \ objects.o \ - output.o \ write_collect.o \ write_issue.o
fs/netfs/buffered_write.c +26 -21
110 lines not on this page · raw message
fs/netfs/direct_write.c +14 -12
@@ -34,6 +34,7 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iovunsigned long long start = iocb->ki_pos;unsigned long long end = start +iov_iter_count (iter);ssize_t ret, n; +size_t len =iov_iter_count (iter);bool async = !is_sync_kiocb (iocb);_enter ("" );
@@ -46,13 +47,17 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_debug ("uw %llx-%llx" , start, end); - wreq =netfs_alloc_request (iocb->ki_filp->f_mapping, iocb->ki_filp, - start, end - start, - iocb->ki_flags &IOCB_DIRECT ? -NETFS_DIO_WRITE :NETFS_UNBUFFERED_WRITE ); + wreq =netfs_create_write_req (iocb->ki_filp->f_mapping, iocb->ki_filp, start, + iocb->ki_flags &IOCB_DIRECT ? +NETFS_DIO_WRITE :NETFS_UNBUFFERED_WRITE );if (IS_ERR (wreq))return PTR_ERR (wreq); + wreq->io_streams[0 ].avail = true; +trace_netfs_write (wreq, (iocb->ki_flags &IOCB_DIRECT ? + netfs_write_trace_dio_write : + netfs_write_trace_unbuffered_write)); + {/* If this is an async op and we're not using a bounce buffer, * we have to save the source buffer as the iterator is only
@@ -63,7 +68,7 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov* request. */ if (async ||user_backed_iter (iter)) { - n =netfs_extract_user_iter (iter, wreq->len, &wreq->iter,0 ); + n =netfs_extract_user_iter (iter, len, &wreq->iter,0 );if (n <0 ) { ret = n; goto out;
@@ -71,7 +76,6 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov wreq->direct_bv = (struct bio_vec *)wreq->iter.bvec; wreq->direct_bv_count = n; wreq->direct_bv_unpin =iov_iter_extract_will_pin (iter); - wreq->len =iov_iter_count (&wreq->iter); }else { wreq->iter = *iter; }
@@ -79,6 +83,8 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov wreq->io_iter = wreq->iter; } +__set_bit (NETFS_RREQ_USE_IO_ITER , &wreq->flags); +/* Copy the data into the bounce buffer and encrypt it. */ // TODO
@@ -87,10 +93,7 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iovif (async) wreq->iocb = iocb; wreq->cleanup = netfs_cleanup_dio_write; - ret =netfs_begin_write (wreq,is_sync_kiocb (iocb), - iocb->ki_flags &IOCB_DIRECT ? - netfs_write_trace_dio_write : - netfs_write_trace_unbuffered_write); + ret =netfs_unbuffered_write (wreq,is_sync_kiocb (iocb),iov_iter_count (&wreq->io_iter));if (ret <0 ) {_debug ("begin = %zd" , ret); goto out;
@@ -100,9 +103,8 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iovtrace_netfs_rreq (wreq, netfs_rreq_trace_wait_ip);wait_on_bit (&wreq->flags,NETFS_RREQ_IN_PROGRESS ,TASK_UNINTERRUPTIBLE ); - +smp_rmb ();/* Read error/transferred after RIP flag */ ret = wreq->error; -_debug ("waited = %zd" , ret);if (ret ==0 ) { ret = wreq->transferred; iocb->ki_pos += ret;
fs/netfs/internal.h +6 -15
@@ -92,15 +92,6 @@ static inline void netfs_see_request(struct netfs_io_request *rreq,trace_netfs_rreq_ref (rreq->debug_id,refcount_read (&rreq->ref), what); } -/* -* output.c -*/ -int netfs_begin_write (struct netfs_io_request *wreq,bool may_wait, -enum netfs_write_trace what); -struct netfs_io_request *netfs_begin_writethrough (struct kiocb *iocb,size_t len); -int netfs_advance_writethrough (struct netfs_io_request *wreq,size_t copied,bool to_page_end); -int netfs_end_writethrough (struct netfs_io_request *wreq,struct kiocb *iocb); -/* * stats.c */
@@ -172,12 +163,12 @@ void netfs_reissue_write(struct netfs_io_stream *stream,int netfs_advance_write (struct netfs_io_request *wreq,struct netfs_io_stream *stream,loff_t start,size_t len,bool to_eof); -struct netfs_io_request *new_netfs_begin_writethrough (struct kiocb *iocb,size_t len); -int new_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); -int new_netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, -struct folio *writethrough_cache); +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); +int netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, +struct folio *writethrough_cache);int netfs_unbuffered_write (struct netfs_io_request *wreq,bool may_wait,size_t len);/*
fs/netfs/write_collect.c +4 -4
@@ -709,7 +709,7 @@ void netfs_wake_write_collector(struct netfs_io_request *wreq, bool was_async) }/** -* new_netfs_write_subrequest_terminated - Note the termination of a write operation. +* netfs_write_subrequest_terminated - Note the termination of a write operation. * @_op: The I/O request that has terminated. * @transferred_or_error: The amount of data transferred or an error code. * @was_async: The termination was asynchronous
@@ -731,8 +731,8 @@ void netfs_wake_write_collector(struct netfs_io_request *wreq, bool was_async)* Note that %_op is a void* so that the function can be passed to * kiocb::term_func without the need for a casting wrapper. */ -void new_netfs_write_subrequest_terminated (void *_op,ssize_t transferred_or_error, -bool was_async) +void netfs_write_subrequest_terminated (void *_op,ssize_t transferred_or_error, +bool was_async) {struct netfs_io_subrequest *subreq = _op;struct netfs_io_request *wreq = subreq->rreq;
@@ -800,4 +800,4 @@ void new_netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_errnetfs_put_subrequest (subreq, was_async, netfs_sreq_trace_put_terminated); } -EXPORT_SYMBOL (new_netfs_write_subrequest_terminated); +EXPORT_SYMBOL (netfs_write_subrequest_terminated);
fs/netfs/write_issue.c +9 -9
@@ -485,8 +485,8 @@ static int netfs_write_folio(struct netfs_io_request *wreq,/* * Write some of the pending data back to the server */ -int new_netfs_writepages (struct address_space *mapping, -struct writeback_control *wbc) +int netfs_writepages (struct address_space *mapping, +struct writeback_control *wbc) {struct netfs_inode *ictx =netfs_inode (mapping->host);struct netfs_io_request *wreq =NULL ;
@@ -547,12 +547,12 @@ int new_netfs_writepages(struct address_space *mapping,_leave (" = %d" , error);return error; } -EXPORT_SYMBOL (new_netfs_writepages); +EXPORT_SYMBOL (netfs_writepages);/* * Begin a write operation for writing through the pagecache. */ -struct netfs_io_request *new_netfs_begin_writethrough (struct kiocb *iocb,size_t len) +struct netfs_io_request *netfs_begin_writethrough (struct kiocb *iocb,size_t len) {struct netfs_io_request *wreq =NULL ;struct netfs_inode *ictx =netfs_inode (file_inode (iocb->ki_filp));
@@ -577,9 +577,9 @@ struct netfs_io_request *new_netfs_begin_writethrough(struct kiocb *iocb, size_t* to the request. If we've added more than wsize then we need to create a new * subrequest. */ -int new_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) +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) {_enter ("R=%x ic=%zu ws=%u cp=%zu tp=%u" , wreq->debug_id, wreq->iter.count, wreq->wsize, copied, to_page_end);
@@ -609,8 +609,8 @@ int new_netfs_advance_writethrough(struct netfs_io_request *wreq, struct writeba/* * End a write operation used when writing through the pagecache. */ -int new_netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, -struct folio *writethrough_cache) +int netfs_end_writethrough (struct netfs_io_request *wreq,struct writeback_control *wbc, +struct folio *writethrough_cache) {struct netfs_inode *ictx =netfs_inode (wreq->inode);int ret;
include/linux/netfs.h +0 -9
@@ -303,8 +303,6 @@ struct netfs_request_ops {void (*update_i_size)(struct inode *inode,loff_t i_size);/* Write request handling */ -void (*create_write_requests)(struct netfs_io_request *wreq, -loff_t start,size_t len);void (*begin_writeback)(struct netfs_io_request *wreq);void (*prepare_write)(struct netfs_io_subrequest *subreq);void (*issue_write)(struct netfs_io_subrequest *subreq);
@@ -409,8 +407,6 @@ int netfs_write_begin(struct netfs_inode *, struct file *, struct folio **, void **fsdata);int netfs_writepages (struct address_space *mapping,struct writeback_control *wbc); -int new_netfs_writepages (struct address_space *mapping, -struct writeback_control *wbc);bool netfs_dirty_folio (struct address_space *mapping,struct folio *folio);int netfs_unpin_writeback (struct inode *inode,struct writeback_control *wbc);void netfs_clear_inode_writeback (struct inode *inode,const void *aux);
@@ -431,14 +427,9 @@ ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len, 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); -struct netfs_io_subrequest *netfs_create_write_request ( -struct netfs_io_request *wreq,enum netfs_io_source dest, -loff_t start,size_t len,work_func_t worker);void netfs_prepare_write_failed (struct netfs_io_subrequest *subreq);void netfs_write_subrequest_terminated (void *_op,ssize_t transferred_or_error,bool was_async); -void new_netfs_write_subrequest_terminated (void *_op,ssize_t transferred_or_error, -bool was_async);void netfs_queue_write_request (struct netfs_io_subrequest *subreq);int netfs_start_io_read (struct inode *inode);
David Howells
maintainerPATCH v2 20/22 netfs: Remove the old writeback code
In reply to David HowellsRemove the old writeback code.
---
Notes:
Changes
=======
ver #2)
- Remove the use of %lx to display a size_t.fs/9p/vfs_addr.c | 34 --- fs/afs/write.c | 40 --- fs/netfs/buffered_write.c | 629 -------------------------------------- fs/netfs/output.c | 477 ----------------------------- 4 files changed, 1180 deletions(-) delete mode 100644 fs/netfs/output.c
fs/9p/vfs_addr.c +0 -34
@@ -60,40 +60,6 @@ static void v9fs_issue_write(struct netfs_io_subrequest *subreq)netfs_write_subrequest_terminated (subreq, len ?: err, false); } -#if 0 // TODO: Remove -static void v9fs_upload_to_server (struct netfs_io_subrequest *subreq) -{ -struct p9_fid *fid = subreq->rreq->netfs_priv; -int err, len; - -trace_netfs_sreq (subreq, netfs_sreq_trace_submit); - len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); -netfs_write_subrequest_terminated (subreq, len ?: err, false); -} - -static void v9fs_upload_to_server_worker (struct work_struct *work) -{ -struct netfs_io_subrequest *subreq = - container_of(work, struct netfs_io_subrequest, work); - -v9fs_upload_to_server (subreq); -} - -/* -* Set up write requests for a writeback slice. We need to add a write request -* for each write we want to make. -*/ -static void v9fs_create_write_requests (struct netfs_io_request *wreq,loff_t start,size_t len) -{ -struct netfs_io_subrequest *subreq; - - subreq =netfs_create_write_request (wreq,NETFS_UPLOAD_TO_SERVER , - start, len, v9fs_upload_to_server_worker); -if (subreq) -netfs_queue_write_request (subreq); -} -#endif -/** * v9fs_issue_read - Issue a read from 9P * @subreq: The read to make
fs/afs/write.c +0 -40
@@ -156,46 +156,6 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_treturn afs_put_operation (op); } -#if 0 // TODO: Remove -static void afs_upload_to_server (struct netfs_io_subrequest *subreq) -{ -struct afs_vnode *vnode =AFS_FS_I (subreq->rreq->inode); -ssize_t ret; - -_enter ("%x[%x],%zx" , - subreq->rreq->debug_id, subreq->debug_index, subreq->io_iter.count); - -trace_netfs_sreq (subreq, netfs_sreq_trace_submit); - ret =afs_store_data (vnode, &subreq->io_iter, subreq->start); -netfs_write_subrequest_terminated (subreq, ret <0 ? ret : subreq->len, - false); -} - -static void afs_upload_to_server_worker (struct work_struct *work) -{ -struct netfs_io_subrequest *subreq = - container_of(work, struct netfs_io_subrequest, work); - -afs_upload_to_server (subreq); -} - -/* -* Set up write requests for a writeback slice. We need to add a write request -* for each write we want to make. -*/ -void afs_create_write_requests (struct netfs_io_request *wreq,loff_t start,size_t len) -{ -struct netfs_io_subrequest *subreq; - -_enter ("%x,%llx-%llx" , wreq->debug_id, start, start + len); - - subreq =netfs_create_write_request (wreq,NETFS_UPLOAD_TO_SERVER , - start, len, afs_upload_to_server_worker); -if (subreq) -netfs_queue_write_request (subreq); -} -#endif -/* * Writeback calls this when it finds a folio that needs uploading. This isn't * called if writeback only has copy-to-cache to deal with.
fs/netfs/buffered_write.c +0 -629
632 lines not on this page · raw message
fs/netfs/output.c deleted +0 -477
477 lines not on this page · raw message
David Howells
maintainerPATCH v2 21/22 netfs: Miscellaneous tidy ups
In reply to David HowellsDo a couple of miscellaneous tidy ups:
(1) Add a qualifier into a file banner comment.
(2) Put the writeback folio traces back into alphabetical order.
(3) Remove some unused folio traces.
--- fs/netfs/buffered_write.c | 2 +- include/trace/events/netfs.h | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)
fs/netfs/buffered_write.c +1 -1
@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only -/* Network filesystem high-level write support. +/* Network filesystem high-level buffered write support. * * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected])
include/trace/events/netfs.h +1 -5
@@ -141,12 +141,9 @@ EM(netfs_folio_trace_cancel_copy, "cancel-copy") \ EM(netfs_folio_trace_clear, "clear") \ EM(netfs_folio_trace_clear_cc, "clear-cc") \ - EM(netfs_folio_trace_clear_s, "clear-s") \ EM(netfs_folio_trace_clear_g, "clear-g") \ - EM(netfs_folio_trace_copy, "copy") \ - EM(netfs_folio_trace_copy_plus, "copy+") \ + EM(netfs_folio_trace_clear_s, "clear-s") \ EM(netfs_folio_trace_copy_to_cache, "mark-copy") \ - EM(netfs_folio_trace_end_copy, "end-copy") \ EM(netfs_folio_trace_filled_gaps, "filled-gaps") \ EM(netfs_folio_trace_kill, "kill") \EM (netfs_folio_trace_kill_cc,"kill-cc" ) \
@@ -156,7 +153,6 @@ EM(netfs_folio_trace_mkwrite_plus, "mkwrite+") \ EM(netfs_folio_trace_not_under_wback, "!wback") \ EM(netfs_folio_trace_read_gaps, "read-gaps") \ - EM(netfs_folio_trace_redirty, "redirty") \ EM(netfs_folio_trace_redirtied, "redirtied") \ EM(netfs_folio_trace_store, "store") \EM (netfs_folio_trace_store_copy,"store-copy" ) \
David Howells
maintainerPATCH v2 22/22 netfs, afs: Use writeback retry to deal with alternate keys
In reply to David HowellsUse a hook in the new writeback code's retry algorithm to rotate the keys once all the outstanding subreqs have failed rather than doing it separately on each subreq.
---
Notes:
Changes
=======
ver #2)
- Change a comma ending a statement to a semicolon.fs/afs/file.c | 1 + fs/afs/internal.h | 1 + fs/afs/write.c | 191 +++++++++++++++++++-------------------- fs/netfs/write_collect.c | 9 +- include/linux/netfs.h | 2 + 5 files changed, 104 insertions(+), 100 deletions(-)
fs/afs/file.c +1 -0
@@ -368,6 +368,7 @@ static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len,static void afs_free_request (struct netfs_io_request *rreq) {key_put (rreq->netfs_priv); +afs_put_wb_key (rreq->netfs_priv2); }static void afs_update_i_size (struct inode *inode,loff_t new_i_size)
fs/afs/internal.h +1 -0
@@ -1601,6 +1601,7 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);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); +void afs_retry_request (struct netfs_io_request *wreq,struct netfs_io_stream *stream);extern int afs_writepages (struct address_space *,struct writeback_control *);extern int afs_fsync (struct file *,loff_t ,loff_t ,int );extern vm_fault_t afs_page_mkwrite (struct vm_fault *vmf);
fs/afs/write.c +93 -98
260 lines not on this page · raw message
fs/netfs/write_collect.c +7 -2
@@ -163,6 +163,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,_enter ("R=%x[%x:]" , wreq->debug_id, stream->stream_nr); +if (list_empty (&stream->subrequests)) +return ; + +if (stream->source ==NETFS_UPLOAD_TO_SERVER && + wreq->netfs_ops->retry_request) + wreq->netfs_ops->retry_request (wreq, stream); +if (unlikely (stream->failed))return ;
@@ -182,8 +189,6 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,return ; } -if (list_empty (&stream->subrequests)) -return ; next = stream->subrequests.next; do {
include/linux/netfs.h +2 -0
@@ -235,6 +235,7 @@ struct netfs_io_request {struct iov_iter iter;/* Unencrypted-side iterator */ struct iov_iter io_iter;/* I/O (Encrypted-side) iterator */ void *netfs_priv;/* Private data for the netfs */ +void *netfs_priv2;/* Private data for the netfs */ struct bio_vec *direct_bv;/* DIO buffer list (when handling iovec-iter) */ unsigned int direct_bv_count;/* Number of elements in direct_bv[] */ unsigned int debug_id;
@@ -306,6 +307,7 @@ struct netfs_request_ops {void (*begin_writeback)(struct netfs_io_request *wreq);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);void (*invalidate_cache)(struct netfs_io_request *wreq); };