Skip to content

Commit e6435f1

Browse files
committed
fscache: Add a tracepoint for cookie use/unuse
Add a tracepoint to track fscache_use/unuse_cookie(). Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/164021588628.640689.12942919367404043608.stgit@warthog.procyon.org.uk/ # v4
1 parent e048434 commit e6435f1

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

fs/fscache/cookie.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify)
556556
{
557557
enum fscache_cookie_state state;
558558
bool queue = false;
559+
int n_active;
559560

560561
_enter("c=%08x", cookie->debug_id);
561562

@@ -565,7 +566,11 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify)
565566

566567
spin_lock(&cookie->lock);
567568

568-
atomic_inc(&cookie->n_active);
569+
n_active = atomic_inc_return(&cookie->n_active);
570+
trace_fscache_active(cookie->debug_id, refcount_read(&cookie->ref),
571+
n_active, atomic_read(&cookie->n_accesses),
572+
will_modify ?
573+
fscache_active_use_modify : fscache_active_use);
569574

570575
again:
571576
state = fscache_cookie_state(cookie);
@@ -638,13 +643,29 @@ static void fscache_unuse_cookie_locked(struct fscache_cookie *cookie)
638643
void __fscache_unuse_cookie(struct fscache_cookie *cookie,
639644
const void *aux_data, const loff_t *object_size)
640645
{
646+
unsigned int debug_id = cookie->debug_id;
647+
unsigned int r = refcount_read(&cookie->ref);
648+
unsigned int a = atomic_read(&cookie->n_accesses);
649+
unsigned int c;
650+
641651
if (aux_data || object_size)
642652
__fscache_update_cookie(cookie, aux_data, object_size);
643653

644-
if (atomic_dec_and_lock(&cookie->n_active, &cookie->lock)) {
645-
fscache_unuse_cookie_locked(cookie);
646-
spin_unlock(&cookie->lock);
654+
/* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
655+
c = atomic_fetch_add_unless(&cookie->n_active, -1, 1);
656+
if (c != 1) {
657+
trace_fscache_active(debug_id, r, c - 1, a, fscache_active_unuse);
658+
return;
647659
}
660+
661+
spin_lock(&cookie->lock);
662+
r = refcount_read(&cookie->ref);
663+
a = atomic_read(&cookie->n_accesses);
664+
c = atomic_dec_return(&cookie->n_active);
665+
trace_fscache_active(debug_id, r, c, a, fscache_active_unuse);
666+
if (c == 0)
667+
fscache_unuse_cookie_locked(cookie);
668+
spin_unlock(&cookie->lock);
648669
}
649670
EXPORT_SYMBOL(__fscache_unuse_cookie);
650671

include/trace/events/fscache.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ enum fscache_cookie_trace {
7171
fscache_cookie_see_work,
7272
};
7373

74+
enum fscache_active_trace {
75+
fscache_active_use,
76+
fscache_active_use_modify,
77+
fscache_active_unuse,
78+
};
79+
7480
enum fscache_access_trace {
7581
fscache_access_acquire_volume,
7682
fscache_access_acquire_volume_end,
@@ -146,6 +152,11 @@ enum fscache_access_trace {
146152
EM(fscache_cookie_see_withdraw, "- x-wth") \
147153
E_(fscache_cookie_see_work, "- work ")
148154

155+
#define fscache_active_traces \
156+
EM(fscache_active_use, "USE ") \
157+
EM(fscache_active_use_modify, "USE-m ") \
158+
E_(fscache_active_unuse, "UNUSE ")
159+
149160
#define fscache_access_traces \
150161
EM(fscache_access_acquire_volume, "BEGIN acq_vol") \
151162
EM(fscache_access_acquire_volume_end, "END acq_vol") \
@@ -264,6 +275,39 @@ TRACE_EVENT(fscache_cookie,
264275
__entry->ref)
265276
);
266277

278+
TRACE_EVENT(fscache_active,
279+
TP_PROTO(unsigned int cookie_debug_id,
280+
int ref,
281+
int n_active,
282+
int n_accesses,
283+
enum fscache_active_trace why),
284+
285+
TP_ARGS(cookie_debug_id, ref, n_active, n_accesses, why),
286+
287+
TP_STRUCT__entry(
288+
__field(unsigned int, cookie )
289+
__field(int, ref )
290+
__field(int, n_active )
291+
__field(int, n_accesses )
292+
__field(enum fscache_active_trace, why )
293+
),
294+
295+
TP_fast_assign(
296+
__entry->cookie = cookie_debug_id;
297+
__entry->ref = ref;
298+
__entry->n_active = n_active;
299+
__entry->n_accesses = n_accesses;
300+
__entry->why = why;
301+
),
302+
303+
TP_printk("c=%08x %s r=%d a=%d c=%d",
304+
__entry->cookie,
305+
__print_symbolic(__entry->why, fscache_active_traces),
306+
__entry->ref,
307+
__entry->n_accesses,
308+
__entry->n_active)
309+
);
310+
267311
TRACE_EVENT(fscache_access_cache,
268312
TP_PROTO(unsigned int cache_debug_id,
269313
int ref,

0 commit comments

Comments
 (0)