[dm-devel] [PATCH] dm.c : Per-device caches

Kevin Corry corryk at us.ibm.com
Mon Jan 13 11:23:01 UTC 2003


If the per-device-cache patch is accepted, here is a corresponding one for 
2.4.

--- linux-2.4.20a/drivers/md/dm.c	2003/01/10 20:11:44
+++ linux-2.4.20b/drivers/md/dm.c	2003/01/13 16:11:51
@@ -65,11 +65,11 @@
 	/*
 	 * io objects are allocated from here.
 	 */
+	kmem_cache_t *io_cache;
 	mempool_t *io_pool;
 };
 
 #define MIN_IOS 256
-static kmem_cache_t *_io_cache;
 
 /* block device arrays */
 static int _block_size[MAX_DEVICES];
@@ -85,18 +85,10 @@
 {
 	int r;
 
-	/* allocate a slab for the dm_ios */
-	_io_cache = kmem_cache_create("dm io",
-				      sizeof(struct dm_io), 0, 0, NULL, NULL);
-
-	if (!_io_cache)
-		return -ENOMEM;
-
 	_major = major;
 	r = register_blkdev(_major, _name, &dm_blk_dops);
 	if (r < 0) {
 		DMERR("register_blkdev failed");
-		kmem_cache_destroy(_io_cache);
 		return r;
 	}
 
@@ -116,8 +108,6 @@
 
 static void local_exit(void)
 {
-	kmem_cache_destroy(_io_cache);
-
 	if (unregister_blkdev(_major, _name) < 0)
 		DMERR("devfs_unregister_blkdev failed");
 
@@ -585,6 +575,7 @@
 static struct mapped_device *alloc_dev(int minor)
 {
 	struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
+	char name[15];
 
 	if (!md) {
 		DMWARN("unable to allocate device, out of memory.");
@@ -601,9 +592,19 @@
 	DMWARN("allocating minor %d.", minor);
 	memset(md, 0, sizeof(*md));
 
+	snprintf(name, 15, "dm io %d", minor);
+	md->io_cache = kmem_cache_create(name, sizeof(struct dm_io),
+					 0, 0, NULL, NULL);
+	if (!md->io_cache) {
+		free_minor(minor);
+		kfree(md);
+		return NULL;
+	}
+
 	md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
-				     mempool_free_slab, _io_cache);
+				     mempool_free_slab, md->io_cache);
 	if (!md->io_pool) {
+		kmem_cache_destroy(md->io_cache);
 		free_minor(minor);
 		kfree(md);
 		return NULL;
@@ -622,6 +623,7 @@
 {
 	free_minor(minor(md->dev));
 	mempool_destroy(md->io_pool);
+	kmem_cache_destroy(md->io_cache);
 	kfree(md);
 }
 




More information about the dm-devel mailing list