From 3929eca769b5a231010b4978acc61c0735da198f Mon Sep 17 00:00:00 2001 From: David Howells Date: Thu, 21 Oct 2021 21:58:29 +0100 Subject: fscache, cachefiles: Display stats of no-space events Add stat counters of no-space events that caused caching not to happen and display in /proc/fs/fscache/stats. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/163819653216.215744.17210522251617386509.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906958369.143852.7257100711818401748.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967166917.1823006.14842444049198947892.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021566184.640689.4417328329632709265.stgit@warthog.procyon.org.uk/ # v4 --- fs/cachefiles/cache.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'fs/cachefiles/cache.c') diff --git a/fs/cachefiles/cache.c b/fs/cachefiles/cache.c index e2cbbc08bad9..809519286335 100644 --- a/fs/cachefiles/cache.c +++ b/fs/cachefiles/cache.c @@ -147,7 +147,7 @@ int cachefiles_add_cache(struct cachefiles_cache *cache) pr_info("File cache on %s registered\n", cache_cookie->name); /* check how much space the cache has */ - cachefiles_has_space(cache, 0, 0); + cachefiles_has_space(cache, 0, 0, cachefiles_has_space_check); cachefiles_end_secure(cache, saved_cred); _leave(" = 0 [%px]", cache->cache); return 0; @@ -175,7 +175,8 @@ error_getsec: * cache */ int cachefiles_has_space(struct cachefiles_cache *cache, - unsigned fnr, unsigned bnr) + unsigned fnr, unsigned bnr, + enum cachefiles_has_space_for reason) { struct kstatfs stats; u64 b_avail, b_writing; @@ -233,7 +234,7 @@ int cachefiles_has_space(struct cachefiles_cache *cache, ret = -ENOBUFS; if (stats.f_ffree < cache->fstop || b_avail < cache->bstop) - goto begin_cull; + goto stop_and_begin_cull; ret = 0; if (stats.f_ffree < cache->fcull || @@ -252,6 +253,17 @@ int cachefiles_has_space(struct cachefiles_cache *cache, //_leave(" = 0"); return 0; +stop_and_begin_cull: + switch (reason) { + case cachefiles_has_space_for_write: + fscache_count_no_write_space(); + break; + case cachefiles_has_space_for_create: + fscache_count_no_create_space(); + break; + default: + break; + } begin_cull: if (!test_and_set_bit(CACHEFILES_CULLING, &cache->flags)) { _debug("### CULL CACHE ###"); -- cgit v1.2.3