diff mbox

[3/4] rbd: allocate object requests with a slab allocator

Message ID 51818AC4.3070702@inktank.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Elder May 1, 2013, 9:36 p.m. UTC
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>
---
 drivers/block/rbd.c |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

 		return NULL;
@@ -1814,7 +1815,8 @@ static void rbd_obj_request_destroy(struct kref *kref)
 	}

 	kfree(obj_request->object_name);
-	kfree(obj_request);
+	obj_request->object_name = NULL;
+	kmem_cache_free(rbd_obj_request_cache, obj_request);
 }

 /*
@@ -5008,14 +5010,29 @@ static int rbd_slab_init(void)
 					sizeof (struct rbd_img_request),
 					__alignof__(struct rbd_img_request),
 					0, NULL);
-	if (rbd_img_request_cache)
+	if (!rbd_img_request_cache)
+		return -ENOMEM;
+
+	rbd_assert(!rbd_obj_request_cache);
+	rbd_obj_request_cache = kmem_cache_create("rbd_obj_request",
+					sizeof (struct rbd_obj_request),
+					__alignof__(struct rbd_obj_request),
+					0, NULL);
+	if (rbd_obj_request_cache)
 		return 0;

+	kmem_cache_destroy(rbd_img_request_cache);
+	rbd_img_request_cache = NULL;
+
 	return -ENOMEM;
 }

 static void rbd_slab_exit(void)
 {
+	rbd_assert(rbd_obj_request_cache);
+	kmem_cache_destroy(rbd_obj_request_cache);
+	rbd_obj_request_cache = NULL;
+
 	rbd_assert(rbd_img_request_cache);
 	kmem_cache_destroy(rbd_img_request_cache);
 	rbd_img_request_cache = NULL;

Comments

Josh Durgin May 2, 2013, 4:21 p.m. UTC | #1
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

On 05/01/2013 02:36 PM, Alex Elder wrote:
> 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>
> ---
>   drivers/block/rbd.c |   23 ++++++++++++++++++++---
>   1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
> index da9f41d..28a5ea3 100644
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -346,6 +346,7 @@ static LIST_HEAD(rbd_client_list);		/* clients */
>   static DEFINE_SPINLOCK(rbd_client_list_lock);
>
>   static struct kmem_cache	*rbd_img_request_cache;
> +static struct kmem_cache	*rbd_obj_request_cache;
>
>   static int rbd_img_request_submit(struct rbd_img_request *img_request);
>
> @@ -1762,7 +1763,7 @@ static struct rbd_obj_request
> *rbd_obj_request_create(const char *object_name,
>   	if (!name)
>   		return NULL;
>
> -	obj_request = kzalloc(sizeof (*obj_request), GFP_KERNEL);
> +	obj_request = kmem_cache_zalloc(rbd_obj_request_cache, GFP_KERNEL);
>   	if (!obj_request) {
>   		kfree(name);
>   		return NULL;
> @@ -1814,7 +1815,8 @@ static void rbd_obj_request_destroy(struct kref *kref)
>   	}
>
>   	kfree(obj_request->object_name);
> -	kfree(obj_request);
> +	obj_request->object_name = NULL;
> +	kmem_cache_free(rbd_obj_request_cache, obj_request);
>   }
>
>   /*
> @@ -5008,14 +5010,29 @@ static int rbd_slab_init(void)
>   					sizeof (struct rbd_img_request),
>   					__alignof__(struct rbd_img_request),
>   					0, NULL);
> -	if (rbd_img_request_cache)
> +	if (!rbd_img_request_cache)
> +		return -ENOMEM;
> +
> +	rbd_assert(!rbd_obj_request_cache);
> +	rbd_obj_request_cache = kmem_cache_create("rbd_obj_request",
> +					sizeof (struct rbd_obj_request),
> +					__alignof__(struct rbd_obj_request),
> +					0, NULL);
> +	if (rbd_obj_request_cache)
>   		return 0;
>
> +	kmem_cache_destroy(rbd_img_request_cache);
> +	rbd_img_request_cache = NULL;
> +
>   	return -ENOMEM;
>   }
>
>   static void rbd_slab_exit(void)
>   {
> +	rbd_assert(rbd_obj_request_cache);
> +	kmem_cache_destroy(rbd_obj_request_cache);
> +	rbd_obj_request_cache = NULL;
> +
>   	rbd_assert(rbd_img_request_cache);
>   	kmem_cache_destroy(rbd_img_request_cache);
>   	rbd_img_request_cache = NULL;
>

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index da9f41d..28a5ea3 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -346,6 +346,7 @@  static LIST_HEAD(rbd_client_list);		/* clients */
 static DEFINE_SPINLOCK(rbd_client_list_lock);

 static struct kmem_cache	*rbd_img_request_cache;
+static struct kmem_cache	*rbd_obj_request_cache;

 static int rbd_img_request_submit(struct rbd_img_request *img_request);

@@ -1762,7 +1763,7 @@  static struct rbd_obj_request
*rbd_obj_request_create(const char *object_name,
 	if (!name)
 		return NULL;

-	obj_request = kzalloc(sizeof (*obj_request), GFP_KERNEL);
+	obj_request = kmem_cache_zalloc(rbd_obj_request_cache, GFP_KERNEL);
 	if (!obj_request) {
 		kfree(name);