Skip to content

Commit 20ec197

Browse files
committed
fscache: Use refcount_t for the cookie refcount instead of atomic_t
Use refcount_t for the fscache_cookie refcount instead of atomic_t and rename the 'usage' member to 'ref' in such cases. The tracepoints that reference it change from showing "u=%d" to "r=%d". Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/162431204358.2908479.8006938388213098079.stgit@warthog.procyon.org.uk/
1 parent 33cba85 commit 20ec197

File tree

6 files changed

+55
-43
lines changed

6 files changed

+55
-43
lines changed

fs/fscache/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ int fscache_add_cache(struct fscache_cache *cache,
269269
hlist_add_head(&ifsdef->cookie_link,
270270
&fscache_fsdef_index.backing_objects);
271271

272-
atomic_inc(&fscache_fsdef_index.usage);
272+
refcount_inc(&fscache_fsdef_index.ref);
273273

274274
/* done */
275275
spin_unlock(&fscache_fsdef_index.lock);

fs/fscache/cookie.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct fscache_cookie *fscache_alloc_cookie(
164164
goto nomem;
165165
}
166166

167-
atomic_set(&cookie->usage, 1);
167+
refcount_set(&cookie->ref, 1);
168168
atomic_set(&cookie->n_children, 0);
169169
cookie->debug_id = atomic_inc_return(&fscache_cookie_debug_id);
170170

@@ -225,7 +225,7 @@ struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate)
225225

226226
collision:
227227
if (test_and_set_bit(FSCACHE_COOKIE_ACQUIRED, &cursor->flags)) {
228-
trace_fscache_cookie(cursor->debug_id, atomic_read(&cursor->usage),
228+
trace_fscache_cookie(cursor->debug_id, refcount_read(&cursor->ref),
229229
fscache_cookie_collision);
230230
pr_err("Duplicate cookie detected\n");
231231
fscache_print_cookie(cursor, 'O');
@@ -826,13 +826,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie,
826826
BUG_ON(!radix_tree_empty(&cookie->stores));
827827

828828
if (cookie->parent) {
829-
ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0);
829+
ASSERTCMP(refcount_read(&cookie->parent->ref), >, 0);
830830
ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0);
831831
atomic_dec(&cookie->parent->n_children);
832832
}
833833

834834
/* Dispose of the netfs's link to the cookie */
835-
ASSERTCMP(atomic_read(&cookie->usage), >, 0);
836835
fscache_cookie_put(cookie, fscache_cookie_put_relinquish);
837836

