Network fs helper library & fscache kiocb API
Subsystems (31)
David Howells
maintainerv6 cover Network fs helper library & fscache kiocb API
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and vfs_write() on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.
Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the PG_fscache page flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.
This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(), fscache_write_page() and fscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.
The patchset contains the following parts:
(1) Some helper patches, including provision of an ITER_XARRAY iov iterator and a function to do readahead expansion.
(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph also passes the expected tests.
The netfs lib and fscache/cachefiles patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-lib
The afs patches can be found on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-netfs-lib
Changes
=======
ver #6:
Merged in some fixes and added an additional tracepoint[8], including fixing the amalgamation of contiguous subrequests that are to be written to the cache.
Added/merged some patches from Matthew Wilcox to make readahead_expand() appropriately adjust the trigger for the next readahead[9]. Also included is a patch to kerneldocify the file_ra_state struct.
Altered netfs_write_begin() to use DEFINE_READAHEAD()[10].
Split the afs patches out into their own branch.
ver #5:
Fixed some review comments from Matthew Wilcox:
- Put a comment into netfs_readahead() to indicate why there's a loop that puts, but doesn't unlock, "unconsumed" pages at the end when it could just return said pages to the caller to dispose of[6]. (This is because where those pages are marked consumed).
- Use the page_file_mapping() and page_index() helper functions rather than accessing the page struct directly[6].
- Better names for wrangling functions for PG_private_2 and PG_fscache wrangling functions[7]. Came up with {set,end,wait_for}_page_private_2() and aliased these for fscache.
Moved the taking of/dropping a page ref for the PG_private_2 flag into the set and end functions.
ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].
Moved the declaration of readahead_expand() to a better location[5].
Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.
Adjusted the functions that unlock and wait for PG_fscache according to Linus's suggestion[1].
Hold a ref on a page when PG_fscache is set as per Linus's suggestion[2].
Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.
References
==========
These patches have been published for review before, firstly as part of a larger set:
Then as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: Add ITER_XARRAY
mm: Add set/end/wait functions for PG_private_2
mm: Implement readahead_control pageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: Move PG_fscache helper funcs to linux/netfs.h netfs, mm: Add set/end/wait_on_page_fscache() aliases
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Add write_begin helper
netfs: Define an interface to talk to a cache
netfs: Add a tracepoint to log failures that would be otherwise unseen fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operation debug_id when logging an unexpected data version
afs: Move key to afs_read struct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up the iov_iter before calling afs_extract_data()
afs: Use ITER_XARRAY for writing
afs: Wait on PG_fscache before modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new netfs lib read helper API
afs: Use the netfs_write_begin() helper
Matthew Wilcox (Oracle) (2):
mm/filemap: Pass the file_ra_state in the ractl
fs: Document file_ra_state
Documentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 657 +++++----- fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++ fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1185 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fs.h | 24 +- include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 234 ++++ include/linux/pagemap.h | 41 +- include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 261 ++++ mm/filemap.c | 63 +- mm/internal.h | 7 +- mm/readahead.c | 97 +- net/rxrpc/recvmsg.c | 9 +- 44 files changed, 3998 insertions(+), 1108 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/io.c create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
David Howells
maintainerPATCH v6 1/30 iov_iter: Add ITER_XARRAY
Add an iterator, ITER_XARRAY, that walks through a set of pages attached to an xarray, starting at a given page and offset and walking for the specified amount of bytes. The iterator supports transparent huge pages.
The iterate_xarray() macro calls the helper function with rcu_access() helped. I think that this is only a problem for iov_iter_for_each_range()
- and that returns an error for ITER_XARRAY (also, this function does not appear to be called).
The caller must guarantee that the pages are all present and they must be locked using PG_locked, PG_writeback or PG_fscache to prevent them from going away or being migrated whilst they're being accessed.
This is useful for copying data from socket buffers to inodes in network filesystems and for transferring data between those inodes and the cache using direct I/O.
Whilst it is true that ITER_BVEC could be used instead, that would require a bio_vec array to be allocated to refer to all the pages - which should be redundant if inode->i_pages also points to all these pages.
Note that older versions of this patch implemented an ITER_MAPPING instead, which was almost the same.
---
include/linux/uio.h | 11 ++ lib/iov_iter.c | 313 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 301 insertions(+), 23 deletions(-)
include/linux/uio.h +11 -0
@@ -10,6 +10,7 @@#include <uapi/linux/uio.h> struct page ; +struct address_space ;struct pipe_inode_info ;struct kvec {
@@ -24,6 +25,7 @@ enum iter_type {ITER_BVEC =16 ,ITER_PIPE =32 ,ITER_DISCARD =64 , + ITER_XARRAY = 128, }; struct iov_iter {
@@ -39,6 +41,7 @@ struct iov_iter {const struct iovec *iov;const struct kvec *kvec;const struct bio_vec *bvec; +struct xarray *xarray;struct pipe_inode_info *pipe; };union {
@@ -47,6 +50,7 @@ struct iov_iter {unsigned int head;unsigned int start_head; }; +loff_t xarray_start; }; };
@@ -80,6 +84,11 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)return iov_iter_type (i) ==ITER_DISCARD ; } +static inline bool iov_iter_is_xarray (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_XARRAY ; +} +static inline unsigned char iov_iter_rw (const struct iov_iter *i) {return i->type & (READ |WRITE );
@@ -221,6 +230,8 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_void iov_iter_pipe (struct iov_iter *i,unsigned int direction,struct pipe_inode_info *pipe,size_t count);void iov_iter_discard (struct iov_iter *i,unsigned int direction,size_t count); +void iov_iter_xarray (struct iov_iter *i,unsigned int direction,struct xarray *xarray, +loff_t start,size_t count);ssize_t iov_iter_get_pages (struct iov_iter *i,struct page **pages,size_t maxsize,unsigned maxpages,size_t *start); ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages,
lib/iov_iter.c +290 -23
522 lines not on this page · raw message
Al Viro
maintainerRe: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
Quoted 8 lines · David Howells
Add an iterator,
ITER_XARRAY, that walks through a set of pages attached to an xarray, starting at a given page and offset and walking for the specified amount of bytes. The iterator supports transparent huge pages.The
iterate_xarray()macro calls the helper function withrcu_access()helped. I think that this is only a problem foriov_iter_for_each_range()
- and that returns an error forITER_XARRAY(also, this function does not appear to be called).
Unused since lustre had gone away.
Quoted 1 line
+#define
iterate_all_kinds(i, n, v, I, B, K, X){ \
Do you have any users that would pass different B and X?
lib/iov_iter.c ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, · line 1668
Quoted 6 lines
lib/iov_iter.c +1
-1@@ -1440,7 +1665,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }) + }), 0
Correction - users that might get that flavour. This one explicitly checks for xarray and doesn't get to iterate_... in that case.
David Howells
maintainerRe: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
Quoted 4 lines · Al Viro
Quoted 1 line
+#define
iterate_all_kinds(i, n, v, I, B, K, X){ \Do you have any users that would pass different B and X?
Quoted 9 lines
lib/iov_iter.c ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, · line 1668
Quoted 6 lines
lib/iov_iter.c +1
-1@@ -1440,7 +1665,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }) + }), 0Correction - users that might get that flavour. This one explicitly checks for xarray and doesn't get to
iterate_... in that case.
This is the case for iterate_all_kinds(), but not for iterate_and_advance().
See _copy_mc_to_iter() for example: that can return directly out of the middle of the loop, so the X variant must drop the rcu_read_lock(), but the B variant doesn't need to. You also can't just use break to get out as the X variant has a loop within a loop to handle iteration over the subelements of a THP.
But with iterate_all_kinds(), I could just drop the X parameter and use the B parameter for both, I think.
David
Matthew Wilcox
maintainerRe: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
Quoted 16 lines · David Howells
Quoted 4 lines · Al Viro
Quoted 1 line
+#define
iterate_all_kinds(i, n, v, I, B, K, X){ \Do you have any users that would pass different B and X?
Quoted 9 lines
lib/iov_iter.c ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, · line 1668
Quoted 6 lines
lib/iov_iter.c +1
-1@@ -1440,7 +1665,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }) + }), 0Correction - users that might get that flavour. This one explicitly checks for xarray and doesn't get to
iterate_... in that case.
Quoted 6 lines
This is the case for
iterate_all_kinds(), but not foriterate_and_advance().See
_copy_mc_to_iter()for example: that can return directly out of the middle of the loop, so the X variant must drop thercu_read_lock(), but the B variant doesn't need to. You also can't just use break to get out as the X variant has a loop within a loop to handle iteration over the subelements of a THP.
"Why does it need a loop? bvecs can contain multi-page vectors" "memcpy_from_page can't handle that"
"doesn't that mean that iterating over a bvec is already broken?" "yes"
David Howells
maintainerRFC PATCH 1/2 iov_iter: Remove iov_iter_for_each_range()
In reply to Al ViroRemove iov_iter_for_each_range() as it's no longer used with the removal of lustre.
---
include/linux/uio.h | 4 ---- lib/iov_iter.c | 27 --------------------------- 2 files changed, 31 deletions(-)
include/linux/uio.h +0 -4
@@ -295,8 +295,4 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec,int import_single_range (int type,void __user *buf,size_t len,struct iovec *iov,struct iov_iter *i); -int iov_iter_for_each_range (struct iov_iter *i,size_t bytes, -int (*f)(struct kvec *vec,void *context), -void *context); -#endif
lib/iov_iter.c +0 -27
@@ -2094,30 +2094,3 @@ int import_single_range(int rw, void __user *buf, size_t len,return 0 ; }EXPORT_SYMBOL (import_single_range); - -int iov_iter_for_each_range (struct iov_iter *i,size_t bytes, -int (*f)(struct kvec *vec,void *context), -void *context) -{ -struct kvec w; -int err = -EINVAL ; -if (!bytes) -return 0 ; - -iterate_all_kinds (i, bytes, v, -EINVAL , ({ - w.iov_base =kmap (v.bv_page) + v.bv_offset; - w.iov_len = v.bv_len; - err =f (&w, context); -kunmap (v.bv_page); - err;}), ({ - w = v; - err =f (&w, context);}), ({ - w.iov_base =kmap (v.bv_page) + v.bv_offset; - w.iov_len = v.bv_len; - err =f (&w, context); -kunmap (v.bv_page); - err;}) - ) -return err; -} -EXPORT_SYMBOL (iov_iter_for_each_range);
David Howells
maintainerRFC PATCH 2/2 iov_iter: Drop the X argument from iterate_all_kinds() and use B instead
In reply to Al ViroDrop the X argument from iterate_all_kinds() and use the B argument instead as it's always the same unless the ITER_XARRAY is handled specially.
---
lib/iov_iter.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-)
lib/iov_iter.c +12 -30
@@ -79,8 +79,8 @@#define iterate_xarray (i, n, __v, skip,STEP ) { \ struct page *head = NULL; \ size_t wanted = n, seg, offset; \ - loff_t start = i->xarray_start + skip; \ - pgoff_t index = start >> PAGE_SHIFT; \ + loff_t xarray_start = i->xarray_start + skip; \ + pgoff_t index = xarray_start >> PAGE_SHIFT; \ int j; \ \ XA_STATE(xas, i->xarray, index); \
@@ -113,7 +113,7 @@ n = wanted - n; \ } -#define iterate_all_kinds (i, n, v,I ,B ,K ,X ) { \ +#define iterate_all_kinds (i, n, v,I ,B ,K ) { \ if (likely(n)) { \ size_t skip = i->iov_offset; \ if (unlikely(i->type & ITER_BVEC)) { \
@@ -127,7 +127,7 @@ }else if (unlikely (i->type &ITER_DISCARD )) { \ }else if (unlikely (i->type &ITER_XARRAY )) { \struct bio_vec v; \ -iterate_xarray (i, n, v, skip, (X )); \ +iterate_xarray (i, n, v, skip, (B )); \ }else { \const struct iovec *iov; \struct iovec v; \
@@ -842,9 +842,7 @@ bool _copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i) 0;}), memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), - memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, - v.bv_offset, v.bv_len) + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) )iov_iter_advance (i, bytes);
@@ -927,9 +925,7 @@ bool _copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i) 0;}), memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), - memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, - v.bv_offset, v.bv_len) + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) )iov_iter_advance (i, bytes);
@@ -1058,9 +1054,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page, copyin((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), memcpy_from_page((p += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), -memcpy ((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), -memcpy_from_page ((p += v.bv_len) - v.bv_len, v.bv_page, - v.bv_offset, v.bv_len) + memcpy((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) )kunmap_atomic (kaddr);return bytes;
@@ -1349,8 +1343,7 @@ unsigned long iov_iter_alignment(const struct iov_iter *i)iterate_all_kinds (i, size, v, (res |= (unsigned long )v.iov_base | v.iov_len,0 ), res |= v.bv_offset | v.bv_len, - res |= (unsigned long )v.iov_base | v.iov_len, - res |= v.bv_offset | v.bv_len + res |= (unsigned long )v.iov_base | v.iov_len )return res; }
@@ -1372,9 +1365,7 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i) (res |= (!res ?0 : (unsigned long )v.bv_offset) | (size != v.bv_len ? size :0 )), (res |= (!res ?0 : (unsigned long )v.iov_base) | - (size != v.iov_len ? size :0 )), - (res |= (!res ?0 : (unsigned long )v.bv_offset) | - (size != v.bv_len ? size :0 )) + (size != v.iov_len ? size :0 )) );return res; }
@@ -1530,8 +1521,7 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }), - 0 + }) )return 0 ; }
@@ -1665,7 +1655,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }), 0 + }) )return 0 ; }
@@ -1751,13 +1741,6 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, v.iov_base, v.iov_len, sum, off); off += v.iov_len; - }), ({ -char *p =kmap_atomic (v.bv_page); - sum =csum_and_memcpy ((to += v.bv_len) - v.bv_len, - p + v.bv_offset, v.bv_len, - sum, off); -kunmap_atomic (p); - off += v.bv_len; }) ) *csum = sum;
@@ -1892,8 +1875,7 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) - p /PAGE_SIZE ;if (npages >= maxpages)return maxpages; - }), - 0 + }) )return npages; }
Re: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
In reply to David HowellsQuoted 113 lines · David Howells
Add an iterator,
ITER_XARRAY, that walks through a set of pages attached to an xarray, starting at a given page and offset and walking for the specified amount of bytes. The iterator supports transparent huge pages.The
iterate_xarray()macro calls the helper function withrcu_access()helped. I think that this is only a problem foriov_iter_for_each_range()
- and that returns an error forITER_XARRAY(also, this function does not appear to be called).The caller must guarantee that the pages are all present and they must be locked using
PG_locked,PG_writebackorPG_fscacheto prevent them from going away or being migrated whilst they're being accessed.This is useful for copying data from socket buffers to inodes in network filesystems and for transferring data between those inodes and the cache using direct I/O.
Whilst it is true that
ITER_BVECcould be used instead, that would require abio_vecarray to be allocated to refer to all the pages - which should be redundant ifinode->i_pagesalso points to all these pages.Note that older versions of this patch implemented an
ITER_MAPPINGinstead, which was almost the same.Signed-off-by David Howells <[email protected]>cc Alexander Viro <[email protected]>cc Matthew Wilcox (Oracle) <[email protected]>cc Christoph Hellwig <[email protected]>Link https://lore.kernel.org/r/158861205740.340223.16592990225607814022.stgit@warthog.procyon.org.uk/ # rfc open hereLink https://lore.kernel.org/r/159465785214.1376674.6062549291411362531.stgit@warthog.procyon.org.uk/ open hereLink https://lore.kernel.org/r/160588477334.3465195.3608963255682568730.stgit@warthog.procyon.org.uk/ # rfc open hereLink https://lore.kernel.org/r/161118129703.1232039.17141248432017826976.stgit@warthog.procyon.org.uk/ # rfc open hereLink https://lore.kernel.org/r/161161026313.2537118.14676007075365418649.stgit@warthog.procyon.org.uk/ # v2 open hereLink https://lore.kernel.org/r/161340386671.1303470.10752208972482479840.stgit@warthog.procyon.org.uk/ # v3 open here---
include/linux/uio.h | 11 ++ lib/iov_iter.c | 313 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 301 insertions(+), 23 deletions(-)include/linux/uio.h +11
-0@@ -10,6 +10,7 @@#include <uapi/linux/uio.h> struct page ; +struct address_space ;struct pipe_inode_info ;struct kvec {@@ -24,6 +25,7 @@ enum iter_type {ITER_BVEC =16 ,ITER_PIPE =32 ,ITER_DISCARD =64 , + ITER_XARRAY = 128, }; struct iov_iter {@@ -39,6 +41,7 @@ struct iov_iter {const struct iovec *iov;const struct kvec *kvec;const struct bio_vec *bvec; +struct xarray *xarray;struct pipe_inode_info *pipe; };union {@@ -47,6 +50,7 @@ struct iov_iter {unsigned int head;unsigned int start_head; }; +loff_t xarray_start; }; };@@ -80,6 +84,11 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)return iov_iter_type (i) ==ITER_DISCARD ; } +static inline bool iov_iter_is_xarray (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_XARRAY ; +} +static inline unsigned char iov_iter_rw (const struct iov_iter *i) {return i->type & (READ |WRITE );@@ -221,6 +230,8 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_void iov_iter_pipe (struct iov_iter *i,unsigned int direction,struct pipe_inode_info *pipe,size_t count);void iov_iter_discard (struct iov_iter *i,unsigned int direction,size_t count); +void iov_iter_xarray (struct iov_iter *i,unsigned int direction,struct xarray *xarray, +loff_t start,size_t count);ssize_t iov_iter_get_pages (struct iov_iter *i,struct page **pages,size_t maxsize,unsigned maxpages,size_t *start); ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages,lib/iov_iter.c +0
-0
lib/iov_iter.c line 78
Quoted 3 lines
lib/iov_iter.c +0
-0@@ -76,7 +76,44 @@ } \ }
As a general note, iov_iter.c could really do with some (verbose) comments explaining things. A kerneldoc header that explains the arguments to iterate_all_kinds would sure make this easier to review.
Quoted 212 lines
lib/iov_iter.c +86
-13-#define iterate_all_kinds (i, n, v,I ,B ,K ) { \ +#define iterate_xarray (i, n, __v, skip,STEP ) { \ + struct page *head = NULL; \ + size_t wanted = n, seg, offset; \ + loff_t start = i->xarray_start + skip; \ + pgoff_t index = start >> PAGE_SHIFT; \ + int j; \ + \ + XA_STATE(xas, i->xarray, index); \ + \ + rcu_read_lock(); \ + xas_for_each(&xas, head, ULONG_MAX) { \ + if (xas_retry(&xas, head)) \ + continue; \ + if (WARN_ON(xa_is_value(head))) \ + break; \ + if (WARN_ON(PageHuge(head))) \ + break; \ + for (j = (head->index < index) ? index - head->index : 0; \ + j < thp_nr_pages(head); j++) { \ + __v.bv_page = head + j; \ + offset = (i->xarray_start + skip) & ~PAGE_MASK; \ + seg = PAGE_SIZE - offset; \ + __v.bv_offset = offset; \ + __v.bv_len = min(n, seg); \ + (void)(STEP); \ + n -= __v.bv_len; \ + skip += __v.bv_len; \ + if (n == 0) \ + break; \ + } \ + if (n == 0) \ + break; \ + } \ + rcu_read_unlock(); \ + n = wanted - n; \ +} + +#define iterate_all_kinds (i, n, v,I ,B ,K ,X ) { \ if (likely(n)) { \ size_t skip = i->iov_offset; \ if (unlikely(i->type & ITER_BVEC)) { \@@ -88,6 +125,9 @@struct kvec v; \ iterate_kvec(i, n, v, kvec, skip, (K)) \ }else if (unlikely (i->type &ITER_DISCARD )) { \ + }else if (unlikely (i->type &ITER_XARRAY )) { \ +struct bio_vec v; \ +iterate_xarray (i, n, v, skip, (X )); \ }else { \const struct iovec *iov; \struct iovec v; \@@ -96,7 +136,7 @@ } \ } -#define iterate_and_advance (i, n, v,I ,B ,K ) { \ +#define iterate_and_advance (i, n, v,I ,B ,K ,X ) { \ if (unlikely(i->count < n)) \ n = i->count; \ if (i->count) { \@@ -121,6 +161,9 @@ i->kvec = kvec; \ }else if (unlikely (i->type &ITER_DISCARD )) { \ skip += n; \ + }else if (unlikely (i->type &ITER_XARRAY )) { \ +struct bio_vec v; \ + iterate_xarray(i, n, v, skip, (X)) \ }else { \const struct iovec *iov; \struct iovec v; \@@ -622,7 +665,9 @@ size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i)copyout (v.iov_base, (from += v.iov_len) - v.iov_len, v.iov_len),memcpy_to_page (v.bv_page, v.bv_offset, (from += v.bv_len) - v.bv_len, v.bv_len), -memcpy (v.iov_base, (from += v.iov_len) - v.iov_len, v.iov_len) +memcpy (v.iov_base, (from += v.iov_len) - v.iov_len, v.iov_len), +memcpy_to_page (v.bv_page, v.bv_offset, + (from += v.bv_len) - v.bv_len, v.bv_len) ) return bytes;@@ -738,6 +783,16 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) bytes = curr_addr - s_addr - rem;return bytes; } + }), + ({ + rem =copy_mc_to_page (v.bv_page, v.bv_offset, + (from += v.bv_len) - v.bv_len, v.bv_len); +if (rem) { + curr_addr = (unsigned long ) from; + bytes = curr_addr - s_addr - rem; +rcu_read_unlock (); +return bytes; + } }) )@@ -759,7 +814,9 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)copyin ((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len),memcpy_from_page ((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), -memcpy ((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) +memcpy ((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), +memcpy_from_page ((to += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) ) return bytes;@@ -785,7 +842,9 @@ bool _copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i) 0;}), memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), + memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) )iov_iter_advance (i, bytes);@@ -805,7 +864,9 @@ size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i) v.iov_base, v.iov_len), memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), + memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) )return bytes;@@ -840,7 +901,9 @@ size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)memcpy_page_flushcache ((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len),memcpy_flushcache ((to += v.iov_len) - v.iov_len, v.iov_base, - v.iov_len) + v.iov_len), +memcpy_page_flushcache ((to += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) ) return bytes;@@ -864,7 +927,9 @@ bool _copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i) 0;}), memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), + memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) )iov_iter_advance (i, bytes);@@ -901,7 +966,7 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, {if (unlikely (!page_copy_sane (page, offset, bytes)))return 0 ; -if (i->type & (ITER_BVEC |ITER_KVEC )) { +if (i->type & (ITER_BVEC |ITER_KVEC |ITER_XARRAY )) {void *kaddr =kmap_atomic (page);size_t wanted =copy_to_iter (kaddr + offset, bytes, i);kunmap_atomic (kaddr);@@ -924,7 +989,7 @@ size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes,WARN_ON (1 );return 0 ; } -if (i->type & (ITER_BVEC |ITER_KVEC )) { +if (i->type & (ITER_BVEC |ITER_KVEC |ITER_XARRAY )) {void *kaddr =kmap_atomic (page);size_t wanted =_copy_from_iter (kaddr + offset, bytes, i);kunmap_atomic (kaddr);@@ -968,7 +1033,8 @@ size_t iov_iter_zero(size_t bytes, struct iov_iter *i)iterate_and_advance (i, bytes, v,clear_user (v.iov_base, v.iov_len),memzero_page (v.bv_page, v.bv_offset, v.bv_len), -memset (v.iov_base,0 , v.iov_len) +memset (v.iov_base,0 , v.iov_len), +memzero_page (v.bv_page, v.bv_offset, v.bv_len) )return bytes;@@ -992,7 +1058,9 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,copyin ((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len),memcpy_from_page ((p += v.bv_len) - v.bv_len, v.bv_page, v.bv_offset, v.bv_len), - memcpy((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) +memcpy ((p += v.iov_len) - v.iov_len, v.iov_base, v.iov_len), +memcpy_from_page ((p += v.bv_len) - v.bv_len, v.bv_page, + v.bv_offset, v.bv_len) ) kunmap_atomic(kaddr);return bytes;@@ -1078,11 +1146,16 @@ void iov_iter_advance(struct iov_iter *i, size_t size) i->count -= size;return ; } +if (unlikely (iov_iter_is_xarray (i))) { + i->iov_offset += size; + i->count -= size; +return ; + }if (iov_iter_is_bvec (i)) {iov_iter_bvec_advance (i, size);return ; } - iterate_and_advance(i, size, v, 0, 0, 0) + iterate_and_advance(i, size, v, 0, 0, 0, 0) }EXPORT_SYMBOL (iov_iter_advance);
lib/iov_iter.c void iov_iter_revert(struct iov_iter *i, size_t unroll) · line 1206
Quoted 9 lines
lib/iov_iter.c +5
-1@@ -1126,7 +1199,12 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)return ; } unroll -= i->iov_offset; -if (iov_iter_is_bvec (i)) { +if (iov_iter_is_xarray (i)) { +BUG ();/* We should never go beyond the start of the specified +* range since we might then be straying into pages that +* aren't pinned. +*/
It's not needed now, but there are a lot of calls to iov_iter_revert in the kernel, and going backward doesn't necessarily mean we'd be straying into an unpinned range. xarray_start never changes; would it not be ok to allow reverting as long as you don't move to a lower offset than that point?
Quoted 70 lines
lib/iov_iter.c +33
-4+ }else if (iov_iter_is_bvec (i)) {const struct bio_vec *bvec = i->bvec;while (1 ) {size_t n = (--bvec)->bv_len;@@ -1163,9 +1241,9 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)return i->count;// it is a silly place, anyway if (i->nr_segs ==1 )return i->count; -if (unlikely (iov_iter_is_discard (i))) +if (unlikely (iov_iter_is_discard (i) ||iov_iter_is_xarray (i)))return i->count; -else if (iov_iter_is_bvec (i)) +if (iov_iter_is_bvec (i))return min (i->count, i->bvec->bv_len - i->iov_offset);else return min (i->count, i->iov->iov_len - i->iov_offset);@@ -1213,6 +1291,31 @@ void iov_iter_pipe(struct iov_iter *i, unsigned int direction, }EXPORT_SYMBOL (iov_iter_pipe); +/** +* iov_iter_xarray - Initialise an I/O iterator to use the pages in an xarray +* @i: The iterator to initialise. +* @direction: The direction of the transfer. +* @xarray: The xarray to access. +* @start: The start file position. +* @count: The size of the I/O buffer in bytes. +* +* Set up an I/O iterator to either draw data out of the pages attached to an +* inode or to inject data into those pages. The pages *must* be prevented +* from evaporation, either by taking a ref on them or locking them by the +* caller. +*/ +void iov_iter_xarray (struct iov_iter *i,unsigned int direction, +struct xarray *xarray,loff_t start,size_t count) +{ +BUG_ON (direction & ~1 ); + i->type =ITER_XARRAY | (direction & (READ |WRITE )); + i->xarray = xarray; + i->xarray_start = start; + i->count = count; + i->iov_offset =0 ; +} +EXPORT_SYMBOL (iov_iter_xarray); +/** * iov_iter_discard - Initialise an I/O iterator that discards data * @i: The iterator to initialise. @@ -1246,7 +1349,8 @@ unsigned long iov_iter_alignment(const struct iov_iter *i)iterate_all_kinds (i, size, v, (res |= (unsigned long )v.iov_base | v.iov_len,0 ), res |= v.bv_offset | v.bv_len, - res |= (unsigned long )v.iov_base | v.iov_len + res |= (unsigned long )v.iov_base | v.iov_len, + res |= v.bv_offset | v.bv_len )return res; }@@ -1268,7 +1372,9 @@ unsigned long iov_iter_gap_alignment(const struct iov_iter *i) (res |= (!res ?0 : (unsigned long )v.bv_offset) | (size != v.bv_len ? size :0 )), (res |= (!res ?0 : (unsigned long )v.iov_base) | - (size != v.iov_len ? size :0 )) + (size != v.iov_len ? size :0 )), + (res |= (!res ?0 : (unsigned long )v.bv_offset) | + (size != v.bv_len ? size :0 )) );return res; }
lib/iov_iter.c static ssize_t pipe_get_pages(struct iov_iter *i, · line 1428
Quoted 5 lines
lib/iov_iter.c +2
-0@@ -1318,6 +1424,75 @@ static ssize_t pipe_get_pages(struct iov_iter *i,return __pipe_get_pages (i,min (maxsize, capacity), pages, iter_head, start); } +static ssize_t iter_xarray_copy_pages (struct page **pages,struct xarray *xa, +pgoff_t index,unsigned int nr_pages)
nit: This could use a different name -- I was expecting to see page _contents_ copied here, but it's just populating the page array with pointers.
Quoted 248 lines
lib/iov_iter.c +158
-4+{ +XA_STATE (xas, xa, index); +struct page *page; +unsigned int ret =0 ; + +rcu_read_lock (); +for (page =xas_load (&xas); page; page =xas_next (&xas)) { +if (xas_retry (&xas, page)) +continue ; + +/* Has the page moved or been split? */ +if (unlikely (page !=xas_reload (&xas))) { +xas_reset (&xas); +continue ; + } + + pages[ret] =find_subpage (page, xas.xa_index); +get_page (pages[ret]); +if (++ret == nr_pages) +break ; + } +rcu_read_unlock (); +return ret; +} + +static ssize_t iter_xarray_get_pages (struct iov_iter *i, +struct page **pages,size_t maxsize, +unsigned maxpages,size_t *_start_offset) +{ +unsigned nr, offset; +pgoff_t index, count; +size_t size = maxsize, actual; +loff_t pos; + +if (!size || !maxpages) +return 0 ; + + pos = i->xarray_start + i->iov_offset; + index = pos >>PAGE_SHIFT ; + offset = pos & ~PAGE_MASK ; + *_start_offset = offset; + + count =1 ; +if (size >PAGE_SIZE - offset) { + size -=PAGE_SIZE - offset; + count += size >>PAGE_SHIFT ; + size &= ~PAGE_MASK ; +if (size) + count++; + } + +if (count > maxpages) + count = maxpages; + + nr =iter_xarray_copy_pages (pages, i->xarray, index, count); +if (nr ==0 ) +return 0 ; + + actual =PAGE_SIZE * nr; + actual -= offset; +if (nr == count && size >0 ) { +unsigned last_offset = (nr >1 ) ?0 : offset; + actual -=PAGE_SIZE - (last_offset + size); + } +return actual; +} +ssize_t iov_iter_get_pages (struct iov_iter *i,struct page **pages,size_t maxsize,unsigned maxpages,size_t *start)@@ -1327,6 +1502,8 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,if (unlikely (iov_iter_is_pipe (i)))return pipe_get_pages (i, pages, maxsize, maxpages, start); +if (unlikely (iov_iter_is_xarray (i))) +return iter_xarray_get_pages (i, pages, maxsize, maxpages, start);if (unlikely (iov_iter_is_discard (i)))return -EFAULT ;@@ -1353,7 +1530,8 @@ ssize_t iov_iter_get_pages(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }) + }), + 0 )return 0 ; }@@ -1397,6 +1575,51 @@ static ssize_t pipe_get_pages_alloc(struct iov_iter *i,return n; } +static ssize_t iter_xarray_get_pages_alloc (struct iov_iter *i, +struct page ***pages,size_t maxsize, +size_t *_start_offset) +{ +struct page **p; +unsigned nr, offset; +pgoff_t index, count; +size_t size = maxsize, actual; +loff_t pos; + +if (!size) +return 0 ; + + pos = i->xarray_start + i->iov_offset; + index = pos >>PAGE_SHIFT ; + offset = pos & ~PAGE_MASK ; + *_start_offset = offset; + + count =1 ; +if (size >PAGE_SIZE - offset) { + size -=PAGE_SIZE - offset; + count += size >>PAGE_SHIFT ; + size &= ~PAGE_MASK ; +if (size) + count++; + } + + p =get_pages_array (count); +if (!p) +return -ENOMEM ; + *pages = p; + + nr =iter_xarray_copy_pages (p, i->xarray, index, count); +if (nr ==0 ) +return 0 ; + + actual =PAGE_SIZE * nr; + actual -= offset; +if (nr == count && size >0 ) { +unsigned last_offset = (nr >1 ) ?0 : offset; + actual -=PAGE_SIZE - (last_offset + size); + } +return actual; +} +ssize_t iov_iter_get_pages_alloc (struct iov_iter *i,struct page ***pages,size_t maxsize,size_t *start)@@ -1408,6 +1631,8 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,if (unlikely (iov_iter_is_pipe (i)))return pipe_get_pages_alloc (i, pages, maxsize, start); +if (unlikely (iov_iter_is_xarray (i))) +return iter_xarray_get_pages_alloc (i, pages, maxsize, start);if (unlikely (iov_iter_is_discard (i)))return -EFAULT ;@@ -1440,7 +1665,7 @@ ssize_t iov_iter_get_pages_alloc(struct iov_iter *i,return v.bv_len; }),({return -EFAULT ; - }) + }), 0 )return 0 ; }@@ -1478,6 +1703,13 @@ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, v.iov_base, v.iov_len, sum, off); off += v.iov_len; + }), ({ +char *p =kmap_atomic (v.bv_page); + sum =csum_and_memcpy ((to += v.bv_len) - v.bv_len, + p + v.bv_offset, v.bv_len, + sum, off); +kunmap_atomic (p); + off += v.bv_len; }) ) *csum = sum;@@ -1519,6 +1751,13 @@ bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, v.iov_base, v.iov_len, sum, off); off += v.iov_len; + }), ({ +char *p =kmap_atomic (v.bv_page); + sum =csum_and_memcpy ((to += v.bv_len) - v.bv_len, + p + v.bv_offset, v.bv_len, + sum, off); +kunmap_atomic (p); + off += v.bv_len; }) ) *csum = sum;@@ -1565,6 +1804,13 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, (from += v.iov_len) - v.iov_len, v.iov_len, sum, off); off += v.iov_len; + }), ({ + char *p = kmap_atomic(v.bv_page); + sum = csum_and_memcpy(p + v.bv_offset, + (from += v.bv_len) - v.bv_len, + v.bv_len, sum, off); + kunmap_atomic(p); + off += v.bv_len; }) ) csstate->csum = sum;@@ -1615,6 +1861,21 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) npages =pipe_space_for_user (iter_head, pipe->tail, pipe);if (npages >= maxpages)return maxpages; + }else if (unlikely (iov_iter_is_xarray (i))) { +unsigned offset; + + offset = (i->xarray_start + i->iov_offset) & ~PAGE_MASK ; + + npages =1 ; +if (size >PAGE_SIZE - offset) { + size -=PAGE_SIZE - offset; + npages += size >>PAGE_SHIFT ; + size &= ~PAGE_MASK ; +if (size) + npages++; + } +if (npages >= maxpages) +return maxpages; } else iterate_all_kinds(i, size, v, ({ unsigned long p = (unsigned long)v.iov_base; npages += DIV_ROUND_UP(p + v.iov_len, PAGE_SIZE)@@ -1631,7 +1892,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages) - p /PAGE_SIZE ;if (npages >= maxpages)return maxpages; - }) + }), + 0 )return npages; }@@ -1644,7 +1906,7 @@ const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags)WARN_ON (1 );return NULL ; } -if (unlikely (iov_iter_is_discard (new))) +if (unlikely (iov_iter_is_discard (new) ||iov_iter_is_xarray (new)))return NULL ;if (iov_iter_is_bvec (new)) return new->bvec = kmemdup(new->bvec,@@ -1849,7 +2111,12 @@ int iov_iter_for_each_range(struct iov_iter *i, size_t bytes,kunmap (v.bv_page); err;}), ({ w = v;
lib/iov_iter.c int iov_iter_for_each_range(struct iov_iter *i, size_t bytes, · line 2122
Quoted 10 lines
lib/iov_iter.c +6
-1- err = f(&w, context);}) + err = f(&w, context);}), ({ + w.iov_base = kmap(v.bv_page) + v.bv_offset; + w.iov_len = v.bv_len; + err = f(&w, context); + kunmap(v.bv_page); + err;}) )return err; }
I think you've planned to remove iov_iter_for_each_range as well? I'll assume that this is going away. It might be nice to post the latest version of this patch with that change, just for posterity.
In any case, this all looks reasonable to me, modulo a few nits and a general dearth of comments.
David Howells
maintainerRe: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
Quoted 3 lines · Jeff Layton
As a general note,
iov_iter.ccould really do with some (verbose) comments explaining things. A kerneldoc header that explains the arguments toiterate_all_kindswould sure make this easier to review.
Definitely. But that really requires a separate patch.
Quoted 8 lines
Quoted 8 lines
lib/iov_iter.c +3
-1@@ -1126,7 +1199,12 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)return ; } unroll -= i->iov_offset; -if (iov_iter_is_bvec (i)) { +if (iov_iter_is_xarray (i)) { +BUG ();/* We should never go beyond the start of the specified +* range since we might then be straying into pages that
Quoted 8 lines
lib/iov_iter.c void iov_iter_revert(struct iov_iter *i, size_t unroll) · line 1206
Quoted 2 lines
lib/iov_iter.c +2
-0+* aren't pinned. +*/ It's not needed now, but there are a lot of calls to
iov_iter_revertin the kernel, and going backward doesn't necessarily mean we'd be straying into an unpinned range.xarray_startnever changes; would it not be ok to allow reverting as long as you don't move to a lower offset than that point?
This is handled starting a couple of lines above the start of the hunk:
if (unroll <= i->iov_offset) {
i->iov_offset -= unroll;
return;
}As long as the amount you want to unroll by doesn't exceed the amount you've consumed of the iterator, it will allow you to do it. The BUG is there to catch someone attempting to over-revert (and there's no way to return an error).
Quoted 6 lines
lib/iov_iter.c static ssize_t pipe_get_pages(struct iov_iter *i, · line 1428
Quoted 2 lines
lib/iov_iter.c +2
-0+static ssize_t iter_xarray_copy_pages (struct page **pages,struct xarray *xa, +pgoff_t index,unsigned int nr_pages)nit: This could use a different name -- I was expecting to see page _contents_ copied here, but it's just populating the page array with pointers.
Fair point. Um... how about iter_xarray_populate_pages() or iter_xarray_list_pages()?
Quoted 3 lines
I think you've planned to remove
iov_iter_for_each_rangeas well? I'll assume that this is going away. It might be nice to post the latest version of this patch with that change, just for posterity.
I'll put that in a separate patch.
Quoted 4 lines
In any case, this all looks reasonable to me, modulo a few nits and a general dearth of comments.
Reviewed-by Jeff Layton <[email protected]>
Thanks,
David
Jeff Layton
maintainerRe: [PATCH v6 01/30] iov_iter: Add ITER_XARRAY
Quoted 8 lines · David Howells
Quoted 3 lines · Jeff Layton
As a general note,
iov_iter.ccould really do with some (verbose) comments explaining things. A kerneldoc header that explains the arguments toiterate_all_kindswould sure make this easier to review.Definitely. But that really requires a separate patch.
I suppose.
Quoted 24 lines
Quoted 8 lines
Quoted 8 lines
lib/iov_iter.c +3
-1@@ -1126,7 +1199,12 @@ void iov_iter_revert(struct iov_iter *i, size_t unroll)return ; } unroll -= i->iov_offset; -if (iov_iter_is_bvec (i)) { +if (iov_iter_is_xarray (i)) { +BUG ();/* We should never go beyond the start of the specified +* range since we might then be straying into pages that Quoted 8 lines
lib/iov_iter.c void iov_iter_revert(struct iov_iter *i, size_t unroll) · line 1206
Quoted 2 lines
lib/iov_iter.c +2
-0+* aren't pinned. +*/ It's not needed now, but there are a lot of calls to
iov_iter_revertin the kernel, and going backward doesn't necessarily mean we'd be straying into an unpinned range.xarray_startnever changes; would it not be ok to allow reverting as long as you don't move to a lower offset than that point?This is handled starting a couple of lines above the start of the hunk:
if (unroll <= i->iov_offset) { i->iov_offset -= unroll; return; }
Quoted 5 lines
As long as the amount you want to unroll by doesn't exceed the amount you've consumed of the iterator, it will allow you to do it. The BUG is there to catch someone attempting to over-revert (and there's no way to return an error).
Ahh thanks. I misread that bit. That makes sense. Sucks about having to BUG() there, but I'm not sure what else you can do.
Quoted 10 lines
Quoted 6 lines
lib/iov_iter.c static ssize_t pipe_get_pages(struct iov_iter *i, · line 1428
Quoted 2 lines
lib/iov_iter.c +2
-0+static ssize_t iter_xarray_copy_pages (struct page **pages,struct xarray *xa, +pgoff_t index,unsigned int nr_pages)nit: This could use a different name -- I was expecting to see page _contents_ copied here, but it's just populating the page array with pointers.
Fair point. Um... how about
iter_xarray_populate_pages()oriter_xarray_list_pages()?
I like "populate" better.
Quoted 6 lines
Quoted 3 lines
I think you've planned to remove
iov_iter_for_each_rangeas well? I'll assume that this is going away. It might be nice to post the latest version of this patch with that change, just for posterity.I'll put that in a separate patch.
Quoted 8 lines
Quoted 4 lines
In any case, this all looks reasonable to me, modulo a few nits and a general dearth of comments.
Reviewed-by Jeff Layton <[email protected]>Thanks,
David
Cheers,
Signature · 1 line
Jeff Layton <[email protected]>
David Howells
maintainerPATCH v6 2/30 mm: Add set/end/wait functions for PG_private_2
In reply to David HowellsAdd three functions to manipulate PG_private_2:
(*) set_page_private_2() - Set the flag and take an appropriate reference
on the flagged page.
(*) end_page_private_2() - Clear the flag, drop the reference and wake up
any waiters, somewhat analogously with end_page_writeback().
(*) wait_on_page_private_2() - Wait for the flag to be cleared.
Wrappers will need to be placed in the netfs lib header in the patch that adds that.
[This implements a suggestion by Linus[1] to not mix the terminology of
PG_private_2 and PG_fscache in the mm core function]
Changes:
v5:
- Add set and end functions, calling the end function end rather than unlock[3].
- Keep a ref on the page when PG_private_2 is set[4][5].
v4:
- Remove extern from the declaration[2].
---
include/linux/pagemap.h | 19 +++++++++++++++ mm/filemap.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
include/linux/pagemap.h +19 -0
@@ -688,6 +688,25 @@ void wait_for_stable_page(struct page *page);void page_endio (struct page *page,bool is_write,int err); +/** +* set_page_private_2 - Set PG_private_2 on a page and take a ref +* @page: The page. +* +* Set the PG_private_2 flag on a page and take the reference needed for the VM +* to handle its lifetime correctly. This sets the flag and takes the +* reference unconditionally, so care must be taken not to set the flag again +* if it's already set. +*/ +static inline void set_page_private_2 (struct page *page) +{ +get_page (page); +SetPagePrivate2 (page); +} + +void end_page_private_2 (struct page *page); +void wait_on_page_private_2 (struct page *page); +int wait_on_page_private_2_killable (struct page *page); +/* * Add an arbitrary waiter to a page's wait queue */
mm/filemap.c +59 -0
65 lines not on this page · raw message
Matthew Wilcox
maintainerRe: [PATCH v6 02/30] mm: Add set/end/wait functions for PG_private_2
include/linux/pagemap.h void wait_for_stable_page(struct page *page); · line 703
Quoted 4 lines · David Howells
include/linux/pagemap.h +4
-0+static inline void set_page_private_2 (struct page *page) +{ +get_page (page); +SetPagePrivate2 (page);
PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)
So we can set Private2 on any tail page ...
mm/filemap.c void unlock_page(struct page *page) · line 1451
Quoted 6 lines
mm/filemap.c +6
-0+void end_page_private_2 (struct page *page) +{ + page =compound_head (page); +VM_BUG_ON_PAGE (!PagePrivate2 (page), page); +clear_bit_unlock (PG_private_2, &page->flags); +wake_up_page_bit (page, PG_private_2);
... but when we try to end on a tail, we actually wake up the head ...
mm/filemap.c void unlock_page(struct page *page) · line 1465
Quoted 4 lines
mm/filemap.c +4
-0+void wait_on_page_private_2 (struct page *page) +{ +while (PagePrivate2 (page)) +wait_on_page_bit (page, PG_private_2);
... although if we were waiting on a tail, the wake up won't find us ...
if only we had a way to ensure this kind of bug can't happen *cough, lend your support to the page folio patches*.
David Howells
maintainerRe: [PATCH v6 02/30] mm: Add set/end/wait functions for PG_private_2
Quoted 8 lines · Matthew Wilcox
mm/filemap.c void unlock_page(struct page *page) · line 1451
Quoted 6 lines
mm/filemap.c +6
-0+void end_page_private_2 (struct page *page) +{ + page =compound_head (page); +VM_BUG_ON_PAGE (!PagePrivate2 (page), page); +clear_bit_unlock (PG_private_2, &page->flags); +wake_up_page_bit (page, PG_private_2);... but when we try to end on a tail, we actually wake up the head ...
Question is, should I remove compound_head() here or add it into the other functions?
David
David Howells
maintainerRe: [PATCH v6 02/30] mm: Add set/end/wait functions for PG_private_2
In reply to Matthew WilcoxHere's a partial change, but we still need to deal with the assumption that page_has_private() makes that its output can be used to count the number of refs held for PG_private *and* PG_private_2 - which isn't true for my code here.
David
---
commit e7c28d83b84b972c3faa0dd86020548aa50eda75
Author: David Howells <[email protected]> Date: Thu Apr 8 16:33:20 2021 +0100
netfs: Fix PG_private_2 helper functions to consistently use compound_head()
include/linux/pagemap.h +1 -0
@@ -699,6 +699,7 @@ void page_endio(struct page *page, bool is_write, int err);*/ static inline void set_page_private_2 (struct page *page) { + page =compound_head (page);get_page (page);SetPagePrivate2 (page); }
mm/filemap.c +2 -0
@@ -1461,6 +1461,7 @@ EXPORT_SYMBOL(end_page_private_2);*/ void wait_on_page_private_2 (struct page *page) { + page =compound_head (page);while (PagePrivate2 (page))wait_on_page_bit (page, PG_private_2); }
@@ -1481,6 +1482,7 @@ int wait_on_page_private_2_killable(struct page *page) {int ret =0 ; + page =compound_head (page);while (PagePrivate2 (page)) { ret =wait_on_page_bit_killable (page, PG_private_2);if (ret <0 )
David Howells
maintainerRFC PATCH 1/1 mm: Split page_has_private() in two to better handle PG_private_2
Hi Willy, Linus,
How about this to handle the situation with PG_private_2? I think it handles things according to Linus's suggestion.
David
---
mm: Split page_has_private() in two to better handle PG_private_2
Split page_has_private() into two functions:
(1) page_needs_cleanup() to find out if a page needs the ->releasepage(), ->invalidatepage(), etc. address space ops calling upon it.
This returns true when either PG_private or PG_private_2 are set.
(2) page_private_count() which returns a count of the number of refs contributed to a page for attached private data.
This returns 1 if PG_private is set and 0 otherwise.
I think the suggestion[1] is that PG_private_2 should just have a ref on the page, but this isn't accounted in the same way as PG_private's ref.
Notes:
(*) The following:
btrfs_migratepage()
iomap_set_range_uptodate()
iomap_migrate_page()
to_iomap_page()
should probably all use PagePrivate() rather than page_has_private() since they're interested in what's attached to page->private when they're doing this, and not PG_private_2.
It may not matter in these cases since page->private is probably NULL if PG_private is not set.
(*) Do we actually need PG_private, or is it possible just to see if
page->private is NULL?
(*) There's a lot of "if (page_has_private()) try_to_release_page()"
combos. Does it make sense to create a inline function for this?
--- fs/btrfs/disk-io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ext4/move_extent.c | 8 ++++---- fs/fuse/dev.c | 2 +- fs/iomap/buffered-io.c | 6 +++--- fs/splice.c | 2 +- include/linux/page-flags.h | 17 +++++++++++++++-- include/trace/events/pagemap.h | 2 +- mm/khugepaged.c | 4 ++-- mm/migrate.c | 10 +++++----- mm/readahead.c | 2 +- mm/truncate.c | 12 ++++++------ mm/vmscan.c | 12 ++++++------ 13 files changed, 47 insertions(+), 34 deletions(-)
fs/btrfs/disk-io.c +1 -1
@@ -936,7 +936,7 @@ static int btree_migratepage(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return -EAGAIN ;return migrate_page (mapping, newpage, page, mode);
fs/btrfs/inode.c +1 -1
@@ -8333,7 +8333,7 @@ static int btrfs_migratepage(struct address_space *mapping,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (page_has_private (page)) +if (PagePrivate (page))attach_page_private (newpage,detach_page_private (page));if (PagePrivate2 (page)) {
fs/ext4/move_extent.c +4 -4
@@ -329,9 +329,9 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,ext4_double_up_write_data_sem (orig_inode, donor_inode); goto data_copy; } -if ((page_has_private (pagep[0 ]) && +if ((page_needs_cleanup (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || - (page_has_private (pagep[1 ]) && + (page_needs_cleanup (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { *err = -EBUSY ; goto drop_data_sem;
@@ -351,8 +351,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,/* At this point all buffers in range are uptodate, old mapping layout * is no longer required, try to drop it now. */ -if ((page_has_private (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || - (page_has_private (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { +if ((page_needs_cleanup (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || + (page_needs_cleanup (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { *err = -EBUSY ; goto unlock_pages; }
fs/fuse/dev.c +1 -1
@@ -837,7 +837,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)*/ if (WARN_ON (page_mapped (oldpage))) goto out_fallback_unlock; -if (WARN_ON (page_has_private (oldpage))) +if (WARN_ON (page_needs_cleanup (oldpage))) goto out_fallback_unlock;if (WARN_ON (PageDirty (oldpage) ||PageWriteback (oldpage))) goto out_fallback_unlock;
fs/iomap/buffered-io.c +3 -3
@@ -41,7 +41,7 @@ static inline struct iomap_page *to_iomap_page(struct page *page)*/ VM_BUG_ON_PGFLAGS (PageTail (page), page); -if (page_has_private (page)) +if (page_needs_cleanup (page))return (struct iomap_page *)page_private (page);return NULL ; }
@@ -163,7 +163,7 @@ iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)if (PageError (page))return ; -if (page_has_private (page)) +if (PagePrivate (page))iomap_iop_set_range_uptodate (page, off, len);else SetPageUptodate (page);
@@ -502,7 +502,7 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (page_has_private (page)) +if (PagePrivate (page))attach_page_private (newpage,detach_page_private (page));if (mode !=MIGRATE_SYNC_NO_COPY )
fs/splice.c +1 -1
@@ -65,7 +65,7 @@ static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,*/ wait_on_page_writeback (page); -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL )) goto out_unlock;
include/linux/page-flags.h +15 -2
@@ -832,14 +832,27 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2) + +/** +* page_private_count - Find out how many refs a page's private data contribute +* @page: The page to be checked +* +* Return the contribution to the pagecount of the private data attached to a +* page. +*/ +static inline int page_private_count (struct page *page) +{ +return test_bit (PG_private, &page->flags) ?1 :0 ; +} +/** -* page_has_private - Determine if page has private stuff +* page_needs_cleanup - Determine if page has private stuff that needs cleaning * @page: The page to be checked * * Determine if a page has private stuff, indicating that release routines * should be invoked upon it. */ -static inline int page_has_private (struct page *page) +static inline int page_needs_cleanup (struct page *page) {return !!(page->flags &PAGE_FLAGS_PRIVATE ); }
include/trace/events/pagemap.h +1 -1
@@ -22,7 +22,7 @@ (PageSwapCache (page) ?PAGEMAP_SWAPCACHE :0 ) | \ (PageSwapBacked (page) ?PAGEMAP_SWAPBACKED :0 ) | \ (PageMappedToDisk (page) ?PAGEMAP_MAPPEDDISK :0 ) | \ - (page_has_private (page) ?PAGEMAP_BUFFERS :0 ) \ + (page_needs_cleanup (page) ?PAGEMAP_BUFFERS :0 ) \ ) TRACE_EVENT(mm_lru_insertion,
mm/khugepaged.c +2 -2
@@ -1822,7 +1822,7 @@ static void collapse_file(struct mm_struct *mm, goto out_unlock; } -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL )) { result =SCAN_PAGE_HAS_PRIVATE ;putback_lru_page (page);
@@ -2019,7 +2019,7 @@ static void khugepaged_scan_file(struct mm_struct *mm, }if (page_count (page) != -1 +page_mapcount (page) +page_has_private (page)) { +1 +page_mapcount (page) +page_private_count (page)) { result =SCAN_PAGE_COUNT ;break ; }
mm/migrate.c +5 -5
@@ -382,7 +382,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page)*/ expected_count +=is_device_private_page (page);if (mapping) - expected_count +=thp_nr_pages (page) +page_has_private (page); + expected_count +=thp_nr_pages (page) +page_private_count (page);return expected_count; }
@@ -530,7 +530,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping,int expected_count;xas_lock_irq (&xas); - expected_count =2 +page_has_private (page); + expected_count =2 +page_private_count (page);if (page_count (page) != expected_count ||xas_load (&xas) != page) {xas_unlock_irq (&xas);return -EAGAIN ;
@@ -924,7 +924,7 @@ static int fallback_migrate_page(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return mode ==MIGRATE_SYNC ? -EAGAIN : -EBUSY ;
@@ -1117,7 +1117,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,*/ if (!page->mapping) {VM_BUG_ON_PAGE (PageAnon (page), page); -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {try_to_free_buffers (page); goto out_unlock_both; }
@@ -2618,7 +2618,7 @@ static bool migrate_vma_check_page(struct page *page)/* For file back page */ if (page_mapping (page)) - extra +=1 +page_has_private (page); + extra +=1 +page_private_count (page);if ((page_count (page) - extra) >page_mapcount (page))return false;
mm/readahead.c +1 -1
@@ -48,7 +48,7 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);static void read_cache_pages_invalidate_page (struct address_space *mapping,struct page *page) { -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (!trylock_page (page))BUG (); page->mapping = mapping;
mm/truncate.c +6 -6
@@ -176,7 +176,7 @@ truncate_cleanup_page(struct address_space *mapping, struct page *page)unmap_mapping_pages (mapping, page->index, nr, false); } -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page,0 ,thp_size (page));/*
@@ -204,7 +204,7 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (page_has_private (page) && !try_to_release_page (page,0 )) +if (page_needs_cleanup (page) && !try_to_release_page (page,0 ))return 0 ; ret =remove_mapping (mapping, page);
@@ -346,7 +346,7 @@ void truncate_inode_pages_range(struct address_space *mapping,wait_on_page_writeback (page);zero_user_segment (page, partial_start, top);cleancache_invalidate_page (mapping, page); -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page, partial_start, top - partial_start);unlock_page (page);
@@ -359,7 +359,7 @@ void truncate_inode_pages_range(struct address_space *mapping,wait_on_page_writeback (page);zero_user_segment (page,0 , partial_end);cleancache_invalidate_page (mapping, page); -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page,0 , partial_end);unlock_page (page);
@@ -581,14 +581,14 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;xa_lock_irqsave (&mapping->i_pages, flags);if (PageDirty (page)) goto failed; -BUG_ON (page_has_private (page)); +BUG_ON (page_needs_cleanup (page));__delete_from_page_cache (page,NULL );xa_unlock_irqrestore (&mapping->i_pages, flags);
mm/vmscan.c +6 -6
@@ -725,7 +725,7 @@ static inline int is_page_cache_freeable(struct page *page)* heads at page->private. */ int page_cache_pins =thp_nr_pages (page); -return page_count (page) -page_has_private (page) ==1 + page_cache_pins; +return page_count (page) -page_private_count (page) ==1 + page_cache_pins; }static int may_write_to_inode (struct inode *inode)
@@ -801,7 +801,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping)* Some data journaling orphaned pages can have * page->mapping == NULL while being dirty with clean buffers. */ -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (try_to_free_buffers (page)) {ClearPageDirty (page);pr_info ("%s: orphaned page\n" , __func__);
@@ -1057,7 +1057,7 @@ static void page_check_dirty_writeback(struct page *page, *writeback =PageWriteback (page);/* Verify dirty/writeback state if the filesystem supports it */ -if (!page_has_private (page)) +if (!page_needs_cleanup (page))return ; mapping =page_mapping (page);
@@ -1399,7 +1399,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,* process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. */ -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (!try_to_release_page (page, sc->gfp_mask)) goto activate_locked;if (!mapping &&page_count (page) ==1 ) {
@@ -2050,8 +2050,8 @@ static void shrink_active_list(unsigned long nr_to_scan, }if (unlikely (buffer_heads_over_limit)) { -if (page_has_private (page) &&trylock_page (page)) { -if (page_has_private (page)) +if (page_needs_cleanup (page) &&trylock_page (page)) { +if (page_needs_cleanup (page))try_to_release_page (page,0 );unlock_page (page); }
Re: [RFC][PATCH] mm: Split page_has_private() in two to better handle PG_private_2
Quoted 2 lines · David Howells
mm: Split
page_has_private()in two to better handlePG_private_2
From a look through the patch and some (limited) thinking about it, I like the patch. I think it clarifies the two very different cases, and makes it clear that one is about that page cleanup, and the other is about the magical reference counting. The two are separate issues, even if for PG_private both happen to be true.
So this seems sane to me.
That said, I had a couple of reactions:
include/linux/page-flags.h static inline void ClearPageSlabPfmemalloc(struct page *page) · line 834
Quoted 8 lines
include/linux/page-flags.h +0
-0@@ -832,14 +832,27 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2)
I think this should be re-named to be PAGE_FLAGS_CLEANUP, because I don't think it makes any other sense to "combine" the two PG_private* bits any more. No?
include/linux/page-flags.h static inline void ClearPageSlabPfmemalloc(struct page *page) · line 846
Quoted 4 lines
include/linux/page-flags.h +4
-0+static inline int page_private_count (struct page *page) +{ +return test_bit (PG_private, &page->flags) ?1 :0 ; +}
Why is this open-coding the bit test, rather than just doing
return PagePrivate(page) ? 1 : 0;
instead? In fact, since test_bit() _should_ return a 'bool', I think even just
return PagePrivate(page);
should work and give the same result, but I could imagine that some architecture version of "test_bit()" might return some other non-zero value (although honestly, I think that should be fixed if so).
Linus
David Howells
maintainerRe: [RFC][PATCH] mm: Split page_has_private() in two to better handle PG_private_2
Quoted 6 lines · Linus Torvalds
Quoted 2 lines
#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2)I think this should be re-named to be
PAGE_FLAGS_CLEANUP, because I don't think it makes any other sense to "combine" the two PG_private* bits any more. No?
Sure. Do we even want it still, or should I just fold it into page_needs_cleanup()? It seems to be the only place it's used.
Quoted 7 lines
include/linux/page-flags.h static inline void ClearPageSlabPfmemalloc(struct page *page) · line 846
Quoted 4 lines
include/linux/page-flags.h +4
-0+static inline int page_private_count (struct page *page) +{ +return test_bit (PG_private, &page->flags) ?1 :0 ; +}Why is this open-coding the bit test, rather than just doing
Quoted 5 lines
return PagePrivate(page) ? 1 : 0;instead? In fact, since
test_bit()_should_ return a 'bool', I think even justreturn PagePrivate(page);
Sorry, yes, it should be that. I was looking at transforming the "1 << PG_private" and completely overlooked that this should be PagePrivate().
Quoted 3 lines
should work and give the same result, but I could imagine that some architecture version of "
test_bit()" might return some other non-zero value (although honestly, I think that should be fixed if so).
Yeah. I seem to recall that test_bit() on some arches used to return the datum just with the other bits masked off, but I may be misremembering.
In asm-generic/bitops/non-atomic.h:
static inline int test_bit(int nr, const volatile unsigned long *addr)
{
return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
}should perhaps return bool?
I wonder, should:
static __always_inline int PageTail(struct page *page) static __always_inline int PageCompound(struct page *page) static __always_inline int Page##uname(struct page *page) static __always_inline int TestSetPage##uname(struct page *page) static __always_inline int TestClearPage##uname(struct page *page)
also all return bool?
David
David Howells
maintainerRFC PATCH 1/3 Make the generic bitops return bool
In reply to Linus TorvaldsMake the generic bitops return bool when returning the value of a tested bit.
---
include/asm-generic/bitops/atomic.h | 6 +++--- include/asm-generic/bitops/le.h | 10 +++++----- include/asm-generic/bitops/lock.h | 4 ++-- include/asm-generic/bitops/non-atomic.h | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-)
include/asm-generic/bitops/atomic.h +3 -3
@@ -29,7 +29,7 @@ static __always_inline void change_bit(unsigned int nr, volatile unsigned long *atomic_long_xor (BIT_MASK (nr), (atomic_long_t *)p); } -static inline int test_and_set_bit (unsigned int nr,volatile unsigned long *p) +static inline bool test_and_set_bit (unsigned int nr,volatile unsigned long *p) {long old;unsigned long mask =BIT_MASK (nr);
@@ -42,7 +42,7 @@ static inline int test_and_set_bit(unsigned int nr, volatile unsigned long *p)return !!(old & mask); } -static inline int test_and_clear_bit (unsigned int nr,volatile unsigned long *p) +static inline bool test_and_clear_bit (unsigned int nr,volatile unsigned long *p) {long old;unsigned long mask =BIT_MASK (nr);
@@ -55,7 +55,7 @@ static inline int test_and_clear_bit(unsigned int nr, volatile unsigned long *p)return !!(old & mask); } -static inline int test_and_change_bit (unsigned int nr,volatile unsigned long *p) +static inline bool test_and_change_bit (unsigned int nr,volatile unsigned long *p) {long old;unsigned long mask =BIT_MASK (nr);
include/asm-generic/bitops/le.h +5 -5
@@ -50,7 +50,7 @@ extern unsigned long find_next_bit_le(const void *addr,#error "Please fix <asm/byteorder.h>"#endif -static inline int test_bit_le (int nr,const void *addr) +static inline bool test_bit_le (int nr,const void *addr) {return test_bit (nr ^BITOP_LE_SWIZZLE , addr); }
@@ -75,22 +75,22 @@ static inline void __clear_bit_le(int nr, void *addr)__clear_bit (nr ^BITOP_LE_SWIZZLE , addr); } -static inline int test_and_set_bit_le (int nr,void *addr) +static inline bool test_and_set_bit_le (int nr,void *addr) {return test_and_set_bit (nr ^BITOP_LE_SWIZZLE , addr); } -static inline int test_and_clear_bit_le (int nr,void *addr) +static inline bool test_and_clear_bit_le (int nr,void *addr) {return test_and_clear_bit (nr ^BITOP_LE_SWIZZLE , addr); } -static inline int __test_and_set_bit_le (int nr,void *addr) +static inline bool __test_and_set_bit_le (int nr,void *addr) {return __test_and_set_bit (nr ^BITOP_LE_SWIZZLE , addr); } -static inline int __test_and_clear_bit_le (int nr,void *addr) +static inline bool __test_and_clear_bit_le (int nr,void *addr) {return __test_and_clear_bit (nr ^BITOP_LE_SWIZZLE , addr); }
include/asm-generic/bitops/lock.h +2 -2
@@ -15,8 +15,8 @@* the returned value is 0. * It can be used to implement bit locks. */ -static inline int test_and_set_bit_lock (unsigned int nr, -volatile unsigned long *p) +static inline bool test_and_set_bit_lock (unsigned int nr, +volatile unsigned long *p) {long old;unsigned long mask =BIT_MASK (nr);
include/asm-generic/bitops/non-atomic.h +4 -4
@@ -55,7 +55,7 @@ static inline void __change_bit(int nr, volatile unsigned long *addr)* If two examples of this operation race, one can appear to succeed * but actually fail. You must protect multiple accesses with a lock. */ -static inline int __test_and_set_bit (int nr,volatile unsigned long *addr) +static inline bool __test_and_set_bit (int nr,volatile unsigned long *addr) {unsigned long mask =BIT_MASK (nr);unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr);
@@ -74,7 +74,7 @@ static inline int __test_and_set_bit(int nr, volatile unsigned long *addr)* If two examples of this operation race, one can appear to succeed * but actually fail. You must protect multiple accesses with a lock. */ -static inline int __test_and_clear_bit (int nr,volatile unsigned long *addr) +static inline bool __test_and_clear_bit (int nr,volatile unsigned long *addr) {unsigned long mask =BIT_MASK (nr);unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr);
@@ -85,7 +85,7 @@ static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) }/* WARNING: non atomic and it can be reordered! */ -static inline int __test_and_change_bit (int nr, +static inline bool __test_and_change_bit (int nr,volatile unsigned long *addr) {unsigned long mask =BIT_MASK (nr);
@@ -101,7 +101,7 @@ static inline int __test_and_change_bit(int nr,* @nr: bit number to test * @addr: Address to start counting from */ -static inline int test_bit (int nr,const volatile unsigned long *addr) +static inline bool test_bit (int nr,const volatile unsigned long *addr) {return 1UL & (addr[BIT_WORD (nr)] >> (nr & (BITS_PER_LONG -1 ))); }
David Howells
maintainerRFC PATCH 2/3 mm: Return bool from pagebit test functions
In reply to Linus TorvaldsMake functions that test page bits return a bool, not an int. This means that the value is definitely 0 or 1 if they're used in arithmetic, rather than rely on test_bit() and friends to return this (though they probably should).
---
include/linux/page-flags.h | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
include/linux/page-flags.h +25 -25
@@ -188,18 +188,18 @@ static inline struct page *compound_head(struct page *page)return page; } -static __always_inline int PageTail(struct page *page) +static __always_inline bool PageTail(struct page *page) {return READ_ONCE (page->compound_head) &1 ; } -static __always_inline int PageCompound(struct page *page) +static __always_inline bool PageCompound(struct page *page) {return test_bit (PG_head, &page->flags) ||PageTail (page); }#define PAGE_POISON_PATTERN -1l -static inline int PagePoisoned (const struct page *page) +static inline bool PagePoisoned (const struct page *page) {return page->flags ==PAGE_POISON_PATTERN ; }
@@ -260,7 +260,7 @@ static inline void page_init_poison(struct page *page, size_t size)* Macros to create function definitions for page flags */ #define TESTPAGEFLAG (uname, lname, policy) \ -static __always_inline int Page##uname(struct page *page) \ +static __always_inline bool Page##uname(struct page *page) \ { return test_bit(PG_##lname, &policy(page, 0)->flags); }#define SETPAGEFLAG (uname, lname, policy) \
@@ -280,11 +280,11 @@ static __always_inline void __ClearPage##uname(struct page *page) \ { __clear_bit(PG_##lname, &policy(page, 1)->flags); }#define TESTSETFLAG (uname, lname, policy) \ -static __always_inline int TestSetPage##uname(struct page *page) \ +static __always_inline bool TestSetPage##uname(struct page *page) \ { return test_and_set_bit(PG_##lname, &policy(page, 1)->flags); }#define TESTCLEARFLAG (uname, lname, policy) \ -static __always_inline int TestClearPage##uname(struct page *page) \ +static __always_inline bool TestClearPage##uname(struct page *page) \ { return test_and_clear_bit(PG_##lname, &policy(page, 1)->flags); }#define PAGEFLAG (uname, lname, policy) \
@@ -302,7 +302,7 @@ static __always_inline int TestClearPage##uname(struct page *page) \ TESTCLEARFLAG(uname, lname, policy)#define TESTPAGEFLAG_FALSE (uname) \ -static inline int Page##uname(const struct page *page) { return 0; } +static inline bool Page##uname(const struct page *page) { return false; }#define SETPAGEFLAG_NOOP (uname) \ static inline void SetPage##uname(struct page *page) { }
@@ -314,10 +314,10 @@ static inline void ClearPage##uname(struct page *page) { } static inline void __ClearPage##uname(struct page *page) { }#define TESTSETFLAG_FALSE (uname) \ -static inline int TestSetPage##uname(struct page *page) { return 0; } +static inline bool TestSetPage##uname(struct page *page) { return false; }#define TESTCLEARFLAG_FALSE (uname) \ -static inline int TestClearPage##uname(struct page *page) { return 0; } +static inline bool TestClearPage##uname(struct page *page) { return false; }#define PAGEFLAG_FALSE (uname) TESTPAGEFLAG_FALSE(uname) \ SETPAGEFLAG_NOOP(uname) CLEARPAGEFLAG_NOOP(uname)
@@ -393,7 +393,7 @@ PAGEFLAG_FALSE(HighMem)#endif #ifdef CONFIG_SWAP -static __always_inline int PageSwapCache(struct page *page) +static __always_inline bool PageSwapCache(struct page *page) {#ifdef CONFIG_THP_SWAP page =compound_head (page);
@@ -473,18 +473,18 @@ __PAGEFLAG(Reported, reported, PF_NO_COMPOUND)#define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE)#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) -static __always_inline int PageMappingFlags(struct page *page) +static __always_inline bool PageMappingFlags(struct page *page) {return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) !=0 ; } -static __always_inline int PageAnon(struct page *page) +static __always_inline bool PageAnon(struct page *page) { page =compound_head (page);return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ; } -static __always_inline int __PageMovable(struct page *page) +static __always_inline bool __PageMovable(struct page *page) {return ((unsigned long )page->mapping &PAGE_MAPPING_FLAGS ) ==PAGE_MAPPING_MOVABLE ;
@@ -497,7 +497,7 @@ static __always_inline int __PageMovable(struct page *page)* is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any * anon_vma, but to that page's node of the stable tree. */ -static __always_inline int PageKsm(struct page *page) +static __always_inline bool PageKsm(struct page *page) { page =compound_head (page); return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
@@ -509,9 +509,9 @@ TESTPAGEFLAG_FALSE(Ksm)u64 stable_page_flags (struct page *page); -static inline int PageUptodate (struct page *page) +static inline bool PageUptodate (struct page *page) { -int ret; +bool ret; page =compound_head (page); ret =test_bit (PG_uptodate, &(page)->flags);/*
@@ -607,7 +607,7 @@ TESTPAGEFLAG_FALSE(HeadHuge)* hugetlbfs pages, but not normal pages. PageTransHuge() can only be * called only in the core VM paths where hugetlbfs pages can't exist. */ -static inline int PageTransHuge (struct page *page) +static inline bool PageTransHuge (struct page *page) {VM_BUG_ON_PAGE (PageTail (page), page);return PageHead (page);
@@ -618,7 +618,7 @@ static inline int PageTransHuge(struct page *page)* and hugetlbfs pages, so it should only be called when it's known * that hugetlbfs pages aren't involved. */ -static inline int PageTransCompound (struct page *page) +static inline bool PageTransCompound (struct page *page) {return PageCompound (page); }
@@ -644,12 +644,12 @@ static inline int PageTransCompound(struct page *page)* mapped in the current process so comparing subpage's _mapcount to * compound_mapcount to filter out PTE mapped case. */ -static inline int PageTransCompoundMap (struct page *page) +static inline bool PageTransCompoundMap (struct page *page) {struct page *head;if (!PageTransCompound (page)) -return 0 ; +return false;if (PageAnon (page))return atomic_read (&page->_mapcount) <0 ;
@@ -665,7 +665,7 @@ static inline int PageTransCompoundMap(struct page *page)* and hugetlbfs pages, so it should only be called when it's known * that hugetlbfs pages aren't involved. */ -static inline int PageTransTail (struct page *page) +static inline bool PageTransTail (struct page *page) {return PageTail (page); }
@@ -714,13 +714,13 @@ PAGEFLAG_FALSE(DoubleMap)#define PageType (page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) -static inline int page_has_type (struct page *page) +static inline bool page_has_type (struct page *page) {return (int )page->page_type <PAGE_MAPCOUNT_RESERVE ; }#define PAGE_TYPE_OPS (uname, lname) \ -static __always_inline int Page##uname(struct page *page) \ +static __always_inline bool Page##uname(struct page *page) \ { \ return PageType(page, PG_##lname); \ } \
@@ -778,7 +778,7 @@ __PAGEFLAG(Isolated, isolated, PF_ANY);* If network-based swap is enabled, sl*b must keep track of whether pages * were allocated from pfmemalloc reserves. */ -static inline int PageSlabPfmemalloc (struct page *page) +static inline bool PageSlabPfmemalloc (struct page *page) {VM_BUG_ON_PAGE (!PageSlab (page), page);return PageActive (page);
@@ -839,7 +839,7 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)* Determine if a page has private stuff, indicating that release routines * should be invoked upon it. */ -static inline int page_has_private (struct page *page) +static inline bool page_has_private (struct page *page) {return !!(page->flags &PAGE_FLAGS_PRIVATE ); }
Matthew Wilcox
maintainerRe: [RFC PATCH 2/3] mm: Return bool from pagebit test functions
Quoted 4 lines · David Howells
Make functions that test page bits return a bool, not an int. This means that the value is definitely 0 or 1 if they're used in arithmetic, rather than rely on
test_bit()and friends to return this (though they probably should).
iirc i looked at doing this as part of the folio work, and it ended up increasing the size of the kernel. Did you run bloat-o-meter on the result of doing this?
David Howells
maintainerRe: [RFC PATCH 2/3] mm: Return bool from pagebit test functions
Quoted 9 lines · Matthew Wilcox
Quoted 4 lines · David Howells
Make functions that test page bits return a bool, not an int. This means that the value is definitely 0 or 1 if they're used in arithmetic, rather than rely on
test_bit()and friends to return this (though they probably should).iirc i looked at doing this as part of the folio work, and it ended up increasing the size of the kernel. Did you run bloat-o-meter on the result of doing this?
Hmmm. With my usual monolithic x86_64 kernel, it makes vmlinux text section 100 bytes larger (19392347 rather than 19392247). I can look into why.
David
David Howells
maintainerRe: [RFC PATCH 2/3] mm: Return bool from pagebit test functions
In reply to Matthew WilcoxQuoted 3 lines · Matthew Wilcox
iirc i looked at doing this as part of the folio work, and it ended up increasing the size of the kernel. Did you run bloat-o-meter on the result of doing this?
add/remove: 2/2 grow/shrink: 15/16 up/down: 408/-599 (-191)
Function old new delta iomap_write_end_inline - 128 +128 try_to_free_swap 59 179 +120 page_to_index.part - 36 +36 page_size 432 456 +24 PageTransCompound 154 175 +21 truncate_inode_pages_range 791 807 +16 invalidate_inode_pages2_range 504 518 +14 ceph_uninline_data 969 982 +13 iomap_read_inline_data.isra 129 139 +10 page_cache_pipe_buf_confirm 85 93 +8 ceph_writepages_start 3237 3243 +6 hpage_pincount_available 94 97 +3 __collapse_huge_page_isolate 768 771 +3 page_vma_mapped_walk 1070 1072 +2 PageHuge 39 41 +2 collapse_file 2046 2047 +1 __free_pages_ok 449 450 +1 wait_on_page_bit_common 598 597 -1 iomap_page_release 104 103 -1 change_pte_range 818 817 -1 pageblock_skip_persistent 45 42 -3 is_transparent_hugepage 63 60 -3 nfs_readpage 486 482 -4 ext4_readpage_inline 155 151 -4 release_pages 640 635 -5 ext4_write_inline_data_end 286 281 -5 ext4_mb_load_buddy_gfp 690 684 -6 afs_dir_check 536 529 -7 page_trans_huge_map_swapcount 374 363 -11 io_uring_mmap 199 184 -15 io_buffer_account_pin 276 259 -17 page_to_index 50 - -50 iomap_write_end 375 306 -69 try_to_free_swap.part 137 - -137 PageUptodate 716 456 -260
Total: Before=17207139, After=17206948, chg -0.00%
David Howells
maintainerRe: [RFC PATCH 2/3] mm: Return bool from pagebit test functions
Quoted 3 lines · David Howells
add/remove: 2/2 grow/shrink: 15/16 up/down: 408/-599 (-191)
Function old new deltaiomap_write_end_inline- 128 +128
I can get rid of the iomap_write_end_inline() increase for my config by marking it __always_inline, thereby getting:
add/remove: 1/2 grow/shrink: 15/15 up/down: 280/-530 (-250)
It seems that the decision whether or not to inline iomap_write_end_inline() is affected by the switch to bool.
David
David Howells
maintainerRFC PATCH 3/3 mm: Split page_has_private() in two to better handle PG_private_2
In reply to Linus TorvaldsSplit page_has_private() into two functions:
(1) page_needs_cleanup() to find out if a page needs the ->releasepage(), ->invalidatepage(), etc. address space ops calling upon it.
This returns true when either PG_private or PG_private_2 are set.
(2) page_private_count() which returns a count of the number of refs contributed to a page for attached private data.
This returns 1 if PG_private is set and 0 otherwise.
I think suggestion[1] is that PG_private_2 should just have a ref on the page, but this isn't accounted in the same way as PG_private's ref.
Notes:
(*) The following:
btrfs_migratepage()
iomap_set_range_uptodate()
iomap_migrate_page()
to_iomap_page()
should probably all use PagePrivate() rather than page_has_private()
since they're interested in what's attached to page->private when
they're doing this, and not PG_private_2.
It may not matter in these cases since page->private is probably NULL
if PG_private is not set. (*) Do we actually need PG_private, or is it possible just to see if
page->private is NULL?
(*) There's a lot of "if (page_has_private()) try_to_release_page()"
combos. Does it make sense to have a pot this into an inline function?
---
arch/s390/kernel/uv.c | 2 +- fs/btrfs/disk-io.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ext4/move_extent.c | 8 ++++---- fs/fuse/dev.c | 2 +- fs/iomap/buffered-io.c | 6 +++--- fs/splice.c | 2 +- include/linux/page-flags.h | 21 +++++++++++++++++---- include/trace/events/pagemap.h | 2 +- mm/khugepaged.c | 4 ++-- mm/memory-failure.c | 2 +- mm/migrate.c | 10 +++++----- mm/readahead.c | 2 +- mm/truncate.c | 12 ++++++------ mm/vmscan.c | 12 ++++++------ 15 files changed, 51 insertions(+), 38 deletions(-)
arch/s390/kernel/uv.c +1 -1
@@ -175,7 +175,7 @@ static int expected_page_refs(struct page *page) res++; }else if (page_mapping (page)) { res++; -if (page_has_private (page)) +if (page_private_count (page)) res++; }return res;
fs/btrfs/disk-io.c +1 -1
@@ -936,7 +936,7 @@ static int btree_migratepage(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return -EAGAIN ;return migrate_page (mapping, newpage, page, mode);
fs/btrfs/inode.c +1 -1
@@ -8333,7 +8333,7 @@ static int btrfs_migratepage(struct address_space *mapping,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (page_has_private (page)) +if (PagePrivate (page))attach_page_private (newpage,detach_page_private (page));if (PagePrivate2 (page)) {
fs/ext4/move_extent.c +4 -4
@@ -329,9 +329,9 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,ext4_double_up_write_data_sem (orig_inode, donor_inode); goto data_copy; } -if ((page_has_private (pagep[0 ]) && +if ((page_needs_cleanup (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || - (page_has_private (pagep[1 ]) && + (page_needs_cleanup (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { *err = -EBUSY ; goto drop_data_sem;
@@ -351,8 +351,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,/* At this point all buffers in range are uptodate, old mapping layout * is no longer required, try to drop it now. */ -if ((page_has_private (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || - (page_has_private (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { +if ((page_needs_cleanup (pagep[0 ]) && !try_to_release_page (pagep[0 ],0 )) || + (page_needs_cleanup (pagep[1 ]) && !try_to_release_page (pagep[1 ],0 ))) { *err = -EBUSY ; goto unlock_pages; }
fs/fuse/dev.c +1 -1
@@ -837,7 +837,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)*/ if (WARN_ON (page_mapped (oldpage))) goto out_fallback_unlock; -if (WARN_ON (page_has_private (oldpage))) +if (WARN_ON (page_needs_cleanup (oldpage))) goto out_fallback_unlock;if (WARN_ON (PageDirty (oldpage) ||PageWriteback (oldpage))) goto out_fallback_unlock;
fs/iomap/buffered-io.c +3 -3
@@ -41,7 +41,7 @@ static inline struct iomap_page *to_iomap_page(struct page *page)*/ VM_BUG_ON_PGFLAGS (PageTail (page), page); -if (page_has_private (page)) +if (page_needs_cleanup (page))return (struct iomap_page *)page_private (page);return NULL ; }
@@ -163,7 +163,7 @@ iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)if (PageError (page))return ; -if (page_has_private (page)) +if (PagePrivate (page))iomap_iop_set_range_uptodate (page, off, len);else SetPageUptodate (page);
@@ -502,7 +502,7 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (page_has_private (page)) +if (PagePrivate (page))attach_page_private (newpage,detach_page_private (page));if (mode !=MIGRATE_SYNC_NO_COPY )
fs/splice.c +1 -1
@@ -65,7 +65,7 @@ static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,*/ wait_on_page_writeback (page); -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL )) goto out_unlock;
include/linux/page-flags.h +17 -4
@@ -830,18 +830,31 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)#define PAGE_FLAGS_CHECK_AT_PREP \ (((1UL << NR_PAGEFLAGS) - 1) & ~__PG_HWPOISON) -#define PAGE_FLAGS_PRIVATE \ +#define PAGE_FLAGS_CLEANUP \ (1UL << PG_private | 1UL << PG_private_2) + +/** +* page_private_count - Find out how many refs a page's private data contribute +* @page: The page to be checked +* +* Return the contribution to the pagecount of the private data attached to a +* page. +*/ +static inline int page_private_count (struct page *page) +{ +return PagePrivate (page); +} +/** -* page_has_private - Determine if page has private stuff +* page_needs_cleanup - Determine if page has private stuff that needs cleaning * @page: The page to be checked * * Determine if a page has private stuff, indicating that release routines * should be invoked upon it. */ -static inline bool page_has_private (struct page *page) +static inline bool page_needs_cleanup (struct page *page) { -return !!(page->flags &PAGE_FLAGS_PRIVATE ); +return page->flags &PAGE_FLAGS_CLEANUP ; }#undef PF_ANY
include/trace/events/pagemap.h +1 -1
@@ -22,7 +22,7 @@ (PageSwapCache (page) ?PAGEMAP_SWAPCACHE :0 ) | \ (PageSwapBacked (page) ?PAGEMAP_SWAPBACKED :0 ) | \ (PageMappedToDisk (page) ?PAGEMAP_MAPPEDDISK :0 ) | \ - (page_has_private (page) ?PAGEMAP_BUFFERS :0 ) \ + (page_needs_cleanup (page) ?PAGEMAP_BUFFERS :0 ) \ ) TRACE_EVENT(mm_lru_insertion,
mm/khugepaged.c +2 -2
@@ -1822,7 +1822,7 @@ static void collapse_file(struct mm_struct *mm, goto out_unlock; } -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL )) { result =SCAN_PAGE_HAS_PRIVATE ;putback_lru_page (page);
@@ -2019,7 +2019,7 @@ static void khugepaged_scan_file(struct mm_struct *mm, }if (page_count (page) != -1 +page_mapcount (page) +page_has_private (page)) { +1 +page_mapcount (page) +page_private_count (page)) { result =SCAN_PAGE_COUNT ;break ; }
mm/memory-failure.c +1 -1
@@ -629,7 +629,7 @@ static int truncate_error_page(struct page *p, unsigned long pfn,if (err !=0 ) {pr_info ("Memory failure: %#lx: Failed to punch page: %d\n" , pfn, err); - }else if (page_has_private (p) && + }else if (page_needs_cleanup (p) && !try_to_release_page (p,GFP_NOIO )) {pr_info ("Memory failure: %#lx: failed to release buffers\n" , pfn);
mm/migrate.c +5 -5
@@ -382,7 +382,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page)*/ expected_count +=is_device_private_page (page);if (mapping) - expected_count +=thp_nr_pages (page) +page_has_private (page); + expected_count +=thp_nr_pages (page) +page_private_count (page);return expected_count; }
@@ -530,7 +530,7 @@ int migrate_huge_page_move_mapping(struct address_space *mapping,int expected_count;xas_lock_irq (&xas); - expected_count =2 +page_has_private (page); + expected_count =2 +page_private_count (page);if (page_count (page) != expected_count ||xas_load (&xas) != page) {xas_unlock_irq (&xas);return -EAGAIN ;
@@ -924,7 +924,7 @@ static int fallback_migrate_page(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (page_has_private (page) && +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return mode ==MIGRATE_SYNC ? -EAGAIN : -EBUSY ;
@@ -1117,7 +1117,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage,*/ if (!page->mapping) {VM_BUG_ON_PAGE (PageAnon (page), page); -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {try_to_free_buffers (page); goto out_unlock_both; }
@@ -2618,7 +2618,7 @@ static bool migrate_vma_check_page(struct page *page)/* For file back page */ if (page_mapping (page)) - extra +=1 +page_has_private (page); + extra +=1 +page_private_count (page);if ((page_count (page) - extra) >page_mapcount (page))return false;
mm/readahead.c +1 -1
@@ -48,7 +48,7 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);static void read_cache_pages_invalidate_page (struct address_space *mapping,struct page *page) { -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (!trylock_page (page))BUG (); page->mapping = mapping;
mm/truncate.c +6 -6
@@ -176,7 +176,7 @@ truncate_cleanup_page(struct address_space *mapping, struct page *page)unmap_mapping_pages (mapping, page->index, nr, false); } -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page,0 ,thp_size (page));/*
@@ -204,7 +204,7 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (page_has_private (page) && !try_to_release_page (page,0 )) +if (page_needs_cleanup (page) && !try_to_release_page (page,0 ))return 0 ; ret =remove_mapping (mapping, page);
@@ -346,7 +346,7 @@ void truncate_inode_pages_range(struct address_space *mapping,wait_on_page_writeback (page);zero_user_segment (page, partial_start, top);cleancache_invalidate_page (mapping, page); -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page, partial_start, top - partial_start);unlock_page (page);
@@ -359,7 +359,7 @@ void truncate_inode_pages_range(struct address_space *mapping,wait_on_page_writeback (page);zero_user_segment (page,0 , partial_end);cleancache_invalidate_page (mapping, page); -if (page_has_private (page)) +if (page_needs_cleanup (page))do_invalidatepage (page,0 , partial_end);unlock_page (page);
@@ -581,14 +581,14 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_needs_cleanup (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;xa_lock_irqsave (&mapping->i_pages, flags);if (PageDirty (page)) goto failed; -BUG_ON (page_has_private (page)); +BUG_ON (page_needs_cleanup (page));__delete_from_page_cache (page,NULL );xa_unlock_irqrestore (&mapping->i_pages, flags);
mm/vmscan.c +6 -6
@@ -725,7 +725,7 @@ static inline int is_page_cache_freeable(struct page *page)* heads at page->private. */ int page_cache_pins =thp_nr_pages (page); -return page_count (page) -page_has_private (page) ==1 + page_cache_pins; +return page_count (page) -page_private_count (page) ==1 + page_cache_pins; }static int may_write_to_inode (struct inode *inode)
@@ -801,7 +801,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping)* Some data journaling orphaned pages can have * page->mapping == NULL while being dirty with clean buffers. */ -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (try_to_free_buffers (page)) {ClearPageDirty (page);pr_info ("%s: orphaned page\n" , __func__);
@@ -1057,7 +1057,7 @@ static void page_check_dirty_writeback(struct page *page, *writeback =PageWriteback (page);/* Verify dirty/writeback state if the filesystem supports it */ -if (!page_has_private (page)) +if (!page_needs_cleanup (page))return ; mapping =page_mapping (page);
@@ -1399,7 +1399,7 @@ static unsigned int shrink_page_list(struct list_head *page_list,* process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. */ -if (page_has_private (page)) { +if (page_needs_cleanup (page)) {if (!try_to_release_page (page, sc->gfp_mask)) goto activate_locked;if (!mapping &&page_count (page) ==1 ) {
@@ -2050,8 +2050,8 @@ static void shrink_active_list(unsigned long nr_to_scan, }if (unlikely (buffer_heads_over_limit)) { -if (page_has_private (page) &&trylock_page (page)) { -if (page_has_private (page)) +if (page_needs_cleanup (page) &&trylock_page (page)) { +if (page_needs_cleanup (page))try_to_release_page (page,0 );unlock_page (page); }
Matthew Wilcox
maintainerRe: [RFC PATCH 3/3] mm: Split page_has_private() in two to better handle PG_private_2
fs/iomap/buffered-io.c static inline struct iomap_page *to_iomap_page(struct page *page) · line 44
Quoted 10 lines · David Howells
fs/iomap/buffered-io.c +1
-1@@ -41,7 +41,7 @@ static inline struct iomap_page *to_iomap_page(struct page *page)*/ VM_BUG_ON_PGFLAGS (PageTail (page), page); -if (page_has_private (page)) +if (page_needs_cleanup (page))
That should be PagePrivate(page)
Quoted 21 lines
fs/iomap/buffered-io.c +2
-2return (struct iomap_page *)page_private (page);return NULL ; }@@ -163,7 +163,7 @@ iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len)if (PageError (page))return ; -if (page_has_private (page)) +if (PagePrivate (page))iomap_iop_set_range_uptodate (page, off, len);else SetPageUptodate (page);@@ -502,7 +502,7 @@ iomap_migrate_page(struct address_space *mapping, struct page *newpage,if (ret !=MIGRATEPAGE_SUCCESS )return ret; -if (page_has_private (page)) +if (PagePrivate (page))attach_page_private (newpage,detach_page_private (page));if (mode !=MIGRATE_SYNC_NO_COPY )
kernel test robot
build botRe: [RFC][PATCH] mm: Split page_has_private() in two to better handle PG_private_2
In reply to David Howells[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi David,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on kdave/for-next]
[also build test ERROR on ext4/dev fuse/for-next xfs-linux/for-next tip/perf/core linux/master linus/master v5.12-rc6 next-20210408] [cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/David-Howells/mm-Split-page_has_private-in-two-to-better-handle-PG_private_2/20210409-051632 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next config: s390-debug_defconfig (attached as .config) compiler: s390-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/a00a255f7bf637156368e8545b2c64e39c93718b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Howells/mm-Split-page_has_private-in-two-to-better-handle-PG_private_2/20210409-051632 git checkout a00a255f7bf637156368e8545b2c64e39c93718b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/s390/kernel/uv.c: In function 'expected_page_refs':
>> arch/s390/kernel/uv.c:178:7: error: implicit declaration of function 'page_has_private'; did you mean 'page_private'? [-Werror=implicit-function-declaration]
178 | if (page_has_private(page))
| ^~~~~~~~~~~~~~~~
| page_privatecc1: some warnings being treated as errors
vim +178 arch/s390/kernel/uv.c
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 162
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 163 /*
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 164 * Calculate the expected ref_count for a page that would otherwise have no
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 165 * further pins. This was cribbed from similar functions in other places in
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 166 * the kernel, but with some slight modifications. We know that a secure
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 167 * page can not be a huge page for example.
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 168 */
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 169 static int expected_page_refs(struct page *page)
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 170 {
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 171 int res;
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 172
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 173 res = page_mapcount(page);
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 174 if (PageSwapCache(page)) {
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 175 res++;
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 176 } else if (page_mapping(page)) {
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 177 res++;
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 @178 if (page_has_private(page))
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 179 res++;
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 180 }
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 181 return res;
214d9bbcd3a672 Claudio Imbrenda 2020-01-21 182 }214d9bbcd3a672 Claudio Imbrenda 2020-01-21 183
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [RFC][PATCH] mm: Split page_has_private() in two to better handle PG_private_2
In reply to David Howells[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi David,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on kdave/for-next]
[also build test ERROR on ext4/dev fuse/for-next xfs-linux/for-next tip/perf/core linux/master linus/master v5.12-rc6 next-20210409] [cannot apply to hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/David-Howells/mm-Split-page_has_private-in-two-to-better-handle-PG_private_2/20210409-051632 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next config: x86_64-randconfig-a005-20210409 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project dd453a1389b6a7e6d9214b449d3c54981b1a89b6)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/a00a255f7bf637156368e8545b2c64e39c93718b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Howells/mm-Split-page_has_private-in-two-to-better-handle-PG_private_2/20210409-051632 git checkout a00a255f7bf637156368e8545b2c64e39c93718b
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> mm/memory-failure.c:632:14: error: implicit declaration of function 'page_has_private' [-Werror,-Wimplicit-function-declaration]
} else if (page_has_private(p) &&
^1 error generated.
vim +/page_has_private +632 mm/memory-failure.c
dc2a1cbf7d862e9 Wu Fengguang 2009-12-16 620
78bb920344b8a6f Naoya Horiguchi 2017-07-10 621 static int truncate_error_page(struct page *p, unsigned long pfn,
78bb920344b8a6f Naoya Horiguchi 2017-07-10 622 struct address_space *mapping)
78bb920344b8a6f Naoya Horiguchi 2017-07-10 623 {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 624 int ret = MF_FAILED;
78bb920344b8a6f Naoya Horiguchi 2017-07-10 625
78bb920344b8a6f Naoya Horiguchi 2017-07-10 626 if (mapping->a_ops->error_remove_page) {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 627 int err = mapping->a_ops->error_remove_page(mapping, p);
78bb920344b8a6f Naoya Horiguchi 2017-07-10 628
78bb920344b8a6f Naoya Horiguchi 2017-07-10 629 if (err != 0) {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 630 pr_info("Memory failure: %#lx: Failed to punch page: %d\n",
78bb920344b8a6f Naoya Horiguchi 2017-07-10 631 pfn, err);
78bb920344b8a6f Naoya Horiguchi 2017-07-10 @632 } else if (page_has_private(p) &&
78bb920344b8a6f Naoya Horiguchi 2017-07-10 633 !try_to_release_page(p, GFP_NOIO)) {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 634 pr_info("Memory failure: %#lx: failed to release buffers\n",
78bb920344b8a6f Naoya Horiguchi 2017-07-10 635 pfn);
78bb920344b8a6f Naoya Horiguchi 2017-07-10 636 } else {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 637 ret = MF_RECOVERED;
78bb920344b8a6f Naoya Horiguchi 2017-07-10 638 }
78bb920344b8a6f Naoya Horiguchi 2017-07-10 639 } else {
78bb920344b8a6f Naoya Horiguchi 2017-07-10 640 /*
78bb920344b8a6f Naoya Horiguchi 2017-07-10 641 * If the file system doesn't support it just invalidate
78bb920344b8a6f Naoya Horiguchi 2017-07-10 642 * This fails on dirty or anything with private pages
78bb920344b8a6f Naoya Horiguchi 2017-07-10 643 */
78bb920344b8a6f Naoya Horiguchi 2017-07-10 644 if (invalidate_inode_page(p))
78bb920344b8a6f Naoya Horiguchi 2017-07-10 645 ret = MF_RECOVERED;
78bb920344b8a6f Naoya Horiguchi 2017-07-10 646 else
78bb920344b8a6f Naoya Horiguchi 2017-07-10 647 pr_info("Memory failure: %#lx: Failed to invalidate\n",
78bb920344b8a6f Naoya Horiguchi 2017-07-10 648 pfn);
78bb920344b8a6f Naoya Horiguchi 2017-07-10 649 }
78bb920344b8a6f Naoya Horiguchi 2017-07-10 650
78bb920344b8a6f Naoya Horiguchi 2017-07-10 651 return ret;
78bb920344b8a6f Naoya Horiguchi 2017-07-10 652 }
78bb920344b8a6f Naoya Horiguchi 2017-07-10 653 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
David Howells
maintainerPATCH v7 1/1 mm: Add set/end/wait functions for PG_private_2
In reply to Matthew WilcoxAdd three functions to manipulate PG_private_2:
(*) set_page_private_2() - Set the flag and take an appropriate reference
on the flagged page.
(*) end_page_private_2() - Clear the flag, drop the reference and wake up
any waiters, somewhat analogously with end_page_writeback().
(*) wait_on_page_private_2() - Wait for the flag to be cleared.
Wrappers will need to be placed in the netfs lib header in the patch that adds that.
[This implements a suggestion by Linus[1] to not mix the terminology of
PG_private_2 and PG_fscache in the mm core function]
Changes:
v7:
- Use compound_head() in all the functions to make them THP safe[6].
v5:
- Add set and end functions, calling the end function end rather than unlock[3].
- Keep a ref on the page when PG_private_2 is set[4][5].
v4:
- Remove extern from the declaration[2].
--- include/linux/pagemap.h | 20 +++++++++++++++ mm/filemap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)
include/linux/pagemap.h +20 -0
@@ -688,6 +688,26 @@ void wait_for_stable_page(struct page *page);void page_endio (struct page *page,bool is_write,int err); +/** +* set_page_private_2 - Set PG_private_2 on a page and take a ref +* @page: The page. +* +* Set the PG_private_2 flag on a page and take the reference needed for the VM +* to handle its lifetime correctly. This sets the flag and takes the +* reference unconditionally, so care must be taken not to set the flag again +* if it's already set. +*/ +static inline void set_page_private_2 (struct page *page) +{ + page =compound_head (page); +get_page (page); +SetPagePrivate2 (page); +} + +void end_page_private_2 (struct page *page); +void wait_on_page_private_2 (struct page *page); +int wait_on_page_private_2_killable (struct page *page); +/* * Add an arbitrary waiter to a page's wait queue */
mm/filemap.c +61 -0
67 lines not on this page · raw message
Re: [PATCH v7] mm: Add set/end/wait functions for PG_private_2
Quoted 4 lines · David Howells
Suggested-by Linus Torvalds <[email protected]>Signed-off-by David Howells <[email protected]>Tested-by Jeff Layton <[email protected]>Tested-by Dave Wysochanski <[email protected]>
David Howells
maintainerPATCH v6 3/30 mm/filemap: Pass the file_ra_state in the ractl
In reply to David HowellsFrom: Matthew Wilcox (Oracle) <[email protected]>
For readahead_expand(), we need to modify the file ra_state, so pass it down by adding it to the ractl. We have to do this because it's not always the same as f_ra in the struct file that is already being passed.
---
fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- include/linux/pagemap.h | 20 +++++++++++--------- mm/filemap.c | 4 ++-- mm/internal.h | 7 +++---- mm/readahead.c | 22 +++++++++++----------- 7 files changed, 30 insertions(+), 29 deletions(-)
fs/ext4/verity.c +1 -1
@@ -370,7 +370,7 @@ static struct page *ext4_read_merkle_tree_page(struct inode *inode,pgoff_t index, unsigned long num_ra_pages) { - DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, index); + DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index);struct page *page; index +=ext4_verity_metadata_pos (inode) >>PAGE_SHIFT ;
fs/f2fs/file.c +1 -1
@@ -4051,7 +4051,7 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)static int redirty_blocks (struct inode *inode,pgoff_t page_idx,int len) { -DEFINE_READAHEAD (ractl,NULL , inode->i_mapping, page_idx); +DEFINE_READAHEAD (ractl,NULL ,NULL , inode->i_mapping, page_idx);struct address_space *mapping = inode->i_mapping;struct page *page;pgoff_t redirty_idx = page_idx;
fs/f2fs/verity.c +1 -1
@@ -228,7 +228,7 @@ static struct page *f2fs_read_merkle_tree_page(struct inode *inode,pgoff_t index, unsigned long num_ra_pages) { - DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, index); + DEFINE_READAHEAD(ractl, NULL, NULL, inode->i_mapping, index);struct page *page; index +=f2fs_verity_metadata_pos (inode) >>PAGE_SHIFT ;
include/linux/pagemap.h +11 -9
@@ -811,20 +811,23 @@ static inline int add_to_page_cache(struct page *page,* @file: The file, used primarily by network filesystems for authentication. * May be NULL if invoked internally by the filesystem. * @mapping: Readahead this filesystem object. +* @ra: File readahead state. May be NULL. */ struct readahead_control {struct file *file;struct address_space *mapping; +struct file_ra_state *ra;/* private: use the readahead_* accessors instead */ pgoff_t _index;unsigned int _nr_pages;unsigned int _batch_count; }; -#define DEFINE_READAHEAD (rac, f, m, i) \ - struct readahead_control rac = { \ +#define DEFINE_READAHEAD (ractl, f, r, m, i) \ + struct readahead_control ractl = { \ .file = f, \ .mapping = m, \ + .ra = r, \ ._index = i, \ }
@@ -832,10 +835,9 @@ struct readahead_control {void page_cache_ra_unbounded (struct readahead_control *,unsigned long nr_to_read,unsigned long lookahead_count); -void page_cache_sync_ra (struct readahead_control *,struct file_ra_state *, +void page_cache_sync_ra (struct readahead_control *,unsigned long req_count); +void page_cache_async_ra (struct readahead_control *,struct page *,unsigned long req_count); -void page_cache_async_ra (struct readahead_control *,struct file_ra_state *, -struct page *,unsigned long req_count);/** * page_cache_sync_readahead - generic file readahead
@@ -855,8 +857,8 @@ void page_cache_sync_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, pgoff_t index, unsigned long req_count) { -DEFINE_READAHEAD (ractl ,file ,mapping ,index ); -page_cache_sync_ra (&ractl, ra, req_count); +DEFINE_READAHEAD (ractl ,file ,ra ,mapping ,index ); +page_cache_sync_ra (&ractl, req_count); }/**
@@ -878,8 +880,8 @@ void page_cache_async_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, struct page *page, pgoff_t index, unsigned long req_count) { -DEFINE_READAHEAD (ractl ,file ,mapping ,index ); -page_cache_async_ra (&ractl, ra, page, req_count); +DEFINE_READAHEAD (ractl ,file ,ra ,mapping ,index ); +page_cache_async_ra (&ractl, page, req_count); }/**
mm/filemap.c +2 -2
@@ -2830,7 +2830,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)struct file *file = vmf->vma->vm_file;struct file_ra_state *ra = &file->f_ra;struct address_space *mapping = file->f_mapping; -DEFINE_READAHEAD (ractl, file, mapping, vmf->pgoff); +DEFINE_READAHEAD (ractl, file, ra, mapping, vmf->pgoff);struct file *fpin =NULL ;unsigned int mmap_miss;
@@ -2842,7 +2842,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)if (vmf->vma->vm_flags &VM_SEQ_READ ) { fpin =maybe_unlock_mmap_for_io (vmf, fpin); -page_cache_sync_ra (&ractl, ra, ra->ra_pages); +page_cache_sync_ra (&ractl, ra->ra_pages);return fpin; }
mm/internal.h +3 -4
@@ -51,13 +51,12 @@ void unmap_page_range(struct mmu_gather *tlb,void do_page_cache_ra (struct readahead_control *,unsigned long nr_to_read,unsigned long lookahead_size); -void force_page_cache_ra (struct readahead_control *,struct file_ra_state *, -unsigned long nr); +void force_page_cache_ra (struct readahead_control *,unsigned long nr);static inline void force_page_cache_readahead (struct address_space *mapping,struct file *file,pgoff_t index,unsigned long nr_to_read) { -DEFINE_READAHEAD (ractl, file, mapping, index); -force_page_cache_ra (&ractl, &file->f_ra, nr_to_read); +DEFINE_READAHEAD (ractl, file, &file->f_ra, mapping, index); +force_page_cache_ra (&ractl, nr_to_read); } unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,
mm/readahead.c +11 -11
@@ -272,9 +272,10 @@ void do_page_cache_ra(struct readahead_control *ractl,* memory at once. */ void force_page_cache_ra (struct readahead_control *ractl, -struct file_ra_state *ra,unsigned long nr_to_read) +unsigned long nr_to_read) {struct address_space *mapping = ractl->mapping; +struct file_ra_state *ra = ractl->ra;struct backing_dev_info *bdi =inode_to_bdi (mapping->host);unsigned long max_pages, index;
@@ -433,10 +434,10 @@ static int try_context_readahead(struct address_space *mapping,* A minimal readahead algorithm for trivial sequential/random reads. */ static void ondemand_readahead (struct readahead_control *ractl, -struct file_ra_state *ra,bool hit_readahead_marker, -unsigned long req_size) +bool hit_readahead_marker,unsigned long req_size) {struct backing_dev_info *bdi =inode_to_bdi (ractl->mapping->host); +struct file_ra_state *ra = ractl->ra;unsigned long max_pages = ra->ra_pages;unsigned long add_pages;unsigned long index =readahead_index (ractl);
@@ -550,7 +551,7 @@ static void ondemand_readahead(struct readahead_control *ractl, }void page_cache_sync_ra (struct readahead_control *ractl, -struct file_ra_state *ra,unsigned long req_count) +unsigned long req_count) {bool do_forced_ra = ractl->file && (ractl->file->f_mode &FMODE_RANDOM );
@@ -560,7 +561,7 @@ void page_cache_sync_ra(struct readahead_control *ractl,* read-ahead will do the right thing and limit the read to just the * requested range, which we'll set to 1 page for this case. */ -if (!ra->ra_pages ||blk_cgroup_congested ()) { +if (!ractl->ra->ra_pages ||blk_cgroup_congested ()) {if (!ractl->file)return ; req_count =1 ;
@@ -569,21 +570,20 @@ void page_cache_sync_ra(struct readahead_control *ractl,/* be dumb */ if (do_forced_ra) { -force_page_cache_ra (ractl, ra, req_count); +force_page_cache_ra (ractl, req_count);return ; }/* do read-ahead */ -ondemand_readahead (ractl, ra, false, req_count); +ondemand_readahead (ractl, false, req_count); }EXPORT_SYMBOL_GPL (page_cache_sync_ra);void page_cache_async_ra (struct readahead_control *ractl, -struct file_ra_state *ra,struct page *page, -unsigned long req_count) +struct page *page,unsigned long req_count) {/* no read-ahead */ -if (!ra->ra_pages) +if (!ractl->ra->ra_pages)return ;/*
@@ -604,7 +604,7 @@ void page_cache_async_ra(struct readahead_control *ractl,return ;/* do read-ahead */ -ondemand_readahead (ractl, ra, true, req_count); +ondemand_readahead (ractl, true, req_count); }EXPORT_SYMBOL_GPL (page_cache_async_ra);
David Howells
maintainerPATCH v6 4/30 fs: Document file_ra_state
In reply to David HowellsFrom: Matthew Wilcox (Oracle) <[email protected]>
Turn the comments into kernel-doc and improve the wording slightly.
---
include/linux/fs.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
include/linux/fs.h +14 -10
@@ -891,18 +891,22 @@ struct fown_struct {int signum;/* posix.1b rt signal to be delivered on IO */ }; -/* -* Track a single file's readahead state +/** +* struct file_ra_state - Track a file's readahead state. +* @start: Where the most recent readahead started. +* @size: Number of pages read in the most recent readahead. +* @async_size: Start next readahead when this many pages are left. +* @ra_pages: Maximum size of a readahead request. +* @mmap_miss: How many mmap accesses missed in the page cache. +* @prev_pos: The last byte in the most recent read request. */ struct file_ra_state { -pgoff_t start;/* where readahead started */ -unsigned int size;/* # of readahead pages */ -unsigned int async_size;/* do asynchronous readahead when -there are only # of pages ahead */ - -unsigned int ra_pages;/* Maximum readahead window */ -unsigned int mmap_miss;/* Cache miss stat for mmap accesses */ -loff_t prev_pos;/* Cache last read() position */ +pgoff_t start; +unsigned int size; +unsigned int async_size; +unsigned int ra_pages; +unsigned int mmap_miss; +loff_t prev_pos; };/*
David Howells
maintainerPATCH v6 5/30 mm: Implement readahead_control pageset expansion
In reply to David HowellsProvide a function, readahead_expand(), that expands the set of pages specified by a readahead_control object to encompass a revised area with a proposed size and length.
The proposed area must include all of the old area and may be expanded yet more by this function so that the edges align on (transparent huge) page boundaries as allocated.
The expansion will be cut short if a page already exists in either of the areas being expanded into. Note that any expansion made in such a case is not rolled back.
This will be used by fscache so that reads can be expanded to cache granule boundaries, thereby allowing whole granules to be stored in the cache, but there are other potential users also.
Changes:
v6:
- Fold in a patch from Matthew Wilcox to tell the ondemand readahead algorithm about the expansion so that the next readahead starts at the right place[2].
v4:
- Moved the declaration of readahead_expand() to a better place[1].
---
include/linux/pagemap.h | 2 + mm/readahead.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
include/linux/pagemap.h +2 -0
@@ -838,6 +838,8 @@ void page_cache_ra_unbounded(struct readahead_control *,void page_cache_sync_ra (struct readahead_control *,unsigned long req_count);void page_cache_async_ra (struct readahead_control *,struct page *,unsigned long req_count); +void readahead_expand (struct readahead_control *ractl, +loff_t new_start,size_t new_len);/** * page_cache_sync_readahead - generic file readahead
mm/readahead.c +75 -0
78 lines not on this page · raw message
Re: [PATCH v6 05/30] mm: Implement readahead_control pageset expansion
Quoted 2 lines · David Howells
Suggested-by Matthew Wilcox (Oracle) <[email protected]>Signed-off-by David Howells <[email protected]>
David Howells
maintainerPATCH v6 6/30 netfs: Make a netfs helper module
In reply to David HowellsMake a netfs helper module to manage read request segmentation, caching support and transparent huge page support on behalf of a network filesystem.
---
fs/netfs/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 fs/netfs/Kconfig
fs/netfs/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config NETFS_SUPPORT + tristate "Support for network filesystem high-level I/O" + help + This option enables support for network filesystems, including + helpers for high-level buffered I/O, abstracting out read + segmentation, local caching and transparent huge page support.
David Howells
maintainerPATCH v6 7/30 netfs: Documentation for helper library
In reply to David HowellsAdd interface documentation for the netfs helper library.
---
Documentation/filesystems/index.rst | 1 Documentation/filesystems/netfs_library.rst | 526 +++++++++++++++++++++++++++ 2 files changed, 527 insertions(+) create mode 100644 Documentation/filesystems/netfs_library.rst
Documentation/filesystems/index.rst +1 -0
@@ -53,6 +53,7 @@ filesystem implementations. journalling fscrypt fsverity + netfs_library Filesystems ===========
Documentation/filesystems/netfs_library.rst new file +526 -0
526 lines not on this page · raw message
David Howells
maintainerPATCH v6 8/30 netfs, mm: Move PG_fscache helper funcs to linux/netfs.h
In reply to David HowellsMove the PG_fscache related helper funcs (such as SetPageFsCache()) to linux/netfs.h rather than linux/fscache.h as the intention is to move to a model where they're used by the network filesystem and the helper library, but not by fscache/cachefiles itself.
---
include/linux/fscache.h | 11 +---------- include/linux/netfs.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 include/linux/netfs.h
include/linux/fscache.h +1 -10
@@ -19,6 +19,7 @@#include <linux/pagemap.h> #include <linux/pagevec.h> #include <linux/list_bl.h> +#include <linux/netfs.h> #if defined(CONFIG_FSCACHE ) || defined(CONFIG_FSCACHE_MODULE )#define fscache_available () (1)
@@ -29,16 +30,6 @@#endif -/* -* overload PG_private_2 to give us PG_fscache - this is used to indicate that -* a page is currently backed by a local disk cache -*/ -#define PageFsCache (page) PagePrivate2((page)) -#define SetPageFsCache (page) SetPagePrivate2((page)) -#define ClearPageFsCache (page) ClearPagePrivate2((page)) -#define TestSetPageFsCache (page) TestSetPagePrivate2((page)) -#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) -/* pattern used to fill dead space in an index entry */ #define FSCACHE_INDEX_DEADFILL_PATTERN 0x79
include/linux/netfs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Network filesystem support services. +* +* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* See: +* +* Documentation/filesystems/netfs_library.rst +* +* for a description of the network filesystem interface declared here. +*/ + +#ifndef _LINUX_NETFS_H +#define _LINUX_NETFS_H + +#include <linux/pagemap.h> + +/* +* Overload PG_private_2 to give us PG_fscache - this is used to indicate that +* a page is currently backed by a local disk cache +*/ +#define PageFsCache (page) PagePrivate2((page)) +#define SetPageFsCache (page) SetPagePrivate2((page)) +#define ClearPageFsCache (page) ClearPagePrivate2((page)) +#define TestSetPageFsCache (page) TestSetPagePrivate2((page)) +#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) + +#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v6 9/30 netfs, mm: Add set/end/wait_on_page_fscache() aliases
In reply to David HowellsAdd set/end/wait_on_page_fscache() as aliases of set/end/wait_page_private_2(). These allow a page to marked with PG_fscache, the flag to be removed and waiters woken and waiting for the flag to be cleared. A ref on the page is also taken and dropped.
[Linus suggested putting the fscache-themed functions into the
caching-specific headers rather than pagemap.h[1]]
Changes:
v5:
- Mirror the changes to the core routines[2].
---
include/linux/netfs.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
include/linux/netfs.h +57 -0
@@ -26,4 +26,61 @@#define TestSetPageFsCache (page) TestSetPagePrivate2((page))#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) +/** +* set_page_fscache - Set PG_fscache on a page and take a ref +* @page: The page. +* +* Set the PG_fscache (PG_private_2) flag on a page and take the reference +* needed for the VM to handle its lifetime correctly. This sets the flag and +* takes the reference unconditionally, so care must be taken not to set the +* flag again if it's already set. +*/ +static inline void set_page_fscache (struct page *page) +{ +set_page_private_2 (page); +} + +/** +* end_page_fscache - Clear PG_fscache and release any waiters +* @page: The page +* +* Clear the PG_fscache (PG_private_2) bit on a page and wake up any sleepers +* waiting for this. The page ref held for PG_private_2 being set is released. +* +* This is, for example, used when a netfs page is being written to a local +* disk cache, thereby allowing writes to the cache for the same page to be +* serialised. +*/ +static inline void end_page_fscache (struct page *page) +{ +end_page_private_2 (page); +} + +/** +* wait_on_page_fscache - Wait for PG_fscache to be cleared on a page +* @page: The page to wait on +* +* Wait for PG_fscache (aka PG_private_2) to be cleared on a page. +*/ +static inline void wait_on_page_fscache (struct page *page) +{ +wait_on_page_private_2 (page); +} + +/** +* wait_on_page_fscache_killable - Wait for PG_fscache to be cleared on a page +* @page: The page to wait on +* +* Wait for PG_fscache (aka PG_private_2) to be cleared on a page or until a +* fatal signal is received by the calling task. +* +* Return: +* - 0 if successful. +* - -EINTR if a fatal signal was encountered. +*/ +static inline int wait_on_page_fscache_killable (struct page *page) +{ +return wait_on_page_private_2_killable (page); +} +#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v6 10/30 netfs: Provide readahead and readpage netfs helpers
In reply to David HowellsAdd a pair of helper functions:
(*) netfs_readahead()
(*) netfs_readpage()
to do the work of handling a readahead or a readpage, where the page(s) that form part of the request may be split between the local cache, the server or just require clearing, and may be single pages and transparent huge pages. This is all handled within the helper.
Note that while both will read from the cache if there is data present, only netfs_readahead() will expand the request beyond what it was asked to do, and only netfs_readahead() will write back to the cache.
netfs_readpage(), on the other hand, is synchronous and only fetches the page (which might be a THP) it is asked for.
The netfs gives the helper parameters from the VM, the cache cookie it wants to use (or NULL) and a table of operations (only one of which is mandatory):
(*) expand_readahead() [optional]
Called to allow the netfs to request an expansion of a readahead request to meet its own alignment requirements. This is done by changing rreq->start and rreq->len.
(*) clamp_length() [optional]
Called to allow the netfs to cut down a subrequest to meet its own boundary requirements. If it does this, the helper will generate additional subrequests until the full request is satisfied.
(*) is_still_valid() [optional]
Called to find out if the data just read from the cache has been invalidated and must be reread from the server.
(*) issue_op() [required]
Called to ask the netfs to issue a read to the server. The subrequest describes the read. The read request holds information about the file being accessed.
The netfs can cache information in rreq->netfs_priv.
Upon completion, the netfs should set the error, transferred and can also set FSCACHE_SREQ_CLEAR_TAIL and then call fscache_subreq_terminated().
(*) done() [optional]
Called after the pages have been unlocked. The read request is still pinning the file and mapping and may still be pinning pages with PG_fscache. rreq->error indicates any error that has been accumulated.
(*) cleanup() [optional]
Called when the helper is disposing of a finished read request. This allows the netfs to clear rreq->netfs_priv.
Netfs support is enabled with CONFIG_NETFS_SUPPORT=y. It will be built even if CONFIG_FSCACHE=n and in this case much of it should be optimised away, allowing the filesystem to use it even when caching is disabled.
Changes:
v5:
- Comment why netfs_readahead() is putting pages[2].
- Use page_file_mapping() rather than page->mapping[2].
- Use page_index() rather than page->index[2].
- Use set_page_fscache()[3] rather then SetPageFsCache() as this takes an appropriate ref too[4].
v4:
- Folded in a kerneldoc comment fix.
- Folded in a fix for the error handling in the case that ENOMEM occurs.
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
---
fs/Kconfig | 1 fs/Makefile | 1 fs/netfs/Makefile | 6 fs/netfs/internal.h | 61 ++++ fs/netfs/read_helper.c | 725 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 83 +++++ 6 files changed, 877 insertions(+) create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c
fs/Kconfig +1 -0
@@ -125,6 +125,7 @@ source "fs/overlayfs/Kconfig" menu "Caches" +source "fs/netfs/Kconfig" source "fs/fscache/Kconfig" source "fs/cachefiles/Kconfig"
fs/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-y += devpts/ obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line +obj-$(CONFIG_NETFS_SUPPORT) += netfs/ obj-$(CONFIG_FSCACHE) += fscache/ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT4_FS) += ext4/
fs/netfs/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +netfs-y := \ + read_helper.o + +obj-$(CONFIG_NETFS_SUPPORT) := netfs.o
fs/netfs/internal.h new file +61 -0
61 lines not on this page · raw message
fs/netfs/read_helper.c new file +725 -0
725 lines not on this page · raw message
include/linux/netfs.h +83 -0
93 lines not on this page · raw message
David Howells
maintainerPATCH v6 11/30 netfs: Add tracepoints
In reply to David HowellsAdd three tracepoints to track the activity of the read helpers:
(1) netfs/netfs_read
This logs entry to the read helpers and also expansion of the range in a readahead request.
(2) netfs/netfs_rreq
This logs the progress of netfs_read_request objects which track read requests. A read request may be a compound of multiple subrequests.
(3) netfs/netfs_sreq
This logs the progress of netfs_read_subrequest objects, which track the contributions from various sources to a read request.
---
fs/netfs/read_helper.c | 26 +++++ include/linux/netfs.h | 1 include/trace/events/netfs.h | 199 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 include/trace/events/netfs.h
fs/netfs/read_helper.c +26 -0
@@ -16,6 +16,8 @@#include <linux/task_io_accounting_ops.h> #include <linux/netfs.h> #include "internal.h" +#define CREATE_TRACE_POINTS +#include <trace/events/netfs.h> MODULE_DESCRIPTION ("Network fs support" );MODULE_AUTHOR ("Red Hat, Inc." );
@@ -84,6 +86,7 @@ static void netfs_free_read_request(struct work_struct *work)netfs_rreq_clear_subreqs (rreq, false);if (rreq->netfs_priv) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv); +trace_netfs_rreq (rreq, netfs_rreq_trace_free);kfree (rreq); }
@@ -129,6 +132,7 @@ static void __netfs_put_subrequest(struct netfs_read_subrequest *subreq, {struct netfs_read_request *rreq = subreq->rreq; +trace_netfs_sreq (subreq, netfs_sreq_trace_free);kfree (subreq);netfs_put_read_request (rreq, was_async); }
@@ -183,6 +187,7 @@ static void netfs_read_from_server(struct netfs_read_request *rreq,*/ static void netfs_rreq_completed (struct netfs_read_request *rreq,bool was_async) { +trace_netfs_rreq (rreq, netfs_rreq_trace_done);netfs_rreq_clear_subreqs (rreq, was_async);netfs_put_read_request (rreq, was_async); }
@@ -221,6 +226,8 @@ static void netfs_rreq_unlock(struct netfs_read_request *rreq) iopos =0 ; subreq_failed = (subreq->error <0 ); +trace_netfs_rreq (rreq, netfs_rreq_trace_unlock); +rcu_read_lock ();xas_for_each (&xas, page, last_page) {unsigned int pgpos = (page->index - start_page) *PAGE_SIZE ;
@@ -281,6 +288,8 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,__clear_bit (NETFS_SREQ_SHORT_READ , &subreq->flags);__set_bit (NETFS_SREQ_SEEK_DATA_READ , &subreq->flags); +trace_netfs_sreq (subreq, netfs_sreq_trace_resubmit_short); +netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);netfs_read_from_server (rreq, subreq);
@@ -296,6 +305,8 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)WARN_ON (in_interrupt ()); +trace_netfs_rreq (rreq, netfs_rreq_trace_resubmit); +/* We don't want terminating submissions trying to wake us up whilst * we're still going through the list. */
@@ -308,6 +319,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)break ; subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->error =0 ; +trace_netfs_sreq (subreq, netfs_sreq_trace_download_instead);netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);netfs_read_from_server (rreq, subreq);
@@ -332,6 +344,8 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)*/ static void netfs_rreq_assess (struct netfs_read_request *rreq,bool was_async) { +trace_netfs_rreq (rreq, netfs_rreq_trace_assess); + again:if (!test_bit (NETFS_RREQ_FAILED , &rreq->flags) &&test_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags)) {
@@ -422,6 +436,8 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq,set_bit (NETFS_RREQ_WRITE_TO_CACHE , &rreq->flags); out: +trace_netfs_sreq (subreq, netfs_sreq_trace_terminated); +/* If we decrement nr_rd_ops to 0, the ref belongs to us. */ u =atomic_dec_return (&rreq->nr_rd_ops);if (u ==0 )
@@ -510,6 +526,7 @@ netfs_rreq_prepare_read(struct netfs_read_request *rreq, out: subreq->source = source; +trace_netfs_sreq (subreq, netfs_sreq_trace_prepare);return source; }
@@ -549,6 +566,7 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq, rreq->submitted += subreq->len; +trace_netfs_sreq (subreq, netfs_sreq_trace_submit);switch (source) {case NETFS_FILL_WITH_ZEROES :netfs_fill_with_zeroes (rreq, subreq);
@@ -591,6 +609,9 @@ static void netfs_rreq_expand(struct netfs_read_request *rreq,readahead_expand (ractl, rreq->start, rreq->len); rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); + +trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), + netfs_read_trace_expanded); } }
@@ -632,6 +653,9 @@ void netfs_readahead(struct readahead_control *ractl, rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); +trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), + netfs_read_trace_readahead); +netfs_rreq_expand (rreq, ractl);atomic_set (&rreq->nr_rd_ops,1 );
@@ -698,6 +722,8 @@ int netfs_readpage(struct file *file, rreq->start =page_index (page) *PAGE_SIZE ; rreq->len =thp_size (page); +trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage); +netfs_get_read_request (rreq);atomic_set (&rreq->nr_rd_ops,1 );
include/linux/netfs.h +1 -0
@@ -124,6 +124,7 @@ struct netfs_read_request {struct list_head subrequests;/* Requests to fetch I/O from disk or net */ void *netfs_priv;/* Private data for the netfs */ unsigned int debug_id; +unsigned int cookie_debug_id;atomic_t nr_rd_ops;/* Number of read ops in progress */ size_t submitted;/* Amount submitted for I/O so far */ size_t len;/* Length of the request */
include/trace/events/netfs.h new file +199 -0
199 lines not on this page · raw message
David Howells
maintainerPATCH v6 12/30 netfs: Gather stats
In reply to David HowellsGather statistics from the netfs interface that can be exported through a seqfile. This is intended to be called by a later patch when viewing /proc/fs/fscache/stats.
---
fs/netfs/Kconfig | 15 +++++++++++++ fs/netfs/Makefile | 3 +-- fs/netfs/internal.h | 34 ++++++++++++++++++++++++++++++ fs/netfs/read_helper.c | 23 ++++++++++++++++++++ fs/netfs/stats.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 1 + 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 fs/netfs/stats.c
fs/netfs/Kconfig +15 -0
@@ -6,3 +6,18 @@ config NETFS_SUPPORT This option enables support for network filesystems, including helpers for high-level buffered I/O, abstracting out read segmentation, local caching and transparent huge page support. + +config NETFS_STATS + bool "Gather statistical information on local caching" + depends on NETFS_SUPPORT && PROC_FS + help + This option causes statistical information to be gathered on local + caching and exported through file: + + /proc/fs/fscache/stats + + The gathering of statistics adds a certain amount of overhead to + execution as there are a quite a few stats gathered, and on a + multi-CPU system these may be on cachelines that keep bouncing + between CPUs. On the other hand, the stats are very useful for + debugging purposes. Saying 'Y' here is recommended.
fs/netfs/Makefile +1 -2
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -netfs-y := \ - read_helper.o +netfs-y := read_helper.o stats.o obj-$(CONFIG_NETFS_SUPPORT) := netfs.o
fs/netfs/internal.h +34 -0
@@ -16,8 +16,42 @@*/ extern unsigned int netfs_debug; +/* +* stats.c +*/ +#ifdef CONFIG_NETFS_STATS +extern atomic_t netfs_n_rh_readahead; +extern atomic_t netfs_n_rh_readpage; +extern atomic_t netfs_n_rh_rreq; +extern atomic_t netfs_n_rh_sreq; +extern atomic_t netfs_n_rh_download; +extern atomic_t netfs_n_rh_download_done; +extern atomic_t netfs_n_rh_download_failed; +extern atomic_t netfs_n_rh_download_instead; +extern atomic_t netfs_n_rh_read; +extern atomic_t netfs_n_rh_read_done; +extern atomic_t netfs_n_rh_read_failed; +extern atomic_t netfs_n_rh_zero; +extern atomic_t netfs_n_rh_short_read; +extern atomic_t netfs_n_rh_write; +extern atomic_t netfs_n_rh_write_done; +extern atomic_t netfs_n_rh_write_failed; + + +static inline void netfs_stat (atomic_t *stat) +{ +atomic_inc (stat); +} + +static inline void netfs_stat_d (atomic_t *stat) +{ +atomic_dec (stat); +} + +#else #define netfs_stat (x) do {} while(0)#define netfs_stat_d (x) do {} while(0) +#endif /*****************************************************************************/ /*
fs/netfs/read_helper.c +23 -0
@@ -56,6 +56,7 @@ static struct netfs_read_request *netfs_alloc_read_request(refcount_set (&rreq->usage,1 );__set_bit (NETFS_RREQ_IN_PROGRESS , &rreq->flags); ops->init_rreq (rreq, file); +netfs_stat (&netfs_n_rh_rreq); }return rreq;
@@ -88,6 +89,7 @@ static void netfs_free_read_request(struct work_struct *work) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv);trace_netfs_rreq (rreq, netfs_rreq_trace_free);kfree (rreq); +netfs_stat_d (&netfs_n_rh_rreq); }static void netfs_put_read_request (struct netfs_read_request *rreq,bool was_async)
@@ -117,6 +119,7 @@ static struct netfs_read_subrequest *netfs_alloc_subrequest(refcount_set (&subreq->usage,2 ); subreq->rreq = rreq;netfs_get_read_request (rreq); +netfs_stat (&netfs_n_rh_sreq); }return subreq;
@@ -134,6 +137,7 @@ static void __netfs_put_subrequest(struct netfs_read_subrequest *subreq,trace_netfs_sreq (subreq, netfs_sreq_trace_free);kfree (subreq); +netfs_stat_d (&netfs_n_rh_sreq);netfs_put_read_request (rreq, was_async); }
@@ -156,6 +160,7 @@ static void netfs_clear_unread(struct netfs_read_subrequest *subreq)static void netfs_fill_with_zeroes (struct netfs_read_request *rreq,struct netfs_read_subrequest *subreq) { +netfs_stat (&netfs_n_rh_zero);__set_bit (NETFS_SREQ_CLEAR_TAIL , &subreq->flags);netfs_subreq_terminated (subreq,0 , false); }
@@ -179,6 +184,7 @@ static void netfs_fill_with_zeroes(struct netfs_read_request *rreq,static void netfs_read_from_server (struct netfs_read_request *rreq,struct netfs_read_subrequest *subreq) { +netfs_stat (&netfs_n_rh_download); rreq->netfs_ops->issue_op (subreq); }
@@ -288,6 +294,7 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,__clear_bit (NETFS_SREQ_SHORT_READ , &subreq->flags);__set_bit (NETFS_SREQ_SEEK_DATA_READ , &subreq->flags); +netfs_stat (&netfs_n_rh_short_read);trace_netfs_sreq (subreq, netfs_sreq_trace_resubmit_short);netfs_get_read_subrequest (subreq);
@@ -319,6 +326,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)break ; subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->error =0 ; +netfs_stat (&netfs_n_rh_download_instead);trace_netfs_sreq (subreq, netfs_sreq_trace_download_instead);netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);
@@ -414,6 +422,17 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq, subreq->debug_index, subreq->start, subreq->flags, transferred_or_error); +switch (subreq->source) { +case NETFS_READ_FROM_CACHE : +netfs_stat (&netfs_n_rh_read_done); +break ; +case NETFS_DOWNLOAD_FROM_SERVER : +netfs_stat (&netfs_n_rh_download_done); +break ; +default : +break ; + } +if (IS_ERR_VALUE (transferred_or_error)) { subreq->error = transferred_or_error; goto failed;
@@ -470,8 +489,10 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq, failed:if (subreq->source ==NETFS_READ_FROM_CACHE ) { +netfs_stat (&netfs_n_rh_read_failed);set_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags); }else { +netfs_stat (&netfs_n_rh_download_failed);set_bit (NETFS_RREQ_FAILED , &rreq->flags); rreq->error = subreq->error; }
@@ -653,6 +674,7 @@ void netfs_readahead(struct readahead_control *ractl, rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); +netfs_stat (&netfs_n_rh_readahead);trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), netfs_read_trace_readahead);
@@ -722,6 +744,7 @@ int netfs_readpage(struct file *file, rreq->start =page_index (page) *PAGE_SIZE ; rreq->len =thp_size (page); +netfs_stat (&netfs_n_rh_readpage);trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage);netfs_get_read_request (rreq);
fs/netfs/stats.c new file +54 -0
54 lines not on this page · raw message
include/linux/netfs.h +1 -0
@@ -166,5 +166,6 @@ extern int netfs_readpage(struct file *, void *);extern void netfs_subreq_terminated (struct netfs_read_subrequest *,ssize_t ,bool ); +extern void netfs_stats_show (struct seq_file *);#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v6 13/30 netfs: Add write_begin helper
In reply to David HowellsAdd a helper to do the pre-reading work for the netfs write_begin address space op.
Changes
v6:
- Fixed a missing rreq put in netfs_write_begin()[3].
- Use DEFINE_READAHEAD()[4].
v5:
- Made the wait for PG_fscache in netfs_write_begin() killable[2].
v4:
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
---
fs/netfs/internal.h | 2 + fs/netfs/read_helper.c | 164 ++++++++++++++++++++++++++++++++++++++++++ fs/netfs/stats.c | 11 ++- include/linux/netfs.h | 8 ++ include/trace/events/netfs.h | 4 + 5 files changed, 185 insertions(+), 4 deletions(-)
fs/netfs/internal.h +2 -0
@@ -34,8 +34,10 @@ extern atomic_t netfs_n_rh_read_failed;extern atomic_t netfs_n_rh_zero;extern atomic_t netfs_n_rh_short_read;extern atomic_t netfs_n_rh_write; +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;static inline void netfs_stat (atomic_t *stat)
fs/netfs/read_helper.c +164 -0
167 lines not on this page · raw message
fs/netfs/stats.c +8 -3
@@ -24,19 +24,24 @@ atomic_t netfs_n_rh_read_failed;atomic_t netfs_n_rh_zero;atomic_t netfs_n_rh_short_read;atomic_t netfs_n_rh_write; +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;void netfs_stats_show (struct seq_file *m) { -seq_printf (m,"RdHelp : RA=%u RP=%u rr=%u sr=%u\n" , +seq_printf (m,"RdHelp : RA=%u RP=%u WB=%u WBZ=%u rr=%u sr=%u\n" ,atomic_read (&netfs_n_rh_readahead),atomic_read (&netfs_n_rh_readpage), +atomic_read (&netfs_n_rh_write_begin), +atomic_read (&netfs_n_rh_write_zskip),atomic_read (&netfs_n_rh_rreq),atomic_read (&netfs_n_rh_sreq)); -seq_printf (m,"RdHelp : ZR=%u sh=%u\n" , +seq_printf (m,"RdHelp : ZR=%u sh=%u sk=%u\n" ,atomic_read (&netfs_n_rh_zero), -atomic_read (&netfs_n_rh_short_read)); +atomic_read (&netfs_n_rh_short_read), +atomic_read (&netfs_n_rh_write_zskip)); seq_printf(m, "RdHelp : DL=%u ds=%u df=%u di=%u\n", atomic_read(&netfs_n_rh_download), atomic_read(&netfs_n_rh_download_done),
include/linux/netfs.h +8 -0
@@ -147,11 +147,14 @@ struct netfs_read_request {* Operations the network filesystem can/must provide to the helpers. */ struct netfs_read_request_ops { +bool (*is_cache_enabled)(struct inode *inode);void (*init_rreq)(struct netfs_read_request *rreq,struct file *file);void (*expand_readahead)(struct netfs_read_request *rreq);bool (*clamp_length)(struct netfs_read_subrequest *subreq);void (*issue_op)(struct netfs_read_subrequest *subreq);bool (*is_still_valid)(struct netfs_read_request *rreq); +int (*check_write_begin)(struct file *file,loff_t pos,unsigned len, +struct page *page,void **_fsdata);void (*done)(struct netfs_read_request *rreq);void (*cleanup)(struct address_space *mapping,void *netfs_priv); };
@@ -164,6 +167,11 @@ extern int netfs_readpage(struct file *, struct page *, const struct netfs_read_request_ops *, void *); +extern int netfs_write_begin (struct file *,struct address_space *, +loff_t ,unsigned int ,unsigned int ,struct page **, +void **, +const struct netfs_read_request_ops *, +void *);extern void netfs_subreq_terminated (struct netfs_read_subrequest *,ssize_t ,bool );extern void netfs_stats_show (struct seq_file *);
include/trace/events/netfs.h +3 -1
@@ -22,6 +22,7 @@ enum netfs_read_trace { netfs_read_trace_expanded, netfs_read_trace_readahead, netfs_read_trace_readpage, + netfs_read_trace_write_begin, }; enum netfs_rreq_trace {
@@ -50,7 +51,8 @@ enum netfs_sreq_trace {#define netfs_read_traces \ EM(netfs_read_trace_expanded, "EXPANDED ") \ EM(netfs_read_trace_readahead, "READAHEAD") \ - E_(netfs_read_trace_readpage, "READPAGE ") + EM(netfs_read_trace_readpage, "READPAGE ") \ + E_(netfs_read_trace_write_begin, "WRITEBEGN")#define netfs_rreq_traces \ EM(netfs_rreq_trace_assess, "ASSESS") \
David Howells
maintainerPATCH v6 14/30 netfs: Define an interface to talk to a cache
In reply to David HowellsAdd an interface to the netfs helper library for reading data from the cache instead of downloading it from the server and support for writing data just downloaded or cleared to the cache.
The API passes an iov_iter to the cache read/write routines to indicate the data/buffer to be used. This is done using the ITER_XARRAY type to provide direct access to the netfs inode's pagecache.
When the netfs's ->begin_cache_operation() method is called, this must fill in the cache_resources in the netfs_read_request struct, including the netfs_cache_ops used by the helper lib to talk to the cache. The helper lib does not directly access the cache.
Changes:
v6:
- Call trace_netfs_read() after beginning the cache op so that the cookie debug ID can be logged[3].
- Don't record the error from writing to the cache. We don't want to pass it back to the netfs[4].
- Fix copy-to-cache subreq amalgamation to not round up as it goes along otherwise it overcalculates the length of the write[5].
v5:
- Use end_page_fscache() rather than unlock_page_fscache()[2].
v4:
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
- Add missing inc of netfs_n_rh_read stat.
- Move initial definition of fscache_begin_read_operation() elsewhere.
- Need to call op->begin_cache_operation() from netfs_write_begin().
---
fs/netfs/read_helper.c | 239 ++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 55 ++++++++++ include/trace/events/netfs.h | 2 3 files changed, 295 insertions(+), 1 deletion(-)
fs/netfs/read_helper.c +238 -1
@@ -88,6 +88,8 @@ static void netfs_free_read_request(struct work_struct *work)if (rreq->netfs_priv) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv);trace_netfs_rreq (rreq, netfs_rreq_trace_free); +if (rreq->cache_resources.ops) + rreq->cache_resources.ops->end_operation (&rreq->cache_resources);kfree (rreq);netfs_stat_d (&netfs_n_rh_rreq); }
@@ -154,6 +156,34 @@ static void netfs_clear_unread(struct netfs_read_subrequest *subreq)iov_iter_zero (iov_iter_count (&iter), &iter); } +static void netfs_cache_read_terminated (void *priv,ssize_t transferred_or_error, +bool was_async) +{ +struct netfs_read_subrequest *subreq = priv; + +netfs_subreq_terminated (subreq, transferred_or_error, was_async); +} + +/* +* Issue a read against the cache. +* - Eats the caller's ref on subreq. +*/ +static void netfs_read_from_cache (struct netfs_read_request *rreq, +struct netfs_read_subrequest *subreq, +bool seek_data) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; +struct iov_iter iter; + +netfs_stat (&netfs_n_rh_read); +iov_iter_xarray (&iter,READ , &rreq->mapping->i_pages, + subreq->start + subreq->transferred, + subreq->len - subreq->transferred); + + cres->ops->read (cres, subreq->start, &iter, seek_data, + netfs_cache_read_terminated, subreq); +} +/* * Fill a subrequest region with zeroes. */
@@ -198,6 +228,141 @@ static void netfs_rreq_completed(struct netfs_read_request *rreq, bool was_asyncnetfs_put_read_request (rreq, was_async); } +/* +* Deal with the completion of writing the data to the cache. We have to clear +* the PG_fscache bits on the pages involved and release the caller's ref. +* +* May be called in softirq mode and we inherit a ref from the caller. +*/ +static void netfs_rreq_unmark_after_write (struct netfs_read_request *rreq, +bool was_async) +{ +struct netfs_read_subrequest *subreq; +struct page *page; +pgoff_t unlocked =0 ; +bool have_unlocked = false; + +rcu_read_lock (); + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +XA_STATE (xas, &rreq->mapping->i_pages, subreq->start /PAGE_SIZE ); + +xas_for_each (&xas, page, (subreq->start + subreq->len -1 ) /PAGE_SIZE ) { +/* We might have multiple writes from the same huge +* page, but we mustn't unlock a page more than once. +*/ +if (have_unlocked && page->index <= unlocked) +continue ; + unlocked = page->index; +end_page_fscache (page); + have_unlocked = true; + } + } + +rcu_read_unlock (); +netfs_rreq_completed (rreq, was_async); +} + +static void netfs_rreq_copy_terminated (void *priv,ssize_t transferred_or_error, +bool was_async) +{ +struct netfs_read_subrequest *subreq = priv; +struct netfs_read_request *rreq = subreq->rreq; + +if (IS_ERR_VALUE (transferred_or_error)) { +netfs_stat (&netfs_n_rh_write_failed); + }else { +netfs_stat (&netfs_n_rh_write_done); + } + +trace_netfs_sreq (subreq, netfs_sreq_trace_write_term); + +/* If we decrement nr_wr_ops to 0, the ref belongs to us. */ +if (atomic_dec_and_test (&rreq->nr_wr_ops)) +netfs_rreq_unmark_after_write (rreq, was_async); + +netfs_put_subrequest (subreq, was_async); +} + +/* +* Perform any outstanding writes to the cache. We inherit a ref from the +* caller. +*/ +static void netfs_rreq_do_write_to_cache (struct netfs_read_request *rreq) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; +struct netfs_read_subrequest *subreq, *next, *p; +struct iov_iter iter; +int ret; + +trace_netfs_rreq (rreq, netfs_rreq_trace_write); + +/* We don't want terminating writes trying to wake us up whilst we're +* still going through the list. +*/ +atomic_inc (&rreq->nr_wr_ops); + +list_for_each_entry_safe (subreq, p, &rreq->subrequests, rreq_link) { +if (!test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) { +list_del_init (&subreq->rreq_link); +netfs_put_subrequest (subreq, false); + } + } + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +/* Amalgamate adjacent writes */ +while (!list_is_last (&subreq->rreq_link, &rreq->subrequests)) { + next =list_next_entry (subreq, rreq_link); +if (next->start != subreq->start + subreq->len) +break ; + subreq->len += next->len; +list_del_init (&next->rreq_link); +netfs_put_subrequest (next, false); + } + + ret = cres->ops->prepare_write (cres, &subreq->start, &subreq->len, + rreq->i_size); +if (ret <0 ) { +trace_netfs_sreq (subreq, netfs_sreq_trace_write_skip); +continue ; + } + +iov_iter_xarray (&iter,WRITE , &rreq->mapping->i_pages, + subreq->start, subreq->len); + +atomic_inc (&rreq->nr_wr_ops); +netfs_stat (&netfs_n_rh_write); +netfs_get_read_subrequest (subreq); +trace_netfs_sreq (subreq, netfs_sreq_trace_write); + cres->ops->write (cres, subreq->start, &iter, + netfs_rreq_copy_terminated, subreq); + } + +/* If we decrement nr_wr_ops to 0, the usage ref belongs to us. */ +if (atomic_dec_and_test (&rreq->nr_wr_ops)) +netfs_rreq_unmark_after_write (rreq, false); +} + +static void netfs_rreq_write_to_cache_work (struct work_struct *work) +{ +struct netfs_read_request *rreq = + container_of(work, struct netfs_read_request, work); + +netfs_rreq_do_write_to_cache (rreq); +} + +static void netfs_rreq_write_to_cache (struct netfs_read_request *rreq, +bool was_async) +{ +if (was_async) { + rreq->work.func = netfs_rreq_write_to_cache_work; +if (!queue_work (system_unbound_wq, &rreq->work)) +BUG (); + }else { +netfs_rreq_do_write_to_cache (rreq); + } +} +/* * Unlock the pages in a read operation. We need to set PG_fscache on any * pages we're going to write back before we unlock them.
@@ -299,7 +464,10 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops); -netfs_read_from_server (rreq, subreq); +if (subreq->source ==NETFS_READ_FROM_CACHE ) +netfs_read_from_cache (rreq, subreq, true); +else +netfs_read_from_server (rreq, subreq); }/*
@@ -344,6 +512,25 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)return false; } +/* +* Check to see if the data read is still valid. +*/ +static void netfs_rreq_is_still_valid (struct netfs_read_request *rreq) +{ +struct netfs_read_subrequest *subreq; + +if (!rreq->netfs_ops->is_still_valid || + rreq->netfs_ops->is_still_valid (rreq)) +return ; + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +if (subreq->source ==NETFS_READ_FROM_CACHE ) { + subreq->error = -ESTALE ; +__set_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags); + } + } +} +/* * Assess the state of a read request and decide what to do next. *
@@ -355,6 +542,8 @@ static void netfs_rreq_assess(struct netfs_read_request *rreq, bool was_async)trace_netfs_rreq (rreq, netfs_rreq_trace_assess); again: +netfs_rreq_is_still_valid (rreq); +if (!test_bit (NETFS_RREQ_FAILED , &rreq->flags) &&test_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags)) {if (netfs_rreq_perform_resubmissions (rreq))
@@ -367,6 +556,9 @@ static void netfs_rreq_assess(struct netfs_read_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_WRITE_TO_CACHE , &rreq->flags)) +return netfs_rreq_write_to_cache (rreq, was_async); +netfs_rreq_completed (rreq, was_async); }
@@ -504,7 +696,10 @@ static enum netfs_read_source netfs_cache_prepare_read(struct netfs_read_subrequ loff_t i_size) {struct netfs_read_request *rreq = subreq->rreq; +struct netfs_cache_resources *cres = &rreq->cache_resources; +if (cres->ops) +return cres->ops->prepare_read (subreq, i_size);if (subreq->start >= rreq->i_size)return NETFS_FILL_WITH_ZEROES ;return NETFS_DOWNLOAD_FROM_SERVER ;
@@ -595,6 +790,9 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq,case NETFS_DOWNLOAD_FROM_SERVER :netfs_read_from_server (rreq, subreq);break ; +case NETFS_READ_FROM_CACHE : +netfs_read_from_cache (rreq, subreq, false); +break ;default :BUG (); }
@@ -607,9 +805,23 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq,return false; } +static void netfs_cache_expand_readahead (struct netfs_read_request *rreq, +loff_t *_start,size_t *_len,loff_t i_size) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; + +if (cres->ops && cres->ops->expand_readahead) + cres->ops->expand_readahead (cres, _start, _len, i_size); +} +static void netfs_rreq_expand (struct netfs_read_request *rreq,struct readahead_control *ractl) { +/* Give the cache a chance to change the request parameters. The +* resultant request must contain the original region. +*/ +netfs_cache_expand_readahead (rreq, &rreq->start, &rreq->len, rreq->i_size); +/* Give the netfs a chance to change the request parameters. The * resultant request must contain the original region. */
@@ -661,6 +873,7 @@ void netfs_readahead(struct readahead_control *ractl,struct netfs_read_request *rreq;struct page *page;unsigned int debug_index =0 ; +int ret;_enter ("%lx,%x" ,readahead_index (ractl),readahead_count (ractl));
@@ -674,6 +887,12 @@ void netfs_readahead(struct readahead_control *ractl, rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) + goto cleanup_free; + } +netfs_stat (&netfs_n_rh_readahead);trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), netfs_read_trace_readahead);
@@ -698,6 +917,9 @@ void netfs_readahead(struct readahead_control *ractl,netfs_rreq_assess (rreq, false);return ; +cleanup_free: +netfs_put_read_request (rreq, false); +return ; cleanup:if (netfs_priv) ops->cleanup (ractl->mapping, netfs_priv);
@@ -744,6 +966,14 @@ int netfs_readpage(struct file *file, rreq->start =page_index (page) *PAGE_SIZE ; rreq->len =thp_size (page); +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) { +unlock_page (page); + goto out; + } + } +netfs_stat (&netfs_n_rh_readpage);trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage);
@@ -768,6 +998,7 @@ int netfs_readpage(struct file *file, ret = rreq->error;if (ret ==0 && rreq->submitted < rreq->len) ret = -EIO ; +out:netfs_put_read_request (rreq, false);return ret; }
@@ -873,6 +1104,12 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,__set_bit (NETFS_RREQ_NO_UNLOCK_PAGE , &rreq->flags); netfs_priv =NULL ; +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) + goto error_put; + } +netfs_stat (&netfs_n_rh_write_begin);trace_netfs_read (rreq, pos, len, netfs_read_trace_write_begin);
include/linux/netfs.h +55 -0
84 lines not on this page · raw message
include/trace/events/netfs.h +2 -0
@@ -43,6 +43,7 @@ enum netfs_sreq_trace { netfs_sreq_trace_submit, netfs_sreq_trace_terminated, netfs_sreq_trace_write, + netfs_sreq_trace_write_skip, netfs_sreq_trace_write_term, };
@@ -77,6 +78,7 @@ enum netfs_sreq_trace { EM(netfs_sreq_trace_submit, "SUBMT") \ EM(netfs_sreq_trace_terminated, "TERM ") \ EM(netfs_sreq_trace_write, "WRITE") \ + EM(netfs_sreq_trace_write_skip, "SKIP ") \E_ (netfs_sreq_trace_write_term,"WTERM" )
David Howells
maintainerPATCH v6 15/30 netfs: Add a tracepoint to log failures that would be otherwise unseen
In reply to David HowellsAdd a tracepoint to log internal failures (such as cache errors) that we don't otherwise want to pass back to the netfs.
---
fs/netfs/read_helper.c | 14 +++++++++- include/trace/events/netfs.h | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-)
fs/netfs/read_helper.c +12 -2
@@ -271,6 +271,8 @@ static void netfs_rreq_copy_terminated(void *priv, ssize_t transferred_or_error,if (IS_ERR_VALUE (transferred_or_error)) {netfs_stat (&netfs_n_rh_write_failed); +trace_netfs_failure (rreq, subreq, transferred_or_error, + netfs_fail_copy_to_cache); }else {netfs_stat (&netfs_n_rh_write_done); }
@@ -323,6 +325,7 @@ static void netfs_rreq_do_write_to_cache(struct netfs_read_request *rreq) ret = cres->ops->prepare_write (cres, &subreq->start, &subreq->len, rreq->i_size);if (ret <0 ) { +trace_netfs_failure (rreq, subreq, ret, netfs_fail_prepare_write);trace_netfs_sreq (subreq, netfs_sreq_trace_write_skip);continue ; }
@@ -627,6 +630,8 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq,if (IS_ERR_VALUE (transferred_or_error)) { subreq->error = transferred_or_error; +trace_netfs_failure (rreq, subreq, transferred_or_error, + netfs_fail_read); goto failed; }
@@ -996,8 +1001,10 @@ int netfs_readpage(struct file *file, }while (test_bit (NETFS_RREQ_IN_PROGRESS , &rreq->flags)); ret = rreq->error; -if (ret ==0 && rreq->submitted < rreq->len) +if (ret ==0 && rreq->submitted < rreq->len) { +trace_netfs_failure (rreq,NULL , ret, netfs_fail_short_readpage); ret = -EIO ; + } out:netfs_put_read_request (rreq, false);return ret;
@@ -1069,6 +1076,7 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,/* Allow the netfs (eg. ceph) to flush conflicts. */ ret = ops->check_write_begin (file, pos, len, page, _fsdata);if (ret <0 ) { +trace_netfs_failure (NULL ,NULL , ret, netfs_fail_check_write_begin);if (ret == -EAGAIN ) goto retry; goto error;
@@ -1145,8 +1153,10 @@ int netfs_write_begin(struct file *file, struct address_space *mapping, } ret = rreq->error; -if (ret ==0 && rreq->submitted < rreq->len) +if (ret ==0 && rreq->submitted < rreq->len) { +trace_netfs_failure (rreq,NULL , ret, netfs_fail_short_write_begin); ret = -EIO ; + }netfs_put_read_request (rreq, false);if (ret <0 ) goto error;
include/trace/events/netfs.h +58 -0
82 lines not on this page · raw message
David Howells
maintainerPATCH v6 16/30 fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
In reply to David HowellsAdd an alternate API by which the cache can be accessed through a kiocb, doing async DIO, rather than using the current API that tells the cache where all the pages are.
The new API is intended to be used in conjunction with the netfs helper library. A filesystem must pick one or the other and not mix them.
Filesystems wanting to use the new API must #define FSCACHE_USE_NEW_IO_API before #including the header. This prevents them from continuing to use the old API at the same time as there are incompatibilities in how the PG_fscache page bit is used.
Changes:
v6:
- Provide a routine to shape a write so that the start and length can be aligned for DIO[3].
v4:
- Use the vfs_iocb_iter_read/write() helpers[1]
- Move initial definition of fscache_begin_read_operation() here.
- Remove a commented-out line[2]
- Combine ki->term_func calls in cachefiles_read_complete()[2].
- Remove explicit NULL initialiser[2].
- Remove extern on func decl[2].
- Put in param names on func decl[2].
- Remove redundant else[2].
- Fill out the kdoc comment for fscache_begin_read_operation().
- Rename fs/fscache/page2.c to io.c to match later patches.
---
fs/cachefiles/Makefile | 1 fs/cachefiles/interface.c | 5 fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++++++++++++++++++++++++++++++++++++ fs/fscache/Kconfig | 1 fs/fscache/Makefile | 1 fs/fscache/internal.h | 4 fs/fscache/io.c | 116 +++++++++++ fs/fscache/page.c | 2 fs/fscache/stats.c | 1 include/linux/fscache-cache.h | 4 include/linux/fscache.h | 39 ++++ 12 files changed, 600 insertions(+), 3 deletions(-) create mode 100644 fs/cachefiles/io.c create mode 100644 fs/fscache/io.c
fs/cachefiles/Makefile +1 -0
@@ -7,6 +7,7 @@ cachefiles-y := \ bind.o \ daemon.o \ interface.o \ + io.o \ key.o \ main.o \ namei.o \
fs/cachefiles/interface.c +3 -2
@@ -319,8 +319,8 @@ static void cachefiles_drop_object(struct fscache_object *_object)/* * dispose of a reference to an object */ -static void cachefiles_put_object (struct fscache_object *_object, -enum fscache_obj_ref_trace why) +void cachefiles_put_object (struct fscache_object *_object, +enum fscache_obj_ref_trace why) {struct cachefiles_object *object;struct fscache_cache *cache;
@@ -568,4 +568,5 @@ const struct fscache_cache_ops cachefiles_cache_ops = { .uncache_page = cachefiles_uncache_page, .dissociate_pages = cachefiles_dissociate_pages, .check_consistency = cachefiles_check_consistency, + .begin_read_operation = cachefiles_begin_read_operation, };
fs/cachefiles/internal.h +9 -0
@@ -150,6 +150,9 @@ extern int cachefiles_has_space(struct cachefiles_cache *cache,*/ extern const struct fscache_cache_ops cachefiles_cache_ops; +void cachefiles_put_object (struct fscache_object *_object, +enum fscache_obj_ref_trace why); +/* * key.c */
@@ -217,6 +220,12 @@ extern int cachefiles_allocate_pages(struct fscache_retrieval *,extern int cachefiles_write_page (struct fscache_storage *,struct page *);extern void cachefiles_uncache_page (struct fscache_object *,struct page *); +/* +* rdwr2.c +*/ +extern int cachefiles_begin_read_operation (struct netfs_read_request *, +struct fscache_retrieval *); +/* * security.c */
fs/cachefiles/io.c new file +420 -0
420 lines not on this page · raw message
fs/fscache/Kconfig +1 -0
@@ -2,6 +2,7 @@ config FSCACHE tristate "General filesystem local caching manager" + select NETFS_SUPPORT help This option enables a generic filesystem caching manager that can be used by various network and other filesystems to cache data locally.
fs/fscache/Makefile +1 -0
@@ -7,6 +7,7 @@ fscache-y := \ cache.o \ cookie.o \ fsdef.o \ + io.o \ main.o \ netfs.o \ object.o \
fs/fscache/internal.h +4 -0
@@ -142,6 +142,10 @@ extern int fscache_wait_for_operation_activation(struct fscache_object *, atomic_t *, atomic_t *);extern void fscache_invalidate_writes (struct fscache_cookie *); +struct fscache_retrieval *fscache_alloc_retrieval (struct fscache_cookie *cookie, +struct address_space *mapping, +fscache_rw_complete_t end_io_func, +void *context);/* * proc.c
fs/fscache/io.c new file +116 -0
116 lines not on this page · raw message
fs/fscache/page.c +1 -1
@@ -299,7 +299,7 @@ static void fscache_release_retrieval_op(struct fscache_operation *_op)/* * allocate a retrieval op */ -static struct fscache_retrieval *fscache_alloc_retrieval( +struct fscache_retrieval *fscache_alloc_retrieval( struct fscache_cookie *cookie, struct address_space *mapping, fscache_rw_complete_t end_io_func,
fs/fscache/stats.c +1 -0
@@ -278,5 +278,6 @@ int fscache_stats_show(struct seq_file *m, void *v)atomic_read (&fscache_n_cache_stale_objects),atomic_read (&fscache_n_cache_retired_objects), atomic_read(&fscache_n_cache_culled_objects)); +netfs_stats_show (m);return 0 ; }
include/linux/fscache-cache.h +4 -0
@@ -304,6 +304,10 @@ struct fscache_cache_ops {/* dissociate a cache from all the pages it was backing */ void (*dissociate_pages)(struct fscache_cache *cache); + +/* Begin a read operation for the netfs lib */ +int (*begin_read_operation)(struct netfs_read_request *rreq, +struct fscache_retrieval *op); };extern struct fscache_cookie fscache_fsdef_index;
include/linux/fscache.h +39 -0
@@ -37,6 +37,7 @@ struct pagevec;struct fscache_cache_tag ;struct fscache_cookie ;struct fscache_netfs ; +struct netfs_read_request ; typedef void (*fscache_rw_complete_t)(struct page *page, void *context,
@@ -191,6 +192,10 @@ extern void __fscache_update_cookie(struct fscache_cookie *, const void *);extern int __fscache_attr_changed (struct fscache_cookie *);extern void __fscache_invalidate (struct fscache_cookie *);extern void __fscache_wait_on_invalidate (struct fscache_cookie *); + +#ifdef FSCACHE_USE_NEW_IO_API +extern int __fscache_begin_read_operation (struct netfs_read_request *,struct fscache_cookie *); +#else extern int __fscache_read_or_alloc_page(struct fscache_cookie *, struct page *, fscache_rw_complete_t,
@@ -214,6 +219,8 @@ extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *, struct inode *);extern void __fscache_readpages_cancel (struct fscache_cookie *cookie,struct list_head *pages); +#endif /* FSCACHE_USE_NEW_IO_API */ +extern void __fscache_disable_cookie (struct fscache_cookie *,const void *,bool );extern void __fscache_enable_cookie (struct fscache_cookie *,const void *,loff_t ,bool (*)(void *),void *);
@@ -498,6 +505,36 @@ int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size)return -ENOBUFS ; } +#ifdef FSCACHE_USE_NEW_IO_API + +/** +* fscache_begin_read_operation - Begin a read operation for the netfs lib +* @rreq: The read request being undertaken +* @cookie: The cookie representing the cache object +* +* Begin a read operation on behalf of the netfs helper library. @rreq +* indicates the read request to which the operation state should be attached; +* @cookie indicates the cache object that will be accessed. +* +* This is intended to be called from the ->begin_cache_operation() netfs lib +* operation as implemented by the network filesystem. +* +* Returns: +* * 0 - Success +* * -ENOBUFS - No caching available +* * Other error code from the cache, such as -ENOMEM. +*/ +static inline +int fscache_begin_read_operation (struct netfs_read_request *rreq, +struct fscache_cookie *cookie) +{ +if (fscache_cookie_valid (cookie) &&fscache_cookie_enabled (cookie)) +return __fscache_begin_read_operation (rreq, cookie); +return -ENOBUFS ; +} + +#else /* FSCACHE_USE_NEW_IO_API */ +/** * fscache_read_or_alloc_page - Read a page from the cache or allocate a block * in which to store it
@@ -777,6 +814,8 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie, __fscache_uncache_all_inode_pages(cookie, inode); } +#endif /* FSCACHE_USE_NEW_IO_API */ +/** * fscache_disable_cookie - Disable a cookie * @cookie: The cookie representing the cache object
David Howells
maintainerPATCH v6 17/30 afs: Disable use of the fscache I/O routines
In reply to David HowellsDisable use of the fscache I/O routined by the AFS filesystem. It's about to transition to passing iov_iters down and fscache is about to have its I/O path to use iov_iter, so all that needs to change.
---
fs/afs/file.c | 199 ++++++++++---------------------------------------------- fs/afs/inode.c | 2 - fs/afs/write.c | 10 --- 3 files changed, 36 insertions(+), 175 deletions(-)
fs/afs/file.c +35 -164
@@ -202,24 +202,6 @@ void afs_put_read(struct afs_read *req) } } -#ifdef CONFIG_AFS_FSCACHE -/* -* deal with notification that a page was read from the cache -*/ -static void afs_file_readpage_read_complete (struct page *page, -void *data, -int error) -{ -_enter ("%p,%p,%d" , page, data, error); - -/* if the read completes with an error, we just unlock the page and let -* the VM reissue the readpage */ -if (!error) -SetPageUptodate (page); -unlock_page (page); -} -#endif -static void afs_fetch_data_success (struct afs_operation *op) {struct afs_vnode *vnode = op->file[0 ].vnode;
@@ -287,89 +269,46 @@ int afs_page_filler(void *data, struct page *page)if (test_bit (AFS_VNODE_DELETED , &vnode->flags)) goto error; -/* is it cached? */ -#ifdef CONFIG_AFS_FSCACHE - ret =fscache_read_or_alloc_page (vnode->cache, - page, - afs_file_readpage_read_complete, -NULL , -GFP_KERNEL ); -#else - ret = -ENOBUFS ; -#endif -switch (ret) { -/* read BIO submitted (page in cache) */ -case 0 : -break ; - -/* page not yet cached */ -case -ENODATA : -_debug ("cache said ENODATA" ); - goto go_on; - -/* page will not be cached */ -case -ENOBUFS : -_debug ("cache said ENOBUFS" ); - - fallthrough; -default : - go_on: - req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); -if (!req) - goto enomem; - -/* We request a full page. If the page is a partial one at the -* end of the file, the server will return a short read and the -* unmarshalling code will clear the unfilled space. -*/ -refcount_set (&req->usage,1 ); - req->pos = (loff_t )page->index <<PAGE_SHIFT ; - req->len =PAGE_SIZE ; - req->nr_pages =1 ; - req->pages = req->array; - req->pages[0 ] = page; -get_page (page); - -/* read the contents of the file from the server into the -* page */ - ret =afs_fetch_data (vnode, key, req); -afs_put_read (req); - -if (ret <0 ) { -if (ret == -ENOENT ) { -_debug ("got NOENT from server" -" - marking file deleted and stale" ); -set_bit (AFS_VNODE_DELETED , &vnode->flags); - ret = -ESTALE ; - } - -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif -BUG_ON (PageFsCache (page)); - -if (ret == -EINTR || - ret == -ENOMEM || - ret == -ERESTARTSYS || - ret == -EAGAIN ) - goto error; - goto io_error; - } + req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); +if (!req) + goto enomem; -SetPageUptodate (page); +/* We request a full page. If the page is a partial one at the +* end of the file, the server will return a short read and the +* unmarshalling code will clear the unfilled space. +*/ +refcount_set (&req->usage,1 ); + req->pos = (loff_t )page->index <<PAGE_SHIFT ; + req->len =PAGE_SIZE ; + req->nr_pages =1 ; + req->pages = req->array; + req->pages[0 ] = page; +get_page (page); + +/* read the contents of the file from the server into the +* page */ + ret =afs_fetch_data (vnode, key, req); +afs_put_read (req); -/* send the page to the cache */ -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page) && -fscache_write_page (vnode->cache, page, vnode->status.size, -GFP_KERNEL ) !=0 ) { -fscache_uncache_page (vnode->cache, page); -BUG_ON (PageFsCache (page)); +if (ret <0 ) { +if (ret == -ENOENT ) { +_debug ("got NOENT from server" +" - marking file deleted and stale" ); +set_bit (AFS_VNODE_DELETED , &vnode->flags); + ret = -ESTALE ; } -#endif -unlock_page (page); + +if (ret == -EINTR || + ret == -ENOMEM || + ret == -ERESTARTSYS || + ret == -EAGAIN ) + goto error; + goto io_error; } +SetPageUptodate (page); +unlock_page (page); +_leave (" = 0" );return 0 ;
@@ -415,23 +354,10 @@ static int afs_readpage(struct file *file, struct page *page)*/ static void afs_readpages_page_done (struct afs_read *req) { -#ifdef CONFIG_AFS_FSCACHE -struct afs_vnode *vnode = req->vnode; -#endif struct page *page = req->pages[req->index]; req->pages[req->index] =NULL ;SetPageUptodate (page); - -/* send the page to the cache */ -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page) && -fscache_write_page (vnode->cache, page, vnode->status.size, -GFP_KERNEL ) !=0 ) { -fscache_uncache_page (vnode->cache, page); -BUG_ON (PageFsCache (page)); - } -#endif unlock_page (page);put_page (page); }
@@ -490,9 +416,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, index = page->index;if (add_to_page_cache_lru (page, mapping, index,readahead_gfp_mask (mapping))) { -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif put_page (page);break ; }
@@ -525,9 +448,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,for (i =0 ; i < req->nr_pages; i++) { page = req->pages[i];if (page) { -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif SetPageError (page);unlock_page (page); }
@@ -559,37 +479,6 @@ static int afs_readpages(struct file *file, struct address_space *mapping, }/* attempt to read as many of the pages as possible */ -#ifdef CONFIG_AFS_FSCACHE - ret =fscache_read_or_alloc_pages (vnode->cache, - mapping, - pages, - &nr_pages, - afs_file_readpage_read_complete, -NULL , -mapping_gfp_mask (mapping)); -#else - ret = -ENOBUFS ; -#endif - -switch (ret) { -/* all pages are being read from the cache */ -case 0 : -BUG_ON (!list_empty (pages)); -BUG_ON (nr_pages !=0 ); -_leave (" = 0 [reading all]" ); -return 0 ; - -/* there were pages that couldn't be read from the cache */ -case -ENODATA : -case -ENOBUFS : -break ; - -/* other error */ -default : -_leave (" = %d" , ret); -return ret; - } -while (!list_empty (pages)) { ret =afs_readpages_one (file, mapping, pages);if (ret <0 )
@@ -669,17 +558,6 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,BUG_ON (!PageLocked (page)); -#ifdef CONFIG_AFS_FSCACHE -/* we clean up only if the entire page is being invalidated */ -if (offset ==0 && length ==PAGE_SIZE ) { -if (PageFsCache (page)) { -struct afs_vnode *vnode =AFS_FS_I (page->mapping->host); -fscache_wait_on_page_write (vnode->cache, page); -fscache_uncache_page (vnode->cache, page); - } - } -#endif -if (PagePrivate (page))afs_invalidate_dirty (page, offset, length);
@@ -701,13 +579,6 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ -#ifdef CONFIG_AFS_FSCACHE -if (!fscache_maybe_release_page (vnode->cache, page, gfp_flags)) { -_leave (" = F [cache busy]" ); -return 0 ; - } -#endif -if (PagePrivate (page)) { priv = (unsigned long )detach_page_private (page); trace_afs_page_dirty(vnode, tracepoint_string("rel"),
fs/afs/inode.c +1 -1
@@ -427,7 +427,7 @@ static void afs_get_inode_cache(struct afs_vnode *vnode) }__packed key;struct afs_vnode_cache_aux aux; -if (vnode->status.type ==AFS_FTYPE_DIR ) { +if (vnode->status.type !=AFS_FTYPE_FILE ) { vnode->cache =NULL ;return ; }
fs/afs/write.c +0 -10
@@ -847,9 +847,6 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)/* Wait for the page to be written to the cache before we allow it to * be modified. We then assume the entire page will need writing back. */ -#ifdef CONFIG_AFS_FSCACHE -fscache_wait_on_page_write (vnode->cache, vmf->page); -#endif if (wait_on_page_writeback_killable (vmf->page))return VM_FAULT_RETRY ;
@@ -935,12 +932,5 @@ int afs_launder_page(struct page *page) priv = (unsigned long )detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("laundered" ), page->index, priv); - -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page)) { -fscache_wait_on_page_write (vnode->cache, page); -fscache_uncache_page (vnode->cache, page); - } -#endif return ret; }
David Howells
maintainerPATCH v6 18/30 afs: Pass page into dirty region helpers to provide THP size
In reply to David HowellsPass a pointer to the page being accessed into the dirty region helpers so that the size of the page can be determined in case it's a transparent huge page.
This also required the page to be passed into the afs_page_dirty trace point - so there's no need to specifically pass in the index or private data as these can be retrieved directly from the page struct.
---
fs/afs/file.c | 20 +++++++-------- fs/afs/internal.h | 16 ++++++------ fs/afs/write.c | 60 ++++++++++++++++++-------------------------- include/trace/events/afs.h | 23 ++++++++++------- 4 files changed, 55 insertions(+), 64 deletions(-)
fs/afs/file.c +9 -11
@@ -514,8 +514,8 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,return ;/* We may need to shorten the dirty region */ - f =afs_page_dirty_from (priv); - t =afs_page_dirty_to (priv); + f =afs_page_dirty_from (page, priv); + t =afs_page_dirty_to (page, priv);if (t <= offset || f >= end)return ;/* Doesn't overlap */
@@ -533,17 +533,17 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,if (f == t) goto undirty; - priv =afs_page_dirty (f, t); + priv =afs_page_dirty (page, f, t);set_page_private (page, priv); -trace_afs_page_dirty (vnode,tracepoint_string ("trunc" ), page->index, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("trunc" ), page);return ; undirty: -trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page->index, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page);clear_page_dirty_for_io (page); full_invalidate: - priv = (unsigned long )detach_page_private (page); -trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page->index, priv); +detach_page_private (page); +trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page); }/*
@@ -571,7 +571,6 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,static int afs_releasepage (struct page *page,gfp_t gfp_flags) {struct afs_vnode *vnode =AFS_FS_I (page->mapping->host); -unsigned long priv; _enter("{{%llx:%llu}[%lu],%lx},%x", vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
@@ -580,9 +579,8 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ if (PagePrivate (page)) { - priv = (unsigned long )detach_page_private (page); -trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), - page->index, priv); +detach_page_private (page); +trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page); }/* indicate that the page can be released */
fs/afs/internal.h +8 -8
@@ -875,31 +875,31 @@ struct afs_vnode_cache_aux {#define __AFS_PAGE_PRIV_MMAPPED 0x8000UL#endif -static inline unsigned int afs_page_dirty_resolution (void ) +static inline unsigned int afs_page_dirty_resolution (struct page *page) { -int shift =PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT -1 ); +int shift =thp_order (page) +PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT -1 );return (shift >0 ) ? shift :0 ; } -static inline size_t afs_page_dirty_from (unsigned long priv) +static inline size_t afs_page_dirty_from (struct page *page,unsigned long priv) {unsigned long x = priv & __AFS_PAGE_PRIV_MASK;/* The lower bound is inclusive */ -return x <<afs_page_dirty_resolution (); +return x <<afs_page_dirty_resolution (page); } -static inline size_t afs_page_dirty_to (unsigned long priv) +static inline size_t afs_page_dirty_to (struct page *page,unsigned long priv) {unsigned long x = (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK;/* The upper bound is immediately beyond the region */ -return (x +1 ) <<afs_page_dirty_resolution (); +return (x +1 ) <<afs_page_dirty_resolution (page); } -static inline unsigned long afs_page_dirty (size_t from,size_t to) +static inline unsigned long afs_page_dirty (struct page *page,size_t from,size_t to) { -unsigned int res =afs_page_dirty_resolution (); +unsigned int res =afs_page_dirty_resolution (page); from >>= res; to = (to -1 ) >> res;return (to << __AFS_PAGE_PRIV_SHIFT) | from;
fs/afs/write.c +25 -35
139 lines not on this page · raw message
include/trace/events/afs.h +13 -10
@@ -969,30 +969,33 @@ TRACE_EVENT(afs_dir_check_failed, );TRACE_EVENT (afs_page_dirty, - TP_PROTO(struct afs_vnode *vnode, const char *where, - pgoff_t page, unsigned long priv), + TP_PROTO(struct afs_vnode *vnode, const char *where, struct page *page), -TP_ARGS (vnode, where, page, priv), +TP_ARGS (vnode, where, page),TP_STRUCT__entry ( __field(struct afs_vnode *, vnode ) __field(const char *, where ) __field(pgoff_t, page ) - __field(unsigned long, priv ) + __field(unsigned long, from ) + __field(unsigned long, to ) ),TP_fast_assign ( __entry->vnode = vnode; __entry->where = where; - __entry->page = page; - __entry->priv = priv; + __entry->page = page->index; + __entry->from = afs_page_dirty_from(page, page->private); + __entry->to = afs_page_dirty_to(page, page->private); + __entry->to |= (afs_is_page_dirty_mmapped (page->private) ? + (1UL << (BITS_PER_LONG - 1)) : 0); ), -TP_printk ("vn=%p %lx %s %zx-%zx%s" , +TP_printk ("vn=%p %lx %s %lx-%lx%s" , __entry->vnode, __entry->page, __entry->where, -afs_page_dirty_from (__entry->priv), -afs_page_dirty_to (__entry->priv), -afs_is_page_dirty_mmapped (__entry->priv) ?" M" :"" ) + __entry->from, + __entry->to & ~(1UL << (BITS_PER_LONG -1 )), + __entry->to & (1UL << (BITS_PER_LONG -1 )) ?" M" :"" ) ); TRACE_EVENT(afs_call_state,
David Howells
maintainerPATCH v6 19/30 afs: Print the operation debug_id when logging an unexpected data version
In reply to David HowellsPrint the afs_operation debug_id when logging an unexpected change in the data version. This allows the logged message to be matched against tracelines.
---
fs/afs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/afs/inode.c +3 -2
@@ -214,11 +214,12 @@ static void afs_apply_status(struct afs_operation *op,if (vp->dv_before + vp->dv_delta != status->data_version) {if (test_bit (AFS_VNODE_CB_PROMISED , &vnode->flags)) -pr_warn ("kAFS: vnode modified {%llx:%llu} %llx->%llx %s\n" , +pr_warn ("kAFS: vnode modified {%llx:%llu} %llx->%llx %s (op=%x)\n" , vnode->fid.vid, vnode->fid.vnode, (unsigned long long )vp->dv_before + vp->dv_delta, (unsigned long long )status->data_version, - op->type ? op->type->name :"???" ); + op->type ? op->type->name :"???" , + op->debug_id); vnode->invalid_before = status->data_version;if (vnode->status.type ==AFS_FTYPE_DIR ) {
David Howells
maintainerPATCH v6 20/30 afs: Move key to afs_read struct
In reply to David HowellsStash the key used to authenticate read operations in the afs_read struct. This will be necessary to reissue the operation against the server if a read from the cache fails in upcoming cache changes.
---
fs/afs/dir.c | 3 ++- fs/afs/file.c | 16 +++++++++------- fs/afs/internal.h | 3 ++- fs/afs/write.c | 12 ++++++------ 4 files changed, 19 insertions(+), 15 deletions(-)
fs/afs/dir.c +2 -1
@@ -241,6 +241,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)return ERR_PTR (-ENOMEM );refcount_set (&req->usage,1 ); + req->key =key_get (key); req->nr_pages = nr_pages; req->actual_len = i_size;/* May change */ req->len = nr_pages *PAGE_SIZE ;/* We can ask for more than there is */
@@ -305,7 +306,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)if (!test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags)) {trace_afs_reload_dir (dvnode); - ret =afs_fetch_data (dvnode, key, req); + ret =afs_fetch_data (dvnode, req);if (ret <0 ) goto error_unlock;
fs/afs/file.c +9 -7
@@ -198,6 +198,7 @@ void afs_put_read(struct afs_read *req)if (req->pages != req->array)kfree (req->pages); } +key_put (req->key);kfree (req); } }
@@ -228,7 +229,7 @@ static const struct afs_operation_ops afs_fetch_data_operation = {/* * Fetch file data from the volume. */ -int afs_fetch_data (struct afs_vnode *vnode,struct key *key,struct afs_read *req) +int afs_fetch_data (struct afs_vnode *vnode,struct afs_read *req) {struct afs_operation *op;
@@ -237,9 +238,9 @@ int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *re vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique, - key_serial(key)); + key_serial(req->key)); - op =afs_alloc_operation (key, vnode->volume); + op =afs_alloc_operation (req->key, vnode->volume);if (IS_ERR (op))return PTR_ERR (op);
@@ -278,6 +279,7 @@ int afs_page_filler(void *data, struct page *page)* unmarshalling code will clear the unfilled space. */ refcount_set (&req->usage,1 ); + req->key =key_get (key); req->pos = (loff_t )page->index <<PAGE_SHIFT ; req->len =PAGE_SIZE ; req->nr_pages =1 ;
@@ -287,7 +289,7 @@ int afs_page_filler(void *data, struct page *page)/* read the contents of the file from the server into the * page */ - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);afs_put_read (req);if (ret <0 ) {
@@ -372,7 +374,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,struct afs_read *req;struct list_head *p;struct page *first, *page; -struct key *key =afs_file_key (file);pgoff_t index;int ret, n, i;
@@ -396,6 +397,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,refcount_set (&req->usage,1 ); req->vnode = vnode; + req->key =key_get (afs_file_key (file)); req->page_done = afs_readpages_page_done; req->pos = first->index; req->pos <<=PAGE_SHIFT ;
@@ -425,11 +427,11 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, }while (req->nr_pages < n);if (req->nr_pages ==0 ) { -kfree (req); +afs_put_read (req);return 0 ; } - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);if (ret <0 ) goto error;
fs/afs/internal.h +2 -1
@@ -204,6 +204,7 @@ struct afs_read {loff_t actual_len;/* How much we're actually getting */ loff_t remain;/* Amount remaining */ loff_t file_size;/* File size returned by server */ +struct key *key;/* The key to use to reissue the read */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage;unsigned int index;/* Which page we're reading into */
@@ -1045,7 +1046,7 @@ extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);extern void afs_put_wb_key (struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *); -extern int afs_fetch_data (struct afs_vnode *,struct key *,struct afs_read *); +extern int afs_fetch_data (struct afs_vnode *,struct afs_read *);extern int afs_page_filler (void *,struct page *);extern void afs_put_read (struct afs_read *);
fs/afs/write.c +6 -6
@@ -25,9 +25,10 @@ int afs_set_page_dirty(struct page *page)/* * partly or wholly fill a page that's under preparation for writing */ -static int afs_fill_page (struct afs_vnode *vnode,struct key *key, +static int afs_fill_page (struct file *file,loff_t pos,unsigned int len,struct page *page) { +struct afs_vnode *vnode =AFS_FS_I (file_inode (file));struct afs_read *req;size_t p;void *data;
@@ -49,6 +50,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,return -ENOMEM ;refcount_set (&req->usage,1 ); + req->key =key_get (afs_file_key (file)); req->pos = pos; req->len = len; req->nr_pages =1 ;
@@ -56,7 +58,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key, req->pages[0 ] = page;get_page (page); - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);afs_put_read (req);if (ret <0 ) {if (ret == -ENOENT ) {
@@ -80,7 +82,6 @@ int afs_write_begin(struct file *file, struct address_space *mapping, {struct afs_vnode *vnode =AFS_FS_I (file_inode (file));struct page *page; -struct key *key =afs_file_key (file);unsigned long priv;unsigned f, from = pos & (PAGE_SIZE -1 );unsigned t, to = from + len;
@@ -95,7 +96,7 @@ int afs_write_begin(struct file *file, struct address_space *mapping,return -ENOMEM ;if (!PageUptodate (page) && len !=PAGE_SIZE ) { - ret =afs_fill_page (vnode, key, pos &PAGE_MASK ,PAGE_SIZE , page); + ret =afs_fill_page (file, pos &PAGE_MASK ,PAGE_SIZE , page);if (ret <0 ) {unlock_page (page);put_page (page);
@@ -163,7 +164,6 @@ int afs_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); -struct key *key =afs_file_key (file);unsigned long priv;unsigned int f, from = pos & (PAGE_SIZE -1 );unsigned int t, to = from + copied;
@@ -193,7 +193,7 @@ int afs_write_end(struct file *file, struct address_space *mapping,* unmarshalling routine will take care of clearing any * bits that are beyond the EOF. */ - ret =afs_fill_page (vnode, key, pos + copied, + ret =afs_fill_page (file, pos + copied, len - copied, page);if (ret <0 ) goto out;
David Howells
maintainerPATCH v6 21/30 afs: Don't truncate iter during data fetch
In reply to David HowellsDon't truncate the iterator to correspond to the actual data size when fetching the data from the server - rather, pass the length we want to read to rxrpc.
This will allow the clear-after-read code in future to simply clear the remaining iterator capacity rather than having to reinitialise the iterator.
---
fs/afs/fsclient.c | 6 ++++-- fs/afs/internal.h | 6 ++++++ fs/afs/rxrpc.c | 13 +++++++++---- fs/afs/yfsclient.c | 6 ++++-- include/net/af_rxrpc.h | 2 +- net/rxrpc/recvmsg.c | 9 +++++---- 6 files changed, 29 insertions(+), 13 deletions(-)
fs/afs/fsclient.c +4 -2
@@ -305,8 +305,9 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)unsigned int size;int ret; -_enter ("{%u,%zu/%llu}" , - call->unmarshall,iov_iter_count (call->iter), req->actual_len); +_enter ("{%u,%zu,%zu/%llu}" , + call->unmarshall, call->iov_len,iov_iter_count (call->iter), + req->actual_len);switch (call->unmarshall) {case 0 :
@@ -343,6 +344,7 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call) size =PAGE_SIZE - req->offset; else size = req->remain; + call->iov_len = size; call->bvec[0 ].bv_len = size; call->bvec[0 ].bv_offset = req->offset; call->bvec[0 ].bv_page = req->pages[req->index];
fs/afs/internal.h +6 -0
@@ -104,6 +104,7 @@ struct afs_call {struct afs_server *server;/* The fileserver record if fs op (pins ref) */ struct afs_vlserver *vlserver;/* The vlserver record if vl op */ void *request;/* request data (first part) */ +size_t iov_len;/* Size of *iter to be used */ struct iov_iter def_iter;/* Default buffer/data iterator */ struct iov_iter *iter;/* Iterator currently in use */ union {/* Convenience for ->def_iter */
@@ -1271,6 +1272,7 @@ static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *cstatic inline void afs_extract_begin (struct afs_call *call,void *buf,size_t size) { + call->iov_len = size; call->kvec[0 ].iov_base = buf; call->kvec[0 ].iov_len = size;iov_iter_kvec (&call->def_iter,READ , call->kvec,1 , size);
@@ -1278,21 +1280,25 @@ static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t sistatic inline void afs_extract_to_tmp (struct afs_call *call) { + call->iov_len =sizeof (call->tmp);afs_extract_begin (call, &call->tmp,sizeof (call->tmp)); }static inline void afs_extract_to_tmp64 (struct afs_call *call) { + call->iov_len =sizeof (call->tmp64);afs_extract_begin (call, &call->tmp64,sizeof (call->tmp64)); }static inline void afs_extract_discard (struct afs_call *call,size_t size) { + call->iov_len = size;iov_iter_discard (&call->def_iter,READ , size); }static inline void afs_extract_to_buf (struct afs_call *call,size_t size) { + call->iov_len = size;afs_extract_begin (call, call->buffer, size); }
fs/afs/rxrpc.c +9 -4
@@ -363,6 +363,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)struct rxrpc_call *rxcall;struct msghdr msg;struct kvec iov[1 ]; +size_t len;s64 tx_total_len;int ret;
@@ -466,9 +467,10 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)rxrpc_kernel_abort_call (call->net->socket, rxcall,RX_USER_ABORT , ret,"KSD" ); }else { + len =0 ;iov_iter_kvec (&msg.msg_iter,READ ,NULL ,0 ,0 );rxrpc_kernel_recv_data (call->net->socket, rxcall, - &msg.msg_iter, false, + &msg.msg_iter, &len, false, &call->abort_code, &call->service_id); ac->abort_code = call->abort_code; ac->responded = true;
@@ -504,6 +506,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)static void afs_deliver_to_call (struct afs_call *call) {enum afs_call_state state; +size_t len;u32 abort_code, remote_abort =0 ;int ret;
@@ -516,10 +519,11 @@ static void afs_deliver_to_call(struct afs_call *call) state == AFS_CALL_SV_AWAIT_ACK ) {if (state ==AFS_CALL_SV_AWAIT_ACK ) { + len =0 ;iov_iter_kvec (&call->def_iter,READ ,NULL ,0 ,0 ); ret =rxrpc_kernel_recv_data (call->net->socket, call->rxcall, &call->def_iter, - false, &remote_abort, + &len, false, &remote_abort, &call->service_id);trace_afs_receive_data (call, &call->def_iter, false, ret);
@@ -929,10 +933,11 @@ int afs_extract_data(struct afs_call *call, bool want_more)u32 remote_abort =0 ;int ret; -_enter ("{%s,%zu},%d" , call->type->name,iov_iter_count (iter), want_more); +_enter ("{%s,%zu,%zu},%d" , + call->type->name, call->iov_len,iov_iter_count (iter), want_more); ret =rxrpc_kernel_recv_data (net->socket, call->rxcall, iter, - want_more, &remote_abort, + &call->iov_len, want_more, &remote_abort, &call->service_id);if (ret ==0 || ret == -EAGAIN )return ret;
fs/afs/yfsclient.c +4 -2
@@ -363,8 +363,9 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)unsigned int size;int ret; -_enter ("{%u,%zu/%llu}" , - call->unmarshall,iov_iter_count (call->iter), req->actual_len); +_enter ("{%u,%zu, %zu/%llu}" , + call->unmarshall, call->iov_len,iov_iter_count (call->iter), + req->actual_len);switch (call->unmarshall) {case 0 :
@@ -396,6 +397,7 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call) size =PAGE_SIZE - req->offset; else size = req->remain; + call->iov_len = size; call->bvec[0 ].bv_len = size; call->bvec[0 ].bv_offset = req->offset; call->bvec[0 ].bv_page = req->pages[req->index];
include/net/af_rxrpc.h +1 -1
@@ -53,7 +53,7 @@ int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *, struct msghdr *, size_t, rxrpc_notify_end_tx_t);int rxrpc_kernel_recv_data (struct socket *,struct rxrpc_call *, -struct iov_iter *,bool ,u32 *,u16 *); +struct iov_iter *,size_t *,bool ,u32 *,u16 *);bool rxrpc_kernel_abort_call (struct socket *,struct rxrpc_call *,u32 ,int ,const char *);void rxrpc_kernel_end_call (struct socket *,struct rxrpc_call *);
net/rxrpc/recvmsg.c +5 -4
@@ -669,6 +669,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,* @sock: The socket that the call exists on * @call: The call to send data through * @iter: The buffer to receive into +* @_len: The amount of data we want to receive (decreased on return) * @want_more: True if more data is expected to be read * @_abort: Where the abort code is stored if -ECONNABORTED is returned * @_service: Where to store the actual service ID (may be upgraded)
@@ -684,7 +685,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,* *_abort should also be initialised to 0. */ int rxrpc_kernel_recv_data (struct socket *sock,struct rxrpc_call *call, -struct iov_iter *iter, +struct iov_iter *iter,size_t *_len,bool want_more,u32 *_abort,u16 *_service) {size_t offset =0 ;
@@ -692,7 +693,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,_enter ("{%d,%s},%zu,%d" , call->debug_id, rxrpc_call_states[call->state], -iov_iter_count (iter), want_more); + *_len, want_more); ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_SECURING);
@@ -703,8 +704,8 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,case RXRPC_CALL_SERVER_RECV_REQUEST :case RXRPC_CALL_SERVER_ACK_REQUEST : ret =rxrpc_recvmsg_data (sock, call,NULL , iter, -iov_iter_count (iter),0 , - &offset); + *_len,0 , &offset); + *_len -= offset;if (ret <0 ) goto out;
David Howells
maintainerPATCH v6 22/30 afs: Log remote unmarshalling errors
In reply to David HowellsLog unmarshalling errors reported by the peer (ie. it can't parse what we sent it). Limit the maximum number of messages to 3.
---
fs/afs/rxrpc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
fs/afs/rxrpc.c +34 -0
@@ -500,6 +500,39 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)_leave (" = %d" , ret); } +/* +* Log remote abort codes that indicate that we have a protocol disagreement +* with the server. +*/ +static void afs_log_error (struct afs_call *call,s32 remote_abort) +{ +static int max =0 ; +const char *msg; +int m; + +switch (remote_abort) { +case RX_EOF : msg ="unexpected EOF" ;break ; +case RXGEN_CC_MARSHAL : msg ="client marshalling" ;break ; +case RXGEN_CC_UNMARSHAL : msg ="client unmarshalling" ;break ; +case RXGEN_SS_MARSHAL : msg ="server marshalling" ;break ; +case RXGEN_SS_UNMARSHAL : msg ="server unmarshalling" ;break ; +case RXGEN_DECODE : msg ="opcode decode" ;break ; +case RXGEN_SS_XDRFREE : msg ="server XDR cleanup" ;break ; +case RXGEN_CC_XDRFREE : msg ="client XDR cleanup" ;break ; +case -32 : msg ="insufficient data" ;break ; +default : +return ; + } + + m = max; +if (m <3 ) { + max = m +1 ; +pr_notice ("kAFS: Peer reported %s failure on %s [%pISp]\n" , + msg, call->type->name, + &call->alist->addrs[call->addr_ix].transport); + } +} +/* * deliver messages to a call */
@@ -563,6 +596,7 @@ static void afs_deliver_to_call(struct afs_call *call) goto out;case -ECONNABORTED : ASSERTCMP(state, ==, AFS_CALL_COMPLETE); +afs_log_error (call, call->abort_code); goto done;case -ENOTSUPP : abort_code =RXGEN_OPCODE ;
David Howells
maintainerPATCH v6 23/30 afs: Set up the iov_iter before calling afs_extract_data()
In reply to David Howellsafs_extract_data() sets up a temporary iov_iter and passes it to AF_RXRPC each time it is called to describe the remaining buffer to be filled.
Instead:
(1) Put an iterator in the afs_call struct.
(2) Set the iterator for each marshalling stage to load data into the appropriate places. A number of convenience functions are provided to this end (eg. afs_extract_to_buf()).
This iterator is then passed to afs_extract_data().
(3) Use the new ITER_XARRAY iterator when reading data to load directly into the inode's pages without needing to create a list of them.
This will allow O_DIRECT calls to be supported in future patches.
---
fs/afs/dir.c | 222 +++++++++++++++++++++++++++++++++++----------------- fs/afs/file.c | 190 ++++++++++++++++++++++++++------------------- fs/afs/fsclient.c | 54 +++---------- fs/afs/internal.h | 16 ++-- fs/afs/write.c | 27 ++++-- fs/afs/yfsclient.c | 54 +++---------- 6 files changed, 314 insertions(+), 249 deletions(-)
fs/afs/dir.c +149 -73
@@ -102,6 +102,35 @@ struct afs_lookup_cookie {struct afs_fid fids[50 ]; }; +/* +* Drop the refs that we're holding on the pages we were reading into. We've +* got refs on the first nr_pages pages. +*/ +static void afs_dir_read_cleanup (struct afs_read *req) +{ +struct address_space *mapping = req->vnode->vfs_inode.i_mapping; +struct page *page; +pgoff_t last = req->nr_pages -1 ; + +XA_STATE (xas, &mapping->i_pages,0 ); + +if (unlikely (!req->nr_pages)) +return ; + +rcu_read_lock (); +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; +BUG_ON (xa_is_value (page)); +BUG_ON (PageCompound (page)); + ASSERTCMP(page->mapping, ==, mapping); + +put_page (page); + } + +rcu_read_unlock (); +} +/* * check that a directory page is valid */
@@ -127,7 +156,7 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, qty /=sizeof (union afs_xdr_dir_block );/* check them */ - dbuf =kmap (page); + dbuf =kmap_atomic (page);for (tmp =0 ; tmp < qty; tmp++) {if (dbuf->blocks[tmp].hdr.magic !=AFS_DIR_MAGIC ) { printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n",
@@ -146,7 +175,7 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, ((u8 *)&dbuf->blocks[tmp])[AFS_DIR_BLOCK_SIZE -1 ] =0 ; } -kunmap (page); +kunmap_atomic (dbuf); checked:afs_stat_v (dvnode, n_read_dir);
@@ -157,35 +186,74 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, }/* -* Check the contents of a directory that we've just read. +* Dump the contents of a directory. */ -static bool afs_dir_check_pages (struct afs_vnode *dvnode,struct afs_read *req) +static void afs_dir_dump (struct afs_vnode *dvnode,struct afs_read *req) {struct afs_xdr_dir_page *dbuf; -unsigned int i, j, qty =PAGE_SIZE /sizeof (union afs_xdr_dir_block ); +struct address_space *mapping = dvnode->vfs_inode.i_mapping; +struct page *page; +unsigned int i, qty =PAGE_SIZE /sizeof (union afs_xdr_dir_block ); +pgoff_t last = req->nr_pages -1 ; -for (i =0 ; i < req->nr_pages; i++) -if (!afs_dir_check_page (dvnode, req->pages[i], req->actual_len)) - goto bad; -return true; +XA_STATE (xas, &mapping->i_pages,0 ); -bad: -pr_warn ("DIR %llx:%llx f=%llx l=%llx al=%llx r=%llx\n" , +pr_warn ("DIR %llx:%llx f=%llx l=%llx al=%llx\n" , dvnode->fid.vid, dvnode->fid.vnode, - req->file_size, req->len, req->actual_len, req->remain); -pr_warn ("DIR %llx %x %x %x\n" , - req->pos, req->index, req->nr_pages, req->offset); + req->file_size, req->len, req->actual_len); +pr_warn ("DIR %llx %x %zx %zx\n" , + req->pos, req->nr_pages, + req->iter->iov_offset,iov_iter_count (req->iter)); -for (i =0 ; i < req->nr_pages; i++) { - dbuf =kmap (req->pages[i]); -for (j =0 ; j < qty; j++) { -union afs_xdr_dir_block *block = &dbuf->blocks[j]; +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; + +BUG_ON (PageCompound (page)); +BUG_ON (page->mapping != mapping); + + dbuf =kmap_atomic (page); +for (i =0 ; i < qty; i++) { +union afs_xdr_dir_block *block = &dbuf->blocks[i]; -pr_warn ("[%02x] %32phN\n" , i * qty + j, block); +pr_warn ("[%02lx] %32phN\n" , page->index * qty + i, block); } -kunmap (req->pages[i]); +kunmap_atomic (dbuf); } -return false; +} + +/* +* Check all the pages in a directory. All the pages are held pinned. +*/ +static int afs_dir_check (struct afs_vnode *dvnode,struct afs_read *req) +{ +struct address_space *mapping = dvnode->vfs_inode.i_mapping; +struct page *page; +pgoff_t last = req->nr_pages -1 ; +int ret =0 ; + +XA_STATE (xas, &mapping->i_pages,0 ); + +if (unlikely (!req->nr_pages)) +return 0 ; + +rcu_read_lock (); +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; + +BUG_ON (PageCompound (page)); +BUG_ON (page->mapping != mapping); + +if (!afs_dir_check_page (dvnode, page, req->file_size)) { +afs_dir_dump (dvnode, req); + ret = -EIO ; +break ; + } + } + +rcu_read_unlock (); +return ret; }/*
@@ -214,58 +282,57 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key) {struct afs_read *req;loff_t i_size; -int nr_pages, nr_inline, i, n; -int ret = -ENOMEM ; +int nr_pages, i, n; +int ret; + +_enter ("" ); -retry: + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return ERR_PTR (-ENOMEM ); + +refcount_set (&req->usage,1 ); + req->vnode = dvnode; + req->key =key_get (key); + req->cleanup = afs_dir_read_cleanup; + +expand: i_size =i_size_read (&dvnode->vfs_inode); -if (i_size <2048 ) -return ERR_PTR (afs_bad (dvnode, afs_file_error_dir_small)); +if (i_size <2048 ) { + ret =afs_bad (dvnode, afs_file_error_dir_small); + goto error; + }if (i_size >2048 *1024 ) {trace_afs_file_error (dvnode, -EFBIG , afs_file_error_dir_big); -return ERR_PTR (-EFBIG ); + ret = -EFBIG ; + goto error; }_enter ("%llu" , i_size); -/* Get a request record to hold the page list. We want to hold it -* inline if we can, but we don't want to make an order 1 allocation. -*/ nr_pages = (i_size +PAGE_SIZE -1 ) /PAGE_SIZE ; - nr_inline = nr_pages; -if (nr_inline > (PAGE_SIZE -sizeof (*req)) /sizeof (struct page *)) - nr_inline =0 ; - req =kzalloc (struct_size (req, array, nr_inline),GFP_KERNEL ); -if (!req) -return ERR_PTR (-ENOMEM ); - -refcount_set (&req->usage,1 ); - req->key =key_get (key); - req->nr_pages = nr_pages; req->actual_len = i_size;/* May change */ req->len = nr_pages *PAGE_SIZE ;/* We can ask for more than there is */ req->data_version = dvnode->status.data_version;/* May change */ -if (nr_inline >0 ) { - req->pages = req->array; - }else { - req->pages =kcalloc (nr_pages,sizeof (struct page *), -GFP_KERNEL ); -if (!req->pages) - goto error; - } +iov_iter_xarray (&req->def_iter,READ , &dvnode->vfs_inode.i_mapping->i_pages, +0 , i_size); + req->iter = &req->def_iter; -/* Get a list of all the pages that hold or will hold the directory -* content. We need to fill in any gaps that we might find where the -* memory reclaimer has been at work. If there are any gaps, we will +/* Fill in any gaps that we might find where the memory reclaimer has +* been at work and pin all the pages. If there are any gaps, we will * need to reread the entire directory contents. */ - i =0 ; - do { + i = req->nr_pages; +while (i < nr_pages) { +struct page *pages[8 ], *page; + n =find_get_pages_contig (dvnode->vfs_inode.i_mapping, i, - req->nr_pages - i, - req->pages + i); - _debug("find %u at %u/%u", n, i, req->nr_pages); + min_t(unsigned int, nr_pages - i, +ARRAY_SIZE (pages)), + pages); +_debug ("find %u at %u/%u" , n, i, nr_pages); +if (n ==0 ) {gfp_t gfp = dvnode->vfs_inode.i_mapping->gfp_mask;
@@ -273,22 +340,24 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)afs_stat_v (dvnode, n_inval); ret = -ENOMEM ; - req->pages[i] =__page_cache_alloc (gfp); -if (!req->pages[i]) + page =__page_cache_alloc (gfp); +if (!page) goto error; - ret =add_to_page_cache_lru (req->pages[i], + ret =add_to_page_cache_lru (page, dvnode->vfs_inode.i_mapping, i, gfp);if (ret <0 ) goto error; -attach_page_private (req->pages[i], (void *)1 ); -unlock_page (req->pages[i]); +attach_page_private (page, (void *)1 ); +unlock_page (page); + req->nr_pages++; i++; }else { + req->nr_pages += n; i += n; } - }while (i < req->nr_pages); + }/* If we're going to reload, we need to lock all the pages to prevent * races.
@@ -312,12 +381,17 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)task_io_account_read (PAGE_SIZE * req->nr_pages); -if (req->len < req->file_size) - goto content_has_grown; +if (req->len < req->file_size) { +/* The content has grown, so we need to expand the +* buffer. +*/ +up_write (&dvnode->validate_lock); + goto expand; + }/* Validate the data we just read. */ - ret = -EIO ; -if (!afs_dir_check_pages (dvnode, req)) + ret =afs_dir_check (dvnode, req); +if (ret <0 ) goto error_unlock;// TODO: Trim excess pages
@@ -335,11 +409,6 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)afs_put_read (req);_leave (" = %d" , ret);return ERR_PTR (ret); - -content_has_grown: -up_write (&dvnode->validate_lock); -afs_put_read (req); - goto retry; }/*
@@ -449,6 +518,7 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx,struct afs_read *req;struct page *page;unsigned blkoff, limit; +void __rcu **slot;int ret;_enter ("{%lu},%u,," , dir->i_ino, (unsigned )ctx->pos);
@@ -473,9 +543,15 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, blkoff = ctx->pos & ~(sizeof (union afs_xdr_dir_block ) -1 );/* Fetch the appropriate page from the directory and re-add it -* to the LRU. +* to the LRU. We have all the pages pinned with an extra ref. */ - page = req->pages[blkoff /PAGE_SIZE ]; +rcu_read_lock (); + page =NULL ; + slot =radix_tree_lookup_slot (&dvnode->vfs_inode.i_mapping->i_pages, + blkoff /PAGE_SIZE ); +if (slot) + page =radix_tree_deref_slot (slot); +rcu_read_unlock ();if (!page) { ret =afs_bad (dvnode, afs_file_error_dir_missing_page);break ;
fs/afs/file.c +110 -80
287 lines not on this page · raw message
fs/afs/fsclient.c +14 -40
103 lines not on this page · raw message
fs/afs/internal.h +8 -8
@@ -31,6 +31,7 @@struct pagevec ;struct afs_call ; +struct afs_vnode ;/* * Partial file-locking emulation mode. (The problem being that AFS3 only
@@ -203,18 +204,18 @@ struct afs_read {loff_t pos;/* Where to start reading */ loff_t len;/* How much we're asking for */ loff_t actual_len;/* How much we're actually getting */ -loff_t remain;/* Amount remaining */ loff_t file_size;/* File size returned by server */ struct key *key;/* The key to use to reissue the read */ +struct afs_vnode *vnode;/* The file being read into. */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage; -unsigned int index;/* Which page we're reading into */ +unsigned int call_debug_id;unsigned int nr_pages; -unsigned int offset;/* offset into current page */ -struct afs_vnode *vnode; -void (*page_done)(struct afs_read *); -struct page **pages; -struct page *array[]; +int error; +void (*done)(struct afs_read *); +void (*cleanup)(struct afs_read *); +struct iov_iter *iter;/* Iterator representing the buffer */ +struct iov_iter def_iter;/* Default iterator */ };/*
@@ -1048,7 +1049,6 @@ extern void afs_put_wb_key(struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *);extern int afs_fetch_data (struct afs_vnode *,struct afs_read *); -extern int afs_page_filler (void *,struct page *);extern void afs_put_read (struct afs_read *);static inline struct afs_read *afs_get_read (struct afs_read *req)
fs/afs/write.c +19 -8
@@ -22,6 +22,16 @@ int afs_set_page_dirty(struct page *page)return __set_page_dirty_nobuffers (page); } +/* +* Handle completion of a read operation to fill a page. +*/ +static void afs_fill_hole (struct afs_read *req) +{ +if (iov_iter_count (req->iter) >0 ) +/* The read was short - clear the excess buffer. */ +iov_iter_zero (iov_iter_count (req->iter), req->iter); +} +/* * partly or wholly fill a page that's under preparation for writing */
@@ -45,18 +55,19 @@ static int afs_fill_page(struct file *file,return 0 ; } - req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); + req =kzalloc (sizeof (struct afs_read ),GFP_KERNEL );if (!req)return -ENOMEM ;refcount_set (&req->usage,1 ); - req->key =key_get (afs_file_key (file)); - req->pos = pos; - req->len = len; - req->nr_pages =1 ; - req->pages = req->array; - req->pages[0 ] = page; -get_page (page); + req->vnode = vnode; + req->done = afs_fill_hole; + req->key =key_get (afs_file_key (file)); + req->pos = pos; + req->len = len; + req->nr_pages =1 ; + req->iter = &req->def_iter; +iov_iter_xarray (&req->def_iter,READ , &file->f_mapping->i_pages, pos, len); ret =afs_fetch_data (vnode, req);afs_put_read (req);
fs/afs/yfsclient.c +14 -40
101 lines not on this page · raw message
David Howells
maintainerPATCH v6 24/30 afs: Use ITER_XARRAY for writing
In reply to David HowellsUse a single ITER_XARRAY iterator to describe the portion of a file to be transmitted to the server rather than generating a series of small ITER_BVEC iterators on the fly. This will make it easier to implement AIO in afs.
In theory we could maybe use one giant ITER_BVEC, but that means potentially allocating a huge array of bio_vec structs (max 256 per page) when in fact the pagecache already has a structure listing all the relevant pages (radix_tree/xarray) that can be walked over.
---
fs/afs/fsclient.c | 50 +++++++++------------ fs/afs/internal.h | 15 +++--- fs/afs/rxrpc.c | 103 ++++++-------------------------------------- fs/afs/write.c | 100 ++++++++++++++++++++++++------------------- fs/afs/yfsclient.c | 25 +++-------- include/trace/events/afs.h | 51 ++++++++-------------- 6 files changed, 126 insertions(+), 218 deletions(-)
fs/afs/fsclient.c +20 -30
@@ -1055,8 +1055,7 @@ static const struct afs_call_type afs_RXFSStoreData64 = {/* * store a set of pages to a very large file */ -static void afs_fs_store_data64 (struct afs_operation *op, -loff_t pos,loff_t size,loff_t i_size) +static void afs_fs_store_data64 (struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call;
@@ -1071,7 +1070,7 @@ static void afs_fs_store_data64(struct afs_operation *op,if (!call)return afs_op_nomem (op); - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1087,47 +1086,38 @@ static void afs_fs_store_data64(struct afs_operation *op, *bp++ =0 ;/* unix mode */ *bp++ =0 ;/* segment size */ - *bp++ =htonl (upper_32_bits (pos)); - *bp++ =htonl (lower_32_bits (pos)); - *bp++ =htonl (upper_32_bits (size)); - *bp++ =htonl (lower_32_bits (size)); - *bp++ =htonl (upper_32_bits (i_size)); - *bp++ =htonl (lower_32_bits (i_size)); + *bp++ =htonl (upper_32_bits (op->store.pos)); + *bp++ =htonl (lower_32_bits (op->store.pos)); + *bp++ =htonl (upper_32_bits (op->store.size)); + *bp++ =htonl (lower_32_bits (op->store.size)); + *bp++ =htonl (upper_32_bits (op->store.i_size)); + *bp++ =htonl (lower_32_bits (op->store.i_size));trace_afs_make_fs_call (call, &vp->fid);afs_make_op_call (op, call,GFP_NOFS ); }/* -* store a set of pages +* Write data to a file on the server. */ void afs_fs_store_data (struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call; -loff_t size, pos, i_size;__be32 *bp;_enter (",%x,{%llx:%llu},," ,key_serial (op->key), vp->fid.vid, vp->fid.vnode); - size = (loff_t )op->store.last_to - (loff_t )op->store.first_offset; -if (op->store.first != op->store.last) - size += (loff_t)(op->store.last - op->store.first) <<PAGE_SHIFT ; - pos = (loff_t )op->store.first <<PAGE_SHIFT ; - pos += op->store.first_offset; - - i_size =i_size_read (&vp->vnode->vfs_inode); -if (pos + size > i_size) - i_size = size + pos; -_debug ("size %llx, at %llx, i_size %llx" , - (unsigned long long ) size, (unsigned long long ) pos, - (unsigned long long ) i_size); + (unsigned long long )op->store.size, + (unsigned long long )op->store.pos, + (unsigned long long )op->store.i_size); -if (upper_32_bits (pos) ||upper_32_bits (i_size) ||upper_32_bits (size) || -upper_32_bits (pos + size)) -return afs_fs_store_data64 (op, pos, size, i_size); +if (upper_32_bits (op->store.pos) || +upper_32_bits (op->store.size) || +upper_32_bits (op->store.i_size)) +return afs_fs_store_data64 (op); call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData, (4 + 6 + 3) * 4,
@@ -1135,7 +1125,7 @@ void afs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1151,9 +1141,9 @@ void afs_fs_store_data(struct afs_operation *op) *bp++ =0 ;/* unix mode */ *bp++ =0 ;/* segment size */ - *bp++ =htonl (lower_32_bits (pos)); - *bp++ =htonl (lower_32_bits (size)); - *bp++ =htonl (lower_32_bits (i_size)); + *bp++ =htonl (lower_32_bits (op->store.pos)); + *bp++ =htonl (lower_32_bits (op->store.size)); + *bp++ =htonl (lower_32_bits (op->store.i_size));trace_afs_make_fs_call (call, &vp->fid);afs_make_op_call (op, call,GFP_NOFS );
fs/afs/internal.h +8 -7
@@ -107,6 +107,7 @@ struct afs_call {void *request;/* request data (first part) */ size_t iov_len;/* Size of *iter to be used */ struct iov_iter def_iter;/* Default buffer/data iterator */ +struct iov_iter *write_iter;/* Iterator defining write to be made */ struct iov_iter *iter;/* Iterator currently in use */ union {/* Convenience for ->def_iter */ struct kvec kvec[1 ];
@@ -133,7 +134,6 @@ struct afs_call {unsigned char unmarshall;/* unmarshalling phase */ unsigned char addr_ix;/* Address in ->alist */ bool drop_ref;/* T if need to drop ref for incoming call */ -bool send_pages;/* T if data from mapping should be sent */ bool need_attention;/* T if RxRPC poked us */ bool async;/* T if asynchronous */ bool upgrade;/* T to request service upgrade */
@@ -811,12 +811,13 @@ struct afs_operation {afs_lock_type_t type; } lock;struct { -struct address_space *mapping;/* Pages being written from */ -pgoff_t first;/* first page in mapping to deal with */ -pgoff_t last;/* last page in mapping to deal with */ -unsigned first_offset;/* offset into mapping[first] */ -unsigned last_to;/* amount of mapping[last] */ -bool laundering;/* Laundering page, PG_writeback not set */ +struct iov_iter *write_iter; +loff_t pos; +loff_t size; +loff_t i_size; +pgoff_t first;/* first page in mapping to deal with */ +pgoff_t last;/* last page in mapping to deal with */ +bool laundering;/* Laundering page, PG_writeback not set */ } store;struct {struct iattr *attr;
fs/afs/rxrpc.c +15 -88
133 lines not on this page · raw message
fs/afs/write.c +57 -43
176 lines not on this page · raw message
fs/afs/yfsclient.c +7 -18
@@ -1078,25 +1078,15 @@ void yfs_fs_store_data(struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call; -loff_t size, pos, i_size;__be32 *bp;_enter (",%x,{%llx:%llu},," ,key_serial (op->key), vp->fid.vid, vp->fid.vnode); - size = (loff_t )op->store.last_to - (loff_t )op->store.first_offset; -if (op->store.first != op->store.last) - size += (loff_t)(op->store.last - op->store.first) <<PAGE_SHIFT ; - pos = (loff_t )op->store.first <<PAGE_SHIFT ; - pos += op->store.first_offset; - - i_size =i_size_read (&vp->vnode->vfs_inode); -if (pos + size > i_size) - i_size = size + pos; -_debug ("size %llx, at %llx, i_size %llx" , - (unsigned long long )size, (unsigned long long )pos, - (unsigned long long )i_size); + (unsigned long long )op->store.size, + (unsigned long long )op->store.pos, + (unsigned long long )op->store.i_size); call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64, sizeof(__be32) +
@@ -1109,8 +1099,7 @@ void yfs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->key = op->key; - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1118,9 +1107,9 @@ void yfs_fs_store_data(struct afs_operation *op) bp =xdr_encode_u32 (bp,0 );/* RPC flags */ bp =xdr_encode_YFSFid (bp, &vp->fid); bp =xdr_encode_YFSStoreStatus_mtime (bp, &op->mtime); - bp =xdr_encode_u64 (bp, pos); - bp =xdr_encode_u64 (bp, size); - bp =xdr_encode_u64 (bp, i_size); + bp =xdr_encode_u64 (bp, op->store.pos); + bp =xdr_encode_u64 (bp, op->store.size); + bp =xdr_encode_u64 (bp, op->store.i_size);yfs_check_req (call, bp);trace_afs_make_fs_call (call, &vp->fid);
include/trace/events/afs.h +19 -32
84 lines not on this page · raw message
David Howells
maintainerPATCH v6 25/30 afs: Wait on PG_fscache before modifying/releasing a page
In reply to David HowellsPG_fscache is going to be used to indicate that a page is being written to the cache, and that the page should not be modified or released until it's finished.
Make afs_invalidatepage() and afs_releasepage() wait for it.
---
fs/afs/file.c | 9 +++++++++ fs/afs/write.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
fs/afs/file.c +9 -0
@@ -593,6 +593,7 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,if (PagePrivate (page))afs_invalidate_dirty (page, offset, length); +wait_on_page_fscache (page);_leave ("" ); }
@@ -610,6 +611,14 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ +#ifdef CONFIG_AFS_FSCACHE +if (PageFsCache (page)) { +if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS)) +return false; +wait_on_page_fscache (page); + } +#endif +if (PagePrivate (page)) {detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page);
fs/afs/write.c +10 -0
@@ -117,6 +117,10 @@ int afs_write_begin(struct file *file, struct address_space *mapping,SetPageUptodate (page); } +#ifdef CONFIG_AFS_FSCACHE +wait_on_page_fscache (page); +#endif + try_again:/* See if this page is already partially written in a way that we can * merge the new write with.
@@ -857,6 +861,11 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)/* Wait for the page to be written to the cache before we allow it to * be modified. We then assume the entire page will need writing back. */ +#ifdef CONFIG_AFS_FSCACHE +if (PageFsCache (vmf->page) && +wait_on_page_bit_killable (vmf->page, PG_fscache) <0 ) +return VM_FAULT_RETRY ; +#endif if (wait_on_page_writeback_killable (vmf->page))return VM_FAULT_RETRY ;
@@ -947,5 +956,6 @@ int afs_launder_page(struct page *page)detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("laundered" ), page); +wait_on_page_fscache (page);return ret; }
David Howells
maintainerPATCH v6 26/30 afs: Extract writeback extension into its own function
In reply to David HowellsExtract writeback extension into its own function to break up the writeback function a bit.
---
fs/afs/write.c | 109 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 42 deletions(-)
fs/afs/write.c +67 -42
@@ -490,47 +490,25 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, }/* -* Synchronously write back the locked page and any subsequent non-locked dirty -* pages. +* Extend the region to be written back to include subsequent contiguously +* dirty pages if possible, but don't sleep while doing so. +* +* If this page holds new content, then we can include filler zeros in the +* writeback. */ -static int afs_write_back_from_locked_page (struct address_space *mapping, -struct writeback_control *wbc, -struct page *primary_page, -pgoff_t final_page) +static void afs_extend_writeback (struct address_space *mapping, +struct afs_vnode *vnode, +long *_count, +pgoff_t start, +pgoff_t final_page, +unsigned *_offset, +unsigned *_to, +bool new_content) { -struct afs_vnode *vnode =AFS_FS_I (mapping->host); -struct iov_iter iter;struct page *pages[8 ], *page; -unsigned long count, priv; -unsigned n, offset, to, f, t; -pgoff_t start, first, last; -loff_t i_size, pos, end; -int loop, ret; - -_enter (",%lx" , primary_page->index); - - count =1 ; -if (test_set_page_writeback (primary_page)) -BUG (); - -/* Find all consecutive lockable dirty pages that have contiguous -* written regions, stopping when we find a page that is not -* immediately lockable, is not dirty or is missing, or we reach the -* end of the range. -*/ - start = primary_page->index; - priv =page_private (primary_page); - offset =afs_page_dirty_from (primary_page, priv); - to =afs_page_dirty_to (primary_page, priv); -trace_afs_page_dirty (vnode,tracepoint_string ("store" ), primary_page); - -WARN_ON (offset == to); -if (offset == to) -trace_afs_page_dirty (vnode,tracepoint_string ("WARN" ), primary_page); - -if (start >= final_page || - (to <PAGE_SIZE && !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags))) - goto no_more; +unsigned long count = *_count, priv; +unsigned offset = *_offset, to = *_to, n, f, t; +int loop; start++; do {
@@ -551,8 +529,7 @@ static int afs_write_back_from_locked_page(struct address_space *mapping,for (loop =0 ; loop < n; loop++) { page = pages[loop]; -if (to !=PAGE_SIZE && - !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags)) +if (to !=PAGE_SIZE && !new_content)break ;if (page->index > final_page)break ;
@@ -566,8 +543,7 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, priv =page_private (page); f =afs_page_dirty_from (page, priv); t =afs_page_dirty_to (page, priv); -if (f !=0 && - !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags)) { +if (f !=0 && !new_content) {unlock_page (page);break ; }
@@ -593,6 +569,55 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, }while (start <= final_page && count <65536 ); no_more: + *_count = count; + *_offset = offset; + *_to = to; +} + +/* +* Synchronously write back the locked page and any subsequent non-locked dirty +* pages. +*/ +static int afs_write_back_from_locked_page (struct address_space *mapping, +struct writeback_control *wbc, +struct page *primary_page, +pgoff_t final_page) +{ +struct afs_vnode *vnode =AFS_FS_I (mapping->host); +struct iov_iter iter; +unsigned long count, priv; +unsigned offset, to; +pgoff_t start, first, last; +loff_t i_size, pos, end; +bool new_content =test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags); +int ret; + +_enter (",%lx" , primary_page->index); + + count =1 ; +if (test_set_page_writeback (primary_page)) +BUG (); + +/* Find all consecutive lockable dirty pages that have contiguous +* written regions, stopping when we find a page that is not +* immediately lockable, is not dirty or is missing, or we reach the +* end of the range. +*/ + start = primary_page->index; + priv =page_private (primary_page); + offset =afs_page_dirty_from (primary_page, priv); + to =afs_page_dirty_to (primary_page, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("store" ), primary_page); + +WARN_ON (offset == to); +if (offset == to) +trace_afs_page_dirty (vnode,tracepoint_string ("WARN" ), primary_page); + +if (start < final_page && + (to ==PAGE_SIZE || new_content)) +afs_extend_writeback (mapping, vnode, &count, start, final_page, + &offset, &to, new_content); +/* We now have a contiguous set of dirty pages, each with writeback * set; the first page is still locked at this point, but all the rest * have been unlocked.
David Howells
maintainerPATCH v6 27/30 afs: Prepare for use of THPs
In reply to David HowellsAs a prelude to supporting transparent huge pages, use thp_size() and similar rather than PAGE_SIZE/SHIFT.
Further, try and frame everything in terms of file positions and lengths rather than page indices and numbers of pages.
---
fs/afs/dir.c | 2 fs/afs/file.c | 8 - fs/afs/internal.h | 2 fs/afs/write.c | 434 +++++++++++++++++++++++++++++------------------------ 4 files changed, 244 insertions(+), 202 deletions(-)
fs/afs/dir.c +1 -1
@@ -2083,6 +2083,6 @@ static void afs_dir_invalidatepage(struct page *page, unsigned int offset,afs_stat_v (dvnode, n_inval);/* we clean up only if the entire page is being invalidated */ -if (offset ==0 && length ==PAGE_SIZE ) +if (offset ==0 && length ==thp_size (page))detach_page_private (page); }
fs/afs/file.c +4 -4
@@ -329,8 +329,8 @@ static int afs_page_filler(struct key *key, struct page *page) req->vnode = vnode; req->key =key_get (key); req->pos = (loff_t )page->index <<PAGE_SHIFT ; - req->len =PAGE_SIZE ; - req->nr_pages =1 ; + req->len =thp_size (page); + req->nr_pages =thp_nr_pages (page); req->done = afs_file_read_done; req->cleanup = afs_file_read_cleanup;
@@ -574,8 +574,8 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page);clear_page_dirty_for_io (page); full_invalidate: -detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page); +detach_page_private (page); }/*
@@ -620,8 +620,8 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)#endif if (PagePrivate (page)) { -detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page); +detach_page_private (page); }/* indicate that the page can be released */
fs/afs/internal.h +0 -2
@@ -815,8 +815,6 @@ struct afs_operation {loff_t pos;loff_t size;loff_t i_size; -pgoff_t first;/* first page in mapping to deal with */ -pgoff_t last;/* last page in mapping to deal with */ bool laundering;/* Laundering page, PG_writeback not set */ } store;struct {
fs/afs/write.c +239 -195
753 lines not on this page · raw message
David Howells
maintainerPATCH v6 28/30 afs: Use the fs operation ops to handle FetchData completion
In reply to David HowellsUse the 'success' and 'aborted' afs_operations_ops methods and add a 'failed' method to handle the completion of an AFS.FetchData, AFS.FetchData64 or YFS.FetchData64 RPC operation rather than directly calling the done func pointed to by the afs_read struct from the call delivery handler.
This means the done function will be called back on error also, not just on successful completion.
This allows motion towards asynchronous data reception on data fetch calls and allows any error to be handed off to the fscache read helper in the same place as a successful completion.
---
fs/afs/file.c | 15 +++++++++++++++ fs/afs/fs_operation.c | 4 +++- fs/afs/fsclient.c | 3 --- fs/afs/internal.h | 1 + fs/afs/yfsclient.c | 3 --- 5 files changed, 19 insertions(+), 7 deletions(-)
fs/afs/file.c +15 -0
@@ -254,6 +254,19 @@ void afs_put_read(struct afs_read *req) } } +static void afs_fetch_data_notify (struct afs_operation *op) +{ +struct afs_read *req = op->fetch.req; +int error = op->error; + +if (error == -ECONNABORTED ) + error =afs_abort_to_error (op->ac.abort_code); + req->error = error; + +if (req->done) + req->done (req); +} +static void afs_fetch_data_success (struct afs_operation *op) {struct afs_vnode *vnode = op->file[0 ].vnode;
@@ -262,6 +275,7 @@ static void afs_fetch_data_success(struct afs_operation *op)afs_vnode_commit_status (op, &op->file[0 ]);afs_stat_v (vnode, n_fetches);atomic_long_add (op->fetch.req->actual_len, &op->net->n_fetch_bytes); +afs_fetch_data_notify (op); }static void afs_fetch_data_put (struct afs_operation *op)
@@ -275,6 +289,7 @@ static const struct afs_operation_ops afs_fetch_data_operation = { .issue_yfs_rpc = yfs_fs_fetch_data, .success = afs_fetch_data_success, .aborted = afs_check_for_remote_deletion, + .failed = afs_fetch_data_notify, .put = afs_fetch_data_put, };
fs/afs/fs_operation.c +3 -1
@@ -198,8 +198,10 @@ void afs_wait_for_operation(struct afs_operation *op)case -ECONNABORTED :if (op->ops->aborted) op->ops->aborted (op); -break ; + fallthrough;default : +if (op->ops->failed) + op->ops->failed (op);break ; }
fs/afs/fsclient.c +0 -3
@@ -392,9 +392,6 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)break ; } -if (req->done) - req->done (req); -_leave (" = 0 [done]" );return 0 ; }
fs/afs/internal.h +1 -0
@@ -742,6 +742,7 @@ struct afs_operation_ops {void (*issue_yfs_rpc)(struct afs_operation *op);void (*success)(struct afs_operation *op);void (*aborted)(struct afs_operation *op); +void (*failed)(struct afs_operation *op);void (*edit_dir)(struct afs_operation *op);void (*put)(struct afs_operation *op); };
fs/afs/yfsclient.c +0 -3
@@ -449,9 +449,6 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)break ; } -if (req->done) - req->done (req); -_leave (" = 0 [done]" );return 0 ; }
David Howells
maintainerPATCH v6 29/30 afs: Use new netfs lib read helper API
In reply to David HowellsMake AFS use the new netfs read helpers to implement the VM read operations:
- afs_readpage() now hands off responsibility to netfs_readpage().
- afs_readpages() is gone and replaced with afs_readahead().
- afs_readahead() just hands off responsibility to netfs_readahead().
These make use of the cache if a cookie is supplied, otherwise just call the ->issue_op() method a sufficient number of times to complete the entire request.
Changes:
v5:
- Use proper wait function for PG_fscache in afs_page_mkwrite()[1].
- Use killable wait for PG_writeback in afs_page_mkwrite()[1].
v4:
- Folded in error handling fixes to afs_req_issue_op().
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue.
---
fs/afs/Kconfig | 1 fs/afs/file.c | 327 +++++++++++++---------------------------------------- fs/afs/fsclient.c | 1 fs/afs/internal.h | 3 fs/afs/write.c | 7 + 5 files changed, 88 insertions(+), 251 deletions(-)
fs/afs/Kconfig +1 -0
@@ -4,6 +4,7 @@ config AFS_FS depends on INET select AF_RXRPC select DNS_RESOLVER + select NETFS_SUPPORT help If you say Y here, you will get an experimental Andrew File System driver. It currently only supports unsecured read-only AFS access.
fs/afs/file.c +78 -249
404 lines not on this page · raw message
fs/afs/fsclient.c +1 -0
@@ -10,6 +10,7 @@#include <linux/sched.h> #include <linux/circ_buf.h> #include <linux/iversion.h> +#include <linux/netfs.h> #include "internal.h" #include "afs_fs.h" #include "xdr_fs.h"
fs/afs/internal.h +3 -0
@@ -14,6 +14,7 @@#include <linux/key.h> #include <linux/workqueue.h> #include <linux/sched.h> +#define FSCACHE_USE_NEW_IO_API #include <linux/fscache.h> #include <linux/backing-dev.h> #include <linux/uuid.h>
@@ -207,6 +208,7 @@ struct afs_read {loff_t file_size;/* File size returned by server */ struct key *key;/* The key to use to reissue the read */ struct afs_vnode *vnode;/* The file being read into. */ +struct netfs_read_subrequest *subreq;/* Fscache helper read request this belongs to */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage;unsigned int call_debug_id;
@@ -1049,6 +1051,7 @@ extern void afs_put_wb_key(struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *);extern int afs_fetch_data (struct afs_vnode *,struct afs_read *); +extern struct afs_read *afs_alloc_read (gfp_t );extern void afs_put_read (struct afs_read *);static inline struct afs_read *afs_get_read (struct afs_read *req)
fs/afs/write.c +5 -2
@@ -930,7 +930,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)*/ #ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page) && -wait_on_page_bit_killable (page, PG_fscache) <0 ) +wait_on_page_fscache_killable (page) <0 )return VM_FAULT_RETRY ;#endif
@@ -944,7 +944,10 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)* details the portion of the page we need to write back and we might * need to redirty the page if there's a problem. */ -wait_on_page_writeback (page); +if (wait_on_page_writeback_killable (page) <0 ) { +unlock_page (page); +return VM_FAULT_RETRY ; + } priv =afs_page_dirty (page,0 ,thp_size (page)); priv =afs_page_dirty_mmapped (priv);
David Howells
maintainerPATCH v6 30/30 afs: Use the netfs_write_begin() helper
In reply to David HowellsMake AFS use the new netfs_write_begin() helper to do the pre-reading required before the write. If successful, the helper returns with the required page filled in and locked. It may read more than just one page, expanding the read to meet cache granularity requirements as necessary.
Note: A more advanced version of this could be made that does generic_perform_write() for a whole cache granule. This would make it easier to avoid doing the download/read for the data to be overwritten.
---
fs/afs/file.c | 19 +++++++++ fs/afs/internal.h | 1 fs/afs/write.c | 108 ++++++----------------------------------------------- 3 files changed, 31 insertions(+), 97 deletions(-)
fs/afs/file.c +18 -1
@@ -333,6 +333,13 @@ static void afs_init_rreq(struct netfs_read_request *rreq, struct file *file) rreq->netfs_priv =key_get (afs_file_key (file)); } +static bool afs_is_cache_enabled (struct inode *inode) +{ +struct fscache_cookie *cookie =afs_vnode_cache (AFS_FS_I (inode)); + +return fscache_cookie_enabled (cookie) && !hlist_empty (&cookie->backing_objects); +} +static int afs_begin_cache_operation (struct netfs_read_request *rreq) {struct afs_vnode *vnode =AFS_FS_I (rreq->inode);
@@ -340,14 +347,24 @@ static int afs_begin_cache_operation(struct netfs_read_request *rreq)return fscache_begin_read_operation (rreq,afs_vnode_cache (vnode)); } +static int afs_check_write_begin (struct file *file,loff_t pos,unsigned len, +struct page *page,void **_fsdata) +{ +struct afs_vnode *vnode =AFS_FS_I (file_inode (file)); + +return test_bit (AFS_VNODE_DELETED , &vnode->flags) ? -ESTALE :0 ; +} +static void afs_priv_cleanup (struct address_space *mapping,void *netfs_priv) {key_put (netfs_priv); } -static const struct netfs_read_request_ops afs_req_ops = { +const struct netfs_read_request_ops afs_req_ops = { .init_rreq = afs_init_rreq, + .is_cache_enabled = afs_is_cache_enabled, .begin_cache_operation = afs_begin_cache_operation, + .check_write_begin = afs_check_write_begin, .issue_op = afs_req_issue_op, .cleanup = afs_priv_cleanup, };
fs/afs/internal.h +1 -0
@@ -1045,6 +1045,7 @@ extern void afs_dynroot_depopulate(struct super_block *);extern const struct address_space_operations afs_fs_aops;extern const struct inode_operations afs_file_inode_operations;extern const struct file_operations afs_file_operations; +extern const struct netfs_read_request_ops afs_req_ops;extern int afs_cache_wb_key (struct afs_vnode *,struct afs_file *);extern void afs_put_wb_key (struct afs_wb_key *);
fs/afs/write.c +12 -96
148 lines not on this page · raw message
Quoted 267 lines · David Howells
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and
vfs_write()on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the
PG_fscachepage flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(),
fscache_write_page()andfscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.The patchset contains the following parts:
(1) Some helper patches, including provision of an
ITER_XARRAYiov iterator and a function to do readahead expansion.(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph also passes the expected tests.
The netfs lib and fscache/cachefiles patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-lib
The afs patches can be found on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-netfs-lib
Changes
=======ver #6:
Merged in some fixes and added an additional tracepoint[8], including fixing the amalgamation of contiguous subrequests that are to be written to the cache.Added/merged some patches from Matthew Wilcox to make
readahead_expand()appropriately adjust the trigger for the next readahead[9]. Also included is a patch to kerneldocify thefile_ra_statestruct.Altered
netfs_write_begin()to use DEFINE_READAHEAD()[10].Split the afs patches out into their own branch.
ver #5:
Fixed some review comments from Matthew Wilcox:- Put a comment into
netfs_readahead()to indicate why there's a loop that puts, but doesn't unlock, "unconsumed" pages at the end when it could just return said pages to the caller to dispose of[6]. (This is because where those pages are marked consumed).- Use the
page_file_mapping()andpage_index()helper functions rather than accessing the page struct directly[6].- Better names for wrangling functions for
PG_private_2andPG_fscachewrangling functions[7]. Came up with {set,end,wait_for}_page_private_2() and aliased these for fscache.Moved the taking of/dropping a page ref for the
PG_private_2flag into the set and end functions.ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].Moved the declaration of
readahead_expand()to a better location[5].Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.Adjusted the functions that unlock and wait for
PG_fscacheaccording to Linus's suggestion[1].Hold a ref on a page when
PG_fscacheis set as per Linus's suggestion[2].Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.Link https://lore.kernel.org/r/CAHk-=wh+2gbF7XEjYc=HV9w_2uVzVf7vs60BPz0gFA=+pUm3ww@mail.gmail.com/ [1] open hereLink https://lore.kernel.org/r/CAHk-=wjgA-74ddehziVk=XAEMTKswPu1Yw4uaro1R3ibs27ztw@mail.gmail.com/ [2] open hereReferences
==========These patches have been published for review before, firstly as part of a larger set:
Link https://lore.kernel.org/r/159465766378.1376105.11619976251039287525.stgit@warthog.procyon.org.uk/ open hereThen as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: AddITER_XARRAY
mm: Add set/end/wait functions forPG_private_2
mm: Implementreadahead_controlpageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: MovePG_fscachehelper funcs tolinux/netfs.hnetfs, mm: Add set/end/wait_on_page_fscache() aliases
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Addwrite_beginhelper
netfs: Define an interface to talk to a cache
netfs: Add a tracepoint to log failures that would be otherwise unseen fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operationdebug_idwhen logging an unexpected data version
afs: Move key toafs_readstruct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up theiov_iterbefore callingafs_extract_data()
afs: UseITER_XARRAYfor writing
afs: Wait onPG_fscachebefore modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new netfs lib read helper API
afs: Use thenetfs_write_begin()helperMatthew Wilcox (Oracle) (2):
mm/filemap: Pass thefile_ra_statein the ractl
fs: Documentfile_ra_stateDocumentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 657 +++++----- fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++ fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1185 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fs.h | 24 +- include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 234 ++++ include/linux/pagemap.h | 41 +- include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 261 ++++ mm/filemap.c | 63 +- mm/internal.h | 7 +- mm/readahead.c | 97 +- net/rxrpc/recvmsg.c | 9 +- 44 files changed, 3998 insertions(+), 1108 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/io.c
Quoted 10 lines
create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
You can add this to 1-16:
Tested with xfstests with fscache enabled on my local machine.
Quoted 269 lines · David Howells
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and
vfs_write()on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the
PG_fscachepage flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(),
fscache_write_page()andfscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.The patchset contains the following parts:
(1) Some helper patches, including provision of an
ITER_XARRAYiov iterator and a function to do readahead expansion.(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph also passes the expected tests.
The netfs lib and fscache/cachefiles patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-lib
The afs patches can be found on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-netfs-lib
Changes
=======ver #6:
Merged in some fixes and added an additional tracepoint[8], including fixing the amalgamation of contiguous subrequests that are to be written to the cache.Added/merged some patches from Matthew Wilcox to make
readahead_expand()appropriately adjust the trigger for the next readahead[9]. Also included is a patch to kerneldocify thefile_ra_statestruct.Altered
netfs_write_begin()to use DEFINE_READAHEAD()[10].Split the afs patches out into their own branch.
ver #5:
Fixed some review comments from Matthew Wilcox:- Put a comment into
netfs_readahead()to indicate why there's a loop that puts, but doesn't unlock, "unconsumed" pages at the end when it could just return said pages to the caller to dispose of[6]. (This is because where those pages are marked consumed).- Use the
page_file_mapping()andpage_index()helper functions rather than accessing the page struct directly[6].- Better names for wrangling functions for
PG_private_2andPG_fscachewrangling functions[7]. Came up with {set,end,wait_for}_page_private_2() and aliased these for fscache.Moved the taking of/dropping a page ref for the
PG_private_2flag into the set and end functions.ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].Moved the declaration of
readahead_expand()to a better location[5].Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.Adjusted the functions that unlock and wait for
PG_fscacheaccording to Linus's suggestion[1].Hold a ref on a page when
PG_fscacheis set as per Linus's suggestion[2].Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.Link https://lore.kernel.org/r/CAHk-=wh+2gbF7XEjYc=HV9w_2uVzVf7vs60BPz0gFA=+pUm3ww@mail.gmail.com/ [1] open hereLink https://lore.kernel.org/r/CAHk-=wjgA-74ddehziVk=XAEMTKswPu1Yw4uaro1R3ibs27ztw@mail.gmail.com/ [2] open hereReferences
==========These patches have been published for review before, firstly as part of a larger set:
Link https://lore.kernel.org/r/159465766378.1376105.11619976251039287525.stgit@warthog.procyon.org.uk/ open hereThen as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: AddITER_XARRAY
mm: Add set/end/wait functions forPG_private_2
mm: Implementreadahead_controlpageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: MovePG_fscachehelper funcs tolinux/netfs.hnetfs, mm: Add set/end/wait_on_page_fscache() aliases
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Addwrite_beginhelper
netfs: Define an interface to talk to a cache
netfs: Add a tracepoint to log failures that would be otherwise unseen fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operationdebug_idwhen logging an unexpected data version
afs: Move key toafs_readstruct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up theiov_iterbefore callingafs_extract_data()
afs: UseITER_XARRAYfor writing
afs: Wait onPG_fscachebefore modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new netfs lib read helper API
afs: Use thenetfs_write_begin()helperMatthew Wilcox (Oracle) (2):
mm/filemap: Pass thefile_ra_statein the ractl
fs: Documentfile_ra_stateDocumentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 657 +++++----- fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++ fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1185 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fs.h | 24 +- include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 234 ++++ include/linux/pagemap.h | 41 +- include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 261 ++++ mm/filemap.c | 63 +- mm/internal.h | 7 +- mm/readahead.c | 97 +- net/rxrpc/recvmsg.c | 9 +- 44 files changed, 3998 insertions(+), 1108 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/io.c
Quoted 10 lines
create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
Similar to Jeff, for most of first 16 patches (except patch 1 and 13) you can add
I rebased my latest NFS patches on top of your netfs-lib branch at the below commit (the 16th patch here)fce8d8a1ae46 fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
With netfs and fscache enabled mount, I ran the following tests, and found the series to be very solid, with no obvious failures (hangs, oopses, etc), and results matched tests run on vanilla 5.12-rc6:
* unit tests: NFSv3, 4.0, 4.1, 4.2; localhost server; with/without all tracepoints enabled (fscache, cachefiles, netfs)
* NFS connectathon: NFSv3, 4.0, 4.1, 4.2; rhel7 server; with/without all tracepoints enabled (fscache, cachefiles, netfs)
* xfstests generic: NFSv3, 4.0, 4.1, 4.2; rhel7, rhel8 server Notes
1. I still have not resolved the pNFS issues so I did not run fscache enabled pNFS tests.
2. Current NFS patches do not use ITER_XARRAY (patch 1/30) or write_begin helper (patch 13/30)
Quoted 282 lines · David Wysochanski
Quoted 269 lines · David Howells
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and
vfs_write()on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the
PG_fscachepage flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(),
fscache_write_page()andfscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.The patchset contains the following parts:
(1) Some helper patches, including provision of an
ITER_XARRAYiov iterator and a function to do readahead expansion.(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph also passes the expected tests.
The netfs lib and fscache/cachefiles patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-lib
The afs patches can be found on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-netfs-lib
Changes
=======ver #6:
Merged in some fixes and added an additional tracepoint[8], including fixing the amalgamation of contiguous subrequests that are to be written to the cache.Added/merged some patches from Matthew Wilcox to make
readahead_expand()appropriately adjust the trigger for the next readahead[9]. Also included is a patch to kerneldocify thefile_ra_statestruct.Altered
netfs_write_begin()to use DEFINE_READAHEAD()[10].Split the afs patches out into their own branch.
ver #5:
Fixed some review comments from Matthew Wilcox:- Put a comment into
netfs_readahead()to indicate why there's a loop that puts, but doesn't unlock, "unconsumed" pages at the end when it could just return said pages to the caller to dispose of[6]. (This is because where those pages are marked consumed).- Use the
page_file_mapping()andpage_index()helper functions rather than accessing the page struct directly[6].- Better names for wrangling functions for
PG_private_2andPG_fscachewrangling functions[7]. Came up with {set,end,wait_for}_page_private_2() and aliased these for fscache.Moved the taking of/dropping a page ref for the
PG_private_2flag into the set and end functions.ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].Moved the declaration of
readahead_expand()to a better location[5].Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.Adjusted the functions that unlock and wait for
PG_fscacheaccording to Linus's suggestion[1].Hold a ref on a page when
PG_fscacheis set as per Linus's suggestion[2].Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.Link https://lore.kernel.org/r/CAHk-=wh+2gbF7XEjYc=HV9w_2uVzVf7vs60BPz0gFA=+pUm3ww@mail.gmail.com/ [1] open hereLink https://lore.kernel.org/r/CAHk-=wjgA-74ddehziVk=XAEMTKswPu1Yw4uaro1R3ibs27ztw@mail.gmail.com/ [2] open hereReferences
==========These patches have been published for review before, firstly as part of a larger set:
Link https://lore.kernel.org/r/159465766378.1376105.11619976251039287525.stgit@warthog.procyon.org.uk/ open hereThen as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: AddITER_XARRAY
mm: Add set/end/wait functions forPG_private_2
mm: Implementreadahead_controlpageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: MovePG_fscachehelper funcs tolinux/netfs.hnetfs, mm: Add set/end/wait_on_page_fscache() aliases
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Addwrite_beginhelper
netfs: Define an interface to talk to a cache
netfs: Add a tracepoint to log failures that would be otherwise unseen fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operationdebug_idwhen logging an unexpected data version
afs: Move key toafs_readstruct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up theiov_iterbefore callingafs_extract_data()
afs: UseITER_XARRAYfor writing
afs: Wait onPG_fscachebefore modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new netfs lib read helper API
afs: Use thenetfs_write_begin()helperMatthew Wilcox (Oracle) (2):
mm/filemap: Pass thefile_ra_statein the ractl
fs: Documentfile_ra_stateDocumentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 657 +++++----- fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++ fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1185 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fs.h | 24 +- include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 234 ++++ include/linux/pagemap.h | 41 +- include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 261 ++++ mm/filemap.c | 63 +- mm/internal.h | 7 +- mm/readahead.c | 97 +- net/rxrpc/recvmsg.c | 9 +- 44 files changed, 3998 insertions(+), 1108 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/io.cQuoted 10 lines
create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
Quoted 4 lines
Similar to Jeff, for most of first 16 patches (except patch 1 and 13) you can add
Tested-by Dave Wysochanski <[email protected]>
Clarification on patch 1. You can include my "Tested-by" on that as well. As you pointed out, the NFS patches used the new netfs API code paths in read_helper.c which in turn use the iter-xarray patch, so my NFS testing also covered patch 1.
My apologies for not looking more carefully.
Quoted 18 lines
I rebased my latest NFS patches on top of your netfs-lib branch at the below commit (the 16th patch here)
fce8d8a1ae46fscache, cachefiles: Add alternate API to use kiocb for read/write to cacheWith netfs and fscache enabled mount, I ran the following tests, and found the series to be very solid, with no obvious failures (hangs, oopses, etc), and results matched tests run on vanilla 5.12-rc6:
* unit tests: NFSv3, 4.0, 4.1, 4.2; localhost server; with/without all tracepoints enabled (fscache, cachefiles, netfs)
* NFS connectathon: NFSv3, 4.0, 4.1, 4.2; rhel7 server; with/without all tracepoints enabled (fscache, cachefiles, netfs)
* xfstests generic: NFSv3, 4.0, 4.1, 4.2; rhel7, rhel8 server Notes
1. I still have not resolved the pNFS issues so I did not run fscache enabled pNFS tests.
2. Current NFS patches do not useITER_XARRAY(patch 1/30) orwrite_beginhelper (patch 13/30)
Quoted 269 lines · David Howells
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and
vfs_write()on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the
PG_fscachepage flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(),
fscache_write_page()andfscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.The patchset contains the following parts:
(1) Some helper patches, including provision of an
ITER_XARRAYiov iterator and a function to do readahead expansion.(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph also passes the expected tests.
The netfs lib and fscache/cachefiles patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=netfs-lib
The afs patches can be found on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=afs-netfs-lib
Changes
=======ver #6:
Merged in some fixes and added an additional tracepoint[8], including fixing the amalgamation of contiguous subrequests that are to be written to the cache.Added/merged some patches from Matthew Wilcox to make
readahead_expand()appropriately adjust the trigger for the next readahead[9]. Also included is a patch to kerneldocify thefile_ra_statestruct.Altered
netfs_write_begin()to use DEFINE_READAHEAD()[10].Split the afs patches out into their own branch.
ver #5:
Fixed some review comments from Matthew Wilcox:- Put a comment into
netfs_readahead()to indicate why there's a loop that puts, but doesn't unlock, "unconsumed" pages at the end when it could just return said pages to the caller to dispose of[6]. (This is because where those pages are marked consumed).- Use the
page_file_mapping()andpage_index()helper functions rather than accessing the page struct directly[6].- Better names for wrangling functions for
PG_private_2andPG_fscachewrangling functions[7]. Came up with {set,end,wait_for}_page_private_2() and aliased these for fscache.Moved the taking of/dropping a page ref for the
PG_private_2flag into the set and end functions.ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].Moved the declaration of
readahead_expand()to a better location[5].Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.Adjusted the functions that unlock and wait for
PG_fscacheaccording to Linus's suggestion[1].Hold a ref on a page when
PG_fscacheis set as per Linus's suggestion[2].Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.Link https://lore.kernel.org/r/CAHk-=wh+2gbF7XEjYc=HV9w_2uVzVf7vs60BPz0gFA=+pUm3ww@mail.gmail.com/ [1] open hereLink https://lore.kernel.org/r/CAHk-=wjgA-74ddehziVk=XAEMTKswPu1Yw4uaro1R3ibs27ztw@mail.gmail.com/ [2] open hereReferences
==========These patches have been published for review before, firstly as part of a larger set:
Link https://lore.kernel.org/r/159465766378.1376105.11619976251039287525.stgit@warthog.procyon.org.uk/ open hereThen as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: AddITER_XARRAY
mm: Add set/end/wait functions forPG_private_2
mm: Implementreadahead_controlpageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: MovePG_fscachehelper funcs tolinux/netfs.hnetfs, mm: Add set/end/wait_on_page_fscache() aliases
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Addwrite_beginhelper
netfs: Define an interface to talk to a cache
netfs: Add a tracepoint to log failures that would be otherwise unseen fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operationdebug_idwhen logging an unexpected data version
afs: Move key toafs_readstruct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up theiov_iterbefore callingafs_extract_data()
afs: UseITER_XARRAYfor writing
afs: Wait onPG_fscachebefore modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new netfs lib read helper API
afs: Use thenetfs_write_begin()helperMatthew Wilcox (Oracle) (2):
mm/filemap: Pass thefile_ra_statein the ractl
fs: Documentfile_ra_stateDocumentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 ++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 657 +++++----- fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/io.c | 420 +++++++ fs/ext4/verity.c | 2 +- fs/f2fs/file.c | 2 +- fs/f2fs/verity.c | 2 +- fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1185 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fs.h | 24 +- include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 234 ++++ include/linux/pagemap.h | 41 +- include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 261 ++++ mm/filemap.c | 63 +- mm/internal.h | 7 +- mm/readahead.c | 97 +- net/rxrpc/recvmsg.c | 9 +- 44 files changed, 3998 insertions(+), 1108 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/io.c
Quoted 10 lines
create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
You can add:
for the series, including the afs changes. Ran it through automated testing that does kernel builds in an AFS mount, both with and without cachefilesd running.
Marc