All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org, netdev@vger.kernel.org
Cc: david@fromorbit.com, jlayton@redhat.com, tgraf@suug.ch
Subject: [PATCH v3 24/32] NFSD: Replace the "init once" mechanism
Date: Fri, 08 Jul 2022 14:26:16 -0400	[thread overview]
Message-ID: <165730477689.28142.2413809301889936542.stgit@klimt.1015granger.net> (raw)
In-Reply-To: <165730437087.28142.6731645688073512500.stgit@klimt.1015granger.net>

In a moment, the nfsd_file_hashtbl global will be replaced with an
rhashtable. Replace the one or two spots that need to check if the
hash table is available. We can easily reuse the SHUTDOWN flag for
this purpose.

Document that this mechanism relies on callers to hold the
nfsd_mutex to prevent init, shutdown, and purging to run
concurrently.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/filecache.c |   42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index 7e857f291d4a..b075c9223377 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -28,7 +28,7 @@
 #define NFSD_FILE_HASH_SIZE                  (1 << NFSD_FILE_HASH_BITS)
 #define NFSD_LAUNDRETTE_DELAY		     (2 * HZ)
 
-#define NFSD_FILE_SHUTDOWN		     (1)
+#define NFSD_FILE_CACHE_UP		     (0)
 
 /* We only care about NFSD_MAY_READ/WRITE for this cache */
 #define NFSD_FILE_MAY_MASK	(NFSD_MAY_READ|NFSD_MAY_WRITE)
@@ -59,7 +59,7 @@ static struct kmem_cache		*nfsd_file_slab;
 static struct kmem_cache		*nfsd_file_mark_slab;
 static struct nfsd_fcache_bucket	*nfsd_file_hashtbl;
 static struct list_lru			nfsd_file_lru;
-static long				nfsd_file_lru_flags;
+static unsigned long			nfsd_file_flags;
 static struct fsnotify_group		*nfsd_file_fsnotify_group;
 static atomic_long_t			nfsd_filecache_count;
 static struct delayed_work		nfsd_filecache_laundrette;
