slub: Allow removal of slab caches during boot
Serialize kmem_cache_create and kmem_cache_destroy using the slub_lock. Only possible after the use of the slub_lock during dynamic dma creation has been removed. Then make sure that the setup of the slab sysfs entries does not race with kmem_cache_create and kmem_cache destroy. If a slab cache is removed before we have setup sysfs then simply skip over the sysfs handling. Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Roland Dreier <rdreier@cisco.com> Signed-off-by: Christoph Lameter <cl@linux-foundation.org> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
This commit is contained in:
parent
e438444de8
commit
2bce648584
24
mm/slub.c
24
mm/slub.c
@ -2491,7 +2491,6 @@ void kmem_cache_destroy(struct kmem_cache *s)
|
|||||||
s->refcount--;
|
s->refcount--;
|
||||||
if (!s->refcount) {
|
if (!s->refcount) {
|
||||||
list_del(&s->list);
|
list_del(&s->list);
|
||||||
up_write(&slub_lock);
|
|
||||||
if (kmem_cache_close(s)) {
|
if (kmem_cache_close(s)) {
|
||||||
printk(KERN_ERR "SLUB %s: %s called for cache that "
|
printk(KERN_ERR "SLUB %s: %s called for cache that "
|
||||||
"still has objects.\n", s->name, __func__);
|
"still has objects.\n", s->name, __func__);
|
||||||
@ -2500,8 +2499,8 @@ void kmem_cache_destroy(struct kmem_cache *s)
|
|||||||
if (s->flags & SLAB_DESTROY_BY_RCU)
|
if (s->flags & SLAB_DESTROY_BY_RCU)
|
||||||
rcu_barrier();
|
rcu_barrier();
|
||||||
sysfs_slab_remove(s);
|
sysfs_slab_remove(s);
|
||||||
} else
|
}
|
||||||
up_write(&slub_lock);
|
up_write(&slub_lock);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(kmem_cache_destroy);
|
EXPORT_SYMBOL(kmem_cache_destroy);
|
||||||
|
|
||||||
@ -3227,14 +3226,12 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
|
|||||||
*/
|
*/
|
||||||
s->objsize = max(s->objsize, (int)size);
|
s->objsize = max(s->objsize, (int)size);
|
||||||
s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
|
s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
|
||||||
up_write(&slub_lock);
|
|
||||||
|
|
||||||
if (sysfs_slab_alias(s, name)) {
|
if (sysfs_slab_alias(s, name)) {
|
||||||
down_write(&slub_lock);
|
|
||||||
s->refcount--;
|
s->refcount--;
|
||||||
up_write(&slub_lock);
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
up_write(&slub_lock);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3243,14 +3240,12 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
|
|||||||
if (kmem_cache_open(s, GFP_KERNEL, name,
|
if (kmem_cache_open(s, GFP_KERNEL, name,
|
||||||
size, align, flags, ctor)) {
|
size, align, flags, ctor)) {
|
||||||
list_add(&s->list, &slab_caches);
|
list_add(&s->list, &slab_caches);
|
||||||
up_write(&slub_lock);
|
|
||||||
if (sysfs_slab_add(s)) {
|
if (sysfs_slab_add(s)) {
|
||||||
down_write(&slub_lock);
|
|
||||||
list_del(&s->list);
|
list_del(&s->list);
|
||||||
up_write(&slub_lock);
|
|
||||||
kfree(s);
|
kfree(s);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
up_write(&slub_lock);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
kfree(s);
|
kfree(s);
|
||||||
@ -4498,6 +4493,13 @@ static int sysfs_slab_add(struct kmem_cache *s)
|
|||||||
|
|
||||||
static void sysfs_slab_remove(struct kmem_cache *s)
|
static void sysfs_slab_remove(struct kmem_cache *s)
|
||||||
{
|
{
|
||||||
|
if (slab_state < SYSFS)
|
||||||
|
/*
|
||||||
|
* Sysfs has not been setup yet so no need to remove the
|
||||||
|
* cache from sysfs.
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
|
||||||
kobject_uevent(&s->kobj, KOBJ_REMOVE);
|
kobject_uevent(&s->kobj, KOBJ_REMOVE);
|
||||||
kobject_del(&s->kobj);
|
kobject_del(&s->kobj);
|
||||||
kobject_put(&s->kobj);
|
kobject_put(&s->kobj);
|
||||||
@ -4543,8 +4545,11 @@ static int __init slab_sysfs_init(void)
|
|||||||
struct kmem_cache *s;
|
struct kmem_cache *s;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
down_write(&slub_lock);
|
||||||
|
|
||||||
slab_kset = kset_create_and_add("slab", &slab_uevent_ops, kernel_kobj);
|
slab_kset = kset_create_and_add("slab", &slab_uevent_ops, kernel_kobj);
|
||||||
if (!slab_kset) {
|
if (!slab_kset) {
|
||||||
|
up_write(&slub_lock);
|
||||||
printk(KERN_ERR "Cannot register slab subsystem.\n");
|
printk(KERN_ERR "Cannot register slab subsystem.\n");
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
@ -4569,6 +4574,7 @@ static int __init slab_sysfs_init(void)
|
|||||||
kfree(al);
|
kfree(al);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
up_write(&slub_lock);
|
||||||
resiliency_test();
|
resiliency_test();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user