aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-05-01 13:43:03 -0400
committerAlex Elder <elder@inktank.com>2013-05-02 12:58:29 -0400
commit1c2a9dfe2107e81b9f0ee90845c687cf7ff84106 (patch)
treee3d81737000df3bc76ed51b46f2963df7a25f45c
parent30d1cff817808fca9801c743d2de4c61f3f38e15 (diff)
rbd: allocate image requests with a slab allocator
Create a slab cache to manage rbd_img_request allocation. Nothing too fancy at this point--we'll still initialize everything at allocation time (no constructor) This is part of: http://tracker.ceph.com/issues/3926 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r--drivers/block/rbd.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 82d9586a4172..e90abde47de0 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -40,6 +40,7 @@
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/fs.h> 41#include <linux/fs.h>
42#include <linux/blkdev.h> 42#include <linux/blkdev.h>
43#include <linux/slab.h>
43 44
44#include "rbd_types.h" 45#include "rbd_types.h"
45 46
@@ -344,6 +345,8 @@ static DEFINE_SPINLOCK(rbd_dev_list_lock);
344static LIST_HEAD(rbd_client_list); /* clients */ 345static LIST_HEAD(rbd_client_list); /* clients */
345static DEFINE_SPINLOCK(rbd_client_list_lock); 346static DEFINE_SPINLOCK(rbd_client_list_lock);
346 347
348static struct kmem_cache *rbd_img_request_cache;
349
347static int rbd_img_request_submit(struct rbd_img_request *img_request); 350static int rbd_img_request_submit(struct rbd_img_request *img_request);
348 351
349static void rbd_dev_device_release(struct device *dev); 352static void rbd_dev_device_release(struct device *dev);
@@ -1821,7 +1824,7 @@ static struct rbd_img_request *rbd_img_request_create(
1821{ 1824{
1822 struct rbd_img_request *img_request; 1825 struct rbd_img_request *img_request;
1823 1826
1824 img_request = kmalloc(sizeof (*img_request), GFP_ATOMIC); 1827 img_request = kmem_cache_alloc(rbd_img_request_cache, GFP_ATOMIC);
1825 if (!img_request) 1828 if (!img_request)
1826 return NULL; 1829 return NULL;
1827 1830
@@ -1884,7 +1887,7 @@ static void rbd_img_request_destroy(struct kref *kref)
1884 if (img_request_child_test(img_request)) 1887 if (img_request_child_test(img_request))
1885 rbd_obj_request_put(img_request->obj_request); 1888 rbd_obj_request_put(img_request->obj_request);
1886 1889
1887 kfree(img_request); 1890 kmem_cache_free(rbd_img_request_cache, img_request);
1888} 1891}
1889 1892
1890static bool rbd_img_obj_end_request(struct rbd_obj_request *obj_request) 1893static bool rbd_img_obj_end_request(struct rbd_obj_request *obj_request)
@@ -4992,6 +4995,26 @@ static void rbd_sysfs_cleanup(void)
4992 device_unregister(&rbd_root_dev); 4995 device_unregister(&rbd_root_dev);
4993} 4996}
4994 4997
4998static int rbd_slab_init(void)
4999{
5000 rbd_assert(!rbd_img_request_cache);
5001 rbd_img_request_cache = kmem_cache_create("rbd_img_request",
5002 sizeof (struct rbd_img_request),
5003 __alignof__(struct rbd_img_request),
5004 0, NULL);
5005 if (rbd_img_request_cache)
5006 return 0;
5007
5008 return -ENOMEM;
5009}
5010
5011static void rbd_slab_exit(void)
5012{
5013 rbd_assert(rbd_img_request_cache);
5014 kmem_cache_destroy(rbd_img_request_cache);
5015 rbd_img_request_cache = NULL;
5016}
5017
4995static int __init rbd_init(void) 5018static int __init rbd_init(void)
4996{ 5019{
4997 int rc; 5020 int rc;
@@ -5001,16 +5024,22 @@ static int __init rbd_init(void)
5001 5024
5002 return -EINVAL; 5025 return -EINVAL;
5003 } 5026 }
5004 rc = rbd_sysfs_init(); 5027 rc = rbd_slab_init();
5005 if (rc) 5028 if (rc)
5006 return rc; 5029 return rc;
5007 pr_info("loaded " RBD_DRV_NAME_LONG "\n"); 5030 rc = rbd_sysfs_init();
5008 return 0; 5031 if (rc)
5032 rbd_slab_exit();
5033 else
5034 pr_info("loaded " RBD_DRV_NAME_LONG "\n");
5035
5036 return rc;
5009} 5037}
5010 5038
5011static void __exit rbd_exit(void) 5039static void __exit rbd_exit(void)
5012{ 5040{
5013 rbd_sysfs_cleanup(); 5041 rbd_sysfs_cleanup();
5042 rbd_slab_exit();
5014} 5043}
5015 5044
5016module_init(rbd_init); 5045module_init(rbd_init);