838837
_leave("");
@@ -862,18 +861,17 @@ void fscache_cookie_put(struct fscache_cookie *cookie,
862861
enum fscache_cookie_trace where)
863862
{
864863
struct fscache_cookie *parent;
865-
int usage;
864+
int ref;
866865

867866
_enter("%x", cookie->debug_id);
868867

869868
do {
870869
unsigned int cookie_debug_id = cookie->debug_id;
871-
usage = atomic_dec_return(&cookie->usage);
872-
trace_fscache_cookie(cookie_debug_id, usage, where);
870+
bool zero = __refcount_dec_and_test(&cookie->ref, &ref);
873871

874-
if (usage > 0)
872+
trace_fscache_cookie(cookie_debug_id, ref - 1, where);
873+
if (!zero)
875874
return;
876-
BUG_ON(usage < 0);
877875

878876
parent = cookie->parent;
879877
fscache_unhash_cookie(cookie);
@@ -886,6 +884,19 @@ void fscache_cookie_put(struct fscache_cookie *cookie,
886884
_leave("");
887885
}
888886

887+
/*
888+
* Get a reference to a cookie.
889+
*/
890+
struct fscache_cookie *fscache_cookie_get(struct fscache_cookie *cookie,
891+
enum fscache_cookie_trace where)
892+
{
893+
int ref;
894+
895+
__refcount_inc(&cookie->ref, &ref);
896+
trace_fscache_cookie(cookie->debug_id, ref + 1, where);
897+
return cookie;
898+
}
899+
889900
/*
890901
* check the consistency between the netfs inode and the backing cache
891902
*
@@ -1003,7 +1014,7 @@ static int fscache_cookies_seq_show(struct seq_file *m, void *v)
10031014
"%08x %08x %5u %5u %3u %s %03lx %-16s %px",
10041015
cookie->debug_id,
10051016
cookie->parent ? cookie->parent->debug_id : 0,
1006-
atomic_read(&cookie->usage),
1017+
refcount_read(&cookie->ref),
10071018
atomic_read(&cookie->n_children),
10081019
atomic_read(&cookie->n_active),
10091020
type,

fs/fscache/fsdef.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static struct fscache_cookie_def fscache_fsdef_index_def = {
4646

4747
struct fscache_cookie fscache_fsdef_index = {
4848
.debug_id = 1,
49-
.usage = ATOMIC_INIT(1),
49+
.ref = REFCOUNT_INIT(1),
5050
.n_active = ATOMIC_INIT(1),
5151
.lock = __SPIN_LOCK_UNLOCKED(fscache_fsdef_index.lock),
5252
.backing_objects = HLIST_HEAD_INIT,

fs/fscache/internal.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ extern struct fscache_cookie *fscache_alloc_cookie(struct fscache_cookie *,
5454
const void *, size_t,
5555
void *, loff_t);
5656
extern struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *);
57+
extern struct fscache_cookie *fscache_cookie_get(struct fscache_cookie *,
58+
enum fscache_cookie_trace);
5759
extern void fscache_cookie_put(struct fscache_cookie *,
5860
enum fscache_cookie_trace);
5961

62+
static inline void fscache_cookie_see(struct fscache_cookie *cookie,
63+
enum fscache_cookie_trace where)
64+
{
65+
trace_fscache_cookie(cookie->debug_id, refcount_read(&cookie->ref),
66+
where);
67+
}
68+
6069
/*
6170
* fsdef.c
6271
*/
@@ -286,14 +295,6 @@ static inline void fscache_raise_event(struct fscache_object *object,
286295
fscache_enqueue_object(object);
287296
}
288297

289-
static inline void fscache_cookie_get(struct fscache_cookie *cookie,
290-
enum fscache_cookie_trace where)
291-
{
292-
int usage = atomic_inc_return(&cookie->usage);
293-
294-
trace_fscache_cookie(cookie->debug_id, usage, where);
295-
}
296-
297298
/*
298299
* get an extra reference to a netfs retrieval context
299300
*/

include/linux/fscache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct fscache_netfs {
123123
* - indices are created on disk just-in-time
124124
*/
125125
struct fscache_cookie {
126-
atomic_t usage; /* number of users of this cookie */
126+
refcount_t ref; /* 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 */
129129
unsigned int debug_id;

include/trace/events/fscache.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,26 @@ fscache_cookie_traces;
161161

162162
TRACE_EVENT(fscache_cookie,
163163
TP_PROTO(unsigned int cookie_debug_id,
164-
int usage,
164+
int ref,
165165
enum fscache_cookie_trace where),
166166

167-
TP_ARGS(cookie_debug_id, usage, where),
167+
TP_ARGS(cookie_debug_id, ref, where),
168168

169169
TP_STRUCT__entry(
170170
__field(unsigned int, cookie )
171171
__field(enum fscache_cookie_trace, where )
172-
__field(int, usage )
172+
__field(int, ref )
173173
),
174174

175175
TP_fast_assign(
176176
__entry->cookie = cookie_debug_id;
177177
__entry->where = where;
178-
__entry->usage = usage;
178+
__entry->ref = ref;
179179
),
180180

181-
TP_printk("%s c=%08x u=%d",
181+
TP_printk("%s c=%08x r=%d",
182182
__print_symbolic(__entry->where, fscache_cookie_traces),
183-
__entry->cookie, __entry->usage)
183+
__entry->cookie, __entry->ref)
184184
);
185185

186186
TRACE_EVENT(fscache_netfs,
@@ -212,23 +212,23 @@ TRACE_EVENT(fscache_acquire,
212212
__field(unsigned int, cookie )
213213
__field(unsigned int, parent )
214214
__array(char, name, 8 )
215-
__field(int, p_usage )
215+
__field(int, p_ref )
216216
__field(int, p_n_children )
217217
__field(u8, p_flags )
218218
),
219219

220220
TP_fast_assign(
221221
__entry->cookie = cookie->debug_id;
222222
__entry->parent = cookie->parent->debug_id;
223-
__entry->p_usage = atomic_read(&cookie->parent->usage);
223+
__entry->p_ref = refcount_read(&cookie->parent->ref);
224224
__entry->p_n_children = atomic_read(&cookie->parent->n_children);
225225
__entry->p_flags = cookie->parent->flags;
226226
memcpy(__entry->name, cookie->def->name, 8);
227227
__entry->name[7] = 0;
228228
),
229229

230-
TP_printk("c=%08x p=%08x pu=%d pc=%d pf=%02x n=%s",
231-
__entry->cookie, __entry->parent, __entry->p_usage,
230+
TP_printk("c=%08x p=%08x pr=%d pc=%d pf=%02x n=%s",
231+
__entry->cookie, __entry->parent, __entry->p_ref,
232232
__entry->p_n_children, __entry->p_flags, __entry->name)
233233
);
234234

@@ -240,7 +240,7 @@ TRACE_EVENT(fscache_relinquish,
240240
TP_STRUCT__entry(
241241
__field(unsigned int, cookie )
242242
__field(unsigned int, parent )
243-
__field(int, usage )
243+
__field(int, ref )
244244
__field(int, n_children )
245245
__field(int, n_active )
246246
__field(u8, flags )
@@ -250,15 +250,15 @@ TRACE_EVENT(fscache_relinquish,
250250
TP_fast_assign(
251251
__entry->cookie = cookie->debug_id;
252252
__entry->parent = cookie->parent->debug_id;
253-
__entry->usage = atomic_read(&cookie->usage);
253+
__entry->ref = refcount_read(&cookie->ref);
254254
__entry->n_children = atomic_read(&cookie->n_children);
255255
__entry->n_active = atomic_read(&cookie->n_active);
256256
__entry->flags = cookie->flags;
257257
__entry->retire = retire;
258258
),
259259

260-
TP_printk("c=%08x u=%d p=%08x Nc=%d Na=%d f=%02x r=%u",
261-
__entry->cookie, __entry->usage,
260+
TP_printk("c=%08x r=%d p=%08x Nc=%d Na=%d f=%02x r=%u",
261+
__entry->cookie, __entry->ref,
262262
__entry->parent, __entry->n_children, __entry->n_active,
263263
__entry->flags, __entry->retire)
264264
);
@@ -270,22 +270,22 @@ TRACE_EVENT(fscache_enable,
270270

271271
TP_STRUCT__entry(
272272
__field(unsigned int, cookie )
273-
__field(int, usage )
273+
__field(int, ref )
274274
__field(int, n_children )
275275
__field(int, n_active )
276276
__field(u8, flags )
277277
),
278278

279279
TP_fast_assign(
280280
__entry->cookie = cookie->debug_id;
281-
__entry->usage = atomic_read(&cookie->usage);
281+
__entry->ref = refcount_read(&cookie->ref);
282282
__entry->n_children = atomic_read(&cookie->n_children);
283283
__entry->n_active = atomic_read(&cookie->n_active);
284284
__entry->flags = cookie->flags;
285285
),
286286

287-
TP_printk("c=%08x u=%d Nc=%d Na=%d f=%02x",
288-
__entry->cookie, __entry->usage,
287+
TP_printk("c=%08x r=%d Nc=%d Na=%d f=%02x",
288+
__entry->cookie, __entry->ref,
289289
__entry->n_children, __entry->n_active, __entry->flags)
290290
);
291291

@@ -296,22 +296,22 @@ TRACE_EVENT(fscache_disable,
296296

297297
TP_STRUCT__entry(
298298
__field(unsigned int, cookie )
299-
__field(int, usage )
299+
__field(int, ref )
300300
__field(int, n_children )
301301
__field(int, n_active )
302302
__field(u8, flags )
303303
),
304304

305305
TP_fast_assign(
306306
__entry->cookie = cookie->debug_id;
307-
__entry->usage = atomic_read(&cookie->usage);
307+
__entry->ref = refcount_read(&cookie->ref);
308308
__entry->n_children = atomic_read(&cookie->n_children);
309309
__entry->n_active = atomic_read(&cookie->n_active);
310310
__entry->flags = cookie->flags;
311311
),
312312

313-
TP_printk("c=%08x u=%d Nc=%d Na=%d f=%02x",
314-
__entry->cookie, __entry->usage,
313+
TP_printk("c=%08x r=%d Nc=%d Na=%d f=%02x",
314+
__entry->cookie, __entry->ref,
315315
__entry->n_children, __entry->n_active, __entry->flags)
316316
);
317317

0 commit comments

Comments
 (0)