@@ -67,9 +67,8 @@ static struct delayed_work		nfsd_filecache_laundrette;
 static void
 nfsd_file_schedule_laundrette(void)
 {
-	long count = atomic_long_read(&nfsd_filecache_count);
-
-	if (count == 0 || test_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags))
+	if ((atomic_long_read(&nfsd_filecache_count) == 0) ||
+	    test_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 0)
 		return;
 
 	queue_delayed_work(system_wq, &nfsd_filecache_laundrette,
@@ -704,9 +703,8 @@ nfsd_file_cache_init(void)
 	int		ret = -ENOMEM;
 	unsigned int	i;
 
-	clear_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
-
-	if (nfsd_file_hashtbl)
+	lockdep_assert_held(&nfsd_mutex);
+	if (test_and_set_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 1)
 		return 0;
 
 	nfsd_filecache_wq = alloc_workqueue("nfsd_filecache", 0, 0);
@@ -792,8 +790,8 @@ nfsd_file_cache_init(void)
 /*
  * Note this can deadlock with nfsd_file_lru_cb.
  */
-void
-nfsd_file_cache_purge(struct net *net)
+static void
+__nfsd_file_cache_purge(struct net *net)
 {
 	unsigned int		i;
 	struct nfsd_file	*nf;
@@ -801,9 +799,6 @@ nfsd_file_cache_purge(struct net *net)
 	LIST_HEAD(dispose);
 	bool del;
 
-	if (!nfsd_file_hashtbl)
-		return;
-
 	for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
 		struct nfsd_fcache_bucket *nfb = &nfsd_file_hashtbl[i];
 
@@ -864,6 +859,19 @@ nfsd_file_cache_start_net(struct net *net)
 	return nn->fcache_disposal ? 0 : -ENOMEM;
 }
 
+/**
+ * nfsd_file_cache_purge - Remove all cache items associated with @net
+ * @net: target net namespace
+ *
+ */
+void
+nfsd_file_cache_purge(struct net *net)
+{
+	lockdep_assert_held(&nfsd_mutex);
+	if (test_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 1)
+		__nfsd_file_cache_purge(net);
+}
+
 void
 nfsd_file_cache_shutdown_net(struct net *net)
 {
@@ -876,7 +884,9 @@ nfsd_file_cache_shutdown(void)
 {
 	int i;
 
-	set_bit(NFSD_FILE_SHUTDOWN, &nfsd_file_lru_flags);
+	lockdep_assert_held(&nfsd_mutex);
+	if (test_and_clear_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 0)
+		return;
 
 	lease_unregister_notifier(&nfsd_file_lease_notifier);
 	unregister_shrinker(&nfsd_file_shrinker);
@@ -885,7 +895,7 @@ nfsd_file_cache_shutdown(void)
 	 * calling nfsd_file_cache_purge
 	 */
 	cancel_delayed_work_sync(&nfsd_filecache_laundrette);
-	nfsd_file_cache_purge(NULL);
+	__nfsd_file_cache_purge(NULL);
 	list_lru_destroy(&nfsd_file_lru);
 	rcu_barrier();
 	fsnotify_put_group(nfsd_file_fsnotify_group);
@@ -1163,7 +1173,7 @@ static int nfsd_file_cache_stats_show(struct seq_file *m, void *v)
 	 * don't end up racing with server shutdown
 	 */
 	mutex_lock(&nfsd_mutex);
-	if (nfsd_file_hashtbl) {
+	if (test_bit(NFSD_FILE_CACHE_UP, &nfsd_file_flags) == 1) {
 		for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) {
 			count += nfsd_file_hashtbl[i].nfb_count;
 			longest = max(longest, nfsd_file_hashtbl[i].nfb_count);



  parent reply	other threads:[~2022-07-08 18:27 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 18:23 [PATCH v3 00/32] Overhaul NFSD filecache Chuck Lever
2022-07-08 18:23 ` [PATCH v3 01/32] NFSD: Demote a WARN to a pr_warn() Chuck Lever
2022-07-08 18:23 ` [PATCH v3 02/32] NFSD: Report filecache LRU size Chuck Lever
2022-07-08 18:23 ` [PATCH v3 03/32] NFSD: Report count of calls to nfsd_file_acquire() Chuck Lever
2022-07-08 18:24 ` [PATCH v3 04/32] NFSD: Report count of freed filecache items Chuck Lever
2022-07-08 18:24 ` [PATCH v3 05/32] NFSD: Report average age of " Chuck Lever
2022-07-08 18:24 ` [PATCH v3 06/32] NFSD: Add nfsd_file_lru_dispose_list() helper Chuck Lever
2022-07-08 18:24 ` [PATCH v3 07/32] NFSD: Refactor nfsd_file_gc() Chuck Lever
2022-07-08 18:24 ` [PATCH v3 08/32] NFSD: Refactor nfsd_file_lru_scan() Chuck Lever
2022-07-08 18:24 ` [PATCH v3 09/32] NFSD: Report the number of items evicted by the LRU walk Chuck Lever
2022-07-08 18:24 ` [PATCH v3 10/32] NFSD: Record number of flush calls Chuck Lever
2022-07-08 18:24 ` [PATCH v3 11/32] NFSD: Zero counters when the filecache is re-initialized Chuck Lever
2022-07-08 18:24 ` [PATCH v3 12/32] NFSD: Hook up the filecache stat file Chuck Lever
2022-07-08 19:16   ` Jeff Layton
2022-07-08 18:25 ` [PATCH v3 13/32] NFSD: WARN when freeing an item still linked via nf_lru Chuck Lever
2022-07-08 18:25 ` [PATCH v3 14/32] NFSD: Trace filecache LRU activity Chuck Lever
2022-07-08 18:25 ` [PATCH v3 15/32] NFSD: Leave open files out of the filecache LRU Chuck Lever
2022-07-08 19:29   ` Jeff Layton
2022-07-09 20:45     ` Chuck Lever III
2022-07-11 11:39       ` Jeff Layton
2022-07-08 18:25 ` [PATCH v3 16/32] NFSD: Fix the filecache LRU shrinker Chuck Lever
2022-07-08 19:37   ` Jeff Layton
2022-07-08 18:25 ` [PATCH v3 17/32] NFSD: Never call nfsd_file_gc() in foreground paths Chuck Lever
2022-07-08 19:43   ` Jeff Layton
2022-07-08 19:45     ` Chuck Lever III
2022-07-08 18:25 ` [PATCH v3 18/32] NFSD: No longer record nf_hashval in the trace log Chuck Lever
2022-07-08 18:25 ` [PATCH v3 19/32] NFSD: Remove lockdep assertion from unhash_and_release_locked() Chuck Lever
2022-07-08 18:25 ` [PATCH v3 20/32] NFSD: nfsd_file_unhash can compute hashval from nf->nf_inode Chuck Lever
2022-07-08 18:25 ` [PATCH v3 21/32] NFSD: Refactor __nfsd_file_close_inode() Chuck Lever
2022-07-08 18:26 ` [PATCH v3 22/32] NFSD: nfsd_file_hash_remove can compute hashval Chuck Lever
2022-07-08 18:26 ` [PATCH v3 23/32] NFSD: Remove nfsd_file::nf_hashval Chuck Lever
2022-07-08 18:26 ` Chuck Lever [this message]
2022-07-08 18:26 ` [PATCH v3 25/32] NFSD: Set up an rhashtable for the filecache Chuck Lever
2022-07-08 18:26 ` [PATCH v3 26/32] NFSD: Convert the filecache to use rhashtable Chuck Lever
2022-07-08 18:26 ` [PATCH v3 27/32] NFSD: Clean up unused code after rhashtable conversion Chuck Lever
2022-07-08 18:26 ` [PATCH v3 28/32] NFSD: Separate tracepoints for acquire and create Chuck Lever
2022-07-08 18:26 ` [PATCH v3 29/32] NFSD: Move nfsd_file_trace_alloc() tracepoint Chuck Lever
2022-07-08 18:26 ` [PATCH v3 30/32] NFSD: Update the nfsd_file_fsnotify_handle_event() tracepoint Chuck Lever
2022-07-08 18:27 ` [PATCH v3 31/32] NFSD: NFSv4 CLOSE should release an nfsd_file immediately Chuck Lever
2022-07-08 18:27 ` [PATCH v3 32/32] NFSD: Ensure nf_inode is never dereferenced Chuck Lever
2022-07-08 20:27 ` [PATCH v3 00/32] Overhaul NFSD filecache Jeff Layton
2022-07-08 20:32   ` Chuck Lever III

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165730477689.28142.2413809301889936542.stgit@klimt.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=david@fromorbit.com \
    --cc=jlayton@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.