mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fscache: make the procfs cookie listing optional
@ 2026-11-11 15:45 Max Kellermann
  0 siblings, 0 replies; only message in thread
From: Max Kellermann @ 2026-11-11 15:45 UTC (permalink / raw)
  To: David Howells, Paulo Alcantara
  Cc: Max Kellermann, netfs, linux-fsdevel, linux-kernel

Add FSCACHE_COOKIE_PROC, enabled by default, to omit the diagnostic
cookie list and its maintenance when not needed.  Caching and counters
are unaffected.  Disabling it reduces the size of the struct by 16
bytes.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 fs/netfs/Kconfig          | 10 ++++++++++
 fs/netfs/fscache_cookie.c |  8 +++++++-
 fs/netfs/fscache_proc.c   |  2 ++
 fs/netfs/internal.h       |  2 ++
 include/linux/fscache.h   |  2 ++
 5 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/fs/netfs/Kconfig b/fs/netfs/Kconfig
index d0e7b0971fa3..881b081e3a52 100644
--- a/fs/netfs/Kconfig
+++ b/fs/netfs/Kconfig
@@ -44,6 +44,16 @@ config FSCACHE
 
 	  See Documentation/filesystems/caching/fscache.rst for more information.
 
+config FSCACHE_COOKIE_PROC
+	bool "List FS-Cache cookies in procfs"
+	depends on FSCACHE && PROC_FS
+	default y
+	help
+	  Provide the diagnostic /proc/fs/netfs/cookies listing (also
+	  available through /proc/fs/fscache/cookies). Disabling this saves
+	  two pointers per cookie and avoids maintaining the global list.
+	  Caching and statistics remain available.
+
 config FSCACHE_STATS
 	bool "Gather statistical information on local caching"
 	depends on FSCACHE && PROC_FS
diff --git a/fs/netfs/fscache_cookie.c b/fs/netfs/fscache_cookie.c
index 5a226f9cbdea..fe0832ec2056 100644
--- a/fs/netfs/fscache_cookie.c
+++ b/fs/netfs/fscache_cookie.c
@@ -23,8 +23,10 @@ static void fscache_perform_invalidation(struct fscache_cookie *cookie);
 
 #define fscache_cookie_hash_shift 15
 static struct hlist_bl_head fscache_cookie_hash[1 << fscache_cookie_hash_shift];
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 static LIST_HEAD(fscache_cookies);
 static DEFINE_RWLOCK(fscache_cookies_lock);
+#endif
 static LIST_HEAD(fscache_cookie_lru);
 static DEFINE_SPINLOCK(fscache_cookie_lru_lock);
 DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out);
@@ -68,9 +70,11 @@ static void fscache_free_cookie(struct fscache_cookie *cookie)
 		return;
 	}
 
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 	write_lock(&fscache_cookies_lock);
 	list_del(&cookie->proc_link);
 	write_unlock(&fscache_cookies_lock);
+#endif
 	if (cookie->aux_len > sizeof(cookie->inline_aux))
 		kfree(cookie->aux);
 	if (cookie->key_len > sizeof(cookie->inline_key))
@@ -363,9 +367,11 @@ static struct fscache_cookie *fscache_alloc_cookie(
 	INIT_WORK(&cookie->work, fscache_cookie_worker);
 	__fscache_set_cookie_state(cookie, FSCACHE_COOKIE_STATE_QUIESCENT);
 
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 	write_lock(&fscache_cookies_lock);
 	list_add_tail(&cookie->proc_link, &fscache_cookies);
 	write_unlock(&fscache_cookies_lock);
+#endif
 	fscache_see_cookie(cookie, fscache_cookie_new_acquire);
 	return cookie;
 
@@ -1104,7 +1110,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie,
 }
 EXPORT_SYMBOL(__fscache_invalidate);
 
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 /*
  * Generate a list of extant cookies in /proc/fs/fscache/cookies
  */
diff --git a/fs/netfs/fscache_proc.c b/fs/netfs/fscache_proc.c
index 874d951bc390..6ab23083cf01 100644
--- a/fs/netfs/fscache_proc.c
+++ b/fs/netfs/fscache_proc.c
@@ -27,9 +27,11 @@ int __init fscache_proc_init(void)
 			     &fscache_volumes_seq_ops))
 		goto error;
 
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 	if (!proc_create_seq("fs/netfs/cookies", S_IFREG | 0444, NULL,
 			     &fscache_cookies_seq_ops))
 		goto error;
+#endif
 	return 0;
 
 error:
diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index 6b583152132f..855fc47fbe6d 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -406,8 +406,10 @@ static inline bool fscache_set_cache_state_maybe(struct fscache_cache *cache,
  */
 extern struct kmem_cache *fscache_cookie_jar;
 #ifdef CONFIG_PROC_FS
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 extern const struct seq_operations fscache_cookies_seq_ops;
 #endif
+#endif
 extern struct timer_list fscache_cookie_lru_timer;
 
 extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
index ecd14d645690..b4aedcfb5945 100644
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -109,7 +109,9 @@ struct fscache_cookie {
 	struct fscache_volume		*volume;	/* Parent volume of this file. */
 	void				*cache_priv;	/* Cache-side representation */
 	struct hlist_bl_node		hash_link;	/* Link in hash table */
+#ifdef CONFIG_FSCACHE_COOKIE_PROC
 	struct list_head		proc_link;	/* Link in proc list */
+#endif
 	struct list_head		commit_link;	/* Link in commit queue */
 	struct work_struct		work;		/* Commit/relinq/withdraw work */
 	uoff_t				object_size;	/* Size of the netfs object */
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-11 15:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 15:45 [PATCH] fscache: make the procfs cookie listing optional Max Kellermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®