Skip to content

Commit 89594c7

Browse files
committed
Merge tag 'fscache-next-20210829' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs
Pull fscache updates from David Howells: "Preparatory work for the fscache rewrite that's being worked on and fix some bugs. These include: - Always select netfs stats when enabling fscache stats since they're displayed through the same procfile. - Add a cookie debug ID that can be used in tracepoints instead of a pointer and cache it in the netfs_cache_resources struct rather than in the netfs_read_request struct to make it more available. - Use file_inode() in cachefiles rather than dereferencing file->f_inode directly. - Provide a procfile to display fscache cookies. - Remove the fscache and cachefiles histogram procfiles. - Remove the fscache object list procfile. - Avoid using %p in fscache and cachefiles as the value is hashed and not comparable to the register dump in an oops trace. - Fix the cookie hash function to actually achieve useful dispersion. - Fix fscache_cookie_put() so that it doesn't dereference the cookie pointer in the tracepoint after the refcount has been decremented (we're only allowed to do that if we decremented it to zero). - Use refcount_t rather than atomic_t for the fscache_cookie refcount" * tag 'fscache-next-20210829' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs: fscache: Use refcount_t for the cookie refcount instead of atomic_t fscache: Fix fscache_cookie_put() to not deref after dec fscache: Fix cookie key hashing cachefiles: Change %p in format strings to something else fscache: Change %p in format strings to something else fscache: Remove the object list procfile fscache, cachefiles: Remove the histogram stuff fscache: Procfile to display cookies fscache: Add a cookie debug ID and use that in traces cachefiles: Use file_inode() rather than accessing ->f_inode netfs: Move cookie debug ID to struct netfs_cache_resources fscache: Select netfs stats if fscache stats are enabled
2 parents 75ae663 + 20ec197 commit 89594c7

31 files changed

+368
-998
lines changed

fs/cachefiles/Kconfig

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,3 @@ config CACHEFILES_DEBUG
1919
caching on files module. If this is set, the debugging output may be
2020
enabled by setting bits in /sys/modules/cachefiles/parameter/debug or
2121
by including a debugging specifier in /etc/cachefilesd.conf.
22-
23-
config CACHEFILES_HISTOGRAM
24-
bool "Gather latency information on CacheFiles"
25-
depends on CACHEFILES && PROC_FS
26-
help
27-
28-
This option causes latency information to be gathered on CacheFiles
29-
operation and exported through file:
30-
31-
/proc/fs/cachefiles/histogram
32-
33-
The generation of this histogram adds a certain amount of overhead to
34-
execution as there are a number of points at which data is gathered,
35-
and on a multi-CPU system these may be on cachelines that keep
36-
bouncing between CPUs. On the other hand, the histogram may be
37-
useful for debugging purposes. Saying 'N' here is recommended.
38-
39-
See Documentation/filesystems/caching/cachefiles.rst for more
40-
information.

fs/cachefiles/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ cachefiles-y := \
1515
security.o \
1616
xattr.o
1717

18-
cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += proc.o
19-
2018
obj-$(CONFIG_CACHEFILES) := cachefiles.o

fs/cachefiles/bind.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
108108
atomic_set(&fsdef->usage, 1);
109109
fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;
110110

111-
_debug("- fsdef %p", fsdef);
112-
113111
/* look up the directory at the root of the cache */
114112
ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
115113
if (ret < 0)

