fscache: Some prep work for fscache rewrite
Subsystems (8)
David Howells
maintainercover fscache: Some prep work for fscache rewrite
Here are some patches that perform some preparatory work for the fscache rewrite that's being worked on. These include:
(1) Always select netfs stats when enabling fscache stats since they're displayed through the same procfile.
(2) 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.
(3) Use file_inode() in cachefiles rather than dereferencing file->f_inode directly.
(4) Provide a procfile to display fscache cookies.
(5) Remove the fscache and cachefiles histogram procfiles.
(6) Remove the fscache object list procfile.
(7) Avoid using %p in fscache and cachefiles as the value is hashed and not comparable to the register dump in an oops trace.
(8) Fix the cookie hash function to actually achieve useful dispersion.
(9) 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).
(10) Use refcount_t rather than atomic_t for the fscache_cookie refcount.
The patches can be found on this branch:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=fscache-next
David
---
David Howells (12):
fscache: Select netfs stats if fscache stats are enabled
netfs: Move cookie debug ID to struct netfs_cache_resources
cachefiles: Use file_inode() rather than accessing ->f_inode
fscache: Add a cookie debug ID and use that in traces
fscache: Procfile to display cookies
fscache, cachefiles: Remove the histogram stuff
fscache: Remove the object list procfile
fscache: Change %p in format strings to something else
cachefiles: Change %p in format strings to something else
fscache: Fix cookie key hashing
fscache: Fix fscache_cookie_put() to not deref after dec
fscache: Use refcount_t for the cookie refcount instead of atomic_t
fs/cachefiles/Kconfig | 19 -- fs/cachefiles/Makefile | 2 - fs/cachefiles/bind.c | 2 - fs/cachefiles/interface.c | 6 +- fs/cachefiles/internal.h | 25 -- fs/cachefiles/io.c | 6 +- fs/cachefiles/key.c | 2 +- fs/cachefiles/main.c | 7 - fs/cachefiles/namei.c | 61 ++--- fs/cachefiles/proc.c | 114 -------- fs/cachefiles/xattr.c | 4 +- fs/fscache/Kconfig | 24 -- fs/fscache/Makefile | 2 - fs/fscache/cache.c | 11 +- fs/fscache/cookie.c | 201 +++++++++++---- fs/fscache/fsdef.c | 3 +- fs/fscache/histogram.c | 87 ------- fs/fscache/internal.h | 57 +--- fs/fscache/main.c | 39 +++ fs/fscache/netfs.c | 2 +- fs/fscache/object-list.c | 414 ------------------------------ fs/fscache/object.c | 8 - fs/fscache/operation.c | 3 - fs/fscache/page.c | 6 - fs/fscache/proc.c | 20 +- include/linux/fscache-cache.h | 4 - include/linux/fscache.h | 4 +- include/linux/netfs.h | 2 +- include/trace/events/cachefiles.h | 68 ++--- include/trace/events/fscache.h | 160 ++++++------ include/trace/events/netfs.h | 2 +- 31 files changed, 367 insertions(+), 998 deletions(-) delete mode 100644 fs/cachefiles/proc.c delete mode 100644 fs/fscache/histogram.c delete mode 100644 fs/fscache/object-list.c
David Howells
maintainerPATCH 1/12 fscache: Select netfs stats if fscache stats are enabled
Unconditionally select the stats produced by the netfs lib if fscache stats are enabled as the former are displayed in the latter's procfile.
---
fs/fscache/Kconfig | 1 + 1 file changed, 1 insertion(+)
fs/fscache/Kconfig +1 -0
@@ -14,6 +14,7 @@ config FSCACHE config FSCACHE_STATS bool "Gather statistical information on local caching" depends on FSCACHE && PROC_FS + select NETFS_STATS help This option causes statistical information to be gathered on local caching and exported through file:
David Howells
maintainerPATCH 2/12 netfs: Move cookie debug ID to struct netfs_cache_resources
In reply to David HowellsMove the cookie debug ID from struct netfs_read_request to struct netfs_cache_resources and drop the 'cookie_' prefix. This makes it available for things that want to use netfs_cache_resources without having a netfs_read_request.
---
fs/cachefiles/io.c | 2 +- include/linux/netfs.h | 2 +- include/trace/events/netfs.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/cachefiles/io.c +1 -1
@@ -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 ;
include/linux/netfs.h +1 -1
@@ -102,6 +102,7 @@ struct netfs_cache_resources {const struct netfs_cache_ops *ops;void *cache_priv;void *cache_priv2; +unsigned int debug_id;/* Cookie debug ID */ };/*
@@ -137,7 +138,6 @@ struct netfs_read_request {struct list_head subrequests;/* Requests to fetch I/O from disk or net */ void *netfs_priv;/* Private data for the netfs */ unsigned int debug_id; -unsigned int cookie_debug_id;atomic_t nr_rd_ops;/* Number of read ops in progress */ atomic_t nr_wr_ops;/* Number of write ops in progress */ size_t submitted;/* Amount submitted for I/O so far */
include/trace/events/netfs.h +1 -1
@@ -139,7 +139,7 @@ TRACE_EVENT(netfs_read,TP_fast_assign ( __entry->rreq = rreq->debug_id; - __entry->cookie = rreq->cookie_debug_id; + __entry->cookie = rreq->cache_resources.debug_id; __entry->start = start; __entry->len = len; __entry->what = what;
David Howells
maintainerPATCH 3/12 cachefiles: Use file_inode() rather than accessing ->f_inode
In reply to David HowellsUse the file_inode() helper rather than accessing ->f_inode directly.
---
fs/cachefiles/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/cachefiles/io.c +2 -2
@@ -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.
@@ -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)
David Howells
maintainerPATCH 4/12 fscache: Add a cookie debug ID and use that in traces
In reply to David HowellsAdd 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.
---
fs/fscache/cookie.c | 29 ++++++--- fs/fscache/fsdef.c | 1 fs/fscache/object-list.c | 14 ++-- include/linux/fscache.h | 1 include/trace/events/cachefiles.h | 68 +++++++++++----------- include/trace/events/fscache.h | 116 +++++++++++++++++++------------------ 6 files changed, 121 insertions(+), 108 deletions(-)
fs/fscache/cookie.c +20 -9
@@ -29,21 +29,29 @@ static int fscache_attach_object(struct fscache_cookie *cookie,static void fscache_print_cookie (struct fscache_cookie *cookie,char prefix) { -struct hlist_node *object; +struct fscache_object *object; +struct hlist_node *o;const u8 *k;unsigned loop; -pr_err ("%c-cookie c=%p [p=%p fl=%lx nc=%u na=%u]\n" , - prefix, cookie, cookie->parent, cookie->flags, +pr_err ("%c-cookie c=%08x [p=%08x fl=%lx nc=%u na=%u]\n" , + prefix, + cookie->debug_id, + cookie->parent ? cookie->parent->debug_id :0 , + cookie->flags,atomic_read (&cookie->n_children),atomic_read (&cookie->n_active)); -pr_err ("%c-cookie d=%p n=%p\n" , - prefix, cookie->def, cookie->netfs_data); +pr_err ("%c-cookie d=%p{%s} n=%p\n" , + prefix, + cookie->def, + cookie->def ? cookie->def->name :"?" , + cookie->netfs_data); - object =READ_ONCE (cookie->backing_objects.first); -if (object) -pr_err ("%c-cookie o=%p\n" , - prefix, hlist_entry(object, struct fscache_object, cookie_link)); + o =READ_ONCE (cookie->backing_objects.first); +if (o) { + object = hlist_entry(o, struct fscache_object, cookie_link); +pr_err ("%c-cookie o=%u\n" , prefix, object->debug_id); + }pr_err ("%c-key=[%u] '" , prefix, cookie->key_len); k = (cookie->key_len <= sizeof(cookie->inline_key)) ?
@@ -129,6 +137,8 @@ static long fscache_compare_cookie(const struct fscache_cookie *a,return memcmp (ka, kb, a->key_len); } +static atomic_t fscache_cookie_debug_id =ATOMIC_INIT (1 ); +/* * Allocate a cookie. */
@@ -163,6 +173,7 @@ struct fscache_cookie *fscache_alloc_cookie(atomic_set (&cookie->usage,1 );atomic_set (&cookie->n_children,0 ); + cookie->debug_id =atomic_inc_return (&fscache_cookie_debug_id);/* We keep the active count elevated until relinquishment to prevent an * attempt to wake up every time the object operations queue quiesces.
fs/fscache/fsdef.c +1 -0
@@ -45,6 +45,7 @@ static struct fscache_cookie_def fscache_fsdef_index_def = { };struct fscache_cookie fscache_fsdef_index = { + .debug_id =1 , .usage =ATOMIC_INIT (1 ), .n_active =ATOMIC_INIT (1 ), .lock =__SPIN_LOCK_UNLOCKED (fscache_fsdef_index.lock),
fs/fscache/object-list.c +7 -7
@@ -170,7 +170,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)if ((unsigned long ) v ==1 ) {seq_puts (m,"OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS" " EM EV FL S" -" | NETFS_COOKIE_DEF TY FL NETFS_DATA" ); +" | COOKIE NETFS_COOKIE_DEF TY FL NETFS_DATA" );if (config & (FSCACHE_OBJLIST_CONFIG_KEY |FSCACHE_OBJLIST_CONFIG_AUX ))seq_puts (m," " );
@@ -189,7 +189,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)if ((unsigned long ) v ==2 ) {seq_puts (m,"======== ======== ==== ===== === === === == =====" " == == == =" -" | ================ == == ================" ); +" | ======== ================ == === ================" );if (config & (FSCACHE_OBJLIST_CONFIG_KEY |FSCACHE_OBJLIST_CONFIG_AUX ))seq_puts (m," ================" );
@@ -231,9 +231,9 @@ static int fscache_objlist_show(struct seq_file *m, void *v) } seq_printf(m, - "%8x %8x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ", + "%08x %08x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ", obj->debug_id, - obj->parent ? obj->parent->debug_id : -1, + obj->parent ? obj->parent->debug_id : UINT_MAX, obj->state->short_name, obj->n_children, obj->n_ops,
@@ -246,7 +246,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v) obj->flags, work_busy(&obj->work)); -if (fscache_use_cookie (obj)) { +if (obj->cookie) {uint16_t keylen =0 , auxlen =0 ;switch (cookie->type) {
@@ -263,7 +263,8 @@ static int fscache_objlist_show(struct seq_file *m, void *v)break ; } - seq_printf(m, "%-16s %s %2lx %16p", + seq_printf(m, "%08x %-16s %s %3lx %16p", + cookie->debug_id, cookie->def->name, type, cookie->flags,
@@ -292,7 +293,6 @@ static int fscache_objlist_show(struct seq_file *m, void *v) }seq_puts (m,"\n" ); -fscache_unuse_cookie (obj); }else {seq_puts (m,"<no_netfs>\n" ); }
include/linux/fscache.h +1 -0
@@ -126,6 +126,7 @@ struct fscache_cookie {atomic_t usage;/* number of users of this cookie */ atomic_t n_children;/* number of children of this cookie */ atomic_t n_active;/* number of active users of netfs ptrs */ +unsigned int debug_id;spinlock_t lock;spinlock_t stores_lock;/* lock on page store tree */ struct hlist_head backing_objects;/* object(s) backing this file/index */
include/trace/events/cachefiles.h +34 -34
220 lines not on this page · raw message
include/trace/events/fscache.h +58 -58
341 lines not on this page · raw message
David Howells
maintainerPATCH v2 4/12 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.
--- fs/fscache/cookie.c | 29 ++++++--- fs/fscache/fsdef.c | 1 fs/fscache/object-list.c | 14 ++-- include/linux/fscache.h | 1 include/trace/events/cachefiles.h | 68 +++++++++++----------- include/trace/events/fscache.h | 116 +++++++++++++++++++------------------- 6 files changed, 121 insertions(+), 108 deletions(-)
fs/fscache/cookie.c +20 -9
@@ -29,21 +29,29 @@ static int fscache_attach_object(struct fscache_cookie *cookie,static void fscache_print_cookie (struct fscache_cookie *cookie,char prefix) { -struct hlist_node *object; +struct fscache_object *object; +struct hlist_node *o;const u8 *k;unsigned loop; -pr_err ("%c-cookie c=%p [p=%p fl=%lx nc=%u na=%u]\n" , - prefix, cookie, cookie->parent, cookie->flags, +pr_err ("%c-cookie c=%08x [p=%08x fl=%lx nc=%u na=%u]\n" , + prefix, + cookie->debug_id, + cookie->parent ? cookie->parent->debug_id :0 , + cookie->flags,atomic_read (&cookie->n_children),atomic_read (&cookie->n_active)); -pr_err ("%c-cookie d=%p n=%p\n" , - prefix, cookie->def, cookie->netfs_data); +pr_err ("%c-cookie d=%p{%s} n=%p\n" , + prefix, + cookie->def, + cookie->def ? cookie->def->name :"?" , + cookie->netfs_data); - object =READ_ONCE (cookie->backing_objects.first); -if (object) -pr_err ("%c-cookie o=%p\n" , - prefix, hlist_entry(object, struct fscache_object, cookie_link)); + o =READ_ONCE (cookie->backing_objects.first); +if (o) { + object = hlist_entry(o, struct fscache_object, cookie_link); +pr_err ("%c-cookie o=%u\n" , prefix, object->debug_id); + }pr_err ("%c-key=[%u] '" , prefix, cookie->key_len); k = (cookie->key_len <= sizeof(cookie->inline_key)) ?
@@ -129,6 +137,8 @@ static long fscache_compare_cookie(const struct fscache_cookie *a,return memcmp (ka, kb, a->key_len); } +static atomic_t fscache_cookie_debug_id =ATOMIC_INIT (1 ); +/* * Allocate a cookie. */
@@ -163,6 +173,7 @@ struct fscache_cookie *fscache_alloc_cookie(atomic_set (&cookie->usage,1 );atomic_set (&cookie->n_children,0 ); + cookie->debug_id =atomic_inc_return (&fscache_cookie_debug_id);/* We keep the active count elevated until relinquishment to prevent an * attempt to wake up every time the object operations queue quiesces.
fs/fscache/fsdef.c +1 -0
@@ -45,6 +45,7 @@ static struct fscache_cookie_def fscache_fsdef_index_def = { };struct fscache_cookie fscache_fsdef_index = { + .debug_id =1 , .usage =ATOMIC_INIT (1 ), .n_active =ATOMIC_INIT (1 ), .lock =__SPIN_LOCK_UNLOCKED (fscache_fsdef_index.lock),
fs/fscache/object-list.c +7 -7
@@ -170,7 +170,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)if ((unsigned long ) v ==1 ) {seq_puts (m,"OBJECT PARENT STAT CHLDN OPS OOP IPR EX READS" " EM EV FL S" -" | NETFS_COOKIE_DEF TY FL NETFS_DATA" ); +" | COOKIE NETFS_COOKIE_DEF TY FL NETFS_DATA" );if (config & (FSCACHE_OBJLIST_CONFIG_KEY |FSCACHE_OBJLIST_CONFIG_AUX ))seq_puts (m," " );
@@ -189,7 +189,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v)if ((unsigned long ) v ==2 ) {seq_puts (m,"======== ======== ==== ===== === === === == =====" " == == == =" -" | ================ == == ================" ); +" | ======== ================ == === ================" );if (config & (FSCACHE_OBJLIST_CONFIG_KEY |FSCACHE_OBJLIST_CONFIG_AUX ))seq_puts (m," ================" );
@@ -231,9 +231,9 @@ static int fscache_objlist_show(struct seq_file *m, void *v) } seq_printf(m, - "%8x %8x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ", + "%08x %08x %s %5u %3u %3u %3u %2u %5u %2lx %2lx %2lx %1x | ", obj->debug_id, - obj->parent ? obj->parent->debug_id : -1, + obj->parent ? obj->parent->debug_id : UINT_MAX, obj->state->short_name, obj->n_children, obj->n_ops,
@@ -246,7 +246,7 @@ static int fscache_objlist_show(struct seq_file *m, void *v) obj->flags, work_busy(&obj->work)); -if (fscache_use_cookie (obj)) { +if (obj->cookie) {uint16_t keylen =0 , auxlen =0 ;switch (cookie->type) {
@@ -263,7 +263,8 @@ static int fscache_objlist_show(struct seq_file *m, void *v)break ; } - seq_printf(m, "%-16s %s %2lx %16p", + seq_printf(m, "%08x %-16s %s %3lx %16p", + cookie->debug_id, cookie->def->name, type, cookie->flags,
@@ -292,7 +293,6 @@ static int fscache_objlist_show(struct seq_file *m, void *v) }seq_puts (m,"\n" ); -fscache_unuse_cookie (obj); }else {seq_puts (m,"<no_netfs>\n" ); }
include/linux/fscache.h +1 -0
@@ -126,6 +126,7 @@ struct fscache_cookie {atomic_t usage;/* number of users of this cookie */ atomic_t n_children;/* number of children of this cookie */ atomic_t n_active;/* number of active users of netfs ptrs */ +unsigned int debug_id;spinlock_t lock;spinlock_t stores_lock;/* lock on page store tree */ struct hlist_head backing_objects;/* object(s) backing this file/index */
include/trace/events/cachefiles.h +34 -34
220 lines not on this page · raw message
include/trace/events/fscache.h +58 -58
341 lines not on this page · raw message
Re: [Linux-cachefs] [PATCH v2 04/12] fscache: Add a cookie debug ID and use that in traces
Quoted 13 lines · David Howells
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 thefscache_optracepoint to handle a NULL cookie pointer.
Quoted 7 lines
Signed-off-by David Howells <[email protected]>Reviewed-by Jeff Layton <[email protected]>Link https://lore.kernel.org/r/158861210988.340223.11688464116498247790.stgit@warthog.procyon.org.uk/ # rfc open hereLink https://lore.kernel.org/r/159465769844.1376105.14119502774019865432.stgit@warthog.procyon.org.uk/ open here
Marc
David Howells
maintainerPATCH 5/12 fscache: Procfile to display cookies
In reply to David HowellsAdd /proc/fs/fscache/cookies to display active cookies.
---
fs/fscache/cookie.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fscache/internal.h | 1 fs/fscache/proc.c | 7 +++ include/linux/fscache.h | 1 4 files changed, 112 insertions(+)
fs/fscache/cookie.c +103 -0
@@ -19,6 +19,8 @@ static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);#define fscache_cookie_hash_shift 15static struct hlist_bl_head fscache_cookie_hash[1 << fscache_cookie_hash_shift]; +static LIST_HEAD (fscache_cookies); +static DEFINE_RWLOCK (fscache_cookies_lock);static int fscache_acquire_non_index_cookie (struct fscache_cookie *cookie,loff_t object_size);
@@ -65,6 +67,9 @@ void fscache_free_cookie(struct fscache_cookie *cookie) {if (cookie) {BUG_ON (!hlist_empty (&cookie->backing_objects)); +write_lock (&fscache_cookies_lock); +list_del (&cookie->proc_link); +write_unlock (&fscache_cookies_lock);if (cookie->aux_len >sizeof (cookie->inline_aux))kfree (cookie->aux);if (cookie->key_len >sizeof (cookie->inline_key))
@@ -192,6 +197,10 @@ struct fscache_cookie *fscache_alloc_cookie(/* radix tree insertion won't use the preallocation pool unless it's * told it may not wait */ INIT_RADIX_TREE (&cookie->stores,GFP_NOFS & ~__GFP_DIRECT_RECLAIM); + +write_lock (&fscache_cookies_lock); +list_add_tail (&cookie->proc_link, &fscache_cookies); +write_unlock (&fscache_cookies_lock);return cookie; nomem:
@@ -969,3 +978,97 @@ int __fscache_check_consistency(struct fscache_cookie *cookie,return -ESTALE ; }EXPORT_SYMBOL (__fscache_check_consistency); + +/* +* Generate a list of extant cookies in /proc/fs/fscache/cookies +*/ +static int fscache_cookies_seq_show (struct seq_file *m,void *v) +{ +struct fscache_cookie *cookie; +unsigned int keylen =0 , auxlen =0 ; +char _type[3 ], *type; +u8 *p; + +if (v == &fscache_cookies) { +seq_puts (m, +"COOKIE PARENT USAGE CHILD ACT TY FL DEF NETFS_DATA\n" +"======== ======== ===== ===== === == === ================ ==========\n" + ); +return 0 ; + } + + cookie = list_entry(v, struct fscache_cookie, proc_link); + +switch (cookie->type) { +case 0 : + type ="IX" ; +break ; +case 1 : + type ="DT" ; +break ; +default : +snprintf (_type,sizeof (_type),"%02u" , + cookie->type); + type = _type; +break ; + } + +seq_printf (m, +"%08x %08x %5u %5u %3u %s %03lx %-16s %px" , + cookie->debug_id, + cookie->parent ? cookie->parent->debug_id :0 , +atomic_read (&cookie->usage), +atomic_read (&cookie->n_children), +atomic_read (&cookie->n_active), + type, + cookie->flags, + cookie->def->name, + cookie->netfs_data); + + keylen = cookie->key_len; + auxlen = cookie->aux_len; + +if (keylen >0 || auxlen >0 ) { +seq_puts (m," " ); + p = keylen <=sizeof (cookie->inline_key) ? + cookie->inline_key : cookie->key; +for (; keylen >0 ; keylen--) +seq_printf (m,"%02x" , *p++); +if (auxlen >0 ) { +seq_puts (m,", " ); + p = auxlen <=sizeof (cookie->inline_aux) ? + cookie->inline_aux : cookie->aux; +for (; auxlen >0 ; auxlen--) +seq_printf (m,"%02x" , *p++); + } + } + +seq_puts (m,"\n" ); +return 0 ; +} + +static void *fscache_cookies_seq_start (struct seq_file *m,loff_t *_pos) +__acquires (fscache_cookies_lock) +{ +read_lock (&fscache_cookies_lock); +return seq_list_start_head (&fscache_cookies, *_pos); +} + +static void *fscache_cookies_seq_next (struct seq_file *m,void *v,loff_t *_pos) +{ +return seq_list_next (v, &fscache_cookies, _pos); +} + +static void fscache_cookies_seq_stop (struct seq_file *m,void *v) +__releases (rcu) +{ +read_unlock (&fscache_cookies_lock); +} + + +const struct seq_operations fscache_cookies_seq_ops = { + .start = fscache_cookies_seq_start, + .next = fscache_cookies_seq_next, + .stop = fscache_cookies_seq_stop, + .show = fscache_cookies_seq_show, +};
fs/fscache/internal.h +1 -0
@@ -45,6 +45,7 @@ extern struct fscache_cache *fscache_select_cache_for_object(* cookie.c */ extern struct kmem_cache *fscache_cookie_jar; +extern const struct seq_operations fscache_cookies_seq_ops;extern void fscache_free_cookie (struct fscache_cookie *); extern struct fscache_cookie *fscache_alloc_cookie(struct fscache_cookie *,
fs/fscache/proc.c +7 -0
@@ -21,6 +21,10 @@ int __init fscache_proc_init(void)if (!proc_mkdir ("fs/fscache" ,NULL )) goto error_dir; +if (!proc_create_seq ("fs/fscache/cookies" ,S_IFREG |0444 ,NULL , + &fscache_cookies_seq_ops)) + goto error_cookies; +#ifdef CONFIG_FSCACHE_STATS if (!proc_create_single ("fs/fscache/stats" ,S_IFREG |0444 ,NULL , fscache_stats_show))
@@ -53,6 +57,8 @@ int __init fscache_proc_init(void)remove_proc_entry ("fs/fscache/stats" ,NULL ); error_stats:#endif +remove_proc_entry ("fs/fscache/cookies" ,NULL ); +error_cookies:remove_proc_entry ("fs/fscache" ,NULL ); error_dir:_leave (" = -ENOMEM" );
@@ -73,5 +79,6 @@ void fscache_proc_cleanup(void)#ifdef CONFIG_FSCACHE_STATS remove_proc_entry ("fs/fscache/stats" ,NULL );#endif +remove_proc_entry ("fs/fscache/cookies" ,NULL );remove_proc_entry ("fs/fscache" ,NULL ); }
include/linux/fscache.h +1 -0
@@ -133,6 +133,7 @@ struct fscache_cookie {const struct fscache_cookie_def *def;/* definition */ struct fscache_cookie *parent;/* parent of this entry */ struct hlist_bl_node hash_link;/* Link in hash table */ +struct list_head proc_link;/* Link in proc list */ void *netfs_data;/* back pointer to netfs */ struct radix_tree_root stores;/* pages to be stored on this cookie */ #define FSCACHE_COOKIE_PENDING_TAG 0/* pages tag: pending write to cache */
David Howells
maintainerPATCH 6/12 fscache, cachefiles: Remove the histogram stuff
In reply to David HowellsRemove the histogram stuff as it's mostly going to be outdated.
---
fs/cachefiles/Kconfig | 19 ------- fs/cachefiles/Makefile | 2 - fs/cachefiles/internal.h | 25 --------- fs/cachefiles/main.c | 7 --- fs/cachefiles/namei.c | 13 ----- fs/cachefiles/proc.c | 114 ----------------------------------------- fs/fscache/Kconfig | 17 ------ fs/fscache/Makefile | 1 fs/fscache/histogram.c | 87 ------------------------------- fs/fscache/internal.h | 24 --------- fs/fscache/object.c | 5 -- fs/fscache/operation.c | 3 - fs/fscache/page.c | 6 -- fs/fscache/proc.c | 13 ----- include/linux/fscache-cache.h | 1 15 files changed, 337 deletions(-) delete mode 100644 fs/cachefiles/proc.c delete mode 100644 fs/fscache/histogram.c
fs/cachefiles/Kconfig +0 -19
@@ -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.
fs/cachefiles/Makefile +0 -2
@@ -15,6 +15,4 @@ cachefiles-y := \ security.o \ xattr.o -cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += proc.o - obj-$(CONFIG_CACHEFILES) := cachefiles.o
fs/cachefiles/internal.h +0 -25
@@ -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 */
fs/cachefiles/main.c +0 -7
@@ -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:
@@ -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); }
fs/cachefiles/namei.c +0 -13
@@ -496,7 +496,6 @@ 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;
@@ -535,9 +534,7 @@ 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;
@@ -568,9 +565,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 )
@@ -604,10 +599,8 @@ 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;
@@ -765,7 +758,6 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, const char *dirname) {struct dentry *subdir; -unsigned long start;struct path path;int ret;
@@ -775,9 +767,7 @@ 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;
@@ -876,7 +866,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",
@@ -885,9 +874,7 @@ 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;
fs/cachefiles/proc.c deleted +0 -114
114 lines not on this page · raw message
fs/fscache/Kconfig +0 -17
@@ -29,23 +29,6 @@ config FSCACHE_STATS See Documentation/filesystems/caching/fscache.rst for more information. -config FSCACHE_HISTOGRAM - bool "Gather latency information on local caching" - depends on FSCACHE && PROC_FS - help - This option causes latency information to be gathered on local - caching and exported through file: - - /proc/fs/fscache/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/fscache.rst for more information. - config FSCACHE_DEBUG bool "Debug FS-Cache" depends on FSCACHE
fs/fscache/Makefile +0 -1
@@ -16,7 +16,6 @@ fscache-y := \ fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o -fscache-$(CONFIG_FSCACHE_HISTOGRAM) += histogram.o fscache-$(CONFIG_FSCACHE_OBJECT_LIST) += object-list.o obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/histogram.c deleted +0 -87
87 lines not on this page · raw message
fs/fscache/internal.h +0 -24
@@ -63,30 +63,6 @@ extern void fscache_cookie_put(struct fscache_cookie *,extern struct fscache_cookie fscache_fsdef_index;extern struct fscache_cookie_def fscache_fsdef_netfs_def; -/* -* histogram.c -*/ -#ifdef CONFIG_FSCACHE_HISTOGRAM -extern atomic_t fscache_obj_instantiate_histogram[HZ ]; -extern atomic_t fscache_objs_histogram[HZ ]; -extern atomic_t fscache_ops_histogram[HZ ]; -extern atomic_t fscache_retrieval_delay_histogram[HZ ]; -extern atomic_t fscache_retrieval_histogram[HZ ]; - -static inline void fscache_hist (atomic_t histogram[],unsigned long start_jif) -{ -unsigned long jif = jiffies - start_jif; -if (jif >=HZ ) - jif =HZ -1 ; -atomic_inc (&histogram[jif]); -} - -extern const struct seq_operations fscache_histogram_ops; - -#else -#define fscache_hist (hist, start_jif) do {} while (0) -#endif -/* * main.c */
fs/fscache/object.c +0 -5
@@ -277,13 +277,10 @@ static void fscache_object_work_func(struct work_struct *work) {struct fscache_object *object = container_of(work, struct fscache_object, work); -unsigned long start;_enter ("{OBJ%x}" , object->debug_id); - start = jiffies;fscache_object_sm_dispatcher (object); -fscache_hist (fscache_objs_histogram, start);fscache_put_object (object, fscache_obj_put_work); }
@@ -436,7 +433,6 @@ static const struct fscache_state *fscache_parent_ready(struct fscache_object *ospin_lock (&parent->lock); parent->n_ops++; parent->n_obj_ops++; - object->lookup_jif = jiffies;spin_unlock (&parent->lock);_leave ("" );
@@ -596,7 +592,6 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec object->cache->ops->lookup_complete (object);fscache_stat_d (&fscache_n_cop_lookup_complete); -fscache_hist (fscache_obj_instantiate_histogram, object->lookup_jif);fscache_stat (&fscache_n_object_avail);_leave ("" );
fs/fscache/operation.c +0 -3
@@ -616,7 +616,6 @@ void fscache_op_work_func(struct work_struct *work) {struct fscache_operation *op = container_of(work, struct fscache_operation, work); -unsigned long start;_enter ("{OBJ%x OP%x,%d}" , op->object->debug_id, op->debug_id,atomic_read (&op->usage));
@@ -624,9 +623,7 @@ void fscache_op_work_func(struct work_struct *work)trace_fscache_op (op->object->cookie, op, fscache_op_work);ASSERT (op->processor !=NULL ); - start = jiffies; op->processor (op); -fscache_hist (fscache_ops_histogram, start);fscache_put_operation (op);_leave ("" );
fs/fscache/page.c +0 -6
@@ -289,7 +289,6 @@ static void fscache_release_retrieval_op(struct fscache_operation *_op)ASSERTIFCMP (op->op.state !=FSCACHE_OP_ST_INITIALISED , atomic_read(&op->n_pages), ==, 0); -fscache_hist (fscache_retrieval_histogram, op->start_time);if (op->context)fscache_put_context (op->cookie, op->context);
@@ -324,7 +323,6 @@ struct fscache_retrieval *fscache_alloc_retrieval( op->mapping = mapping; op->end_io_func = end_io_func; op->context = context; - op->start_time = jiffies;INIT_LIST_HEAD (&op->to_do);/* Pin the netfs read context in case we need to do the actual netfs
@@ -340,8 +338,6 @@ struct fscache_retrieval *fscache_alloc_retrieval(*/ int fscache_wait_for_deferred_lookup (struct fscache_cookie *cookie) { -unsigned long jif; -_enter ("" );if (!test_bit (FSCACHE_COOKIE_LOOKING_UP , &cookie->flags)) {
@@ -351,7 +347,6 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)fscache_stat (&fscache_n_retrievals_wait); - jif = jiffies;if (wait_on_bit (&cookie->flags,FSCACHE_COOKIE_LOOKING_UP ,TASK_INTERRUPTIBLE ) !=0 ) {fscache_stat (&fscache_n_retrievals_intr);
@@ -362,7 +357,6 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)ASSERT (!test_bit (FSCACHE_COOKIE_LOOKING_UP , &cookie->flags));smp_rmb (); -fscache_hist (fscache_retrieval_delay_histogram, jif);_leave (" = 0 [dly]" );return 0 ; }
fs/fscache/proc.c +0 -13
@@ -31,12 +31,6 @@ int __init fscache_proc_init(void) goto error_stats;#endif -#ifdef CONFIG_FSCACHE_HISTOGRAM -if (!proc_create_seq ("fs/fscache/histogram" ,S_IFREG |0444 ,NULL , - &fscache_histogram_ops)) - goto error_histogram; -#endif -#ifdef CONFIG_FSCACHE_OBJECT_LIST if (!proc_create ("fs/fscache/objects" ,S_IFREG |0444 ,NULL , &fscache_objlist_proc_ops))
@@ -49,10 +43,6 @@ int __init fscache_proc_init(void)#ifdef CONFIG_FSCACHE_OBJECT_LIST error_objects:#endif -#ifdef CONFIG_FSCACHE_HISTOGRAM -remove_proc_entry ("fs/fscache/histogram" ,NULL ); -error_histogram: -#endif #ifdef CONFIG_FSCACHE_STATS remove_proc_entry ("fs/fscache/stats" ,NULL ); error_stats:
@@ -73,9 +63,6 @@ void fscache_proc_cleanup(void)#ifdef CONFIG_FSCACHE_OBJECT_LIST remove_proc_entry ("fs/fscache/objects" ,NULL );#endif -#ifdef CONFIG_FSCACHE_HISTOGRAM -remove_proc_entry ("fs/fscache/histogram" ,NULL ); -#endif #ifdef CONFIG_FSCACHE_STATS remove_proc_entry ("fs/fscache/stats" ,NULL );#endif
include/linux/fscache-cache.h +0 -1
@@ -147,7 +147,6 @@ struct fscache_retrieval {fscache_rw_complete_t end_io_func;/* function to call on I/O completion */ void *context;/* netfs read context (pinned) */ struct list_head to_do;/* list of things to be done by the backend */ -unsigned long start_time;/* time at which retrieval started */ atomic_t n_pages;/* number of pages to be retrieved */ };
David Howells
maintainerPATCH 7/12 fscache: Remove the object list procfile
In reply to David HowellsRemove the object list procfile from fscache as objects will become entirely internal to the cache.
---
fs/fscache/Kconfig | 7 - fs/fscache/Makefile | 1 fs/fscache/cache.c | 1 fs/fscache/cookie.c | 2 fs/fscache/internal.h | 13 - fs/fscache/object-list.c | 414 ----------------------------------------- fs/fscache/object.c | 2 include/linux/fscache-cache.h | 3 8 files changed, 443 deletions(-) delete mode 100644 fs/fscache/object-list.c
fs/fscache/Kconfig +0 -7
@@ -38,10 +38,3 @@ config FSCACHE_DEBUG enabled by setting bits in /sys/modules/fscache/parameter/debug. See Documentation/filesystems/caching/fscache.rst for more information. - -config FSCACHE_OBJECT_LIST - bool "Maintain global object list for debugging purposes" - depends on FSCACHE && PROC_FS - help - Maintain a global list of active fscache objects that can be - retrieved through /proc/fs/fscache/objects for debugging purposes
fs/fscache/Makefile +0 -1
@@ -16,6 +16,5 @@ fscache-y := \ fscache-$(CONFIG_PROC_FS) += proc.o fscache-$(CONFIG_FSCACHE_STATS) += stats.o -fscache-$(CONFIG_FSCACHE_OBJECT_LIST) += object-list.o obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/cache.c +0 -1
@@ -261,7 +261,6 @@ int fscache_add_cache(struct fscache_cache *cache,spin_lock (&cache->object_list_lock);list_add_tail (&ifsdef->cache_link, &cache->object_list);spin_unlock (&cache->object_list_lock); -fscache_objlist_add (ifsdef);/* add the cache's netfs definition index object to the top level index * cookie as a known backing object */
fs/fscache/cookie.c +0 -2
@@ -620,8 +620,6 @@ static int fscache_attach_object(struct fscache_cookie *cookie,/* Attach to the cookie. The object already has a ref on it. */ hlist_add_head (&object->cookie_link, &cookie->backing_objects); - -fscache_objlist_add (object); ret =0 ; cant_attach_object:
fs/fscache/internal.h +0 -13
@@ -84,19 +84,6 @@ static inline bool fscache_object_congested(void)*/ extern void fscache_enqueue_object (struct fscache_object *); -/* -* object-list.c -*/ -#ifdef CONFIG_FSCACHE_OBJECT_LIST -extern const struct proc_ops fscache_objlist_proc_ops; - -extern void fscache_objlist_add (struct fscache_object *); -extern void fscache_objlist_remove (struct fscache_object *); -#else -#define fscache_objlist_add (object) do {} while(0) -#define fscache_objlist_remove (object) do {} while(0) -#endif -/* * operation.c */
fs/fscache/object-list.c deleted +0 -414
414 lines not on this page · raw message
fs/fscache/object.c +0 -2
@@ -794,8 +794,6 @@ static void fscache_put_object(struct fscache_object *object,*/ void fscache_object_destroy (struct fscache_object *object) { -fscache_objlist_remove (object); -/* We can get rid of the cookie now */ fscache_cookie_put (object->cookie, fscache_cookie_put_object); object->cookie =NULL ;
include/linux/fscache-cache.h +0 -3
@@ -384,9 +384,6 @@ struct fscache_object {struct list_head dependents;/* FIFO of dependent objects */ struct list_head dep_link;/* link in parent's dependents list */ struct list_head pending_ops;/* unstarted operations on this object */ -#ifdef CONFIG_FSCACHE_OBJECT_LIST -struct rb_node objlist_link;/* link in global object list */ -#endif pgoff_t store_limit;/* current storage limit */ loff_t store_limit_l;/* current storage limit */ };
David Howells
maintainerPATCH 8/12 fscache: Change %p in format strings to something else
In reply to David HowellsChange plain %p in format strings in fscache code to something more useful, since %p is now hashed before printing and thus no longer matches the contents of an oops register dump.
---
fs/fscache/cache.c | 8 ++++---- fs/fscache/cookie.c | 16 +++++++--------- fs/fscache/object.c | 1 - 3 files changed, 11 insertions(+), 14 deletions(-)
fs/fscache/cache.c +4 -4
@@ -116,7 +116,7 @@ struct fscache_cache *fscache_select_cache_for_object( cache =NULL ;spin_unlock (&cookie->lock); -_leave (" = %p [parent]" , cache); +_leave (" = %s [parent]" , cache ? cache->tag->name :"NULL" );return cache; }
@@ -152,14 +152,14 @@ struct fscache_cache *fscache_select_cache_for_object(if (test_bit (FSCACHE_IOERROR , &tag->cache->flags))return NULL ; -_leave (" = %p [specific]" , tag->cache); +_leave (" = %s [specific]" , tag->name);return tag->cache; no_preference:/* netfs has no preference - just select first cache */ cache =list_entry (fscache_cache_list.next, struct fscache_cache, link); -_leave (" = %p [first]" , cache); +_leave (" = %s [first]" , cache->tag->name);return cache; }
@@ -334,7 +334,7 @@ static void fscache_withdraw_all_objects(struct fscache_cache *cache, struct fscache_object, cache_link);list_move_tail (&object->cache_link, dying_objects); -_debug ("withdraw %p" , object->cookie); +_debug ("withdraw %x" , object->cookie->debug_id);/* This must be done under object_list_lock to prevent * a race with fscache_drop_object().
fs/fscache/cookie.c +7 -9
@@ -375,7 +375,7 @@ void __fscache_enable_cookie(struct fscache_cookie *cookie,bool (*can_enable)(void *data), void *data) { - _enter("%p", cookie); + _enter("%x", cookie->debug_id);trace_fscache_enable (cookie);
@@ -472,10 +472,8 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie,/* we may be required to wait for lookup to complete at this point */ if (!fscache_defer_lookup) { -_debug ("non-deferred lookup %p" , &cookie->flags);wait_on_bit (&cookie->flags,FSCACHE_COOKIE_LOOKING_UP ,TASK_UNINTERRUPTIBLE ); -_debug ("complete" );if (test_bit (FSCACHE_COOKIE_UNAVAILABLE , &cookie->flags)) goto unavailable; }
@@ -500,7 +498,7 @@ static int fscache_alloc_object(struct fscache_cache *cache,struct fscache_object *object;int ret; -_enter ("%p,%p{%s}" , cache, cookie, cookie->def->name); +_enter ("%s,%x{%s}" , cache->tag->name, cookie->debug_id, cookie->def->name);spin_lock (&cookie->lock); hlist_for_each_entry(object, &cookie->backing_objects,
@@ -676,7 +674,7 @@ EXPORT_SYMBOL(__fscache_invalidate);*/ void __fscache_wait_on_invalidate (struct fscache_cookie *cookie) { -_enter ("%p" , cookie); +_enter ("%x" , cookie->debug_id);wait_on_bit (&cookie->flags,FSCACHE_COOKIE_INVALIDATING ,TASK_UNINTERRUPTIBLE );
@@ -731,7 +729,7 @@ void __fscache_disable_cookie(struct fscache_cookie *cookie,struct fscache_object *object;bool awaken = false; -_enter ("%p,%u" , cookie, invalidate); +_enter ("%x,%u" , cookie->debug_id, invalidate);trace_fscache_disable (cookie);
@@ -821,8 +819,8 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie,return ; } -_enter ("%p{%s,%p,%d},%d" , - cookie, cookie->def->name, cookie->netfs_data, +_enter ("%x{%s,%d},%d" , + cookie->debug_id, cookie->def->name,atomic_read (&cookie->n_active), retire);trace_fscache_relinquish (cookie, retire);
@@ -877,7 +875,7 @@ void fscache_cookie_put(struct fscache_cookie *cookie,struct fscache_cookie *parent;int usage; -_enter ("%p" , cookie); +_enter ("%x" , cookie->debug_id); do { usage = atomic_dec_return(&cookie->usage);
fs/fscache/object.c +0 -1
@@ -518,7 +518,6 @@ void fscache_object_lookup_negative(struct fscache_object *object)set_bit (FSCACHE_COOKIE_NO_DATA_YET , &cookie->flags);clear_bit (FSCACHE_COOKIE_UNAVAILABLE , &cookie->flags); -_debug ("wake up lookup %p" , &cookie->flags);clear_bit_unlock (FSCACHE_COOKIE_LOOKING_UP , &cookie->flags);wake_up_bit (&cookie->flags,FSCACHE_COOKIE_LOOKING_UP ); }
David Howells
maintainerPATCH 9/12 cachefiles: Change %p in format strings to something else
In reply to David HowellsChange plain %p in format strings in cachefiles code to something more useful, since %p is now hashed before printing and thus no longer matches the contents of an oops register dump.
---
fs/cachefiles/bind.c | 2 -- fs/cachefiles/interface.c | 6 +++--- fs/cachefiles/key.c | 2 +- fs/cachefiles/namei.c | 48 +++++++++++++++++++++------------------------ fs/cachefiles/xattr.c | 4 ++-- 5 files changed, 28 insertions(+), 34 deletions(-)
fs/cachefiles/bind.c +0 -2
@@ -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 )
fs/cachefiles/interface.c +3 -3
@@ -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)
@@ -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:
@@ -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);
fs/cachefiles/key.c +1 -1
@@ -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; }
fs/cachefiles/namei.c +22 -26
137 lines not on this page · raw message
fs/cachefiles/xattr.c +2 -2
@@ -36,7 +36,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object)else snprintf (type,3 ,"%02x" , object->fscache.cookie->def->type); -_enter ("%p{%s}" , object, type); +_enter ("%x{%s}" , object->fscache.debug_id, type);/* attempt to install a type label directly */ ret = vfs_setxattr(&init_user_ns, dentry, cachefiles_xattr_cache, type,
@@ -134,7 +134,7 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,if (!dentry)return -ESTALE ; -_enter ("%p,#%d" , object, auxdata->len); +_enter ("%x,#%d" , object->fscache.debug_id, auxdata->len);/* attempt to install the cache metadata directly */ _debug ("SET #%u" , auxdata->len);
David Howells
maintainerPATCH 10/12 fscache: Fix cookie key hashing
In reply to David HowellsThe current hash algorithm used for hashing cookie keys is really bad, producing almost no dispersion (after a test kernel build, ~30000 files were split over just 18 out of the 32768 hash buckets).
Borrow the full_name_hash() hash function into fscache to do the hashing for cookie keys and, in the future, volume keys.
I don't want to use full_name_hash() as-is because I want the hash value to be consistent across arches and over time as the hash value produced may get used on disk.
I can also optimise parts of it away as the key will always be a padded array of aligned 32-bit words.
---
fs/fscache/cookie.c | 14 +------------- fs/fscache/internal.h | 2 ++ fs/fscache/main.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-)
fs/fscache/cookie.c +1 -13
@@ -87,10 +87,8 @@ void fscache_free_cookie(struct fscache_cookie *cookie)static int fscache_set_key (struct fscache_cookie *cookie,const void *index_key,size_t index_key_len) { -unsigned long long h;u32 *buf;int bufs; -int i; bufs =DIV_ROUND_UP (index_key_len,sizeof (*buf));
@@ -104,17 +102,7 @@ static int fscache_set_key(struct fscache_cookie *cookie, }memcpy (buf, index_key, index_key_len); - -/* Calculate a hash and combine this with the length in the first word -* or first half word -*/ - h = (unsigned long )cookie->parent; - h += index_key_len + cookie->type; - -for (i =0 ; i < bufs; i++) - h += buf[i]; - - cookie->key_hash = h ^ (h >>32 ); + cookie->key_hash =fscache_hash (0 , buf, bufs);return 0 ; }
fs/fscache/internal.h +2 -0
@@ -74,6 +74,8 @@ extern struct workqueue_struct *fscache_object_wq;extern struct workqueue_struct *fscache_op_wq;DECLARE_PER_CPU (wait_queue_head_t, fscache_object_cong_wait); +extern unsigned int fscache_hash (unsigned int salt,unsigned int *data,unsigned int n); +static inline bool fscache_object_congested (void ) {return workqueue_congested (WORK_CPU_UNBOUND , fscache_object_wq);
fs/fscache/main.c +39 -0
@@ -93,6 +93,45 @@ static struct ctl_table fscache_sysctls_root[] = { };#endif +/* +* Mixing scores (in bits) for (7,20): +* Input delta: 1-bit 2-bit +* 1 round: 330.3 9201.6 +* 2 rounds: 1246.4 25475.4 +* 3 rounds: 1907.1 31295.1 +* 4 rounds: 2042.3 31718.6 +* Perfect: 2048 31744 +* (32*64) (32*31/2 * 64) +*/ +#define HASH_MIX (x, y, a) \ + ( x ^= (a), \ + y ^= x, x = rol32(x, 7),\ + x += y, y = rol32(y,20),\ + y *= 9 ) + +static inline unsigned int fold_hash (unsigned long x,unsigned long y) +{ +/* Use arch-optimized multiply if one exists */ +return __hash_32 (y ^__hash_32 (x)); +} + +/* +* Generate a hash. This is derived from full_name_hash(), but we want to be +* sure it is arch independent and that it doesn't change as bits of the +* computed hash value might appear on disk. The caller also guarantees that +* the hashed data will be a series of aligned 32-bit words. +*/ +unsigned int fscache_hash (unsigned int salt,unsigned int *data,unsigned int n) +{ +unsigned int a, x =0 , y = salt; + +for (; n; n--) { + a = *data++; +HASH_MIX (x, y, a); + } +return fold_hash (x, y); +} +/* * initialise the fs caching module */
Re: [PATCH 10/12] fscache: Fix cookie key hashing
Quoted 11 lines · David Howells
The current hash algorithm used for hashing cookie keys is really bad, producing almost no dispersion (after a test kernel build, ~30000 files were split over just 18 out of the 32768 hash buckets).
Borrow the
full_name_hash()hash function into fscache to do the hashing for cookie keys and, in the future, volume keys.I don't want to use
full_name_hash()as-is because I want the hash value to be consistent across arches and over time as the hash value produced may get used on disk.
Quoted 6 lines
I can also optimise parts of it away as the key will always be a padded array of aligned 32-bit words.
Signed-off-by David Howells <[email protected]>---
What happens when this patch encounters a cache that was built before it? Do you need to couple this with some sort of global cache invalidation or rehashing event?
Quoted 104 lines
fs/fscache/cookie.c | 14 +------------- fs/fscache/internal.h | 2 ++ fs/fscache/main.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 13 deletions(-)fs/fscache/cookie.c +1
-13@@ -87,10 +87,8 @@ void fscache_free_cookie(struct fscache_cookie *cookie)static int fscache_set_key (struct fscache_cookie *cookie,const void *index_key,size_t index_key_len) { -unsigned long long h;u32 *buf;int bufs; -int i; bufs =DIV_ROUND_UP (index_key_len,sizeof (*buf));@@ -104,17 +102,7 @@ static int fscache_set_key(struct fscache_cookie *cookie, }memcpy (buf, index_key, index_key_len); - -/* Calculate a hash and combine this with the length in the first word -* or first half word -*/ - h = (unsigned long )cookie->parent; - h += index_key_len + cookie->type; - -for (i =0 ; i < bufs; i++) - h += buf[i]; - - cookie->key_hash = h ^ (h >>32 ); + cookie->key_hash =fscache_hash (0 , buf, bufs);return 0 ; }fs/fscache/internal.h +2
-0@@ -74,6 +74,8 @@ extern struct workqueue_struct *fscache_object_wq;extern struct workqueue_struct *fscache_op_wq;DECLARE_PER_CPU (wait_queue_head_t, fscache_object_cong_wait); +extern unsigned int fscache_hash (unsigned int salt,unsigned int *data,unsigned int n); +static inline bool fscache_object_congested (void ) {return workqueue_congested (WORK_CPU_UNBOUND , fscache_object_wq);fs/fscache/main.c +39
-0@@ -93,6 +93,45 @@ static struct ctl_table fscache_sysctls_root[] = { };#endif +/* +* Mixing scores (in bits) for (7,20): +* Input delta: 1-bit 2-bit +* 1 round: 330.3 9201.6 +* 2 rounds: 1246.4 25475.4 +* 3 rounds: 1907.1 31295.1 +* 4 rounds: 2042.3 31718.6 +* Perfect: 2048 31744 +* (32*64) (32*31/2 * 64) +*/ +#define HASH_MIX (x, y, a) \ + ( x ^= (a), \ + y ^= x, x = rol32(x, 7),\ + x += y, y = rol32(y,20),\ + y *= 9 ) + +static inline unsigned int fold_hash (unsigned long x,unsigned long y) +{ +/* Use arch-optimized multiply if one exists */ +return __hash_32 (y ^__hash_32 (x)); +} + +/* +* Generate a hash. This is derived from full_name_hash(), but we want to be +* sure it is arch independent and that it doesn't change as bits of the +* computed hash value might appear on disk. The caller also guarantees that +* the hashed data will be a series of aligned 32-bit words. +*/ +unsigned int fscache_hash (unsigned int salt,unsigned int *data,unsigned int n) +{ +unsigned int a, x =0 , y = salt; + +for (; n; n--) { + a = *data++; +HASH_MIX (x, y, a); + } +return fold_hash (x, y); +} +/* * initialise the fs caching module */
Signature · 1 line
Jeff Layton <[email protected]>
David Howells
maintainerRe: [PATCH 10/12] fscache: Fix cookie key hashing
Quoted 3 lines · Jeff Layton
What happens when this patch encounters a cache that was built before it? Do you need to couple this with some sort of global cache invalidation or rehashing event?
At the moment, nothing. cachefiles generates a second hash value, but doing so is a duplication of effort.
David
David Howells
maintainerPATCH 11/12 fscache: Fix fscache_cookie_put() to not deref after dec
In reply to David Howellsfscache_cookie_put() accesses the cookie it has just put inside the tracepoint that monitors the change - but this is something it's not allowed to do if we didn't reduce the count to zero.
Fix this by dropping most of those values from the tracepoint and grabbing the cookie debug ID before doing the dec.
Also take the opportunity to switch over the usage and where arguments on the tracepoint to put the reason last.
---
fs/fscache/cookie.c | 10 ++++++---- fs/fscache/internal.h | 2 +- fs/fscache/netfs.c | 2 +- include/trace/events/fscache.h | 24 +++++++----------------- 4 files changed, 15 insertions(+), 23 deletions(-)
fs/fscache/cookie.c +6 -4
@@ -225,8 +225,8 @@ struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate) collision:if (test_and_set_bit (FSCACHE_COOKIE_ACQUIRED , &cursor->flags)) { -trace_fscache_cookie (cursor, fscache_cookie_collision, -atomic_read (&cursor->usage)); +trace_fscache_cookie (cursor->debug_id,atomic_read (&cursor->usage), + fscache_cookie_collision);pr_err ("Duplicate cookie detected\n" );fscache_print_cookie (cursor,'O' );fscache_print_cookie (candidate,'N' );
@@ -305,7 +305,8 @@ struct fscache_cookie *__fscache_acquire_cookie( cookie =fscache_hash_cookie (candidate);if (!cookie) { -trace_fscache_cookie (candidate, fscache_cookie_discard,1 ); +trace_fscache_cookie (candidate->debug_id,1 , + fscache_cookie_discard); goto out; }
@@ -866,8 +867,9 @@ void fscache_cookie_put(struct fscache_cookie *cookie,_enter ("%x" , cookie->debug_id); do { + unsigned int cookie_debug_id = cookie->debug_id; usage = atomic_dec_return(&cookie->usage); - trace_fscache_cookie(cookie, where, usage); + trace_fscache_cookie(cookie_debug_id, usage, where); if (usage > 0) return;
fs/fscache/internal.h +1 -1
@@ -291,7 +291,7 @@ static inline void fscache_cookie_get(struct fscache_cookie *cookie, {int usage =atomic_inc_return (&cookie->usage); -trace_fscache_cookie (cookie, where, usage); +trace_fscache_cookie (cookie->debug_id, usage, where); }/*
fs/fscache/netfs.c +1 -1
@@ -37,7 +37,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)if (!cookie) goto already_registered;if (cookie != candidate) { -trace_fscache_cookie (candidate, fscache_cookie_discard,1 ); +trace_fscache_cookie (candidate->debug_id,1 , fscache_cookie_discard);fscache_free_cookie (candidate); }
include/trace/events/fscache.h +7 -17
@@ -160,37 +160,27 @@ fscache_cookie_traces;TRACE_EVENT (fscache_cookie, - TP_PROTO(struct fscache_cookie *cookie, - enum fscache_cookie_trace where, - int usage), + TP_PROTO(unsigned int cookie_debug_id, + int usage, + enum fscache_cookie_trace where), -TP_ARGS (cookie, where, usage), +TP_ARGS (cookie_debug_id, usage, where),TP_STRUCT__entry ( __field(unsigned int, cookie ) - __field(unsigned int, parent ) __field(enum fscache_cookie_trace, where )__field (int, usage ) - __field(int, n_children ) - __field(int, n_active ) -__field (u8, flags ) ),TP_fast_assign ( - __entry->cookie = cookie->debug_id; - __entry->parent = cookie->parent ? cookie->parent->debug_id : 0; + __entry->cookie = cookie_debug_id; __entry->where = where; __entry->usage = usage; - __entry->n_children = atomic_read(&cookie->n_children); - __entry->n_active = atomic_read(&cookie->n_active); - __entry->flags = cookie->flags; ), -TP_printk ("%s c=%08x u=%d p=%08x Nc=%d Na=%d f=%02x" , +TP_printk ("%s c=%08x u=%d" ,__print_symbolic (__entry->where, fscache_cookie_traces), - __entry->cookie, __entry->usage, - __entry->parent, __entry->n_children, __entry->n_active, - __entry->flags) + __entry->cookie, __entry->usage) ); TRACE_EVENT(fscache_netfs,
Re: [PATCH 11/12] fscache: Fix fscache_cookie_put() to not deref after dec
Quoted 3 lines · David Howells
fscache_cookie_put()accesses the cookie it has just put inside the tracepoint that monitors the change - but this is something it's not allowed to do if we didn't reduce the count to zero.
Do you mean "if the count went to zero." ?
Quoted 119 lines
Fix this by dropping most of those values from the tracepoint and grabbing the cookie debug ID before doing the dec.
Also take the opportunity to switch over the usage and where arguments on the tracepoint to put the reason last.
Signed-off-by David Howells <[email protected]>---
fs/fscache/cookie.c | 10 ++++++---- fs/fscache/internal.h | 2 +- fs/fscache/netfs.c | 2 +- include/trace/events/fscache.h | 24 +++++++----------------- 4 files changed, 15 insertions(+), 23 deletions(-)fs/fscache/cookie.c +6
-4@@ -225,8 +225,8 @@ struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate) collision:if (test_and_set_bit (FSCACHE_COOKIE_ACQUIRED , &cursor->flags)) { -trace_fscache_cookie (cursor, fscache_cookie_collision, -atomic_read (&cursor->usage)); +trace_fscache_cookie (cursor->debug_id,atomic_read (&cursor->usage), + fscache_cookie_collision);pr_err ("Duplicate cookie detected\n" );fscache_print_cookie (cursor,'O' );fscache_print_cookie (candidate,'N' );@@ -305,7 +305,8 @@ struct fscache_cookie *__fscache_acquire_cookie( cookie =fscache_hash_cookie (candidate);if (!cookie) { -trace_fscache_cookie (candidate, fscache_cookie_discard,1 ); +trace_fscache_cookie (candidate->debug_id,1 , + fscache_cookie_discard); goto out; }@@ -866,8 +867,9 @@ void fscache_cookie_put(struct fscache_cookie *cookie,_enter ("%x" , cookie->debug_id); do { + unsigned int cookie_debug_id = cookie->debug_id; usage = atomic_dec_return(&cookie->usage); - trace_fscache_cookie(cookie, where, usage); + trace_fscache_cookie(cookie_debug_id, usage, where); if (usage > 0) return;fs/fscache/internal.h +1
-1@@ -291,7 +291,7 @@ static inline void fscache_cookie_get(struct fscache_cookie *cookie, {int usage =atomic_inc_return (&cookie->usage); -trace_fscache_cookie (cookie, where, usage); +trace_fscache_cookie (cookie->debug_id, usage, where); }/* fs/fscache/netfs.c +1
-1@@ -37,7 +37,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)if (!cookie) goto already_registered;if (cookie != candidate) { -trace_fscache_cookie (candidate, fscache_cookie_discard,1 ); +trace_fscache_cookie (candidate->debug_id,1 , fscache_cookie_discard);fscache_free_cookie (candidate); }include/trace/events/fscache.h +5
-13@@ -160,37 +160,27 @@ fscache_cookie_traces; TRACE_EVENT(fscache_cookie, - TP_PROTO(struct fscache_cookie *cookie, - enum fscache_cookie_trace where, - int usage), + TP_PROTO(unsigned int cookie_debug_id, + int usage, + enum fscache_cookie_trace where), - TP_ARGS(cookie, where, usage), + TP_ARGS(cookie_debug_id, usage, where), TP_STRUCT__entry( __field(unsigned int, cookie ) - __field(unsigned int, parent ) __field(enum fscache_cookie_trace, where ) __field(int, usage ) - __field(int, n_children ) - __field(int, n_active ) - __field(u8, flags ) ), TP_fast_assign( - __entry->cookie = cookie->debug_id; - __entry->parent = cookie->parent ? cookie->parent->debug_id : 0; + __entry->cookie = cookie_debug_id; __entry->where = where; __entry->usage = usage; - __entry->n_children = atomic_read(&cookie->n_children); - __entry->n_active = atomic_read(&cookie->n_active); - __entry->flags = cookie->flags; ),
include/trace/events/fscache.h fscache_cookie_traces; · line 186
Quoted 10 lines
include/trace/events/fscache.h +2
-4-TP_printk ("%s c=%08x u=%d p=%08x Nc=%d Na=%d f=%02x" , +TP_printk ("%s c=%08x u=%d" ,__print_symbolic (__entry->where, fscache_cookie_traces), - __entry->cookie, __entry->usage, - __entry->parent, __entry->n_children, __entry->n_active, - __entry->flags) + __entry->cookie, __entry->usage) ); TRACE_EVENT(fscache_netfs,
Patch itself looks fine though.
Signature · 1 line
Jeff Layton <[email protected]>
David Howells
maintainerRe: [PATCH 11/12] fscache: Fix fscache_cookie_put() to not deref after dec
Quoted 5 lines · Jeff Layton
Quoted 3 lines
fscache_cookie_put()accesses the cookie it has just put inside the tracepoint that monitors the change - but this is something it's not allowed to do if we didn't reduce the count to zero.Do you mean "if the count went to zero." ?
No. If *we* reduced the count to zero, it falls to us to destroy the object, so we're allowed to look into it again.
If we didn't reduce the count to zero, then someone else might destroy it before we look into it again.
David
David Howells
maintainerPATCH 12/12 fscache: Use refcount_t for the cookie refcount instead of atomic_t
In reply to David HowellsUse 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".
---
fs/fscache/cache.c | 2 +- fs/fscache/cookie.c | 31 +++++++++++++++++++--------- fs/fscache/fsdef.c | 2 +- fs/fscache/internal.h | 17 ++++++++------- include/linux/fscache.h | 2 +- include/trace/events/fscache.h | 44 ++++++++++++++++++++-------------------- 6 files changed, 55 insertions(+), 43 deletions(-)
fs/fscache/cache.c +1 -1
@@ -269,7 +269,7 @@ int fscache_add_cache(struct fscache_cache *cache,hlist_add_head (&ifsdef->cookie_link, &fscache_fsdef_index.backing_objects); -atomic_inc (&fscache_fsdef_index.usage); +refcount_inc (&fscache_fsdef_index.ref);/* done */ spin_unlock (&fscache_fsdef_index.lock);
fs/fscache/cookie.c +21 -10
@@ -164,7 +164,7 @@ struct fscache_cookie *fscache_alloc_cookie( goto nomem; } -atomic_set (&cookie->usage,1 ); +refcount_set (&cookie->ref,1 );atomic_set (&cookie->n_children,0 ); cookie->debug_id =atomic_inc_return (&fscache_cookie_debug_id);
@@ -225,7 +225,7 @@ struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate) collision:if (test_and_set_bit (FSCACHE_COOKIE_ACQUIRED , &cursor->flags)) { -trace_fscache_cookie (cursor->debug_id,atomic_read (&cursor->usage), +trace_fscache_cookie (cursor->debug_id,refcount_read (&cursor->ref), fscache_cookie_collision);pr_err ("Duplicate cookie detected\n" );fscache_print_cookie (cursor,'O' );
@@ -826,13 +826,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie,BUG_ON (!radix_tree_empty (&cookie->stores));if (cookie->parent) { - ASSERTCMP(atomic_read(&cookie->parent->usage), >, 0); + ASSERTCMP(refcount_read(&cookie->parent->ref), >, 0); ASSERTCMP(atomic_read(&cookie->parent->n_children), >, 0);atomic_dec (&cookie->parent->n_children); }/* Dispose of the netfs's link to the cookie */ - ASSERTCMP(atomic_read(&cookie->usage), >, 0);fscache_cookie_put (cookie, fscache_cookie_put_relinquish);_leave ("" );
@@ -862,18 +861,17 @@ void fscache_cookie_put(struct fscache_cookie *cookie, enum fscache_cookie_trace where) {struct fscache_cookie *parent; -int usage; +int ref;_enter ("%x" , cookie->debug_id); do { unsigned int cookie_debug_id = cookie->debug_id; - usage = atomic_dec_return(&cookie->usage); - trace_fscache_cookie(cookie_debug_id, usage, where); + bool zero = __refcount_dec_and_test(&cookie->ref, &ref); - if (usage > 0) + trace_fscache_cookie(cookie_debug_id, ref - 1, where); + if (!zero) return; - BUG_ON(usage < 0); parent = cookie->parent; fscache_unhash_cookie(cookie);
@@ -886,6 +884,19 @@ void fscache_cookie_put(struct fscache_cookie *cookie,_leave ("" ); } +/* +* Get a reference to a cookie. +*/ +struct fscache_cookie *fscache_cookie_get (struct fscache_cookie *cookie, +enum fscache_cookie_trace where) +{ +int ref; + +__refcount_inc (&cookie->ref, &ref); +trace_fscache_cookie (cookie->debug_id, ref +1 , where); +return cookie; +} +/* * check the consistency between the netfs inode and the backing cache *
@@ -1003,7 +1014,7 @@ static int fscache_cookies_seq_show(struct seq_file *m, void *v)"%08x %08x %5u %5u %3u %s %03lx %-16s %px" , cookie->debug_id, cookie->parent ? cookie->parent->debug_id :0 , -atomic_read (&cookie->usage), +refcount_read (&cookie->ref),atomic_read (&cookie->n_children),atomic_read (&cookie->n_active), type,
fs/fscache/fsdef.c +1 -1
@@ -46,7 +46,7 @@ static struct fscache_cookie_def fscache_fsdef_index_def = {struct fscache_cookie fscache_fsdef_index = { .debug_id =1 , - .usage =ATOMIC_INIT (1 ), + .ref =REFCOUNT_INIT (1 ), .n_active =ATOMIC_INIT (1 ), .lock =__SPIN_LOCK_UNLOCKED (fscache_fsdef_index.lock), .backing_objects =HLIST_HEAD_INIT ,
fs/fscache/internal.h +9 -8
@@ -54,9 +54,18 @@ extern struct fscache_cookie *fscache_alloc_cookie(struct fscache_cookie *, const void *, size_t, void *, loff_t);extern struct fscache_cookie *fscache_hash_cookie (struct fscache_cookie *); +extern struct fscache_cookie *fscache_cookie_get (struct fscache_cookie *, +enum fscache_cookie_trace );extern void fscache_cookie_put (struct fscache_cookie *,enum fscache_cookie_trace ); +static inline void fscache_cookie_see (struct fscache_cookie *cookie, +enum fscache_cookie_trace where) +{ +trace_fscache_cookie (cookie->debug_id,refcount_read (&cookie->ref), + where); +} +/* * fsdef.c */
@@ -286,14 +295,6 @@ static inline void fscache_raise_event(struct fscache_object *object,fscache_enqueue_object (object); } -static inline void fscache_cookie_get (struct fscache_cookie *cookie, -enum fscache_cookie_trace where) -{ -int usage =atomic_inc_return (&cookie->usage); - -trace_fscache_cookie (cookie->debug_id, usage, where); -} -/* * get an extra reference to a netfs retrieval context */
include/linux/fscache.h +1 -1
@@ -123,7 +123,7 @@ struct fscache_netfs {* - indices are created on disk just-in-time */ struct fscache_cookie { -atomic_t usage;/* number of users of this cookie */ +refcount_t ref;/* number of users of this cookie */ atomic_t n_children;/* number of children of this cookie */ atomic_t n_active;/* number of active users of netfs ptrs */ unsigned int debug_id;
include/trace/events/fscache.h +22 -22
134 lines not on this page · raw message
Quoted 78 lines · David Howells
Here are some patches that perform some preparatory work for the fscache rewrite that's being worked on. These include:
(1) Always select netfs stats when enabling fscache stats since they're displayed through the same procfile.
(2) Add a cookie debug ID that can be used in tracepoints instead of a pointer and cache it in the
netfs_cache_resourcesstruct rather than in thenetfs_read_requeststruct to make it more available.(3) Use
file_inode()in cachefiles rather than dereferencingfile->f_inodedirectly.(4) Provide a procfile to display fscache cookies.
(5) Remove the fscache and cachefiles histogram procfiles.
(6) Remove the fscache object list procfile.
(7) Avoid using %p in fscache and cachefiles as the value is hashed and not comparable to the register dump in an oops trace.
(8) Fix the cookie hash function to actually achieve useful dispersion.
(9) 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).(10) Use
refcount_trather thanatomic_tfor thefscache_cookierefcount.The patches can be found on this branch:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=fscache-next
David
---
David Howells (12):
fscache: Select netfs stats if fscache stats are enabled
netfs: Move cookie debug ID to structnetfs_cache_resources
cachefiles: Usefile_inode()rather than accessing ->f_inode
fscache: Add a cookie debug ID and use that in traces
fscache: Procfile to display cookies
fscache, cachefiles: Remove the histogram stuff
fscache: Remove the object list procfile
fscache: Change %p in format strings to something else
cachefiles: Change %p in format strings to something else
fscache: Fix cookie key hashing
fscache: Fixfscache_cookie_put()to not deref after dec
fscache: Userefcount_tfor the cookie refcount instead ofatomic_tfs/cachefiles/Kconfig | 19 -- fs/cachefiles/Makefile | 2 - fs/cachefiles/bind.c | 2 - fs/cachefiles/interface.c | 6 +- fs/cachefiles/internal.h | 25 -- fs/cachefiles/io.c | 6 +- fs/cachefiles/key.c | 2 +- fs/cachefiles/main.c | 7 - fs/cachefiles/namei.c | 61 ++--- fs/cachefiles/proc.c | 114 -------- fs/cachefiles/xattr.c | 4 +- fs/fscache/Kconfig | 24 -- fs/fscache/Makefile | 2 - fs/fscache/cache.c | 11 +- fs/fscache/cookie.c | 201 +++++++++++---- fs/fscache/fsdef.c | 3 +- fs/fscache/histogram.c | 87 ------- fs/fscache/internal.h | 57 +--- fs/fscache/main.c | 39 +++ fs/fscache/netfs.c | 2 +- fs/fscache/object-list.c | 414 ------------------------------ fs/fscache/object.c | 8 - fs/fscache/operation.c | 3 - fs/fscache/page.c | 6 - fs/fscache/proc.c | 20 +- include/linux/fscache-cache.h | 4 - include/linux/fscache.h | 4 +-
Quoted 10 lines
include/linux/netfs.h | 2 +- include/trace/events/cachefiles.h | 68 ++--- include/trace/events/fscache.h | 160 ++++++------ include/trace/events/netfs.h | 2 +- 31 files changed, 367 insertions(+), 998 deletions(-) delete mode 100644 fs/cachefiles/proc.c delete mode 100644 fs/fscache/histogram.c delete mode 100644 fs/fscache/object-list.c
This all looks good (modulo a nitpicky changelog comment). You can add: