COPY/CLONE pagecache invalidation
Subsystems (2)
cover COPY/CLONE pagecache invalidation
I found a small issue on the client with generic/432 when testing a server that supports COPY/CLONE but doesn't have the open file descriptor cache. Our current knfsd server's cache causes the server to not immediately hand out a read delegation after a COPY/COMMIT, CLOSE, OPEN, so I suspect our normal testing didn't catch this issue.
The client bug can be exposed by adding 5 second delays after xfs_io commands in generic/432, which gives the server enough time to clean up the cache and give the delegation.
Benjamin Coddington (3):
NFSv42: Fix pagecache invalidation after COPY/CLONE
NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
NFS: Add a tracepoint to show the results of nfs_set_cache_invalid()
fs/nfs/inode.c | 5 ++++- fs/nfs/nfs42proc.c | 8 ++++++-- fs/nfs/nfstrace.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/3 NFSv42: Fix pagecache invalidation after COPY/CLONE
The mechanism in use to allow the client to see the results of COPY/CLONE is to drop those pages from the pagecache. This forces the client to read those pages once more from the server. However, truncate_pagecache_range() zeros out partial pages instead of dropping them. Let us instead use invalidate_inode_pages2_range() with full-page offsets to ensure the client properly sees the results of COPY/CLONE operations.
--- fs/nfs/nfs42proc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +4 -1
@@ -285,7 +285,10 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len)loff_t newsize = pos + len;loff_t end = newsize -1 ; -truncate_pagecache_range (inode, pos, end); +int error =invalidate_inode_pages2_range (inode->i_mapping, + pos >>PAGE_SHIFT , end >>PAGE_SHIFT ); +WARN_ON_ONCE (error); +spin_lock (&inode->i_lock);if (newsize >i_size_read (inode))i_size_write (inode, newsize);
Signature · 1 line
2.31.1
Re: [PATCH 1/3] NFSv42: Fix pagecache invalidation after COPY/CLONE
Quoted 26 lines · Benjamin Coddington
The mechanism in use to allow the client to see the results of COPY/CLONE
is to drop those pages from the pagecache. This forces the client to read
those pages once more from the server. However,truncate_pagecache_range()
zeros out partial pages instead of dropping them. Let us instead useinvalidate_inode_pages2_range()with full-page offsets to ensure the client
properly sees the results of COPY/CLONE operations.Cc <[email protected]> # v4.7+Fixes 2e72448b07dc ("NFS: Add COPY nfs operation")Signed-off-by Benjamin Coddington <[email protected]>---
fs/nfs/nfs42proc.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)fs/nfs/nfs42proc.c +0
-0@@ -285,7 +285,10 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) loff_t newsize = pos + len; loff_t end = newsize - 1;
Quoted 5 lines
- truncate_pagecache_range(inode, pos, end);
+ int error = invalidate_inode_pages2_range(inode->i_mapping, + pos >>PAGE_SHIFT, end >>PAGE_SHIFT);
Shouldn't that be "(end + PAGE_SIZE - 1) >> PAGE_SHIFT" in order to align to the set of pages that fully contains the byte range from pos to end?
Quoted 5 lines
+ WARN_ON_ONCE(error);
+
spin_lock(&inode->i_lock);
if (newsize >i_size_read(inode))
i_size_write(inode, newsize);
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH 1/3] NFSv42: Fix pagecache invalidation after COPY/CLONE
Quoted 30 lines · Trond Myklebust
Quoted 29 lines · Benjamin Coddington
The mechanism in use to allow the client to see the results of COPY/CLONE
is to drop those pages from the pagecache. This forces the client to read
those pages once more from the server. However,truncate_pagecache_range()
zeros out partial pages instead of dropping them. Let us instead useinvalidate_inode_pages2_range()with full-page offsets to ensure the client
properly sees the results of COPY/CLONE operations.Cc <[email protected]> # v4.7+Fixes 2e72448b07dc ("NFS: Add COPY nfs operation")Signed-off-by Benjamin Coddington <[email protected]>---
fs/nfs/nfs42proc.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)fs/nfs/nfs42proc.c +0
-0@@ -285,7 +285,10 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) loff_t newsize = pos + len; loff_t end = newsize - 1;
- truncate_pagecache_range(inode, pos, end); + int error =
Quoted 8 lines
Quoted 4 lines
invalidate_inode_pages2_range(inode->i_mapping,
+ pos >>PAGE_SHIFT, end >>PAGE_SHIFT);Shouldn't that be "(end +
PAGE_SIZE- 1) >>PAGE_SHIFT" in order to align to the set of pages that fully contains the byte range from pos to end?
It's embarrassing that I've messed that up, I will resend it.
Ben
Re: [PATCH 1/3] NFSv42: Fix pagecache invalidation after COPY/CLONE
Quoted 34 lines · Benjamin Coddington
Quoted 32 lines · Trond Myklebust
Quoted 31 lines · Benjamin Coddington
The mechanism in use to allow the client to see the results of COPY/CLONE
is to drop those pages from the pagecache. This forces the client to read
those pages once more from the server. However,truncate_pagecache_range()
zeros out partial pages instead of dropping them. Let us instead useinvalidate_inode_pages2_range()with full-page offsets to ensure the client
properly sees the results of COPY/CLONE operations.Cc <[email protected]> # v4.7+Fixes 2e72448b07dc ("NFS: Add COPY nfs operation")Signed-off-by Benjamin Coddington <[email protected]>---
fs/nfs/nfs42proc.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)fs/nfs/nfs42proc.c +0
-0@@ -285,7 +285,10 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) loff_t newsize = pos + len; loff_t end = newsize - 1;
- truncate_pagecache_range(inode, pos, end); + int error = invalidate_inode_pages2_range(inode->i_mapping, + pos
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
PAGE_SHIFT, end >>
PAGE_SHIFT);Shouldn't that be "(end +
PAGE_SIZE- 1) >>PAGE_SHIFT" in order to align to the set of pages that fully contains the byte range from pos to end?It's embarrassing that I've messed that up, I will resend it.
I've had it sitting around a bit too long -- on a second look no, it should be right because invalidate_inode_pages2_range()'s index arguments are inclusive.
Ben
Re: [PATCH 1/3] NFSv42: Fix pagecache invalidation after COPY/CLONE
Quoted 51 lines · Benjamin Coddington
Quoted 49 lines · Benjamin Coddington
Quoted 46 lines · Trond Myklebust
Quoted 37 lines · Benjamin Coddington
The mechanism in use to allow the client to see the results of COPY/CLONE
is to drop those pages from the pagecache. This forces the client
to
read
those pages once more from the server. However,truncate_pagecache_range()
zeros out partial pages instead of dropping them. Let us instead
useinvalidate_inode_pages2_range()with full-page offsets to ensure the
client
properly sees the results of COPY/CLONE operations.Cc <[email protected]> # v4.7+Fixes 2e72448b07dc ("NFS: Add COPY nfs operation")Signed-off-by Benjamin Coddington <[email protected]>---
fs/nfs/nfs42proc.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)fs/nfs/nfs42proc.c +0
-0@@ -285,7 +285,10 @@ static void nfs42_copy_dest_done(structinode
*inode,loff_tpos,loff_tlen)
loff_t newsize = pos + len;
loff_t end = newsize - 1;
- truncate_pagecache_range(inode, pos, end); + int error = invalidate_inode_pages2_range(inode->i_mapping, + posQuoted 2 lines
Quoted 1 line
Quoted 1 line
PAGE_SHIFT, end >>
PAGE_SHIFT);Shouldn't that be "(end +
PAGE_SIZE- 1) >>PAGE_SHIFT" in order to
align to the set of pages that fully contains the byte range from pos
to end?
Quoted 8 lines
Quoted 1 line
It's embarrassing that I've messed that up, I will resend it.
I've had it sitting around a bit too long -- on a second look no, it should
be right because invalidate_inode_pages2_range()'s index arguments are
inclusive.
OK, but can you resend without the unnecessary attribute declaration? WARN_ON_ONCE(invalidate_inode_pages(...)) should be good enough.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
PATCH 2/3 NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
In reply to Benjamin CoddingtonThe nfs_set_cache_invalid() helper drops NFS_INO_INVALID_CHANGE if we hold a delegation, but after a copy or clone the change attribute can be updated on the server. After commit b6f80a2ebb97 "NFS: Fix open coded versions of nfs_set_cache_invalid() in NFSv4", the client stopped updating the change attribute after copy or clone while holding a read delegation.
We can use NFS_INO_REVAL_PAGECACHE to help nfs_set_cache_invalid() know when we really want to keep NFS_INO_INVALID_CHANGE, even if the client holds a delegation.
--- fs/nfs/inode.c | 4 +++- fs/nfs/nfs42proc.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
fs/nfs/inode.c +3 -1
@@ -202,7 +202,9 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) flags &= ~(NFS_INO_INVALID_MODE |NFS_INO_INVALID_OTHER |NFS_INO_INVALID_XATTR ); - flags &= ~(NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ); +if (!(flags &NFS_INO_REVAL_PAGECACHE )) + flags &= ~NFS_INO_INVALID_CHANGE ; + flags &= ~NFS_INO_INVALID_SIZE ; }else if (flags &NFS_INO_REVAL_PAGECACHE ) flags |=NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE ;
fs/nfs/nfs42proc.c +2 -1
@@ -292,7 +292,8 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len)spin_lock (&inode->i_lock);if (newsize >i_size_read (inode))i_size_write (inode, newsize); -nfs_set_cache_invalid (inode,NFS_INO_INVALID_CHANGE | +nfs_set_cache_invalid (inode,NFS_INO_REVAL_PAGECACHE | +NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME |NFS_INO_INVALID_MTIME |NFS_INO_INVALID_BLOCKS );
Signature · 1 line
2.31.1
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 10 lines · Benjamin Coddington
The
nfs_set_cache_invalid()helper dropsNFS_INO_INVALID_CHANGEif we hold
a delegation, but after a copy or clone the change attribute can be updated
on the server. After commitb6f80a2ebb97"NFS: Fix open coded versions ofnfs_set_cache_invalid()in NFSv4", the client stopped updating the change
attribute after copy or clone while holding a read delegation.
Quoted 5 lines
We can use
NFS_INO_REVAL_PAGECACHEto helpnfs_set_cache_invalid()know
when we really want to keepNFS_INO_INVALID_CHANGE, even if the client
holds a delegation.
No, we really shouldn't need to care what the server thinks or does. The client is authoritative for the change attribute while it holds a delegation, not the server.
Quoted 42 lines
Fixes b6f80a2ebb97 ("NFS: Fix open coded versions of
nfs_set_cache_invalid()in NFSv4")Signed-off-by Benjamin Coddington <[email protected]>---
fs/nfs/inode.c | 4 +++-
fs/nfs/nfs42proc.c | 3 ++-2 files changed, 5 insertions(+), 2 deletions(-)fs/nfs/inode.c +0
-0@@ -202,7 +202,9 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags)flags &= ~(NFS_INO_INVALID_MODE |
NFS_INO_INVALID_OTHER|NFS_INO_INVALID_XATTR); - flags &= ~(NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_SIZE);
+ if (!(flags &NFS_INO_REVAL_PAGECACHE)) + flags &= ~NFS_INO_INVALID_CHANGE; + flags &= ~NFS_INO_INVALID_SIZE;
} else if (flags &NFS_INO_REVAL_PAGECACHE) flags |=NFS_INO_INVALID_CHANGE|NFS_INO_INVALID_SIZE;fs/nfs/nfs42proc.c +2
-1@@ -292,7 +292,8 @@ static void nfs42_copy_dest_done(struct inode *inode, loff_t pos, loff_t len) spin_lock(&inode->i_lock); if (newsize > i_size_read(inode)) i_size_write(inode, newsize); - nfs_set_cache_invalid(inode, NFS_INO_INVALID_CHANGE | + nfs_set_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE | + NFS_INO_INVALID_CHANGE |
NFS_INO_INVALID_CTIME|NFS_INO_INVALID_MTIME|NFS_INO_INVALID_BLOCKS);
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 3 lines · Trond Myklebust
No, we really shouldn't need to care what the server thinks or does. The client is authoritative for the change attribute while it holds a delegation, not the server.
My understanding of the intention of the code (which I had to sort of put together from historical patches in this area) is that we want to see ctime, mtime, and block size updates after copy/clone even if we hold a delegation, but without NFS_INO_INVALID_CHANGE, the client won't update those attributes.
If that's not necessary, we can drop this patch.
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 16 lines · Benjamin Coddington
Quoted 5 lines · Trond Myklebust
No, we really shouldn't need to care what the server thinks or does.
The client is authoritative for the change attribute while it holds a
delegation, not the server.My understanding of the intention of the code (which I had to sort of put
together from historical patches in this area) is that we want to see ctime,
mtime, and block size updates after copy/clone even if we hold a delegation,
but withoutNFS_INO_INVALID_CHANGE, the client won't update those attributes.
Quoted 2 lines
If that's not necessary, we can drop this patch.
We will still see the ctime/mtime/block size updates even if NFS_INO_INVALID_CHANGE is not set. Those attributes' cache status are tracked separately through their own NFS_INO_INVALID_* bits.
That said, there really is no reason why we shouldn't treat the copy and clone code exactly the same way we would treat a regular write. Perhaps we can fix up the arguments of nfs_writeback_update_inode() so that it can be called here?
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 20 lines · Trond Myklebust
Quoted 16 lines · Benjamin Coddington
Quoted 5 lines · Trond Myklebust
No, we really shouldn't need to care what the server thinks or does.
The client is authoritative for the change attribute while it holds a
delegation, not the server.My understanding of the intention of the code (which I had to sort of put
together from historical patches in this area) is that we want to see ctime,
mtime, and block size updates after copy/clone even if we hold a delegation,
but withoutNFS_INO_INVALID_CHANGE, the client won't update those attributes.Quoted 2 lines
If that's not necessary, we can drop this patch.
Quoted 8 lines
We will still see the ctime/mtime/block size updates even if
NFS_INO_INVALID_CHANGEis not set. Those attributes' cache status are tracked separately through their own NFS_INO_INVALID_* bits.That said, there really is no reason why we shouldn't treat the copy and clone code exactly the same way we would treat a regular write. Perhaps we can fix up the arguments of
nfs_writeback_update_inode()so that it can be called here?
I wonder if that just kicks the problem down the road to when we return the delegation, and we'll see cases where ctime/mtime move backward. And I don't think we can ever be authoritative for space_used, but maybe it doesn't matter if we're within the attribute timeouts.
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 37 lines · Benjamin Coddington
Quoted 28 lines · Trond Myklebust
Quoted 19 lines · Benjamin Coddington
Quoted 6 lines · Trond Myklebust
No, we really shouldn't need to care what the server thinks or does.
The client is authoritative for the change attribute while it holds
a
delegation, not the server.My understanding of the intention of the code (which I had to sort of
put
together from historical patches in this area) is that we want to see
ctime,
mtime, and block size updates after copy/clone even if we hold a delegation,
but withoutNFS_INO_INVALID_CHANGE, the client won't update those attributes.Quoted 2 lines
If that's not necessary, we can drop this patch.
We will still see the ctime/mtime/block size updates even if
NFS_INO_INVALID_CHANGEis not set. Those attributes' cache status are
tracked separately through their own NFS_INO_INVALID_* bits.Quoted 6 lines
That said, there really is no reason why we shouldn't treat the copy
and clone code exactly the same way we would treat a regular write. Perhaps we can fix up the arguments ofnfs_writeback_update_inode()so
that it can be called here?
Quoted 8 lines
I wonder if that just kicks the problem down the road to when we return the
delegation, and we'll see cases where ctime/mtime move backward. And I
don't think we can ever be authoritative forspace_used, but maybe it doesn't
matter if we're within the attribute timeouts.
I don't understand your point. Mine is that we _should_ be setting the NFS_INO_INVALID_MTIME, NFS_INO_INVALID_CTIME, NFS_INO_INVALID_BLOCKS... flags here, and as far as I can tell, we are indeed doing so in nfs42_copy_dest_done().
At least for clone(), we're then calling nfs_post_op_update_inode(), which updates the attributes with whatever was retrieved in the CLONE call. That will usually contain new values for mtime, ctime and blocks, and so the cache is refreshed.
If the client failed to retrieve attributes as part of the CLONE or COPY call, then we are indeed kicking the can of revalidating the attributes down the road, but only as far as until the next call to nfs_getattr(), or the delegation return, whichever comes first. The fact that we do set the NFS_INO_INVALID_MTIME, ... means that we will update those cached values before replying to a stat() or statx() call.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH 2/3] NFSv42: Don't drop NFS_INO_INVALID_CHANGE if we hold a delegation
Quoted 47 lines · Trond Myklebust
Quoted 37 lines · Benjamin Coddington
Quoted 28 lines · Trond Myklebust
Quoted 19 lines · Benjamin Coddington
Quoted 6 lines · Trond Myklebust
No, we really shouldn't need to care what the server thinks or does.
The client is authoritative for the change attribute while it holds
a
delegation, not the server.My understanding of the intention of the code (which I had to sort of
put
together from historical patches in this area) is that we want to see
ctime,
mtime, and block size updates after copy/clone even if we hold a delegation,
but withoutNFS_INO_INVALID_CHANGE, the client won't update those attributes.Quoted 2 lines
If that's not necessary, we can drop this patch.
We will still see the ctime/mtime/block size updates even if
NFS_INO_INVALID_CHANGEis not set. Those attributes' cache status are
tracked separately through their own NFS_INO_INVALID_* bits.Quoted 6 lines
That said, there really is no reason why we shouldn't treat the copy
and clone code exactly the same way we would treat a regular write. Perhaps we can fix up the arguments ofnfs_writeback_update_inode()so
that it can be called here?Quoted 8 lines
I wonder if that just kicks the problem down the road to when we return the
delegation, and we'll see cases where ctime/mtime move backward. And I
don't think we can ever be authoritative forspace_used, but maybe it doesn't
matter if we're within the attribute timeouts.
Quoted 4 lines
I don't understand your point. Mine is that we _should_ be setting the
NFS_INO_INVALID_MTIME,NFS_INO_INVALID_CTIME,NFS_INO_INVALID_BLOCKS... flags here, and as far as I can tell, we are indeed doing so innfs42_copy_dest_done().
Yes, -- I misunderstood your suggestion to use nfs_writeback_update_inode() as a way to fill in our cached attributes with values we'd expect from the result of the copy.
Quoted 11 lines
At least for
clone(), we're then callingnfs_post_op_update_inode(), which updates the attributes with whatever was retrieved in the CLONE call. That will usually contain new values for mtime, ctime and blocks, and so the cache is refreshed.If the client failed to retrieve attributes as part of the CLONE or COPY call, then we are indeed kicking the can of revalidating the attributes down the road, but only as far as until the next call to
nfs_getattr(), or the delegation return, whichever comes first. The fact that we do set theNFS_INO_INVALID_MTIME, ... means that we will update those cached values before replying to astat()orstatx()call.
Ok, thanks for the looks at this, you've convinced me that this patch is unnecessary. I still need the first one, let me know if you want me to resend it as a stand-alone fix.
Ben
PATCH 3/3 NFS: Add a tracepoint to show the results of nfs_set_cache_invalid()
In reply to Benjamin CoddingtonThis provides some insight into the client's invalidation behavior to show both when the client uses the helper, and the results of calling the helper which can vary depending on how the helper is called.
--- fs/nfs/inode.c | 1 + fs/nfs/nfstrace.h | 1 + 2 files changed, 2 insertions(+)
fs/nfs/inode.c +1 -0
@@ -216,6 +216,7 @@ void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) flags &= ~(NFS_INO_INVALID_DATA |NFS_INO_DATA_INVAL_DEFER ); flags &= ~(NFS_INO_REVAL_PAGECACHE |NFS_INO_REVAL_FORCED ); nfsi->cache_validity |= flags; +trace_nfs_set_cache_invalid (inode,0 ); }EXPORT_SYMBOL_GPL (nfs_set_cache_invalid);
fs/nfs/nfstrace.h +1 -0
@@ -209,6 +209,7 @@ DEFINE_NFS_INODE_EVENT_DONE(nfs_writeback_inode_exit);DEFINE_NFS_INODE_EVENT (nfs_fsync_enter);DEFINE_NFS_INODE_EVENT_DONE (nfs_fsync_exit);DEFINE_NFS_INODE_EVENT (nfs_access_enter); +DEFINE_NFS_INODE_EVENT_DONE (nfs_set_cache_invalid); TRACE_EVENT(nfs_access_exit, TP_PROTO(
Signature · 1 line
2.31.1