fs/cachefiles/interface.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static struct fscache_object *cachefiles_alloc_object(
3333

3434
cache = container_of(_cache, struct cachefiles_cache, cache);
3535

36-
_enter("{%s},%p,", cache->cache.identifier, cookie);
36+
_enter("{%s},%x,", cache->cache.identifier, cookie->debug_id);
3737

3838
lookup_data = kmalloc(sizeof(*lookup_data), cachefiles_gfp);
3939
if (!lookup_data)
@@ -96,7 +96,7 @@ static struct fscache_object *cachefiles_alloc_object(
9696
lookup_data->key = key;
9797
object->lookup_data = lookup_data;
9898

99-
_leave(" = %p [%p]", &object->fscache, lookup_data);
99+
_leave(" = %x [%p]", object->fscache.debug_id, lookup_data);
100100
return &object->fscache;
101101

102102
nomem_key:
@@ -379,7 +379,7 @@ static void cachefiles_sync_cache(struct fscache_cache *_cache)
379379
const struct cred *saved_cred;
380380
int ret;
381381

382-
_enter("%p", _cache);
382+
_enter("%s", _cache->tag->name);
383383

384384
cache = container_of(_cache, struct cachefiles_cache, cache);
385385

fs/cachefiles/internal.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,31 +180,6 @@ extern int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
180180
extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
181181
struct dentry *dir, char *filename);
182182

183-
/*
184-
* proc.c
185-
*/
186-
#ifdef CONFIG_CACHEFILES_HISTOGRAM
187-
extern atomic_t cachefiles_lookup_histogram[HZ];
188-
extern atomic_t cachefiles_mkdir_histogram[HZ];
189-
extern atomic_t cachefiles_create_histogram[HZ];
190-
191-
extern int __init cachefiles_proc_init(void);
192-
extern void cachefiles_proc_cleanup(void);
193-
static inline
194-
void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
195-
{
196-
unsigned long jif = jiffies - start_jif;
197-
if (jif >= HZ)
198-
jif = HZ - 1;
199-
atomic_inc(&histogram[jif]);
200-
}
201-
202-
#else
203-
#define cachefiles_proc_init() (0)
204-
#define cachefiles_proc_cleanup() do {} while (0)
205-
#define cachefiles_hist(hist, start_jif) do {} while (0)
206-
#endif
207-
208183
/*
209184
* rdwr.c
210185
*/

fs/cachefiles/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int cachefiles_read(struct netfs_cache_resources *cres,
7070

7171
_enter("%pD,%li,%llx,%zx/%llx",
7272
file, file_inode(file)->i_ino, start_pos, len,
73-
i_size_read(file->f_inode));
73+
i_size_read(file_inode(file)));
7474

7575
/* If the caller asked us to seek for data before doing the read, then
7676
* we should do that now. If we find a gap, we fill it with zeros.
@@ -194,7 +194,7 @@ static int cachefiles_write(struct netfs_cache_resources *cres,
194194

195195
_enter("%pD,%li,%llx,%zx/%llx",
196196
file, file_inode(file)->i_ino, start_pos, len,
197-
i_size_read(file->f_inode));
197+
i_size_read(file_inode(file)));
198198

199199
ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL);
200200
if (!ki)
@@ -410,7 +410,7 @@ int cachefiles_begin_read_operation(struct netfs_read_request *rreq,
410410
rreq->cache_resources.cache_priv = op;
411411
rreq->cache_resources.cache_priv2 = file;
412412
rreq->cache_resources.ops = &cachefiles_netfs_cache_ops;
413-
rreq->cookie_debug_id = object->fscache.debug_id;
413+
rreq->cache_resources.debug_id = object->fscache.debug_id;
414414
_leave("");
415415
return 0;
416416

fs/cachefiles/key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,6 @@ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type)
150150
key[len++] = 0;
151151
key[len] = 0;
152152

153-
_leave(" = %p %d", key, len);
153+
_leave(" = %s %d", key, len);
154154
return key;
155155
}

fs/cachefiles/main.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,9 @@ static int __init cachefiles_init(void)
6969
goto error_object_jar;
7070
}
7171

72-
ret = cachefiles_proc_init();
73-
if (ret < 0)
74-
goto error_proc;
75-
7672
pr_info("Loaded\n");
7773
return 0;
7874

79-
error_proc:
80-
kmem_cache_destroy(cachefiles_object_jar);
8175
error_object_jar:
8276
misc_deregister(&cachefiles_dev);
8377
error_dev:
@@ -94,7 +88,6 @@ static void __exit cachefiles_exit(void)
9488
{
9589
pr_info("Unloading\n");
9690

97-
cachefiles_proc_cleanup();
9891
kmem_cache_destroy(cachefiles_object_jar);
9992
misc_deregister(&cachefiles_dev);
10093
}

fs/cachefiles/namei.c

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ void __cachefiles_printk_object(struct cachefiles_object *object,
3939
pr_err("%sops=%u inp=%u exc=%u\n",
4040
prefix, object->fscache.n_ops, object->fscache.n_in_progress,
4141
object->fscache.n_exclusive);
42-
pr_err("%sparent=%p\n",
43-
prefix, object->fscache.parent);
42+
pr_err("%sparent=%x\n",
43+
prefix, object->fscache.parent ? object->fscache.parent->debug_id : 0);
4444

4545
spin_lock(&object->fscache.lock);
4646
cookie = object->fscache.cookie;
4747
if (cookie) {
48-
pr_err("%scookie=%p [pr=%p nd=%p fl=%lx]\n",
48+
pr_err("%scookie=%x [pr=%x nd=%p fl=%lx]\n",
4949
prefix,
50-
object->fscache.cookie,
51-
object->fscache.cookie->parent,
52-
object->fscache.cookie->netfs_data,
53-
object->fscache.cookie->flags);
50+
cookie->debug_id,
51+
cookie->parent ? cookie->parent->debug_id : 0,
52+
cookie->netfs_data,
53+
cookie->flags);
5454
pr_err("%skey=[%u] '", prefix, cookie->key_len);
5555
k = (cookie->key_len <= sizeof(cookie->inline_key)) ?
5656
cookie->inline_key : cookie->key;
@@ -110,7 +110,7 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,
110110

111111
/* found the dentry for */
112112
found_dentry:
113-
kdebug("preemptive burial: OBJ%x [%s] %p",
113+
kdebug("preemptive burial: OBJ%x [%s] %pd",
114114
object->fscache.debug_id,
115115
object->fscache.state->name,
116116
dentry);
@@ -140,7 +140,7 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
140140
struct rb_node **_p, *_parent = NULL;
141141
struct dentry *dentry;
142142

143-
_enter(",%p", object);
143+
_enter(",%x", object->fscache.debug_id);
144144

145145
try_again:
146146
write_lock(&cache->active_lock);
@@ -298,8 +298,6 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,
298298

299299
_enter(",'%pd','%pd'", dir, rep);
300300

301-
_debug("remove %p from %p", rep, dir);
302-
303301
/* non-directories can just be unlinked */
304302
if (!d_is_dir(rep)) {
305303
_debug("unlink stale object");
@@ -446,7 +444,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
446444
struct dentry *dir;
447445
int ret;
448446

449-
_enter(",OBJ%x{%p}", object->fscache.debug_id, object->dentry);
447+
_enter(",OBJ%x{%pd}", object->fscache.debug_id, object->dentry);
450448

451449
ASSERT(object->dentry);
452450
ASSERT(d_backing_inode(object->dentry));
@@ -496,11 +494,10 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
496494
struct dentry *dir, *next = NULL;
497495
struct inode *inode;
498496
struct path path;
499-
unsigned long start;
500497
const char *name;
501498
int ret, nlen;
502499

503-
_enter("OBJ%x{%p},OBJ%x,%s,",
500+
_enter("OBJ%x{%pd},OBJ%x,%s,",
504501
parent->fscache.debug_id, parent->dentry,
505502
object->fscache.debug_id, key);
506503

@@ -535,17 +532,15 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
535532

536533
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
537534

538-
start = jiffies;
539535
next = lookup_one_len(name, dir, nlen);
540-
cachefiles_hist(cachefiles_lookup_histogram, start);
541536
if (IS_ERR(next)) {
542537
trace_cachefiles_lookup(object, next, NULL);
543538
goto lookup_error;
544539
}
545540

546541
inode = d_backing_inode(next);
547542
trace_cachefiles_lookup(object, next, inode);
548-
_debug("next -> %p %s", next, inode ? "positive" : "negative");
543+
_debug("next -> %pd %s", next, inode ? "positive" : "negative");
549544

550545
if (!key)
551546
object->new = !inode;
@@ -568,9 +563,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
568563
ret = security_path_mkdir(&path, next, 0);
569564
if (ret < 0)
570565
goto create_error;
571-
start = jiffies;
572566
ret = vfs_mkdir(&init_user_ns, d_inode(dir), next, 0);
573-
cachefiles_hist(cachefiles_mkdir_histogram, start);
574567
if (!key)
575568
trace_cachefiles_mkdir(object, next, ret);
576569
if (ret < 0)
@@ -583,8 +576,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
583576
}
584577
ASSERT(d_backing_inode(next));
585578

586-
_debug("mkdir -> %p{%p{ino=%lu}}",
587-
next, d_backing_inode(next), d_backing_inode(next)->i_ino);
579+
_debug("mkdir -> %pd{ino=%lu}",
580+
next, d_backing_inode(next)->i_ino);
588581

589582
} else if (!d_can_lookup(next)) {
590583
pr_err("inode %lu is not a directory\n",
@@ -604,18 +597,16 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
604597
ret = security_path_mknod(&path, next, S_IFREG, 0);
605598
if (ret < 0)
606599
goto create_error;
607-
start = jiffies;
608600
ret = vfs_create(&init_user_ns, d_inode(dir), next,
609601
S_IFREG, true);
610-
cachefiles_hist(cachefiles_create_histogram, start);
611602
trace_cachefiles_create(object, next, ret);
612603
if (ret < 0)
613604
goto create_error;
614605

615606
ASSERT(d_backing_inode(next));
616607

617-
_debug("create -> %p{%p{ino=%lu}}",
618-
next, d_backing_inode(next), d_backing_inode(next)->i_ino);
608+
_debug("create -> %pd{ino=%lu}",
609+
next, d_backing_inode(next)->i_ino);
619610

620611
} else if (!d_can_lookup(next) &&
621612
!d_is_reg(next)
@@ -765,7 +756,6 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
765756
const char *dirname)
766757
{
767758
struct dentry *subdir;
768-
unsigned long start;
769759
struct path path;
770760
int ret;
771761

@@ -775,16 +765,14 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
775765
inode_lock(d_inode(dir));
776766

777767
retry:
778-
start = jiffies;
779768
subdir = lookup_one_len(dirname, dir, strlen(dirname));
780-
cachefiles_hist(cachefiles_lookup_histogram, start);
781769
if (IS_ERR(subdir)) {
782770
if (PTR_ERR(subdir) == -ENOMEM)
783771
goto nomem_d_alloc;
784772
goto lookup_error;
785773
}
786774

787-
_debug("subdir -> %p %s",
775+
_debug("subdir -> %pd %s",
788776
subdir, d_backing_inode(subdir) ? "positive" : "negative");
789777

790778
/* we need to create the subdir if it doesn't exist yet */
@@ -810,10 +798,8 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
810798
}
811799
ASSERT(d_backing_inode(subdir));
812800

813-
_debug("mkdir -> %p{%p{ino=%lu}}",
814-
subdir,
815-
d_backing_inode(subdir),
816-
d_backing_inode(subdir)->i_ino);
801+
_debug("mkdir -> %pd{ino=%lu}",
802+
subdir, d_backing_inode(subdir)->i_ino);
817803
}
818804

819805
inode_unlock(d_inode(dir));
@@ -876,7 +862,6 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
876862
struct cachefiles_object *object;
877863
struct rb_node *_n;
878864
struct dentry *victim;
879-
unsigned long start;
880865
int ret;
881866

882867
//_enter(",%pd/,%s",
@@ -885,13 +870,11 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
885870
/* look up the victim */
886871
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
887872

888-
start = jiffies;
889873
victim = lookup_one_len(filename, dir, strlen(filename));
890-
cachefiles_hist(cachefiles_lookup_histogram, start);
891874
if (IS_ERR(victim))
892875
goto lookup_error;
893876

894-
//_debug("victim -> %p %s",
877+
//_debug("victim -> %pd %s",
895878
// victim, d_backing_inode(victim) ? "positive" : "negative");
896879

897880
/* if the object is no longer there then we probably retired the object
@@ -922,7 +905,7 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
922905

923906
read_unlock(&cache->active_lock);
924907

925-
//_leave(" = %p", victim);
908+
//_leave(" = %pd", victim);
926909
return victim;
927910

928911
object_in_use:
@@ -968,7 +951,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
968951
if (IS_ERR(victim))
969952
return PTR_ERR(victim);
970953

971-
_debug("victim -> %p %s",
954+
_debug("victim -> %pd %s",
972955
victim, d_backing_inode(victim) ? "positive" : "negative");
973956

974957
/* okay... the victim is not being used so we can cull it

0 commit comments

Comments
 (0)