[PATCH 17/23] cache: support updating maxcount and flags

Darrick J. Wong
2025-11-06T22:47:36Z

A future patchset will create a new io cache manager that uses the
hashtable in cache.c It's desirable for fuse4fs to be able to control
the maximum number of buffers in the IO cache, so add a simple API so
that cache users can set a new max item count.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
lib/support/cache.h | 2 ++
lib/support/cache.c | 10 ++++++++++
2 files changed, 12 insertions(+)

diff --git a/lib/support/cache.h b/lib/support/cache.h
index ae37945c545f46..75e61c92a1fd35 100644
--- a/lib/support/cache.h
+++ b/lib/support/cache.h
@@ -144,6 +144,8 @@ void cache_walk(struct cache *cache, cache_walk_t fn, void *data);
void cache_purge(struct cache *);
bool cache_flush(struct cache *cache);

+void cache_set_maxcount(struct cache *cache, unsigned int maxcount);
+
/* don't allocate a new node */
#define CACHE_GET_INCORE (1U << 0)
int cache_node_get(struct cache *c, cache_key_t key, unsigned int cgflags,
diff --git a/lib/support/cache.c b/lib/support/cache.c
index dbaddc1bd36d3d..e2f9e722eb2ef1 100644
--- a/lib/support/cache.c
+++ b/lib/support/cache.c
@@ -87,6 +87,16 @@ cache_init(
return 0;
}

+void
+cache_set_maxcount(
+ struct cache *cache,
+ unsigned int maxcount)
+{
+ pthread_mutex_lock(&cache->c_mutex);
+ cache->c_maxcount = maxcount;
+ pthread_mutex_unlock(&cache->c_mutex);
+}
+
static void
cache_expand(
struct cache * cache)