Skip to content

Commit 5456ec9

Browse files
committed
Merge tag 'for-6.12/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mikulas Patocka: - fix warnings about duplicate slab cache names * tag 'for-6.12/dm-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm-cache: fix warnings about duplicate slab caches dm-bufio: fix warnings about duplicate slab caches
2 parents 93db202 + 346dbf1 commit 5456ec9

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
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) {

drivers/md/dm-cache-background-tracker.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
#define DM_MSG_PREFIX "dm-background-tracker"
1313

14-
struct bt_work {
15-
struct list_head list;
16-
struct rb_node node;
17-
struct policy_work work;
18-
};
19-
2014
struct background_tracker {
2115
unsigned int max_work;
2216
atomic_t pending_promotes;
@@ -26,10 +20,10 @@ struct background_tracker {
2620
struct list_head issued;
2721
struct list_head queued;
2822
struct rb_root pending;
29-
30-
struct kmem_cache *work_cache;
3123
};
3224

25+
struct kmem_cache *btracker_work_cache = NULL;
26+
3327
struct background_tracker *btracker_create(unsigned int max_work)
3428
{
3529
struct background_tracker *b = kmalloc(sizeof(*b), GFP_KERNEL);
@@ -48,12 +42,6 @@ struct background_tracker *btracker_create(unsigned int max_work)
4842
INIT_LIST_HEAD(&b->queued);
4943

5044
b->pending = RB_ROOT;
51-
b->work_cache = KMEM_CACHE(bt_work, 0);
52-
if (!b->work_cache) {
53-
DMERR("couldn't create mempool for background work items");
54-
kfree(b);
55-
b = NULL;
56-
}
5745

5846
return b;
5947
}
@@ -66,10 +54,9 @@ void btracker_destroy(struct background_tracker *b)
6654
BUG_ON(!list_empty(&b->issued));
6755
list_for_each_entry_safe (w, tmp, &b->queued, list) {
6856
list_del(&w->list);
69-
kmem_cache_free(b->work_cache, w);
57+
kmem_cache_free(btracker_work_cache, w);
7058
}
7159

72-
kmem_cache_destroy(b->work_cache);
7360
kfree(b);
7461
}
7562
EXPORT_SYMBOL_GPL(btracker_destroy);
@@ -180,7 +167,7 @@ static struct bt_work *alloc_work(struct background_tracker *b)
180167
if (max_work_reached(b))
181168
return NULL;
182169

183-
return kmem_cache_alloc(b->work_cache, GFP_NOWAIT);
170+
return kmem_cache_alloc(btracker_work_cache, GFP_NOWAIT);
184171
}
185172

186173
int btracker_queue(struct background_tracker *b,
@@ -203,7 +190,7 @@ int btracker_queue(struct background_tracker *b,
203190
* There was a race, we'll just ignore this second
204191
* bit of work for the same oblock.
205192
*/
206-
kmem_cache_free(b->work_cache, w);
193+
kmem_cache_free(btracker_work_cache, w);
207194
return -EINVAL;
208195
}
209196

@@ -244,7 +231,7 @@ void btracker_complete(struct background_tracker *b,
244231
update_stats(b, &w->work, -1);
245232
rb_erase(&w->node, &b->pending);
246233
list_del(&w->list);
247-
kmem_cache_free(b->work_cache, w);
234+
kmem_cache_free(btracker_work_cache, w);
248235
}
249236
EXPORT_SYMBOL_GPL(btracker_complete);
250237

drivers/md/dm-cache-background-tracker.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
* protected with a spinlock.
2727
*/
2828

29+
struct bt_work {
30+
struct list_head list;
31+
struct rb_node node;
32+
struct policy_work work;
33+
};
34+
35+
extern struct kmem_cache *btracker_work_cache;
36+
2937
struct background_work;
3038
struct background_tracker;
3139

drivers/md/dm-cache-target.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "dm-bio-record.h"
1111
#include "dm-cache-metadata.h"
1212
#include "dm-io-tracker.h"
13+
#include "dm-cache-background-tracker.h"
1314

1415
#include <linux/dm-io.h>
1516
#include <linux/dm-kcopyd.h>
@@ -2263,7 +2264,7 @@ static int parse_cache_args(struct cache_args *ca, int argc, char **argv,
22632264

22642265
/*----------------------------------------------------------------*/
22652266

2266-
static struct kmem_cache *migration_cache;
2267+
static struct kmem_cache *migration_cache = NULL;
22672268

22682269
#define NOT_CORE_OPTION 1
22692270

@@ -3445,22 +3446,36 @@ static int __init dm_cache_init(void)
34453446
int r;
34463447

34473448
migration_cache = KMEM_CACHE(dm_cache_migration, 0);
3448-
if (!migration_cache)
3449-
return -ENOMEM;
3449+
if (!migration_cache) {
3450+
r = -ENOMEM;
3451+
goto err;
3452+
}
3453+
3454+
btracker_work_cache = kmem_cache_create("dm_cache_bt_work",
3455+
sizeof(struct bt_work), __alignof__(struct bt_work), 0, NULL);
3456+
if (!btracker_work_cache) {
3457+
r = -ENOMEM;
3458+
goto err;
3459+
}
34503460

34513461
r = dm_register_target(&cache_target);
34523462
if (r) {
3453-
kmem_cache_destroy(migration_cache);
3454-
return r;
3463+
goto err;
34553464
}
34563465

34573466
return 0;
3467+
3468+
err:
3469+
kmem_cache_destroy(migration_cache);
3470+
kmem_cache_destroy(btracker_work_cache);
3471+
return r;
34583472
}
34593473

34603474
static void __exit dm_cache_exit(void)
34613475
{
34623476
dm_unregister_target(&cache_target);
34633477
kmem_cache_destroy(migration_cache);
3478+
kmem_cache_destroy(btracker_work_cache);
34643479
}
34653480

34663481
module_init(dm_cache_init);

0 commit comments

Comments
 (0)