Skip to content

Commit 182d919

Browse files
committed
FS-Cache: Count culled objects and objects rejected due to lack of space
Count the number of objects that get culled by the cache backend and the number of objects that the cache backend declines to instantiate due to lack of space in the cache. These numbers are made available through /proc/fs/fscache/stats Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Steve Dickson <steved@redhat.com> Acked-by: Jeff Layton <jeff.layton@primarydata.com>
1 parent b2b89eb commit 182d919

8 files changed

Lines changed: 122 additions & 13 deletions

File tree

‎Documentation/filesystems/caching/backend-api.txt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,29 @@ FS-Cache provides some utilities that a cache backend may make use of:
676676
as possible.
677677

678678

679+
(*) Indicate that a stale object was found and discarded:
680+
681+
void fscache_object_retrying_stale(struct fscache_object *object);
682+
683+
This is called to indicate that the lookup procedure found an object in
684+
the cache that the netfs decided was stale. The object has been
685+
discarded from the cache and the lookup will be performed again.
686+
687+
688+
(*) Indicate that the caching backend killed an object:
689+
690+
void fscache_object_mark_killed(struct fscache_object *object,
691+
enum fscache_why_object_killed why);
692+
693+
This is called to indicate that the cache backend preemptively killed an
694+
object. The why parameter should be set to indicate the reason:
695+
696+
FSCACHE_OBJECT_IS_STALE - the object was stale and needs discarding.
697+
FSCACHE_OBJECT_NO_SPACE - there was insufficient cache space
698+
FSCACHE_OBJECT_WAS_RETIRED - the object was retired when relinquished.
699+
FSCACHE_OBJECT_WAS_CULLED - the object was culled to make space.
700+
701+
679702
(*) Get and release references on a retrieval record:
680703

681704
void fscache_get_retrieval(struct fscache_retrieval *op);

‎Documentation/filesystems/caching/fscache.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ proc files.
303303
wrp=N Number of in-progress write_page() cache ops
304304
ucp=N Number of in-progress uncache_page() cache ops
305305
dsp=N Number of in-progress dissociate_pages() cache ops
306+
CacheEv nsp=N Number of object lookups/creations rejected due to lack of space
307+
stl=N Number of stale objects deleted
308+
rtr=N Number of objects retired when relinquished
309+
cul=N Number of objects culled
306310

307311

308312
(*) /proc/fs/fscache/histogram

‎fs/cachefiles/internal.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct cachefiles_object {
4343
loff_t i_size; /* object size */
4444
unsigned long flags;
4545
#define CACHEFILES_OBJECT_ACTIVE 0 /* T if marked active */
46-
#define CACHEFILES_OBJECT_BURIED 1 /* T if preemptively buried */
4746
atomic_t usage; /* object usage count */
4847
uint8_t type; /* object type */
4948
uint8_t new; /* T if object new */

‎fs/cachefiles/namei.c‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static noinline void cachefiles_printk_object(struct cachefiles_object *object,
9797
* call vfs_unlink(), vfs_rmdir() or vfs_rename()
9898
*/
9999
static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
100-
struct dentry *dentry)
100+
struct dentry *dentry,
101+
enum fscache_why_object_killed why)
101102
{
102103
struct cachefiles_object *object;
103104
struct rb_node *p;
@@ -132,8 +133,9 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
132133
pr_err("\n");
133134
pr_err("Error: Can't preemptively bury live object\n");
134135
cachefiles_printk_object(object, NULL);
135-
} else if (test_and_set_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) {
136-
pr_err("Error: Object already preemptively buried\n");
136+
} else {
137+
if (why != FSCACHE_OBJECT_IS_STALE)
138+
fscache_object_mark_killed(&object->fscache, why);
137139
}
138140

139141
write_unlock(&cache->active_lock);
@@ -265,7 +267,8 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
265267
static int cachefiles_bury_object(struct cachefiles_cache *cache,
266268
struct dentry *dir,
267269
struct dentry *rep,
268-
bool preemptive)
270+
bool preemptive,
271+
enum fscache_why_object_killed why)
269272
{
270273
struct dentry *grave, *trap;
271274
struct path path, path_to_graveyard;
@@ -289,7 +292,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
289292
ret = vfs_unlink(dir->d_inode, rep, NULL);
290293

291294
if (preemptive)
292-
cachefiles_mark_object_buried(cache, rep);
295+
cachefiles_mark_object_buried(cache, rep, why);
293296
}
294297

