Skip to content

Commit 41a2128

Browse files
Christoph Lametertorvalds
Christoph Lameter
authored andcommitted
slub: use sysfs'es release mechanism for kmem_cache
debugobjects warning during netfilter exit: ------------[ cut here ]------------ WARNING: CPU: 6 PID: 4178 at lib/debugobjects.c:260 debug_print_object+0x8d/0xb0() ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x20 Modules linked in: CPU: 6 PID: 4178 Comm: kworker/u16:2 Tainted: G W 3.11.0-next-20130906-sasha #3984 Workqueue: netns cleanup_net Call Trace: dump_stack+0x52/0x87 warn_slowpath_common+0x8c/0xc0 warn_slowpath_fmt+0x46/0x50 debug_print_object+0x8d/0xb0 __debug_check_no_obj_freed+0xa5/0x220 debug_check_no_obj_freed+0x15/0x20 kmem_cache_free+0x197/0x340 kmem_cache_destroy+0x86/0xe0 nf_conntrack_cleanup_net_list+0x131/0x170 nf_conntrack_pernet_exit+0x5d/0x70 ops_exit_list+0x5e/0x70 cleanup_net+0xfb/0x1c0 process_one_work+0x338/0x550 worker_thread+0x215/0x350 kthread+0xe7/0xf0 ret_from_fork+0x7c/0xb0 Also during dcookie cleanup: WARNING: CPU: 12 PID: 9725 at lib/debugobjects.c:260 debug_print_object+0x8c/0xb0() ODEBUG: free active (active state 0) object type: timer_list hint: delayed_work_timer_fn+0x0/0x20 Modules linked in: CPU: 12 PID: 9725 Comm: trinity-c141 Not tainted 3.15.0-rc2-next-20140423-sasha-00018-gc4ff6c4 #408 Call Trace: dump_stack (lib/dump_stack.c:52) warn_slowpath_common (kernel/panic.c:430) warn_slowpath_fmt (kernel/panic.c:445) debug_print_object (lib/debugobjects.c:262) __debug_check_no_obj_freed (lib/debugobjects.c:697) debug_check_no_obj_freed (lib/debugobjects.c:726) kmem_cache_free (mm/slub.c:2689 mm/slub.c:2717) kmem_cache_destroy (mm/slab_common.c:363) dcookie_unregister (fs/dcookies.c:302 fs/dcookies.c:343) event_buffer_release (arch/x86/oprofile/../../../drivers/oprofile/event_buffer.c:153) __fput (fs/file_table.c:217) ____fput (fs/file_table.c:253) task_work_run (kernel/task_work.c:125 (discriminator 1)) do_notify_resume (include/linux/tracehook.h:196 arch/x86/kernel/signal.c:751) int_signal (arch/x86/kernel/entry_64.S:807) Sysfs has a release mechanism. Use that to release the kmem_cache structure if CONFIG_SYSFS is enabled. Only slub is changed - slab currently only supports /proc/slabinfo and not /sys/kernel/slab/*. We talked about adding that and someone was working on it. [[email protected]: fix CONFIG_SYSFS=n build] [[email protected]: fix CONFIG_SYSFS=n build even more] Signed-off-by: Christoph Lameter <[email protected]> Reported-by: Sasha Levin <[email protected]> Tested-by: Sasha Levin <[email protected]> Acked-by: Greg KH <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: Russell King <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6237625 commit 41a2128

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

include/linux/slub_def.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,13 @@ struct kmem_cache {
101101
struct kmem_cache_node *node[MAX_NUMNODES];
102102
};
103103

104+
#ifdef CONFIG_SYSFS
105+
#define SLAB_SUPPORTS_SYSFS
106+
void sysfs_slab_remove(struct kmem_cache *);
107+
#else
108+
static inline void sysfs_slab_remove(struct kmem_cache *s)
109+
{
110+
}
111+
#endif
112+
104113
#endif /* _LINUX_SLUB_DEF_H */

mm/slab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
9191
#define CACHE_CREATE_MASK (SLAB_CORE_FLAGS | SLAB_DEBUG_FLAGS | SLAB_CACHE_FLAGS)
9292

