Skip to content

Commit

Permalink
Merge tag 'fscache-next-20210829' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
Linus Torvalds committed Sep 2, 2021
2 parents 75ae663 + 20ec197 commit 89594c7
Show file tree
Hide file tree
Showing 31 changed files with 368 additions and 998 deletions.
19 changes: 0 additions & 19 deletions fs/cachefiles/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,3 @@ config CACHEFILES_DEBUG
caching on files module. If this is set, the debugging output may be
enabled by setting bits in /sys/modules/cachefiles/parameter/debug or
by including a debugging specifier in /etc/cachefilesd.conf.

config CACHEFILES_HISTOGRAM
bool "Gather latency information on CacheFiles"
depends on CACHEFILES && PROC_FS
help

This option causes latency information to be gathered on CacheFiles
operation and exported through file:

/proc/fs/cachefiles/histogram

The generation of this histogram adds a certain amount of overhead to
execution as there are a number of points at which data is gathered,
and on a multi-CPU system these may be on cachelines that keep
bouncing between CPUs. On the other hand, the histogram may be
useful for debugging purposes. Saying 'N' here is recommended.

See Documentation/filesystems/caching/cachefiles.rst for more
information.
2 changes: 0 additions & 2 deletions fs/cachefiles/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ cachefiles-y := \
security.o \
xattr.o

cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += proc.o

obj-$(CONFIG_CACHEFILES) := cachefiles.o
2 changes: 0 additions & 2 deletions fs/cachefiles/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
atomic_set(&fsdef->usage, 1);
fsdef->type = FSCACHE_COOKIE_TYPE_INDEX;

_debug("- fsdef %p", fsdef);

