nfsd: don't free files unconditionally in __nfsd_file_cache_purge
Subsystems (2)
Jeff Layton
maintainerPATCH 1/1 nfsd: don't free files unconditionally in __nfsd_file_cache_purge
nfsd_file_cache_purge is called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.
Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access.
--- fs/nfsd/filecache.c | 61 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 24 deletions(-)
v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.
fs/nfsd/filecache.c +37 -24
@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, }; +/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() ! +*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head *dispose) +{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/** * nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode * @inode: inode on which to close out nfsd_files
@@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock (); }
@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, &dispose); nf =rhashtable_walk_next (&iter); }
Signature · 1 line
2.39.0
Quoted 7 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.
Yeah... cache flush is probably the case we've been missing.
Quoted 22 lines
Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access.
Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/filecache.c| 61 +++++++++++++++++++++++++++------------------1 file changed, 37 insertions(+), 24 deletions(-)v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.fs/nfsd/filecache.c +0
-0@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, };
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 672
Quoted 10 lines
fs/nfsd/filecache.c +9
-0+/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() !
__nfsd_file_cache_purge() isn't holding rcu_read_lock(), it's holding the nfsd_mutex. Is this comment incorrect, or is it just too specific? Or did I miss something obvious?
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 675
Quoted 3 lines
fs/nfsd/filecache.c +3
-0+*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head *dispose)
I prefer the name nfsd_file_try_to_queue() or nfsd_file_try_to_dispose(). nfsd_file_ should be the prefix where possible. Unless you're redriving, I can fix that.
Quoted 74 lines
fs/nfsd/filecache.c +25
-24+{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/** * nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode * @inode: inode on which to close out nfsd_files @@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock (); }@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, &dispose); nf =rhashtable_walk_next (&iter); }Signature · 1 line
2.39.0
--
Chuck Lever
Jeff Layton
maintainerQuoted 33 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 23 lines
Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access.
Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/filecache.c| 61 +++++++++++++++++++++++++++------------------1 file changed, 37 insertions(+), 24 deletions(-)v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.fs/nfsd/filecache.c +0
-0@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, };
Quoted 14 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 672
Quoted 9 lines
fs/nfsd/filecache.c +9
-0+/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() !
__nfsd_file_cache_purge()isn't holdingrcu_read_lock(), it's holding thenfsd_mutex. Is this comment incorrect, or is it just too specific? Or did I miss something obvious?
It's implicitly taken by rhashtable_walk_start and released by rhashtable_walk_stop.
FWIW, it'd be nice if there were a lockdep_assert_held equivalent for the rcu_read_lock() here, but I didn't see one of those. There is a rcu_read_lock_held(), but I didn't see a good way to get that to compile out when lockdep was disabled.
Quoted 10 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 675
Quoted 4 lines
fs/nfsd/filecache.c +3
-0+*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head *dispose)I prefer the name
nfsd_file_try_to_queue()ornfsd_file_try_to_dispose().nfsd_file_should be the prefix where possible. Unless you're redriving, I can fix that.
Rename at will.
Quoted 80 lines
Quoted 74 lines
fs/nfsd/filecache.c +25
-24+{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/** * nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode * @inode: inode on which to close out nfsd_files @@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock (); }@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, &dispose); nf =rhashtable_walk_next (&iter); }Signature · 1 line
2.39.0--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 53 lines · Jeff Layton
Quoted 33 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 23 lines
Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access.
Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/filecache.c| 61 +++++++++++++++++++++++++++------------------1 file changed, 37 insertions(+), 24 deletions(-)v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.fs/nfsd/filecache.c +0
-0@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, };Quoted 14 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 672
Quoted 9 lines
fs/nfsd/filecache.c +9
-0+/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() !
__nfsd_file_cache_purge()isn't holdingrcu_read_lock(), it's holding thenfsd_mutex. Is this comment incorrect, or is it just too specific? Or did I miss something obvious?
Quoted 5 lines
It's implicitly taken by
rhashtable_walk_startand released byrhashtable_walk_stop.FWIW, it'd be nice if there were a
lockdep_assert_heldequivalent for thercu_read_lock()here, but I didn't see one of those.
Would
static voidnfsd_file_cond_queue(struct nfsd_file *nf, struct list_head *dispose)
__must_hold(RCU)
{
do the trick?
Quoted 14 lines
There is a
rcu_read_lock_held(), but I didn't see a good way to get that to compile out when lockdep was disabled.Quoted 9 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 675
Quoted 3 lines
fs/nfsd/filecache.c +3
-0+*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head *dispose)I prefer the name
nfsd_file_try_to_queue()ornfsd_file_try_to_dispose().nfsd_file_should be the prefix where possible. Unless you're redriving, I can fix that.
Quoted 1 line
Rename at will.
Done and applied to nfsd-fixes, replacing v1 of this patch.
Quoted 71 lines
Quoted 71 lines
Quoted 71 lines
fs/nfsd/filecache.c +25
-24+{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/** * nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode * @inode: inode on which to close out nfsd_files @@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock (); }@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, &dispose); nf =rhashtable_walk_next (&iter); }
Quoted 12 lines
Quoted 9 lines
Quoted 3 lines
Signature · 1 line
2.39.0--
Chuck LeverSignature · 1 line
Jeff Layton <[email protected]>
--
Chuck Lever
Jeff Layton
maintainerQuoted 58 lines · Chuck Lever III
Quoted 52 lines · Jeff Layton
Quoted 33 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 23 lines
Instead of walking the cache and freeing everything unconditionally, handle it the same as when we have a notification of conflicting access.
Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/nfsd/filecache.c| 61 +++++++++++++++++++++++++++------------------1 file changed, 37 insertions(+), 24 deletions(-)v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.fs/nfsd/filecache.c +0
-0@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, };Quoted 14 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 672
Quoted 9 lines
fs/nfsd/filecache.c +9
-0+/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() !
__nfsd_file_cache_purge()isn't holdingrcu_read_lock(), it's holding thenfsd_mutex. Is this comment incorrect, or is it just too specific? Or did I miss something obvious?Quoted 5 lines
It's implicitly taken by
rhashtable_walk_startand released byrhashtable_walk_stop.FWIW, it'd be nice if there were a
lockdep_assert_heldequivalent for thercu_read_lock()here, but I didn't see one of those.
Quoted 9 lines
Would
static void
nfsd_file_cond_queue(struct nfsd_file *nf, struct list_head *dispose)__must_hold(RCU){
do the trick?
Seems like a reasonable thing to add.
Quoted 15 lines
Quoted 15 lines
There is a
rcu_read_lock_held(), but I didn't see a good way to get that to compile out when lockdep was disabled.Quoted 9 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 675
Quoted 3 lines
fs/nfsd/filecache.c +3
-0+*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head *dispose)I prefer the name
nfsd_file_try_to_queue()ornfsd_file_try_to_dispose().nfsd_file_should be the prefix where possible. Unless you're redriving, I can fix that.
Quoted 4 lines
Quoted 1 line
Rename at will.
Done and applied to nfsd-fixes, replacing v1 of this patch.
LGTM. Thanks!
Quoted 90 lines
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
fs/nfsd/filecache.c +25
-24+{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/** * nfsd_file_queue_for_close: try to close out any open nfsd_files for an inode * @inode: inode on which to close out nfsd_files @@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock (); }@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, &dispose); nf =rhashtable_walk_next (&iter); }Quoted 12 lines
Quoted 9 lines
Quoted 3 lines
Signature · 1 line
2.39.0--
Chuck LeverSignature · 1 line
Jeff Layton <[email protected]>--
Chuck Lever
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 15 lines · Shachar Kagan
Quoted 14 lines · Chuck Lever III
Quoted 14 lines · Jeff Layton
Quoted 10 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Instead of walking the cache and freeing everything
unconditionally, handle it the same as when we have a notification of conflicting access.Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>
I ran our tests with the commit, the issue didn't occur. Thanks for the quick response.
Quoted 169 lines
Quoted 39 lines
Quoted 33 lines
Quoted 16 lines
Quoted 16 lines
---
fs/nfsd/filecache.c| 61
+++++++++++++++++++++++++++------------------1 file changed, 37 insertions(+), 24 deletions(-)v2: use the same method to purge entries from the cache as we do when
there is a notification of conflicting access.fs/nfsd/filecache.c index renamed from fs/nfsd/filecache.c +0
-0
58ac93e7e680..397ae212b98d100644fs/nfsd/filecache.c +0
-0@@ -661,6 +661,40 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, };Quoted 16 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = { · line 672
Quoted 11 lines
fs/nfsd/filecache.c +11
-0+/** +* maybe_queue_nfsd_file - try to unhash and queue a nfsd_file +to be freed +* @nf: nfsd_file to attempt to queue +* @dispose: private list to queue successfully-put objects +* +* Unhash an nfsd_file, try to get a reference to it, and then +put that +* reference. If it's the last reference, queue it to the dispose list. +* +* The caller MUST hold the rcu_read_lock() !
__nfsd_file_cache_purge()isn't holdingrcu_read_lock(), it's holding thenfsd_mutex. Is this comment incorrect, or is it just too specific? Or did I miss something obvious?Quoted 5 lines
It's implicitly taken by
rhashtable_walk_startand released byrhashtable_walk_stop.FWIW, it'd be nice if there were a
lockdep_assert_heldequivalent for thercu_read_lock()here, but I didn't see one of those.Quoted 9 lines
Would
static void
nfsd_file_cond_queue(struct nfsd_file *nf, struct list_head *dispose)__must_hold(RCU){
do the trick?
Seems like a reasonable thing to add.
Quoted 16 lines
Quoted 16 lines
There is a
rcu_read_lock_held(), but I didn't see a good way to get that to compile out when lockdep was disabled.Quoted 10 lines
fs/nfsd/filecache.c static struct shrinker nfsd_file_shrinker = {
Quoted 4 lines
fs/nfsd/filecache.c +4
-0+*/ +static void +maybe_queue_nfsd_file (struct nfsd_file *nf,struct list_head +*dispose)I prefer the name
nfsd_file_try_to_queue()ornfsd_file_try_to_dispose().nfsd_file_should be the prefix where possible. Unless you're redriving, I can fix that.Quoted 4 lines
Quoted 1 line
Rename at will.
Done and applied to nfsd-fixes, replacing v1 of this patch.
LGTM. Thanks!
Quoted 84 lines
Quoted 84 lines
Quoted 83 lines
Quoted 75 lines
fs/nfsd/filecache.c +22
-0+{ +int decrement =1 ; + +/* If we raced with someone else unhashing, ignore it */ +if (!nfsd_file_unhash (nf)) +return ; + +/* If we can't get a reference, ignore it */ +if (!nfsd_file_get (nf)) +return ; + +/* Extra decrement if we remove from the LRU */ +if (nfsd_file_lru_remove (nf)) + ++decrement; + +/* If refcount goes to 0, then put on the dispose list */ +if (refcount_sub_and_test (decrement, &nf->nf_ref)) { +list_add (&nf->nf_lru, dispose); +trace_nfsd_file_closing (nf); + } +} +/**
*nfsd_file_queue_for_close: try to close out any opennfsd_filesfor an inode
* @inode: inode on which to close outnfsd_filesfs/nfsd/filecache.c +1
-19@@ -688,30 +722,12 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose)rcu_read_lock ();do { -int decrement =1 ; - nf =rhashtable_lookup (&nfsd_file_rhash_tbl, &key, nfsd_file_rhash_params);if (!nf)break ; -/* If we raced with someone else unhashing, ignore it */ -if (!nfsd_file_unhash (nf)) -continue ; - -/* If we can't get a reference, ignore it */ -if (!nfsd_file_get (nf)) -continue ; - -/* Extra decrement if we remove from the LRU */ -if (nfsd_file_lru_remove (nf)) - ++decrement; - -/* If refcount goes to 0, then put on the dispose list */ -if (refcount_sub_and_test (decrement, &nf->nf_ref)) { -list_add (&nf->nf_lru, dispose); -trace_nfsd_file_closing (nf); - } +maybe_queue_nfsd_file (nf, dispose); }while (1 );rcu_read_unlock ();}
fs/nfsd/filecache.c +3
-6@@ -928,11 +944,8 @@ __nfsd_file_cache_purge(struct net *net) nf =rhashtable_walk_next (&iter);while (!IS_ERR_OR_NULL (nf)) { -if (!net || nf->nf_net == net) { -nfsd_file_unhash (nf); -nfsd_file_lru_remove (nf); -list_add (&nf->nf_lru, &dispose); - } +if (!net || nf->nf_net == net) +maybe_queue_nfsd_file (nf, + &dispose); nf =rhashtable_walk_next (&iter); } --Quoted 2 lines
2.39.0
--
Chuck LeverQuoted 8 lines
Quoted 2 lines
--
Jeff Layton <[email protected]>--
Chuck Lever--
Jeff Layton <[email protected]>
Quoted 25 lines · Shachar Kagan
Quoted 18 lines · Shachar Kagan
Quoted 17 lines · Chuck Lever III
Quoted 17 lines · Jeff Layton
Quoted 13 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 3 lines
Instead of walking the cache and freeing everything
unconditionally, handle it the same as when we have a notification of conflicting access.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>I ran our tests with the commit, the issue didn't occur. Thanks for the quick response.
May I add Tested-by: Shachar Kagan <[email protected]> ?
--
Chuck Lever
Quoted 27 lines
Quoted 27 lines · Shachar Kagan
Quoted 24 lines · Chuck Lever III
Quoted 22 lines
Quoted 22 lines · Jeff Layton
Quoted 18 lines · Chuck Lever III
Quoted 6 lines · Jeff Layton
nfsd_file_cache_purgeis called when the server is shutting down, in which case, tearing things down is generally fine, but it also gets called when the exports cache is flushed.Yeah... cache flush is probably the case we've been missing.
Quoted 8 lines
Instead of walking the cache and freeing everything
unconditionally, handle it the same as when we have a notification of conflicting access.Fixes ac3a2585f018 ("nfsd: rework refcounting in filecache")Reported-by Ruben Vestergaard <[email protected]>Reported-by Torkil Svensgaard <[email protected]>Reported-by Shachar Kagan <[email protected]>Signed-off-by Jeff Layton <[email protected]>
Quoted 5 lines
Quoted 2 lines
I ran our tests with the commit, the issue didn't occur. Thanks for the quick response.
May I add Tested-by: Shachar Kagan <[email protected]> ?
Yes
Quoted 2 lines
--
Chuck Lever
--
Shachar Kagan