Skip to content

Commit

Permalink
mm/slab: convert cache name allocations to kstrdup_const
Browse files Browse the repository at this point in the history
slab frequently performs duplication of strings located in read-only
memory section.  Replacing kstrdup by kstrdup_const allows to avoid such
operations.

[[email protected]: make the handling of kmem_cache.name const-correct]
Signed-off-by: Andrzej Hajda <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Mike Turquette <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Greg KH <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Andrzej Hajda authored and torvalds committed Feb 14, 2015
1 parent 612936f commit 3dec16e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mm/slab_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ unsigned long calculate_alignment(unsigned long flags,
}

static struct kmem_cache *
do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
unsigned long flags, void (*ctor)(void *),
do_kmem_cache_create(const char *name, size_t object_size, size_t size,
size_t align, unsigned long flags, void (*ctor)(void *),
struct mem_cgroup *memcg, struct kmem_cache *root_cache)
{
struct kmem_cache *s;
Expand Down Expand Up @@ -363,7 +363,7 @@ kmem_cache_create(const char *name, size_t size, size_t align,
unsigned long flags, void (*ctor)(void *))
{
struct kmem_cache *s;
char *cache_name;
const char *cache_name;
int err;

get_online_cpus();
Expand All @@ -390,7 +390,7 @@ kmem_cache_create(const char *name, size_t size, size_t align,
if (s)
goto out_unlock;

cache_name = kstrdup(name, GFP_KERNEL);
cache_name = kstrdup_const(name, GFP_KERNEL);
if (!cache_name) {
err = -ENOMEM;
goto out_unlock;
Expand All @@ -401,7 +401,7 @@ kmem_cache_create(const char *name, size_t size, size_t align,
flags, ctor, NULL, NULL);
if (IS_ERR(s)) {
err = PTR_ERR(s);
kfree(cache_name);
kfree_const(cache_name);
}

out_unlock:
Expand Down Expand Up @@ -607,7 +607,7 @@ void memcg_destroy_kmem_caches(struct mem_cgroup *memcg)
void slab_kmem_cache_release(struct kmem_cache *s)
{
destroy_memcg_params(s);
kfree(s->name);
kfree_const(s->name);
kmem_cache_free(kmem_cache, s);
}

Expand Down

0 comments on commit 3dec16e

Please sign in to comment.