9393
int __kmem_cache_shutdown(struct kmem_cache *);
94+
void slab_kmem_cache_release(struct kmem_cache *);
9495

9596
struct seq_file;
9697
struct file;

mm/slab_common.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ static int kmem_cache_destroy_memcg_children(struct kmem_cache *s)
323323
}
324324
#endif /* CONFIG_MEMCG_KMEM */
325325

326+
void slab_kmem_cache_release(struct kmem_cache *s)
327+
{
328+
kfree(s->name);
329+
kmem_cache_free(kmem_cache, s);
330+
}
331+
326332
void kmem_cache_destroy(struct kmem_cache *s)
327333
{
328334
get_online_cpus();
@@ -352,8 +358,11 @@ void kmem_cache_destroy(struct kmem_cache *s)
352358
rcu_barrier();
353359

354360
memcg_free_cache_params(s);
355-
kfree(s->name);
356-
kmem_cache_free(kmem_cache, s);
361+
#ifdef SLAB_SUPPORTS_SYSFS
362+
sysfs_slab_remove(s);
363+
#else
364+
slab_kmem_cache_release(s);
365+
#endif
357366
goto out_put_cpus;
358367

359368
out_unlock:

mm/slub.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,11 @@ enum track_item { TRACK_ALLOC, TRACK_FREE };
210210
#ifdef CONFIG_SYSFS
211211
static int sysfs_slab_add(struct kmem_cache *);
212212
static int sysfs_slab_alias(struct kmem_cache *, const char *);
213-
static void sysfs_slab_remove(struct kmem_cache *);
214213
static void memcg_propagate_slab_attrs(struct kmem_cache *s);
215214
#else
216215
static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; }
217216
static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p)
218217
{ return 0; }
219-
static inline void sysfs_slab_remove(struct kmem_cache *s) { }
220-
221218
static inline void memcg_propagate_slab_attrs(struct kmem_cache *s) { }
222219
#endif
223220

@@ -3238,24 +3235,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
32383235

32393236
int __kmem_cache_shutdown(struct kmem_cache *s)
32403237
{
3241-
int rc = kmem_cache_close(s);
3242-
3243-
if (!rc) {
3244-
/*
3245-
* Since slab_attr_store may take the slab_mutex, we should
3246-
* release the lock while removing the sysfs entry in order to
3247-
* avoid a deadlock. Because this is pretty much the last
3248-
* operation we do and the lock will be released shortly after
3249-
* that in slab_common.c, we could just move sysfs_slab_remove
3250-
* to a later point in common code. We should do that when we
3251-
* have a common sysfs framework for all allocators.
3252-
*/
3253-
mutex_unlock(&slab_mutex);
3254-
sysfs_slab_remove(s);
3255-
mutex_lock(&slab_mutex);
3256-
}
3257-
3258-
return rc;
3238+
return kmem_cache_close(s);
32593239
}
32603240

32613241
/********************************************************************
@@ -5122,13 +5102,19 @@ static void memcg_propagate_slab_attrs(struct kmem_cache *s)
51225102
#endif
51235103
}
51245104

5105+
static void kmem_cache_release(struct kobject *k)
5106+
{
5107+
slab_kmem_cache_release(to_slab(k));
5108+
}
5109+
51255110
static const struct sysfs_ops slab_sysfs_ops = {
51265111
.show = slab_attr_show,
51275112
.store = slab_attr_store,
51285113
};
51295114

51305115
static struct kobj_type slab_ktype = {
51315116
.sysfs_ops = &slab_sysfs_ops,
5117+
.release = kmem_cache_release,
51325118
};
51335119

51345120
static int uevent_filter(struct kset *kset, struct kobject *kobj)
@@ -5255,7 +5241,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
52555241
goto out;
52565242
}
52575243

5258-
static void sysfs_slab_remove(struct kmem_cache *s)
5244+
void sysfs_slab_remove(struct kmem_cache *s)
52595245
{
52605246
if (slab_state < FULL)
52615247
/*

0 commit comments

Comments
 (0)