Add some stats to indicate the state of the cookie commit LRU, including an
indication of how many are currently on it, how many have been expired,
removed (withdrawn/reused) or dropped (relinquished) from it and how long
till the next reap happens.

Signed-off-by: David Howells <[email protected]>
---

 fs/fscache/cookie.c   |   10 +++++++++-
 fs/fscache/internal.h |    5 +++++
 fs/fscache/stats.c    |   12 ++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index dfc61b2e105d..c6b553609f33 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -28,7 +28,7 @@ static LIST_HEAD(fscache_cookies);
 static DEFINE_RWLOCK(fscache_cookies_lock);
 static LIST_HEAD(fscache_cookie_lru);
 static DEFINE_SPINLOCK(fscache_cookie_lru_lock);
-static DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out);
+DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out);
 static DECLARE_WORK(fscache_cookie_lru_work, fscache_cookie_lru_worker);
 static const char fscache_cookie_stages[FSCACHE_COOKIE_STAGE__NR] = 
"-LCAIFMWRD";
 unsigned int fscache_lru_cookie_timeout = 10 * HZ;
@@ -60,6 +60,8 @@ static void fscache_free_cookie(struct fscache_cookie *cookie)
                spin_lock(&fscache_cookie_lru_lock);
                list_del_init(&cookie->commit_link);
                spin_unlock(&fscache_cookie_lru_lock);
+               fscache_stat_d(&fscache_n_cookies_lru);
+               fscache_stat(&fscache_n_cookies_lru_removed);
        }
        write_lock(&fscache_cookies_lock);
        list_del(&cookie->proc_link);
@@ -525,6 +527,7 @@ void __fscache_unuse_cookie(struct fscache_cookie *cookie,
                        if (list_empty(&cookie->commit_link)) {
                                fscache_get_cookie(cookie, 
fscache_cookie_get_lru);
                                list_move_tail(&cookie->commit_link, 
&fscache_cookie_lru);
+                               fscache_stat(&fscache_n_cookies_lru);
                        }
                        spin_unlock(&fscache_cookie_lru_lock);
                        timer_reduce(&fscache_cookie_lru_timer,
@@ -624,10 +627,12 @@ static void fscache_cookie_lru_do_one(struct 
fscache_cookie *cookie)
            time_before(jiffies, cookie->unused_at + 
fscache_lru_cookie_timeout) ||
            atomic_read(&cookie->n_active) > 0) {
                spin_unlock(&cookie->lock);
+               fscache_stat(&fscache_n_cookies_lru_removed);
        } else {
                __fscache_set_cookie_stage(cookie, 
FSCACHE_COOKIE_STAGE_COMMITTING);
                set_bit(FSCACHE_COOKIE_DO_COMMIT, &cookie->flags);
                spin_unlock(&cookie->lock);
+               fscache_stat(&fscache_n_cookies_lru_expired);
                _debug("lru c=%x", cookie->debug_id);
                __fscache_withdraw_cookie(cookie);
        }
@@ -652,6 +657,7 @@ static void fscache_cookie_lru_worker(struct work_struct 
*work)
                }
 
                list_del_init(&cookie->commit_link);
+               fscache_stat_d(&fscache_n_cookies_lru);
                spin_unlock(&fscache_cookie_lru_lock);
                fscache_cookie_lru_do_one(cookie);
                spin_lock(&fscache_cookie_lru_lock);
@@ -673,6 +679,8 @@ static void fscache_cookie_drop_from_lru(struct 
fscache_cookie *cookie)
                spin_lock(&fscache_cookie_lru_lock);
                if (!list_empty(&cookie->commit_link)) {
                        list_del_init(&cookie->commit_link);
+                       fscache_stat_d(&fscache_n_cookies_lru);
+                       fscache_stat(&fscache_n_cookies_lru_dropped);
                        need_put = true;
                }
                spin_unlock(&fscache_cookie_lru_lock);
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index f74f7bdea633..62e6a5bbef8e 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -32,6 +32,7 @@ struct fscache_cache *fscache_lookup_cache(const char *name, 
bool is_cache);
  */
 extern struct kmem_cache *fscache_cookie_jar;
 extern const struct seq_operations fscache_cookies_seq_ops;
+extern struct timer_list fscache_cookie_lru_timer;
 
 extern void fscache_print_cookie(struct fscache_cookie *cookie, char prefix);
 extern bool fscache_begin_cookie_access(struct fscache_cookie *cookie,
@@ -70,6 +71,10 @@ extern atomic_t fscache_n_volumes;
 extern atomic_t fscache_n_volumes_collision;
 extern atomic_t fscache_n_volumes_nomem;
 extern atomic_t fscache_n_cookies;
+extern atomic_t fscache_n_cookies_lru;
+extern atomic_t fscache_n_cookies_lru_expired;
+extern atomic_t fscache_n_cookies_lru_removed;
+extern atomic_t fscache_n_cookies_lru_dropped;
 
 extern atomic_t fscache_n_retrievals;
 extern atomic_t fscache_n_retrievals_ok;
diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
index 13e90b940bd2..5700e5712018 100644
--- a/fs/fscache/stats.c
+++ b/fs/fscache/stats.c
@@ -18,6 +18,10 @@ atomic_t fscache_n_volumes;
 atomic_t fscache_n_volumes_collision;
 atomic_t fscache_n_volumes_nomem;
 atomic_t fscache_n_cookies;
+atomic_t fscache_n_cookies_lru;
+atomic_t fscache_n_cookies_lru_expired;
+atomic_t fscache_n_cookies_lru_removed;
+atomic_t fscache_n_cookies_lru_dropped;
 
 atomic_t fscache_n_retrievals;
 atomic_t fscache_n_retrievals_ok;
@@ -89,6 +93,14 @@ int fscache_stats_show(struct seq_file *m, void *v)
                   atomic_read(&fscache_n_acquires_nobufs),
                   atomic_read(&fscache_n_acquires_oom));
 
+       seq_printf(m, "LRU    : n=%u exp=%u rmv=%u drp=%u at=%ld\n",
+                  atomic_read(&fscache_n_cookies_lru),
+                  atomic_read(&fscache_n_cookies_lru_expired),
+                  atomic_read(&fscache_n_cookies_lru_removed),
+                  atomic_read(&fscache_n_cookies_lru_dropped),
+                  timer_pending(&fscache_cookie_lru_timer) ?
+                  fscache_cookie_lru_timer.expires - jiffies : 0);
+
        seq_printf(m, "Invals : n=%u run=%u\n",
                   atomic_read(&fscache_n_invalidates),
                   atomic_read(&fscache_n_invalidates_run));


--
Linux-cachefs mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-cachefs

Reply via email to