295298
mutex_unlock(&dir->d_inode->i_mutex);
@@ -394,7 +397,7 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
394397
"Rename failed with error %d", ret);
395398

396399
if (preemptive)
397-
cachefiles_mark_object_buried(cache, rep);
400+
cachefiles_mark_object_buried(cache, rep, why);
398401
}
399402

400403
unlock_rename(cache->graveyard, dir);
@@ -422,7 +425,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
422425

423426
mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
424427

425-
if (test_bit(CACHEFILES_OBJECT_BURIED, &object->flags)) {
428+
if (test_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->fscache.flags)) {
426429
/* object allocation for the same key preemptively deleted this
427430
* object's file so that it could create its own file */
428431
_debug("object preemptively buried");
@@ -433,7 +436,8 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
433436
* may have been renamed */
434437
if (dir == object->dentry->d_parent) {
435438
ret = cachefiles_bury_object(cache, dir,
436-
object->dentry, false);
439+
object->dentry, false,
440+
FSCACHE_OBJECT_WAS_RETIRED);
437441
} else {
438442
/* it got moved, presumably by cachefilesd culling it,
439443
* so it's no longer in the key path and we can ignore
@@ -522,7 +526,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
522526
if (!next->d_inode) {
523527
ret = cachefiles_has_space(cache, 1, 0);
524528
if (ret < 0)
525-
goto create_error;
529+
goto no_space_error;
526530

527531
path.dentry = dir;
528532
ret = security_path_mkdir(&path, next, 0);
@@ -551,7 +555,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
551555
if (!next->d_inode) {
552556
ret = cachefiles_has_space(cache, 1, 0);
553557
if (ret < 0)
554-
goto create_error;
558+
goto no_space_error;
555559

556560
path.dentry = dir;
557561
ret = security_path_mknod(&path, next, S_IFREG, 0);
@@ -602,14 +606,16 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
602606
* mutex) */
603607
object->dentry = NULL;
604608

605-
ret = cachefiles_bury_object(cache, dir, next, true);
609+
ret = cachefiles_bury_object(cache, dir, next, true,
610+
FSCACHE_OBJECT_IS_STALE);
606611
dput(next);
607612
next = NULL;
608613

609614
if (ret < 0)
610615
goto delete_error;
611616

612617
_debug("redo lookup");
618+
fscache_object_retrying_stale(&object->fscache);
613619
goto lookup_again;
614620
}
615621
}
@@ -662,6 +668,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
662668
_leave(" = 0 [%lu]", object->dentry->d_inode->i_ino);
663669
return 0;
664670

671+
no_space_error:
672+
fscache_object_mark_killed(&object->fscache, FSCACHE_OBJECT_NO_SPACE);
665673
create_error:
666674
_debug("create error %d", ret);
667675
if (ret == -EIO)
@@ -927,7 +935,8 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
927935
/* actually remove the victim (drops the dir mutex) */
928936
_debug("bury");
929937

930-
ret = cachefiles_bury_object(cache, dir, victim, false);
938+
ret = cachefiles_bury_object(cache, dir, victim, false,
939+
FSCACHE_OBJECT_WAS_CULLED);
931940
if (ret < 0)
932941
goto error;
933942

‎fs/fscache/internal.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ extern atomic_t fscache_n_cop_write_page;
271271
extern atomic_t fscache_n_cop_uncache_page;
272272
extern atomic_t fscache_n_cop_dissociate_pages;
273273

