Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm-cache: fix warnings about duplicate slab caches

The commit 4c39529663b9 adds a warning about duplicate cache names if
CONFIG_DEBUG_VM is selected. These warnings are triggered by the dm-cache
code.

The dm-cache code allocates a slab cache for each device. This commit
changes it to allocate just one slab cache in the module init function.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 4c39529663b9 ("slab: Warn on duplicate cache names when DEBUG_VM=y")

+34 -24
+6 -19
drivers/md/dm-cache-background-tracker.c
··· 11 11 12 12 #define DM_MSG_PREFIX "dm-background-tracker" 13 13 14 - struct bt_work { 15 - struct list_head list; 16 - struct rb_node node; 17 - struct policy_work work; 18 - }; 19 - 20 14 struct background_tracker { 21 15 unsigned int max_work; 22 16 atomic_t pending_promotes; ··· 20 26 struct list_head issued; 21 27 struct list_head queued; 22 28 struct rb_root pending; 23 - 24 - struct kmem_cache *work_cache; 25 29 }; 30 + 31 + struct kmem_cache *btracker_work_cache = NULL; 26 32 27 33 struct background_tracker *btracker_create(unsigned int max_work) 28 34 { ··· 42 48 INIT_LIST_HEAD(&b->queued); 43 49 44 50 b->pending = RB_ROOT; 45 - b->work_cache = KMEM_CACHE(bt_work, 0); 46 - if (!b->work_cache) { 47 - DMERR("couldn't create mempool for background work items"); 48 - kfree(b); 49 - b = NULL; 50 - } 51 51 52 52 return b; 53 53 } ··· 54 66 BUG_ON(!list_empty(&b->issued)); 55 67 list_for_each_entry_safe (w, tmp, &b->queued, list) { 56 68 list_del(&w->list); 57 - kmem_cache_free(b->work_cache, w); 69 + kmem_cache_free(btracker_work_cache, w); 58 70 } 59 71 60 - kmem_cache_destroy(b->work_cache); 61 72 kfree(b); 62 73 } 63 74 EXPORT_SYMBOL_GPL(btracker_destroy); ··· 167 180 if (max_work_reached(b)) 168 181 return NULL; 169 182 170 - return kmem_cache_alloc(b->work_cache, GFP_NOWAIT); 183 + return kmem_cache_alloc(btracker_work_cache, GFP_NOWAIT); 171 184 } 172 185 173 186 int btracker_queue(struct background_tracker *b, ··· 190 203 * There was a race, we'll just ignore this second 191 204 * bit of work for the same oblock. 192 205 */ 193 - kmem_cache_free(b->work_cache, w); 206 + kmem_cache_free(btracker_work_cache, w); 194 207 return -EINVAL; 195 208 } 196 209 ··· 231 244 update_stats(b, &w->work, -1); 232 245 rb_erase(&w->node, &b->pending); 233 246 list_del(&w->list); 234 - kmem_cache_free(b->work_cache, w); 247 + kmem_cache_free(btracker_work_cache, w); 235 248 } 236 249 EXPORT_SYMBOL_GPL(btracker_complete); 237 250
+8
drivers/md/dm-cache-background-tracker.h
··· 26 26 * protected with a spinlock. 27 27 */ 28 28 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 + 29 37 struct background_work; 30 38 struct background_tracker; 31 39
+20 -5
drivers/md/dm-cache-target.c
··· 10 10 #include "dm-bio-record.h" 11 11 #include "dm-cache-metadata.h" 12 12 #include "dm-io-tracker.h" 13 + #include "dm-cache-background-tracker.h" 13 14 14 15 #include <linux/dm-io.h> 15 16 #include <linux/dm-kcopyd.h> ··· 2264 2263 2265 2264 /*----------------------------------------------------------------*/ 2266 2265 2267 - static struct kmem_cache *migration_cache; 2266 + static struct kmem_cache *migration_cache = NULL; 2268 2267 2269 2268 #define NOT_CORE_OPTION 1 2270 2269 ··· 3446 3445 int r; 3447 3446 3448 3447 migration_cache = KMEM_CACHE(dm_cache_migration, 0); 3449 - if (!migration_cache) 3450 - return -ENOMEM; 3448 + if (!migration_cache) { 3449 + r = -ENOMEM; 3450 + goto err; 3451 + } 3452 + 3453 + btracker_work_cache = kmem_cache_create("dm_cache_bt_work", 3454 + sizeof(struct bt_work), __alignof__(struct bt_work), 0, NULL); 3455 + if (!btracker_work_cache) { 3456 + r = -ENOMEM; 3457 + goto err; 3458 + } 3451 3459 3452 3460 r = dm_register_target(&cache_target); 3453 3461 if (r) { 3454 - kmem_cache_destroy(migration_cache); 3455 - return r; 3462 + goto err; 3456 3463 } 3457 3464 3458 3465 return 0; 3466 + 3467 + err: 3468 + kmem_cache_destroy(migration_cache); 3469 + kmem_cache_destroy(btracker_work_cache); 3470 + return r; 3459 3471 } 3460 3472 3461 3473 static void __exit dm_cache_exit(void) 3462 3474 { 3463 3475 dm_unregister_target(&cache_target); 3464 3476 kmem_cache_destroy(migration_cache); 3477 + kmem_cache_destroy(btracker_work_cache); 3465 3478 } 3466 3479 3467 3480 module_init(dm_cache_init);