summaryrefslogtreecommitdiffstats
path: root/fs/fscache
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2018-04-04 08:41:27 -0400
committerDavid Howells <dhowells@redhat.com>2018-04-04 08:41:27 -0400
commita18feb55769b705a44c4107786c4045eae2e87b6 (patch)
tree3db7d160e672aa9f16a0437b767b3d3bbb10ecc8 /fs/fscache
parent2c98425720233ae3e135add0c7e869b32913502f (diff)
fscache: Add tracepoints
Add some tracepoints to fscache: (*) fscache_cookie - Tracks a cookie's usage count. (*) fscache_netfs - Logs registration of a network filesystem, including the pointer to the cookie allocated. (*) fscache_acquire - Logs cookie acquisition. (*) fscache_relinquish - Logs cookie relinquishment. (*) fscache_enable - Logs enablement of a cookie. (*) fscache_disable - Logs disablement of a cookie. (*) fscache_osm - Tracks execution of states in the object state machine. and cachefiles: (*) cachefiles_ref - Tracks a cachefiles object's usage count. (*) cachefiles_lookup - Logs result of lookup_one_len(). (*) cachefiles_mkdir - Logs result of vfs_mkdir(). (*) cachefiles_create - Logs result of vfs_create(). (*) cachefiles_unlink - Logs calls to vfs_unlink(). (*) cachefiles_rename - Logs calls to vfs_rename(). (*) cachefiles_mark_active - Logs an object becoming active. (*) cachefiles_wait_active - Logs a wait for an old object to be destroyed. (*) cachefiles_mark_inactive - Logs an object becoming inactive. (*) cachefiles_mark_buried - Logs the burial of an object. Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs/fscache')
-rw-r--r--fs/fscache/cookie.c46
-rw-r--r--fs/fscache/internal.h16
-rw-r--r--fs/fscache/main.c1
-rw-r--r--fs/fscache/netfs.c3
-rw-r--r--fs/fscache/object.c36
5 files changed, 63 insertions, 39 deletions
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index 98d22f495cd8..20bc3341f113 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -101,7 +101,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
101 */ 101 */
102 atomic_set(&cookie->n_active, 1); 102 atomic_set(&cookie->n_active, 1);
103 103
104 atomic_inc(&parent->usage); 104 fscache_cookie_get(parent, fscache_cookie_get_acquire_parent);
105 atomic_inc(&parent->n_children); 105 atomic_inc(&parent->n_children);
106 106
107 cookie->def = def; 107 cookie->def = def;
@@ -125,6 +125,8 @@ struct fscache_cookie *__fscache_acquire_cookie(
125 break; 125 break;
126 } 126 }
127 127
128 trace_fscache_acquire(cookie);
129
128 if (enable) { 130 if (enable) {
129 /* if the object is an index then we need do nothing more here 131 /* if the object is an index then we need do nothing more here
130 * - we create indices on disk when we need them as an index 132 * - we create indices on disk when we need them as an index
@@ -134,7 +136,8 @@ struct fscache_cookie *__fscache_acquire_cookie(
134 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags); 136 set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
135 } else { 137 } else {
136 atomic_dec(&parent->n_children); 138 atomic_dec(&parent->n_children);
137 __fscache_cookie_put(cookie); 139 fscache_cookie_put(cookie,
140 fscache_cookie_put_acquire_nobufs);
138 fscache_stat(&fscache_n_acquires_nobufs); 141 fscache_stat(&fscache_n_acquires_nobufs);
139 _leave(" = NULL"); 142 _leave(" = NULL");
140 return NULL; 143 return NULL;
@@ -159,6 +162,8 @@ void __fscache_enable_cookie(struct fscache_cookie *cookie,
159{ 162{
160 _enter("%p", cookie); 163 _enter("%p", cookie);
161 164
165 trace_fscache_enable(cookie);
166
162 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK, 167 wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
163 TASK_UNINTERRUPTIBLE); 168 TASK_UNINTERRUPTIBLE);
164 169
@@ -318,7 +323,7 @@ static int fscache_alloc_object(struct fscache_cache *cache,
318 * attached to the cookie */ 323 * attached to the cookie */
319 if (fscache_attach_object(cookie, object) < 0) { 324 if (fscache_attach_object(cookie, object) < 0) {
320 fscache_stat(&fscache_n_cop_put_object); 325 fscache_stat(&fscache_n_cop_put_object);
321 cache->ops->put_object(object); 326 cache->ops->put_object(object, fscache_obj_put_attach_fail);
322 fscache_stat_d(&fscache_n_cop_put_object); 327 fscache_stat_d(&fscache_n_cop_put_object);
323 } 328 }
324 329
@@ -338,7 +343,7 @@ object_already_extant:
338 343
339error_put: 344error_put:
340 fscache_stat(&fscache_n_cop_put_object); 345 fscache_stat(&fscache_n_cop_put_object);
341 cache->ops->put_object(object); 346 cache->ops->put_object(object, fscache_obj_put_alloc_fail);
342 fscache_stat_d(&fscache_n_cop_put_object); 347 fscache_stat_d(&fscache_n_cop_put_object);
343error: 348error:
344 _leave(" = %d", ret); 349 _leave(" = %d", ret);
@@ -398,7 +403,7 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
398 403
399 /* attach to the cookie */ 404 /* attach to the cookie */
400 object->cookie = cookie; 405 object->cookie = cookie;
401 atomic_inc(&cookie->usage); 406 fscache_cookie_get(cookie, fscache_cookie_get_attach_object);
402 hlist_add_head(&object->cookie_link, &cookie->backing_objects); 407 hlist_add_head(&object->cookie_link, &cookie->backing_objects);
403 408
404 fscache_objlist_add(object); 409 fscache_objlist_add(object);
@@ -516,6 +521,8 @@ void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
516 521
517 _enter("%p,%u", cookie, invalidate); 522 _enter("%p,%u", cookie, invalidate);
518 523
524 trace_fscache_disable(cookie);
525
519 ASSERTCMP(atomic_read(&cookie->n_active), >, 0); 526 ASSERTCMP(atomic_read(&cookie->n_active), >, 0);
520 527
521 if (atomic_read(&cookie->n_children) != 0) { 528 if (atomic_read(&cookie->n_children) != 0) {
@@ -601,6 +608,8 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
601 cookie, cookie->def->name, cookie->netfs_data, 608 cookie, cookie->def->name, cookie->netfs_data,
602 atomic_read(&cookie->n_active), retire); 609 atomic_read(&cookie->n_active), retire);
603 610
611 trace_fscache_relinquish(cookie, retire);
612
604 /* No further netfs-accessing operations on this cookie permitted */ 613 /* No further netfs-accessing operations on this cookie permitted */
605 if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags)) 614 if (test_and_set_bit(FSCACHE_COOKIE_RELINQUISHED, &cookie->flags))
606 BUG(); 615 BUG();
@@ -620,35 +629,38 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
620 629
621 /* Dispose of the netfs's link to the cookie */ 630 /* Dispose of the netfs's link to the cookie */
622 ASSERTCMP(atomic_read(&cookie->usage), >, 0); 631 ASSERTCMP(atomic_read(&cookie->usage), >, 0);
623 fscache_cookie_put(cookie); 632 fscache_cookie_put(cookie, fscache_cookie_put_relinquish);
624 633
625 _leave(""); 634 _leave("");
626} 635}
627EXPORT_SYMBOL(__fscache_relinquish_cookie); 636EXPORT_SYMBOL(__fscache_relinquish_cookie);
628 637
629/* 638/*
630 * destroy a cookie 639 * Drop a reference to a cookie.
631 */ 640 */
632void __fscache_cookie_put(struct fscache_cookie *cookie) 641void fscache_cookie_put(struct fscache_cookie *cookie,
642 enum fscache_cookie_trace where)
633{ 643{
634 struct fscache_cookie *parent; 644 struct fscache_cookie *parent;
645 int usage;
635 646
636 _enter("%p", cookie); 647 _enter("%p", cookie);
637 648
638 for (;;) { 649 do {
639 _debug("FREE COOKIE %p", cookie); 650 usage = atomic_dec_return(&cookie->usage);
651 trace_fscache_cookie(cookie, where, usage);
652
653 if (usage > 0)
654 return;
655 BUG_ON(usage < 0);
656
640 parent = cookie->parent; 657 parent = cookie->parent;
641 BUG_ON(!hlist_empty(&cookie->backing_objects)); 658 BUG_ON(!hlist_empty(&cookie->backing_objects));
642 kmem_cache_free(fscache_cookie_jar, cookie); 659 kmem_cache_free(fscache_cookie_jar, cookie);
643 660
644 if (!parent)
645 break;
646
647 cookie = parent; 661 cookie = parent;
648 BUG_ON(atomic_read(&cookie->usage) <= 0); 662 where = fscache_cookie_put_parent;
649 if (!atomic_dec_and_test(&cookie->usage)) 663 } while (cookie);
650 break;
651 }
652 664
653 _leave(""); 665 _leave("");
654} 666}
diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
index 0ff4b49a0037..c27e2db3004e 100644
--- a/fs/fscache/internal.h
+++ b/fs/fscache/internal.h
@@ -29,6 +29,7 @@
29#define pr_fmt(fmt) "FS-Cache: " fmt 29#define pr_fmt(fmt) "FS-Cache: " fmt
30 30
31#include <linux/fscache-cache.h> 31#include <linux/fscache-cache.h>
32#include <trace/events/fscache.h>
32#include <linux/sched.h> 33#include <linux/sched.h>
33 34
34#define FSCACHE_MIN_THREADS 4 35#define FSCACHE_MIN_THREADS 4
@@ -49,7 +50,8 @@ extern struct fscache_cache *fscache_select_cache_for_object(
49extern struct kmem_cache *fscache_cookie_jar; 50extern struct kmem_cache *fscache_cookie_jar;
50 51
51extern void fscache_cookie_init_once(void *); 52extern void fscache_cookie_init_once(void *);
52extern void __fscache_cookie_put(struct fscache_cookie *); 53extern void fscache_cookie_put(struct fscache_cookie *,
54 enum fscache_cookie_trace);
53 55
54/* 56/*
55 * fsdef.c 57 * fsdef.c
@@ -311,14 +313,12 @@ static inline void fscache_raise_event(struct fscache_object *object,
311 fscache_enqueue_object(object); 313 fscache_enqueue_object(object);
312} 314}
313 315
314/* 316static inline void fscache_cookie_get(struct fscache_cookie *cookie,
315 * drop a reference to a cookie 317 enum fscache_cookie_trace where)
316 */
317static inline void fscache_cookie_put(struct fscache_cookie *cookie)
318{ 318{
319 BUG_ON(atomic_read(&cookie->usage) <= 0); 319 int usage = atomic_inc_return(&cookie->usage);
320 if (atomic_dec_and_test(&cookie->usage)) 320
321 __fscache_cookie_put(cookie); 321 trace_fscache_cookie(cookie, where, usage);
322} 322}
323 323
324/* 324/*
diff --git a/fs/fscache/main.c b/fs/fscache/main.c
index 249968dcbf5c..7dce110bf17d 100644
--- a/fs/fscache/main.c
+++ b/fs/fscache/main.c
@@ -16,6 +16,7 @@
16#include <linux/completion.h> 16#include <linux/completion.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/seq_file.h> 18#include <linux/seq_file.h>
19#define CREATE_TRACE_POINTS
19#include "internal.h" 20#include "internal.h"
20 21
21MODULE_DESCRIPTION("FS Cache Manager"); 22MODULE_DESCRIPTION("FS Cache Manager");
diff --git a/fs/fscache/netfs.c b/fs/fscache/netfs.c
index a8aa00be4444..c816600d1dde 100644
--- a/fs/fscache/netfs.c
+++ b/fs/fscache/netfs.c
@@ -60,7 +60,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
60 goto already_registered; 60 goto already_registered;
61 } 61 }
62 62
63 atomic_inc(&cookie->parent->usage); 63 fscache_cookie_get(cookie->parent, fscache_cookie_get_register_netfs);
64 atomic_inc(&cookie->parent->n_children); 64 atomic_inc(&cookie->parent->n_children);
65 65
66 netfs->primary_index = cookie; 66 netfs->primary_index = cookie;
@@ -68,6 +68,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
68 ret = 0; 68 ret = 0;
69 69
70 pr_notice("Netfs '%s' registered for caching\n", netfs->name); 70 pr_notice("Netfs '%s' registered for caching\n", netfs->name);
71 trace_fscache_netfs(netfs);
71 72
72already_registered: 73already_registered:
73 up_write(&fscache_addremove_sem); 74 up_write(&fscache_addremove_sem);
diff --git a/fs/fscache/object.c b/fs/fscache/object.c
index 7a182c87f378..99afe64352a5 100644
--- a/fs/fscache/object.c
+++ b/fs/fscache/object.c
@@ -138,8 +138,10 @@ static const struct fscache_transition fscache_osm_run_oob[] = {
138 { 0, NULL } 138 { 0, NULL }
139}; 139};
140 140
141static int fscache_get_object(struct fscache_object *); 141static int fscache_get_object(struct fscache_object *,
142static void fscache_put_object(struct fscache_object *); 142 enum fscache_obj_ref_trace);
143static void fscache_put_object(struct fscache_object *,
144 enum fscache_obj_ref_trace);
143static bool fscache_enqueue_dependents(struct fscache_object *, int); 145static bool fscache_enqueue_dependents(struct fscache_object *, int);
144static void fscache_dequeue_object(struct fscache_object *); 146static void fscache_dequeue_object(struct fscache_object *);
145 147
@@ -170,6 +172,7 @@ static void fscache_object_sm_dispatcher(struct fscache_object *object)
170 const struct fscache_transition *t; 172 const struct fscache_transition *t;
171 const struct fscache_state *state, *new_state; 173 const struct fscache_state *state, *new_state;
172 unsigned long events, event_mask; 174 unsigned long events, event_mask;
175 bool oob;
173 int event = -1; 176 int event = -1;
174 177
175 ASSERT(object != NULL); 178 ASSERT(object != NULL);
@@ -188,6 +191,7 @@ restart_masked:
188 if (events & object->oob_event_mask) { 191 if (events & object->oob_event_mask) {
189 _debug("{OBJ%x} oob %lx", 192 _debug("{OBJ%x} oob %lx",
190 object->debug_id, events & object->oob_event_mask); 193 object->debug_id, events & object->oob_event_mask);
194 oob = true;
191 for (t = object->oob_table; t->events; t++) { 195 for (t = object->oob_table; t->events; t++) {
192 if (events & t->events) { 196 if (events & t->events) {
193 state = t->transit_to; 197 state = t->transit_to;
@@ -199,6 +203,7 @@ restart_masked:
199 } 203 }
200 } 204 }
201 } 205 }
206 oob = false;
202 207
203 /* Wait states are just transition tables */ 208 /* Wait states are just transition tables */
204 if (!state->work) { 209 if (!state->work) {
@@ -207,6 +212,8 @@ restart_masked:
207 if (events & t->events) { 212 if (events & t->events) {
208 new_state = t->transit_to; 213 new_state = t->transit_to;
209 event = fls(events & t->events) - 1; 214 event = fls(events & t->events) - 1;
215 trace_fscache_osm(object, state,
216 true, false, event);
210 clear_bit(event, &object->events); 217 clear_bit(event, &object->events);
211 _debug("{OBJ%x} ev %d: %s -> %s", 218 _debug("{OBJ%x} ev %d: %s -> %s",
212 object->debug_id, event, 219 object->debug_id, event,
@@ -226,6 +233,7 @@ restart_masked:
226execute_work_state: 233execute_work_state:
227 _debug("{OBJ%x} exec %s", object->debug_id, state->name); 234 _debug("{OBJ%x} exec %s", object->debug_id, state->name);
228 235
236 trace_fscache_osm(object, state, false, oob, event);
229 new_state = state->work(object, event); 237 new_state = state->work(object, event);
230 event = -1; 238 event = -1;
231 if (new_state == NO_TRANSIT) { 239 if (new_state == NO_TRANSIT) {
@@ -279,7 +287,7 @@ static void fscache_object_work_func(struct work_struct *work)
279 start = jiffies; 287 start = jiffies;
280 fscache_object_sm_dispatcher(object); 288 fscache_object_sm_dispatcher(object);
281 fscache_hist(fscache_objs_histogram, start); 289 fscache_hist(fscache_objs_histogram, start);
282 fscache_put_object(object); 290 fscache_put_object(object, fscache_obj_put_work);
283} 291}
284 292
285/** 293/**
@@ -397,7 +405,7 @@ static const struct fscache_state *fscache_initialise_object(struct fscache_obje
397 fscache_stat(&fscache_n_cop_grab_object); 405 fscache_stat(&fscache_n_cop_grab_object);
398 success = false; 406 success = false;
399 if (fscache_object_is_live(parent) && 407 if (fscache_object_is_live(parent) &&
400 object->cache->ops->grab_object(object)) { 408 object->cache->ops->grab_object(object, fscache_obj_get_add_to_deps)) {
401 list_add(&object->dep_link, &parent->dependents); 409 list_add(&object->dep_link, &parent->dependents);
402 success = true; 410 success = true;
403 } 411 }
@@ -745,7 +753,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
745 } 753 }
746 754
747 /* this just shifts the object release to the work processor */ 755 /* this just shifts the object release to the work processor */
748 fscache_put_object(object); 756 fscache_put_object(object, fscache_obj_put_drop_obj);
749 fscache_stat(&fscache_n_object_dead); 757 fscache_stat(&fscache_n_object_dead);
750 758
751 _leave(""); 759 _leave("");
@@ -755,12 +763,13 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
755/* 763/*
756 * get a ref on an object 764 * get a ref on an object
757 */ 765 */
758static int fscache_get_object(struct fscache_object *object) 766static int fscache_get_object(struct fscache_object *object,
767 enum fscache_obj_ref_trace why)
759{ 768{
760 int ret; 769 int ret;
761 770
762 fscache_stat(&fscache_n_cop_grab_object); 771 fscache_stat(&fscache_n_cop_grab_object);
763 ret = object->cache->ops->grab_object(object) ? 0 : -EAGAIN; 772 ret = object->cache->ops->grab_object(object, why) ? 0 : -EAGAIN;
764 fscache_stat_d(&fscache_n_cop_grab_object); 773 fscache_stat_d(&fscache_n_cop_grab_object);
765 return ret; 774 return ret;
766} 775}
@@ -768,10 +777,11 @@ static int fscache_get_object(struct fscache_object *object)
768/* 777/*
769 * Discard a ref on an object 778 * Discard a ref on an object
770 */ 779 */
771static void fscache_put_object(struct fscache_object *object) 780static void fscache_put_object(struct fscache_object *object,
781 enum fscache_obj_ref_trace why)
772{ 782{
773 fscache_stat(&fscache_n_cop_put_object); 783 fscache_stat(&fscache_n_cop_put_object);
774 object->cache->ops->put_object(object); 784 object->cache->ops->put_object(object, why);
775 fscache_stat_d(&fscache_n_cop_put_object); 785 fscache_stat_d(&fscache_n_cop_put_object);
776} 786}
777 787
@@ -786,7 +796,7 @@ void fscache_object_destroy(struct fscache_object *object)
786 fscache_objlist_remove(object); 796 fscache_objlist_remove(object);
787 797
788 /* We can get rid of the cookie now */ 798 /* We can get rid of the cookie now */
789 fscache_cookie_put(object->cookie); 799 fscache_cookie_put(object->cookie, fscache_cookie_put_object);
790 object->cookie = NULL; 800 object->cookie = NULL;
791} 801}
792EXPORT_SYMBOL(fscache_object_destroy); 802EXPORT_SYMBOL(fscache_object_destroy);
@@ -798,7 +808,7 @@ void fscache_enqueue_object(struct fscache_object *object)
798{ 808{
799 _enter("{OBJ%x}", object->debug_id); 809 _enter("{OBJ%x}", object->debug_id);
800 810
801 if (fscache_get_object(object) >= 0) { 811 if (fscache_get_object(object, fscache_obj_get_queue) >= 0) {
802 wait_queue_head_t *cong_wq = 812 wait_queue_head_t *cong_wq =
803 &get_cpu_var(fscache_object_cong_wait); 813 &get_cpu_var(fscache_object_cong_wait);
804 814
@@ -806,7 +816,7 @@ void fscache_enqueue_object(struct fscache_object *object)
806 if (fscache_object_congested()) 816 if (fscache_object_congested())
807 wake_up(cong_wq); 817 wake_up(cong_wq);
808 } else 818 } else
809 fscache_put_object(object); 819 fscache_put_object(object, fscache_obj_put_queue);
810 820
811 put_cpu_var(fscache_object_cong_wait); 821 put_cpu_var(fscache_object_cong_wait);
812 } 822 }
@@ -866,7 +876,7 @@ static bool fscache_enqueue_dependents(struct fscache_object *object, int event)
866 list_del_init(&dep->dep_link); 876 list_del_init(&dep->dep_link);
867 877
868 fscache_raise_event(dep, event); 878 fscache_raise_event(dep, event);
869 fscache_put_object(dep); 879 fscache_put_object(dep, fscache_obj_put_enq_dep);
870 880
871 if (!list_empty(&object->dependents) && need_resched()) { 881 if (!list_empty(&object->dependents) && need_resched()) {
872 ret = false; 882 ret = false;