diff options
author | Alex Elder <elder@inktank.com> | 2013-05-01 13:43:03 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2013-05-02 12:58:30 -0400 |
commit | 868311b1ebc9b203bae0d6d1f012ea5cbdadca03 (patch) | |
tree | 972ef543d655be8729ced0e85641fa2f2660dd33 | |
parent | f907ad55967fec6bc6ec5ee84021070c49cf0bb1 (diff) |
rbd: allocate object requests with a slab allocator
Create a slab cache to manage rbd_obj_request allocation. We aren't
using a constructor, and we'll zero-fill object request structures
when they're allocated.
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.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index d74be04ceeff..a72842aa3b53 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -346,6 +346,7 @@ static LIST_HEAD(rbd_client_list); /* clients */ | |||
346 | static DEFINE_SPINLOCK(rbd_client_list_lock); | 346 | static DEFINE_SPINLOCK(rbd_client_list_lock); |
347 | 347 | ||
348 | static struct kmem_cache *rbd_img_request_cache; | 348 | static struct kmem_cache *rbd_img_request_cache; |
349 | static struct kmem_cache *rbd_obj_request_cache; | ||
349 | 350 | ||
350 | static int rbd_img_request_submit(struct rbd_img_request *img_request); | 351 | static int rbd_img_request_submit(struct rbd_img_request *img_request); |
351 | 352 | ||
@@ -1762,7 +1763,7 @@ static struct rbd_obj_request *rbd_obj_request_create(const char *object_name, | |||
1762 | if (!name) | 1763 | if (!name) |
1763 | return NULL; | 1764 | return NULL; |
1764 | 1765 | ||
1765 | obj_request = kzalloc(sizeof (*obj_request), GFP_KERNEL); | 1766 | obj_request = kmem_cache_zalloc(rbd_obj_request_cache, GFP_KERNEL); |
1766 | if (!obj_request) { | 1767 | if (!obj_request) { |
1767 | kfree(name); | 1768 | kfree(name); |
1768 | return NULL; | 1769 | return NULL; |
@@ -1814,7 +1815,8 @@ static void rbd_obj_request_destroy(struct kref *kref) | |||
1814 | } | 1815 | } |
1815 | 1816 | ||
1816 | kfree(obj_request->object_name); | 1817 | kfree(obj_request->object_name); |
1817 | kfree(obj_request); | 1818 | obj_request->object_name = NULL; |
1819 | kmem_cache_free(rbd_obj_request_cache, obj_request); | ||
1818 | } | 1820 | } |
1819 | 1821 | ||
1820 | /* | 1822 | /* |
@@ -5008,14 +5010,29 @@ static int rbd_slab_init(void) | |||
5008 | sizeof (struct rbd_img_request), | 5010 | sizeof (struct rbd_img_request), |
5009 | __alignof__(struct rbd_img_request), | 5011 | __alignof__(struct rbd_img_request), |
5010 | 0, NULL); | 5012 | 0, NULL); |
5011 | if (rbd_img_request_cache) | 5013 | if (!rbd_img_request_cache) |
5014 | return -ENOMEM; | ||
5015 | |||
5016 | rbd_assert(!rbd_obj_request_cache); | ||
5017 | rbd_obj_request_cache = kmem_cache_create("rbd_obj_request", | ||
5018 | sizeof (struct rbd_obj_request), | ||
5019 | __alignof__(struct rbd_obj_request), | ||
5020 | 0, NULL); | ||
5021 | if (rbd_obj_request_cache) | ||
5012 | return 0; | 5022 | return 0; |
5013 | 5023 | ||
5024 | kmem_cache_destroy(rbd_img_request_cache); | ||
5025 | rbd_img_request_cache = NULL; | ||
5026 | |||
5014 | return -ENOMEM; | 5027 | return -ENOMEM; |
5015 | } | 5028 | } |
5016 | 5029 | ||
5017 | static void rbd_slab_exit(void) | 5030 | static void rbd_slab_exit(void) |
5018 | { | 5031 | { |
5032 | rbd_assert(rbd_obj_request_cache); | ||
5033 | kmem_cache_destroy(rbd_obj_request_cache); | ||
5034 | rbd_obj_request_cache = NULL; | ||
5035 | |||
5019 | rbd_assert(rbd_img_request_cache); | 5036 | rbd_assert(rbd_img_request_cache); |
5020 | kmem_cache_destroy(rbd_img_request_cache); | 5037 | kmem_cache_destroy(rbd_img_request_cache); |
5021 | rbd_img_request_cache = NULL; | 5038 | rbd_img_request_cache = NULL; |