From: Alex Elder <elder@inktank.com>
To: Josh Durgin <josh.durgin@inktank.com>
Cc: ceph-devel <ceph-devel@vger.kernel.org>
Subject: Re: [PATCH 4/4] rbd: allocate image object names with a slab allocator
Date: Thu, 02 May 2013 11:30:19 -0500 [thread overview]
Message-ID: <5182949B.50800@inktank.com> (raw)
In-Reply-To: <51829342.10900@inktank.com>
On 05/02/2013 11:24 AM, Josh Durgin wrote:
> On 05/01/2013 02:36 PM, Alex Elder wrote:
>> The names of objects used for image object requests are always fixed
>> size. So create a slab cache to manage them. Define a new function
>> rbd_segment_name_free() to match rbd_segment_name() (which is what
>> supplies the dynamically-allocated name buffer).
>>
>> This is part of:
>> http://tracker.ceph.com/issues/3926
>>
>> Signed-off-by: Alex Elder <elder@inktank.com>
>> ---
>> drivers/block/rbd.c | 34 ++++++++++++++++++++++++++++++----
>> 1 file changed, 30 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
>> index 28a5ea3..8d9aeef 100644
>> --- a/drivers/block/rbd.c
>> +++ b/drivers/block/rbd.c
>> @@ -345,8 +345,11 @@ static DEFINE_SPINLOCK(rbd_dev_list_lock);
>> static LIST_HEAD(rbd_client_list); /* clients */
>> static DEFINE_SPINLOCK(rbd_client_list_lock);
>>
>> +/* Slab caches for frequently-allocated structures */
>> +
>> static struct kmem_cache *rbd_img_request_cache;
>> static struct kmem_cache *rbd_obj_request_cache;
>> +static struct kmem_cache *rbd_segment_name_cache;
>>
>> static int rbd_img_request_submit(struct rbd_img_request *img_request);
>>
>> @@ -985,7 +988,7 @@ static const char *rbd_segment_name(struct
>> rbd_device *rbd_dev, u64 offset)
>> u64 segment;
>> int ret;
>>
>> - name = kmalloc(MAX_OBJ_NAME_SIZE + 1, GFP_NOIO);
>> + name = kmem_cache_alloc(rbd_segment_name_cache, GFP_NOIO);
>> if (!name)
>> return NULL;
>> segment = offset >> rbd_dev->header.obj_order;
>> @@ -1001,6 +1004,13 @@ static const char *rbd_segment_name(struct
>> rbd_device *rbd_dev, u64 offset)
>> return name;
>> }
>>
>> +static void rbd_segment_name_free(const char *name)
>> +{
>> + /* The explicit cast here is needed to drop the const qualifier */
>> +
>> + kmem_cache_free(rbd_segment_name_cache, (void *)name);
>> +}
>> +
>> static u64 rbd_segment_offset(struct rbd_device *rbd_dev, u64 offset)
>> {
>> u64 segment_size = (u64) 1 << rbd_dev->header.obj_order;
>> @@ -2033,7 +2043,8 @@ static int rbd_img_request_fill(struct
>> rbd_img_request *img_request,
>> length = rbd_segment_length(rbd_dev, img_offset, resid);
>> obj_request = rbd_obj_request_create(object_name,
>> offset, length, type);
>> - kfree(object_name); /* object request has its own copy */
>> + /* object request has its own copy of the object name */
>> + rbd_segment_name_free(object_name);
>> if (!obj_request)
>> goto out_unwind;
>>
>> @@ -5018,17 +5029,32 @@ static int rbd_slab_init(void)
>> sizeof (struct rbd_obj_request),
>> __alignof__(struct rbd_obj_request),
>> 0, NULL);
>> - if (rbd_obj_request_cache)
>> - return 0;
>> + if (!rbd_obj_request_cache)
>> + goto out_err;
>>
>> + rbd_assert(!rbd_segment_name_cache);
>> + rbd_segment_name_cache = kmem_cache_create("rbd_segment_name",
>> + MAX_OBJ_NAME_SIZE + 1, 1, 0, NULL);
>> + if (rbd_segment_name_cache)
>> + return 0;
>> +out_err:
>> kmem_cache_destroy(rbd_img_request_cache);
>> rbd_img_request_cache = NULL;
>>
>> + if (rbd_img_request_cache) {
>> + kmem_cache_destroy(rbd_obj_request_cache);
>> + rbd_img_request_cache = NULL;
>
> Should be rbd_obj_request_cache here and in the condition two lines up.
> With that fixed: Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Got it, I'll fix that, and I'll also fix that GFP
mixup in the previous one. Thanks for the review.
-Alex
>> + }
>> +
>> return -ENOMEM;
>> }
>>
>> static void rbd_slab_exit(void)
>> {
>> + rbd_assert(rbd_segment_name_cache);
>> + kmem_cache_destroy(rbd_segment_name_cache);
>> + rbd_segment_name_cache = NULL;
>> +
>> rbd_assert(rbd_obj_request_cache);
>> kmem_cache_destroy(rbd_obj_request_cache);
>> rbd_obj_request_cache = NULL;
>>
>
prev parent reply other threads:[~2013-05-02 16:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 21:34 [PATCH 0/4] rbd: use slab caches for frequently allocated structures Alex Elder
2013-05-01 21:35 ` [PATCH 1/4] rbd: allocate image requests with a slab allocator Alex Elder
2013-05-02 16:19 ` Josh Durgin
2013-05-02 16:28 ` Alex Elder
2013-05-01 21:35 ` [PATCH 2/4] rbd: allocate name separate from obj_request Alex Elder
2013-05-02 16:20 ` Josh Durgin
2013-05-01 21:36 ` [PATCH 3/4] rbd: allocate object requests with a slab allocator Alex Elder
2013-05-02 16:21 ` Josh Durgin
2013-05-01 21:36 ` [PATCH 4/4] rbd: allocate image object names " Alex Elder
2013-05-02 16:24 ` Josh Durgin
2013-05-02 16:30 ` Alex Elder [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5182949B.50800@inktank.com \
--to=elder@inktank.com \
--cc=ceph-devel@vger.kernel.org \
--cc=josh.durgin@inktank.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.