[Linux-cachefs] [PATCH] fscache: print usage count for objects in cache
Jeff Layton
jlayton at kernel.org
Thu Nov 7 19:03:59 UTC 2019
Have the fscache "objects" procfile also display the usage count for
the object to help track down refcounting issues.
Add a new object_usage operation that returns the value, add a new
field to the objects procfile and have fscache query it for the
object.
Signed-off-by: Jeff Layton <jlayton at kernel.org>
---
fs/cachefiles/interface.c | 12 ++++++++++++
fs/fscache/object-list.c | 9 +++++----
include/linux/fscache-cache.h | 3 +++
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/fs/cachefiles/interface.c b/fs/cachefiles/interface.c
index f6ccf25604b1..732639c764f8 100644
--- a/fs/cachefiles/interface.c
+++ b/fs/cachefiles/interface.c
@@ -366,6 +366,17 @@ static void cachefiles_put_object(struct fscache_object *_object,
_leave("");
}
+static int cachefiles_object_usage(struct fscache_object *_object)
+{
+ struct cachefiles_object *object;
+
+ ASSERT(_object);
+
+ object = container_of(_object, struct cachefiles_object, fscache);
+ return atomic_read(&object->usage);
+}
+
+
/*
* sync a cache
*/
@@ -554,6 +565,7 @@ const struct fscache_cache_ops cachefiles_cache_ops = {
.invalidate_object = cachefiles_invalidate_object,
.drop_object = cachefiles_drop_object,
.put_object = cachefiles_put_object,
+ .object_usage = cachefiles_object_usage,
.sync_cache = cachefiles_sync_cache,
.attr_changed = cachefiles_attr_changed,
.read_or_alloc_page = cachefiles_read_or_alloc_page,
diff --git a/fs/fscache/object-list.c b/fs/fscache/object-list.c
index a64a67778714..c3549358570e 100644
--- a/fs/fscache/object-list.c
+++ b/fs/fscache/object-list.c
@@ -168,7 +168,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
if ((unsigned long) v == 1) {
seq_puts(m, "OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS"
- " EM EV FL S"
+ " EM EV FL S U"
" | COOKIE NETFS_COOKIE_DEF TY FL NETFS_DATA");
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
FSCACHE_OBJLIST_CONFIG_AUX))
@@ -187,7 +187,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
if ((unsigned long) v == 2) {
seq_puts(m, "======== ======== ==== ===== === === === == ====="
- " == == == ="
+ " == == == = ="
" | ======== ================ == === ================");
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
FSCACHE_OBJLIST_CONFIG_AUX))
@@ -230,7 +230,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
}
seq_printf(m,
- "%08x %08x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ",
+ "%08x %08x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x %1x | ",
obj->debug_id,
obj->parent ? obj->parent->debug_id : UINT_MAX,
obj->state->short_name,
@@ -243,7 +243,8 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
obj->event_mask,
obj->events,
obj->flags,
- work_busy(&obj->work));
+ work_busy(&obj->work),
+ obj->cache->ops->object_usage(obj));
if (obj->cookie) {
uint16_t keylen = 0, auxlen = 0;
diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
index 143b1594ac94..732b5a7e65c1 100644
--- a/include/linux/fscache-cache.h
+++ b/include/linux/fscache-cache.h
@@ -274,6 +274,9 @@ struct fscache_cache_ops {
void (*put_object)(struct fscache_object *object,
enum fscache_obj_ref_trace why);
+ /* return current usage count of an object */
+ int (*object_usage)(struct fscache_object *object);
+
/* sync a cache */
void (*sync_cache)(struct fscache_cache *cache);
--
2.23.0
More information about the Linux-cachefs
mailing list