Skip to content

Commit 42964e4

Browse files
author
Mikulas Patocka
committed
dm-bufio: fix warnings about duplicate slab caches
The commit 4c39529 adds a warning about duplicate cache names if CONFIG_DEBUG_VM is selected. These warnings are triggered by the dm-bufio code. The dm-bufio code allocates a slab cache with each client. It is not possible to preallocate the caches in the module init function because the size of auxiliary per-buffer data is not known at this point. So, this commit changes dm-bufio so that it appends a unique atomic value to the cache name, to avoid the warnings. Signed-off-by: Mikulas Patocka <[email protected]> Fixes: 4c39529 ("slab: Warn on duplicate cache names when DEBUG_VM=y")
1 parent 2d5404c commit 42964e4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/md/dm-bufio.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,8 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
24712471
int r;
24722472
unsigned int num_locks;
24732473
struct dm_bufio_client *c;
2474-
char slab_name[27];
2474+
char slab_name[64];
2475+
static atomic_t seqno = ATOMIC_INIT(0);
24752476

24762477
if (!block_size || block_size & ((1 << SECTOR_SHIFT) - 1)) {
24772478
DMERR("%s: block size not specified or is not multiple of 512b", __func__);
@@ -2522,7 +2523,8 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
25222523
(block_size < PAGE_SIZE || !is_power_of_2(block_size))) {
25232524
unsigned int align = min(1U << __ffs(block_size), (unsigned int)PAGE_SIZE);
25242525

2525-
snprintf(slab_name, sizeof(slab_name), "dm_bufio_cache-%u", block_size);
2526+
snprintf(slab_name, sizeof(slab_name), "dm_bufio_cache-%u-%u",
2527+
block_size, atomic_inc_return(&seqno));
25262528
c->slab_cache = kmem_cache_create(slab_name, block_size, align,
25272529
SLAB_RECLAIM_ACCOUNT, NULL);
25282530
if (!c->slab_cache) {
@@ -2531,9 +2533,11 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
25312533
}
25322534
}
25332535
if (aux_size)
2534-
snprintf(slab_name, sizeof(slab_name), "dm_bufio_buffer-%u", aux_size);
2536+
snprintf(slab_name, sizeof(slab_name), "dm_bufio_buffer-%u-%u",
2537+
aux_size, atomic_inc_return(&seqno));
25352538
else
2536-
snprintf(slab_name, sizeof(slab_name), "dm_bufio_buffer");
2539+
snprintf(slab_name, sizeof(slab_name), "dm_bufio_buffer-%u",
2540+
atomic_inc_return(&seqno));
25372541
c->slab_buffer = kmem_cache_create(slab_name, sizeof(struct dm_buffer) + aux_size,
25382542
0, SLAB_RECLAIM_ACCOUNT, NULL);
25392543
if (!c->slab_buffer) {

0 commit comments

Comments
 (0)