[lkml]   [2012]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH 01/23] slub: don't create a copy of the name string in kmem_cache_create
    When creating a cache, slub keeps a copy of the cache name through
    strdup. The slab however, doesn't do that. This means that everyone
    registering caches have to keep a copy themselves anyway, since code
    needs to work on all allocators.

    Having slab create a copy of it as well may very well be the right
    thing to do: but at this point, the callers are already there

    My motivation for it comes from the kmem slab cache controller for
    memcg. Because we create duplicate caches, having a more consistent
    behavior here really helps.

    I am sending the patch, however, more to probe on your opinion about
    it. If you guys agree, but don't want to merge it - since it is not
    fixing anything, nor improving any situation etc, I am more than happy
    to carry it in my series until it gets merged (fingers crossed).

    Signed-off-by: Glauber Costa <>
    CC: Christoph Lameter <>
    CC: Pekka Enberg <>
    mm/slub.c | 14 ++------------
    1 files changed, 2 insertions(+), 12 deletions(-)

    diff --git a/mm/slub.c b/mm/slub.c
    index ffe13fd..af8cee9 100644
    --- a/mm/slub.c
    +++ b/mm/slub.c
    @@ -3925,7 +3925,6 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
    size_t align, unsigned long flags, void (*ctor)(void *))
    struct kmem_cache *s;
    - char *n;

    if (WARN_ON(!name))
    return NULL;
    @@ -3949,26 +3948,20 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
    return s;

    - n = kstrdup(name, GFP_KERNEL);
    - if (!n)
    - goto err;
    s = kmalloc(kmem_size, GFP_KERNEL);
    if (s) {
    - if (kmem_cache_open(s, n,
    + if (kmem_cache_open(s, name,
    size, align, flags, ctor)) {
    list_add(&s->list, &slab_caches);
    if (sysfs_slab_add(s)) {
    - kfree(n);
    goto err;
    return s;
    - kfree(n);
    @@ -5212,7 +5205,6 @@ static void kmem_cache_release(struct kobject *kobj)
    struct kmem_cache *s = to_slab(kobj);

    - kfree(s->name);

    @@ -5318,11 +5310,9 @@ static int sysfs_slab_add(struct kmem_cache *s)
    return err;
    kobject_uevent(&s->kobj, KOBJ_ADD);
    - if (!unmergeable) {
    + if (!unmergeable)
    /* Setup first alias */
    sysfs_slab_alias(s, s->name);
    - kfree(name);
    - }
    return 0;


     \ /
      Last update: 2012-04-20 23:53    [W:0.023 / U:83.772 seconds]
    ©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site