Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 373546
b: refs/heads/master
c: 78c2a44
h: refs/heads/master
v: v3
  • Loading branch information
Alex Elder committed May 2, 2013
1 parent c9b1193 commit 342844e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 868311b1ebc9b203bae0d6d1f012ea5cbdadca03
refs/heads/master: 78c2a44aae2950ecf0279590572b861288714946
32 changes: 29 additions & 3 deletions trunk/drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -5018,8 +5029,19 @@ static int rbd_slab_init(void)
sizeof (struct rbd_obj_request),
__alignof__(struct rbd_obj_request),
0, NULL);
if (rbd_obj_request_cache)
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:
if (rbd_obj_request_cache) {
kmem_cache_destroy(rbd_obj_request_cache);
rbd_obj_request_cache = NULL;
}

kmem_cache_destroy(rbd_img_request_cache);
rbd_img_request_cache = NULL;
Expand All @@ -5029,6 +5051,10 @@ static int rbd_slab_init(void)

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;
Expand Down

0 comments on commit 342844e

Please sign in to comment.