Skip to content

Commit 2908f5e

Browse files
committed
fscache: Add a cookie debug ID and use that in traces
Add a cookie debug ID and use that in traces and in procfiles rather than displaying the (hashed) pointer to the cookie. This is easier to correlate and we don't lose anything when interpreting oops output since that shows unhashed addresses and registers that aren't comparable to the hashed values. Changes: ver #2: - Fix the fscache_op tracepoint to handle a NULL cookie pointer. Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/158861210988.340223.11688464116498247790.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/159465769844.1376105.14119502774019865432.stgit@warthog.procyon.org.uk/ Link: https://lore.kernel.org/r/160588459097.3465195.1273313637721852165.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/162431193544.2908479.17556704572948300790.stgit@warthog.procyon.org.uk/
1 parent 1859819 commit 2908f5e

File tree

6 files changed

+121
-108
lines changed

6 files changed

+121
-108
lines changed

fs/fscache/cookie.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,29 @@ static int fscache_attach_object(struct fscache_cookie *cookie,
2929

3030
static void fscache_print_cookie(struct fscache_cookie *cookie, char prefix)
3131
{
32-
struct hlist_node *object;
32+
struct fscache_object *object;
33+
struct hlist_node *o;
3334
const u8 *k;
3435
unsigned loop;
3536

36-
pr_err("%c-cookie c=%p [p=%p fl=%lx nc=%u na=%u]\n",
37-
prefix, cookie, cookie->parent, cookie->flags,
37+
pr_err("%c-cookie c=%08x [p=%08x fl=%lx nc=%u na=%u]\n",
38+
prefix,
39+
cookie->debug_id,
40+
cookie->parent ? cookie->parent->debug_id : 0,
41+
cookie->flags,
3842
atomic_read(&cookie->n_children),
3943
atomic_read(&cookie->n_active));
40-
pr_err("%c-cookie d=%p n=%p\n",
41-
prefix, cookie->def, cookie->netfs_data);
44+
pr_err("%c-cookie d=%p{%s} n=%p\n",
45+
prefix,
46+
cookie->def,
47+
cookie->def ? cookie->def->name : "?",
48+
cookie->netfs_data);
4249

43-
object = READ_ONCE(cookie->backing_objects.first);
44-
if (object)
45-
pr_err("%c-cookie o=%p\n",
46-
prefix, hlist_entry(object, struct fscache_object, cookie_link));
50+
o = READ_ONCE(cookie->backing_objects.first);
51+
if (o) {
52+
object = hlist_entry(o, struct fscache_object, cookie_link);
53+
pr_err("%c-cookie o=%u\n", prefix, object->debug_id);
54+
}
4755

4856
pr_err("%c-key=[%u] '", prefix, cookie->key_len);
4957
k = (cookie->key_len <= sizeof(cookie->inline_key)) ?
@@ -129,6 +137,8 @@ static long fscache_compare_cookie(const struct fscache_cookie *a,
129137
return memcmp(ka, kb, a->key_len);
130138
}
131139

140+
static atomic_t fscache_cookie_debug_id = ATOMIC_INIT(1);
141+
132142
/*
133143
* Allocate a cookie.
134144
*/
@@ -163,6 +173,7 @@ struct fscache_cookie *fscache_alloc_cookie(
163173

164174
atomic_set(&cookie->usage, 1);
165175
atomic_set(&cookie->n_children, 0);
176+
cookie->debug_id = atomic_inc_return(&fscache_cookie_debug_id);
166177

167178
/* We keep the active count elevated until relinquishment to prevent an
168179
* attempt to wake up every time the object operations queue quiesces.

fs/fscache/fsdef.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static struct fscache_cookie_def fscache_fsdef_index_def = {
4545
};
4646

4747
struct fscache_cookie fscache_fsdef_index = {
48+
.debug_id = 1,
4849
.usage = ATOMIC_INIT(1),
4950
.n_active = ATOMIC_INIT(1),
5051
.lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),

fs/fscache/object-list.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
170170
if ((unsigned long) v == 1) {
171171
seq_puts(m, "OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS"
172172
" EM EV FL S"
173-
" | NETFS_COOKIE_DEF TY FL NETFS_DATA");
173+
" | COOKIE NETFS_COOKIE_DEF TY FL NETFS_DATA");
174174
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
175175
FSCACHE_OBJLIST_CONFIG_AUX))
176176
seq_puts(m, " ");
@@ -189,7 +189,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
189189
if ((unsigned long) v == 2) {
190190
seq_puts(m, "======== ======== ==== ===== === === === == ====="
191191
" == == == ="
192-
" | ================ == == ================");
192+
" | ======== ================ == === ================");
193193
if (config & (FSCACHE_OBJLIST_CONFIG_KEY |
194194
FSCACHE_OBJLIST_CONFIG_AUX))
195195
seq_puts(m, " ================");
@@ -231,9 +231,9 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
231231
}
232232

233233
seq_printf(m,
234-
"%8x %8x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ",
234+
"%08x %08x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ",
235235
obj->debug_id,
236-
obj->parent ? obj->parent->debug_id : -1,
236+
obj->parent ? obj->parent->debug_id : UINT_MAX,
237237
obj->state->short_name,
238238
obj->n_children,
239239
obj->n_ops,
@@ -246,7 +246,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
246246
obj->flags,
247247
work_busy(&obj->work));
248248

249-
if (fscache_use_cookie(obj)) {
249+
if (obj->cookie) {
250250
uint16_t keylen = 0, auxlen = 0;
251251

252252
switch (cookie->type) {
@@ -263,7 +263,8 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
263263
break;
264264
}
265265

266-
seq_printf(m, "%-16s %s %2lx %16p",
266+
seq_printf(m, "%08x %-16s %s %3lx %16p",
267+
cookie->debug_id,
267268
cookie->def->name,
268269
type,
269270
cookie->flags,
@@ -292,7 +293,6 @@ static int fscache_objlist_show(struct seq_file *m, void *v)
292293
}
293294

294295
seq_puts(m, "\n");
295-
fscache_unuse_cookie(obj);
296296
} else {
297297
seq_puts(m, "<no_netfs>\n");
298298
}

include/linux/fscache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct fscache_cookie {
126126
atomic_t usage; /* number of users of this cookie */
127127
atomic_t n_children; /* number of children of this cookie */
128128
atomic_t n_active; /* number of active users of netfs ptrs */
129+
unsigned int debug_id;
129130
spinlock_t lock;
130131
spinlock_t stores_lock; /* lock on page store tree */
131132
struct hlist_head backing_objects; /* object(s) backing this file/index */

include/trace/events/cachefiles.h

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,20 @@ TRACE_EVENT(cachefiles_ref,
7878

7979
/* Note that obj may be NULL */
8080
TP_STRUCT__entry(
81-
__field(struct cachefiles_object *, obj )
82-
__field(struct fscache_cookie *, cookie )
81+
__field(unsigned int, obj )
82+
__field(unsigned int, cookie )
8383
__field(enum cachefiles_obj_ref_trace, why )
8484
__field(int, usage )
8585
),
8686

8787
TP_fast_assign(
88-
__entry->obj = obj;
89-
__entry->cookie = cookie;
88+
__entry->obj = obj->fscache.debug_id;
89+
__entry->cookie = cookie->debug_id;
9090
__entry->usage = usage;
9191
__entry->why = why;
9292
),
9393

94-
TP_printk("c=%p o=%p u=%d %s",
94+
TP_printk("c=%08x o=%08x u=%d %s",
9595
__entry->cookie, __entry->obj, __entry->usage,
9696
__print_symbolic(__entry->why, cachefiles_obj_ref_traces))
9797
);
@@ -104,18 +104,18 @@ TRACE_EVENT(cachefiles_lookup,
104104
TP_ARGS(obj, de, inode),
105105

106106
TP_STRUCT__entry(
107-
__field(struct cachefiles_object *, obj )
107+
__field(unsigned int, obj )
108108
__field(struct dentry *, de )
109109
__field(struct inode *, inode )
110110
),
111111

112112
TP_fast_assign(
113-
__entry->obj = obj;
113+
__entry->obj = obj->fscache.debug_id;
114114
__entry->de = de;
115115
__entry->inode = inode;
116116
),
117117

118-
TP_printk("o=%p d=%p i=%p",
118+
TP_printk("o=%08x d=%p i=%p",
119119
__entry->obj, __entry->de, __entry->inode)
120120
);
121121

@@ -126,18 +126,18 @@ TRACE_EVENT(cachefiles_mkdir,
126126
TP_ARGS(obj, de, ret),
127127

128128
TP_STRUCT__entry(
129-
__field(struct cachefiles_object *, obj )
129+
__field(unsigned int, obj )
130130
__field(struct dentry *, de )
131131
__field(int, ret )
132132
),
133133

134134
TP_fast_assign(
135-
__entry->obj = obj;
135+
__entry->obj = obj->fscache.debug_id;
136136
__entry->de = de;
137137
__entry->ret = ret;
138138
),
139139

140-
TP_printk("o=%p d=%p r=%u",
140+
TP_printk("o=%08x d=%p r=%u",
141141
__entry->obj, __entry->de, __entry->ret)
142142
);
143143

@@ -148,18 +148,18 @@ TRACE_EVENT(cachefiles_create,
148148
TP_ARGS(obj, de, ret),
149149

150150
TP_STRUCT__entry(
151-
__field(struct cachefiles_object *, obj )
151+
__field(unsigned int, obj )
152152
__field(struct dentry *, de )
153153
__field(int, ret )
154154
),
155155

156156
TP_fast_assign(
157-
__entry->obj = obj;
157+
__entry->obj = obj->fscache.debug_id;
158158
__entry->de = de;
159159
__entry->ret = ret;
160160
),
161161

162-
TP_printk("o=%p d=%p r=%u",
162+
TP_printk("o=%08x d=%p r=%u",
163163
__entry->obj, __entry->de, __entry->ret)
164164
);
165165

@@ -172,18 +172,18 @@ TRACE_EVENT(cachefiles_unlink,
172172

173173
/* Note that obj may be NULL */
174174
TP_STRUCT__entry(
175-
__field(struct cachefiles_object *, obj )
175+
__field(unsigned int, obj )
176176
__field(struct dentry *, de )
177177
__field(enum fscache_why_object_killed, why )
178178
),
179179

180180
TP_fast_assign(
181-
__entry->obj = obj;
181+
__entry->obj = obj->fscache.debug_id;
182182
__entry->de = de;
183183
__entry->why = why;
184184
),
185185

186-
TP_printk("o=%p d=%p w=%s",
186+
TP_printk("o=%08x d=%p w=%s",
187187
__entry->obj, __entry->de,
188188
__print_symbolic(__entry->why, cachefiles_obj_kill_traces))
189189
);
@@ -198,20 +198,20 @@ TRACE_EVENT(cachefiles_rename,
198198

199199
/* Note that obj may be NULL */
200200
TP_STRUCT__entry(
201-
__field(struct cachefiles_object *, obj )
201+
__field(unsigned int, obj )
202202
__field(struct dentry *, de )
203203
__field(struct dentry *, to )
204204
__field(enum fscache_why_object_killed, why )
205205
),
206206

207207
TP_fast_assign(
208-
__entry->obj = obj;
208+
__entry->obj = obj->fscache.debug_id;
209209
__entry->de = de;
210210
__entry->to = to;
211211
__entry->why = why;
212212
),
213213

214-
TP_printk("o=%p d=%p t=%p w=%s",
214+
TP_printk("o=%08x d=%p t=%p w=%s",
215215
__entry->obj, __entry->de, __entry->to,
216216
__print_symbolic(__entry->why, cachefiles_obj_kill_traces))
217217
);
@@ -224,16 +224,16 @@ TRACE_EVENT(cachefiles_mark_active,
224224

225225
/* Note that obj may be NULL */
226226
TP_STRUCT__entry(
227-
__field(struct cachefiles_object *, obj )
227+
__field(unsigned int, obj )
228228
__field(struct dentry *, de )
229229
),
230230

231231
TP_fast_assign(
232-
__entry->obj = obj;
232+
__entry->obj = obj->fscache.debug_id;
233233
__entry->de = de;
234234
),
235235

236-
TP_printk("o=%p d=%p",
236+
TP_printk("o=%08x d=%p",
237237
__entry->obj, __entry->de)
238238
);
239239

@@ -246,22 +246,22 @@ TRACE_EVENT(cachefiles_wait_active,
246246

247247
/* Note that obj may be NULL */
248248
TP_STRUCT__entry(
249-
__field(struct cachefiles_object *, obj )
249+
__field(unsigned int, obj )
250+
__field(unsigned int, xobj )
250251
__field(struct dentry *, de )
251-
__field(struct cachefiles_object *, xobj )
252252
__field(u16, flags )
253253
__field(u16, fsc_flags )
254254
),
255255

256256
TP_fast_assign(
257-
__entry->obj = obj;
257+
__entry->obj = obj->fscache.debug_id;
258258
__entry->de = de;
259-
__entry->xobj = xobj;
259+
__entry->xobj = xobj->fscache.debug_id;
260260
__entry->flags = xobj->flags;
261261
__entry->fsc_flags = xobj->fscache.flags;
262262
),
263263

264-
TP_printk("o=%p d=%p wo=%p wf=%x wff=%x",
264+
TP_printk("o=%08x d=%p wo=%08x wf=%x wff=%x",
265265
__entry->obj, __entry->de, __entry->xobj,
266266
__entry->flags, __entry->fsc_flags)
267267
);
@@ -275,18 +275,18 @@ TRACE_EVENT(cachefiles_mark_inactive,
275275

276276
/* Note that obj may be NULL */
277277
TP_STRUCT__entry(
278-
__field(struct cachefiles_object *, obj )
278+
__field(unsigned int, obj )
279279
__field(struct dentry *, de )
280280
__field(struct inode *, inode )
281281
),
282282

283283
TP_fast_assign(
284-
__entry->obj = obj;
284+
__entry->obj = obj->fscache.debug_id;
285285
__entry->de = de;
286286
__entry->inode = inode;
287287
),
288288

289-
TP_printk("o=%p d=%p i=%p",
289+
TP_printk("o=%08x d=%p i=%p",
290290
__entry->obj, __entry->de, __entry->inode)
291291
);
292292

@@ -299,18 +299,18 @@ TRACE_EVENT(cachefiles_mark_buried,
299299

300300
/* Note that obj may be NULL */
301301
TP_STRUCT__entry(
302-
__field(struct cachefiles_object *, obj )
302+
__field(unsigned int, obj )
303303
__field(struct dentry *, de )
304304
__field(enum fscache_why_object_killed, why )
305305
),
306306

307307
TP_fast_assign(
308-
__entry->obj = obj;
308+
__entry->obj = obj->fscache.debug_id;
309309
__entry->de = de;
310310
__entry->why = why;
311311
),
312312

313-
TP_printk("o=%p d=%p w=%s",
313+
TP_printk("o=%08x d=%p w=%s",
314314
__entry->obj, __entry->de,
315315
__print_symbolic(__entry->why, cachefiles_obj_kill_traces))
316316
);

0 commit comments

Comments
 (0)