/* look up the directory at the root of the cache */
ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path);
if (ret < 0)
Expand Down
6 changes: 3 additions & 3 deletions fs/cachefiles/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct fscache_object *cachefiles_alloc_object(

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

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

lookup_data = kmalloc(sizeof(*lookup_data), cachefiles_gfp);
if (!lookup_data)
Expand Down Expand Up @@ -96,7 +96,7 @@ static struct fscache_object *cachefiles_alloc_object(
lookup_data->key = key;
object->lookup_data = lookup_data;

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

nomem_key:
Expand Down Expand Up @@ -379,7 +379,7 @@ static void cachefiles_sync_cache(struct fscache_cache *_cache)
const struct cred *saved_cred;
int ret;

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

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

Expand Down
25 changes: 0 additions & 25 deletions fs/cachefiles/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,31 +180,6 @@ extern int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
struct dentry *dir, char *filename);

/*
* proc.c
*/
#ifdef CONFIG_CACHEFILES_HISTOGRAM
extern atomic_t cachefiles_lookup_histogram[HZ];
extern atomic_t cachefiles_mkdir_histogram[HZ];
extern atomic_t cachefiles_create_histogram[HZ];

extern int __init cachefiles_proc_init(void);
extern void cachefiles_proc_cleanup(void);
static inline
void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
{
unsigned long jif = jiffies - start_jif;
if (jif >= HZ)
jif = HZ - 1;
atomic_inc(&histogram[jif]);
}

#else
#define cachefiles_proc_init() (0)
#define cachefiles_proc_cleanup() do {} while (0)
#define cachefiles_hist(hist, start_jif) do {} while (0)
#endif

/*
* rdwr.c
*/
Expand Down
6 changes: 3 additions & 3 deletions fs/cachefiles/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int cachefiles_read(struct netfs_cache_resources *cres,

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

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

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

ki = kzalloc(sizeof(struct cachefiles_kiocb), GFP_KERNEL);
if (!ki)
Expand Down Expand Up @@ -410,7 +410,7 @@ int cachefiles_begin_read_operation(struct netfs_read_request *rreq,
rreq->cache_resources.cache_priv = op;
rreq->cache_resources.cache_priv2 = file;
rreq->cache_resources.ops = &cachefiles_netfs_cache_ops;
rreq->cookie_debug_id = object->fscache.debug_id;
rreq->cache_resources.debug_id = object->fscache.debug_id;
_leave("");
return 0;

Expand Down
2 changes: 1 addition & 1 deletion fs/cachefiles/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ char *cachefiles_cook_key(const u8 *raw, int keylen, uint8_t type)
key[len++] = 0;
key[len] = 0;

_leave(" = %p %d", key, len);
_leave(" = %s %d", key, len);
return key;
}
7 changes: 0 additions & 7 deletions fs/cachefiles/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ static int __init cachefiles_init(void)
goto error_object_jar;
}

ret = cachefiles_proc_init();
if (ret < 0)
goto error_proc;

pr_info("Loaded\n");
return 0;

error_proc:
kmem_cache_destroy(cachefiles_object_jar);
error_object_jar:
misc_deregister(&cachefiles_dev);
error_dev:
Expand All @@ -94,7 +88,6 @@ static void __exit cachefiles_exit(void)
{
pr_info("Unloading\n");

cachefiles_proc_cleanup();
kmem_cache_destroy(cachefiles_object_jar);
misc_deregister(&cachefiles_dev);
}
Expand Down
61 changes: 22 additions & 39 deletions fs/cachefiles/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ void __cachefiles_printk_object(struct cachefiles_object *object,
pr_err("%sops=%u inp=%u exc=%u\n",
prefix, object->fscache.n_ops, object->fscache.n_in_progress,
object->fscache.n_exclusive);
pr_err("%sparent=%p\n",
prefix, object->fscache.parent);
pr_err("%sparent=%x\n",
prefix, object->fscache.parent ? object->fscache.parent->debug_id : 0);

spin_lock(&object->fscache.lock);
cookie = object->fscache.cookie;
if (cookie) {
pr_err("%scookie=%p [pr=%p nd=%p fl=%lx]\n",
pr_err("%scookie=%x [pr=%x nd=%p fl=%lx]\n",
prefix,
object->fscache.cookie,
object->fscache.cookie->parent,
object->fscache.cookie->netfs_data,
object->fscache.cookie->flags);
cookie->debug_id,
cookie->parent ? cookie->parent->debug_id : 0,
cookie->netfs_data,
cookie->flags);
pr_err("%skey=[%u] '", prefix, cookie->key_len);
k = (cookie->key_len <= sizeof(cookie->inline_key)) ?
cookie->inline_key : cookie->key;
Expand Down Expand Up @@ -110,7 +110,7 @@ static void cachefiles_mark_object_buried(struct cachefiles_cache *cache,

/* found the dentry for */
found_dentry:
kdebug("preemptive burial: OBJ%x [%s] %p",
kdebug("preemptive burial: OBJ%x [%s] %pd",
object->fscache.debug_id,
object->fscache.state->name,
dentry);
Expand Down Expand Up @@ -140,7 +140,7 @@ static int cachefiles_mark_object_active(struct cachefiles_cache *cache,
struct rb_node **_p, *_parent = NULL;
struct dentry *dentry;

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

try_again:
write_lock(&cache->active_lock);
Expand Down Expand Up @@ -298,8 +298,6 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,

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

_debug("remove %p from %p", rep, dir);

/* non-directories can just be unlinked */
if (!d_is_dir(rep)) {
_debug("unlink stale object");
Expand Down Expand Up @@ -446,7 +444,7 @@ int cachefiles_delete_object(struct cachefiles_cache *cache,
struct dentry *dir;
int ret;

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

ASSERT(object->dentry);
ASSERT(d_backing_inode(object->dentry));
Expand Down Expand Up @@ -496,11 +494,10 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
struct dentry *dir, *next = NULL;
struct inode *inode;
struct path path;
unsigned long start;
const char *name;
int ret, nlen;

_enter("OBJ%x{%p},OBJ%x,%s,",
_enter("OBJ%x{%pd},OBJ%x,%s,",
parent->fscache.debug_id, parent->dentry,
object->fscache.debug_id, key);

Expand Down Expand Up @@ -535,17 +532,15 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,

inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);

start = jiffies;
next = lookup_one_len(name, dir, nlen);
cachefiles_hist(cachefiles_lookup_histogram, start);
if (IS_ERR(next)) {
trace_cachefiles_lookup(object, next, NULL);
goto lookup_error;
}

inode = d_backing_inode(next);
trace_cachefiles_lookup(object, next, inode);
_debug("next -> %p %s", next, inode ? "positive" : "negative");
_debug("next -> %pd %s", next, inode ? "positive" : "negative");

if (!key)
object->new = !inode;
Expand All @@ -568,9 +563,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
ret = security_path_mkdir(&path, next, 0);
if (ret < 0)
goto create_error;
start = jiffies;
ret = vfs_mkdir(&init_user_ns, d_inode(dir), next, 0);
cachefiles_hist(cachefiles_mkdir_histogram, start);
if (!key)
trace_cachefiles_mkdir(object, next, ret);
if (ret < 0)
Expand All @@ -583,8 +576,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
}
ASSERT(d_backing_inode(next));

_debug("mkdir -> %p{%p{ino=%lu}}",
next, d_backing_inode(next), d_backing_inode(next)->i_ino);
_debug("mkdir -> %pd{ino=%lu}",
next, d_backing_inode(next)->i_ino);

} else if (!d_can_lookup(next)) {
pr_err("inode %lu is not a directory\n",
Expand All @@ -604,18 +597,16 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
ret = security_path_mknod(&path, next, S_IFREG, 0);
if (ret < 0)
goto create_error;
start = jiffies;
ret = vfs_create(&init_user_ns, d_inode(dir), next,
S_IFREG, true);
cachefiles_hist(cachefiles_create_histogram, start);
trace_cachefiles_create(object, next, ret);
if (ret < 0)
goto create_error;

ASSERT(d_backing_inode(next));

_debug("create -> %p{%p{ino=%lu}}",
next, d_backing_inode(next), d_backing_inode(next)->i_ino);
_debug("create -> %pd{ino=%lu}",
next, d_backing_inode(next)->i_ino);

} else if (!d_can_lookup(next) &&
!d_is_reg(next)
Expand Down Expand Up @@ -765,7 +756,6 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
const char *dirname)
{
struct dentry *subdir;
unsigned long start;
struct path path;
int ret;

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

retry:
start = jiffies;
subdir = lookup_one_len(dirname, dir, strlen(dirname));
cachefiles_hist(cachefiles_lookup_histogram, start);
if (IS_ERR(subdir)) {
if (PTR_ERR(subdir) == -ENOMEM)
goto nomem_d_alloc;
goto lookup_error;
}

_debug("subdir -> %p %s",
_debug("subdir -> %pd %s",
subdir, d_backing_inode(subdir) ? "positive" : "negative");

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

_debug("mkdir -> %p{%p{ino=%lu}}",
subdir,
d_backing_inode(subdir),
d_backing_inode(subdir)->i_ino);
_debug("mkdir -> %pd{ino=%lu}",
subdir, d_backing_inode(subdir)->i_ino);
}

inode_unlock(d_inode(dir));
Expand Down Expand Up @@ -876,7 +862,6 @@ static struct dentry *cachefiles_check_active(struct cachefiles_cache *cache,
struct cachefiles_object *object;
struct rb_node *_n;
struct dentry *victim;
unsigned long start;
int ret;

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

start = jiffies;
victim = lookup_one_len(filename, dir, strlen(filename));
cachefiles_hist(cachefiles_lookup_histogram, start);
if (IS_ERR(victim))
goto lookup_error;

//_debug("victim -> %p %s",
//_debug("victim -> %pd %s",
// victim, d_backing_inode(victim) ? "positive" : "negative");

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

read_unlock(&cache->active_lock);

//_leave(" = %p", victim);
//_leave(" = %pd", victim);
return victim;

object_in_use:
Expand Down Expand Up @@ -968,7 +951,7 @@ int cachefiles_cull(struct cachefiles_cache *cache, struct dentry *dir,
if (IS_ERR(victim))
return PTR_ERR(victim);

_debug("victim -> %p %s",
_debug("victim -> %pd %s",
victim, d_backing_inode(victim) ? "positive" : "negative");

/* okay... the victim is not being used so we can cull it
Expand Down
Loading

0 comments on commit 89594c7

Please sign in to comment.