Skip to content

Commit 6040f65

Browse files
sergey-senozhatskyakpm00
authored andcommitted
zsmalloc: use unique zsmalloc caches names
Each zsmalloc pool maintains several named kmem-caches for zs_handle-s and zspage-s. On a system with multiple zsmalloc pools and CONFIG_DEBUG_VM this triggers kmem_cache_sanity_check(): kmem_cache of name 'zspage' already exists WARNING: at mm/slab_common.c:108 do_kmem_cache_create_usercopy+0xb5/0x310 ... kmem_cache of name 'zs_handle' already exists WARNING: at mm/slab_common.c:108 do_kmem_cache_create_usercopy+0xb5/0x310 ... We provide zram device name when init its zsmalloc pool, so we can use that same name for zsmalloc caches and, hence, create unique names that can easily be linked to zram device that has created them. So instead of having this cat /proc/slabinfo slabinfo - version: 2.1 zspage 46 46 ... zs_handle 128 128 ... zspage 34270 34270 ... zs_handle 34816 34816 ... zspage 0 0 ... zs_handle 0 0 ... We now have this cat /proc/slabinfo slabinfo - version: 2.1 zspage-zram2 46 46 ... zs_handle-zram2 128 128 ... zspage-zram0 34270 34270 ... zs_handle-zram0 34816 34816 ... zspage-zram1 0 0 ... zs_handle-zram1 0 0 ... Link: https://lkml.kernel.org/r/[email protected] Fixes: 2e40e16 ("zsmalloc: decouple handle and object") Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent fb497d6 commit 6040f65

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

mm/zsmalloc.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <linux/vmalloc.h>
5555
#include <linux/preempt.h>
5656
#include <linux/spinlock.h>
57+
#include <linux/sprintf.h>
5758
#include <linux/shrinker.h>
5859
#include <linux/types.h>
5960
#include <linux/debugfs.h>
@@ -293,17 +294,27 @@ static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {}
293294

294295
static int create_cache(struct zs_pool *pool)
295296
{
296-
pool->handle_cachep = kmem_cache_create("zs_handle", ZS_HANDLE_SIZE,
297-
0, 0, NULL);
297+
char *name;
298+
299+
name = kasprintf(GFP_KERNEL, "zs_handle-%s", pool->name);
300+
if (!name)
301+
return -ENOMEM;
302+
pool->handle_cachep = kmem_cache_create(name, ZS_HANDLE_SIZE,
303+
0, 0, NULL);
304+
kfree(name);
298305
if (!pool->handle_cachep)
299-
return 1;
306+
return -EINVAL;
300307

301-
pool->zspage_cachep = kmem_cache_create("zspage", sizeof(struct zspage),
302-
0, 0, NULL);
308+
name = kasprintf(GFP_KERNEL, "zspage-%s", pool->name);
309+
if (!name)
310+
return -ENOMEM;
311+
pool->zspage_cachep = kmem_cache_create(name, sizeof(struct zspage),
312+
0, 0, NULL);
313+
kfree(name);
303314
if (!pool->zspage_cachep) {
304315
kmem_cache_destroy(pool->handle_cachep);
305316
pool->handle_cachep = NULL;
306-
return 1;
317+
return -EINVAL;
307318
}
308319

309320
return 0;

0 commit comments

Comments
 (0)