274+
extern atomic_t fscache_n_cache_no_space_reject;
275+
extern atomic_t fscache_n_cache_stale_objects;
276+
extern atomic_t fscache_n_cache_retired_objects;
277+
extern atomic_t fscache_n_cache_culled_objects;
278+
274279
static inline void fscache_stat(atomic_t *stat)
275280
{
276281
atomic_inc(stat);

‎fs/fscache/object.c‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,3 +1016,50 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
10161016
_leave("");
10171017
return transit_to(WAIT_FOR_CMD);
10181018
}
1019+
1020+
/**
1021+
* fscache_object_retrying_stale - Note retrying stale object
1022+
* @object: The object that will be retried
1023+
*
1024+
* Note that an object lookup found an on-disk object that was adjudged to be
1025+
* stale and has been deleted. The lookup will be retried.
1026+
*/
1027+
void fscache_object_retrying_stale(struct fscache_object *object)
1028+
{
1029+
fscache_stat(&fscache_n_cache_no_space_reject);
1030+
}
1031+
EXPORT_SYMBOL(fscache_object_retrying_stale);
1032+
1033+
/**
1034+
* fscache_object_mark_killed - Note that an object was killed
1035+
* @object: The object that was culled
1036+
* @why: The reason the object was killed.
1037+
*
1038+
* Note that an object was killed. Returns true if the object was
1039+
* already marked killed, false if it wasn't.
1040+
*/
1041+
void fscache_object_mark_killed(struct fscache_object *object,
1042+
enum fscache_why_object_killed why)
1043+
{
1044+
if (test_and_set_bit(FSCACHE_OBJECT_KILLED_BY_CACHE, &object->flags)) {
1045+
pr_err("Error: Object already killed by cache [%s]\n",
1046+
object->cache->identifier);
1047+
return;
1048+
}
1049+
1050+
switch (why) {
1051+
case FSCACHE_OBJECT_NO_SPACE:
1052+
fscache_stat(&fscache_n_cache_no_space_reject);
1053+
break;
1054+
case FSCACHE_OBJECT_IS_STALE:
1055+
fscache_stat(&fscache_n_cache_stale_objects);
1056+
break;
1057+
case FSCACHE_OBJECT_WAS_RETIRED:
1058+
fscache_stat(&fscache_n_cache_retired_objects);
1059+
break;
1060+
case FSCACHE_OBJECT_WAS_CULLED:
1061+
fscache_stat(&fscache_n_cache_culled_objects);
1062+
break;
1063+
}
1064+
}
1065+
EXPORT_SYMBOL(fscache_object_mark_killed);

‎fs/fscache/stats.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ atomic_t fscache_n_cop_write_page;
130130
atomic_t fscache_n_cop_uncache_page;
131131
atomic_t fscache_n_cop_dissociate_pages;
132132

133+
atomic_t fscache_n_cache_no_space_reject;
134+
atomic_t fscache_n_cache_stale_objects;
135+
atomic_t fscache_n_cache_retired_objects;
136+
atomic_t fscache_n_cache_culled_objects;
137+
133138
/*
134139
* display the general statistics
135140
*/
@@ -271,6 +276,11 @@ static int fscache_stats_show(struct seq_file *m, void *v)
271276
atomic_read(&fscache_n_cop_write_page),
272277
atomic_read(&fscache_n_cop_uncache_page),
273278
atomic_read(&fscache_n_cop_dissociate_pages));
279+
seq_printf(m, "CacheEv: nsp=%d stl=%d rtr=%d cul=%d\n",
280+
atomic_read(&fscache_n_cache_no_space_reject),
281+
atomic_read(&fscache_n_cache_stale_objects),
282+
atomic_read(&fscache_n_cache_retired_objects),
283+
atomic_read(&fscache_n_cache_culled_objects));
274284
return 0;
275285
}
276286

‎include/linux/fscache-cache.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ struct fscache_object {
371371
#define FSCACHE_OBJECT_IS_LOOKED_UP 4 /* T if object has been looked up */
372372
#define FSCACHE_OBJECT_IS_AVAILABLE 5 /* T if object has become active */
373373
#define FSCACHE_OBJECT_RETIRED 6 /* T if object was retired on relinquishment */
374+
#define FSCACHE_OBJECT_KILLED_BY_CACHE 7 /* T if object was killed by the cache */
374375

375376
struct list_head cache_link; /* link in cache->object_list */
376377
struct hlist_node cookie_link; /* link in cookie->backing_objects */
@@ -551,4 +552,15 @@ extern enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
551552
const void *data,
552553
uint16_t datalen);
553554

555+
extern void fscache_object_retrying_stale(struct fscache_object *object);
556+
557+
enum fscache_why_object_killed {
558+
FSCACHE_OBJECT_IS_STALE,
559+
FSCACHE_OBJECT_NO_SPACE,
560+
FSCACHE_OBJECT_WAS_RETIRED,
561+
FSCACHE_OBJECT_WAS_CULLED,
562+
};
563+
extern void fscache_object_mark_killed(struct fscache_object *object,
564+
enum fscache_why_object_killed why);
565+
554566
#endif /* _LINUX_FSCACHE_CACHE_H */

0 commit comments

Comments
 (0)