Skip to content

Commit

Permalink
libceph: use slab cache for osd client requests
Browse files Browse the repository at this point in the history
Create a slab cache to manage allocation of ceph_osdc_request
structures.

This resolves:
    http://tracker.ceph.com/issues/3926

Signed-off-by: Alex Elder <[email protected]>
Reviewed-by: Josh Durgin <[email protected]>
  • Loading branch information
Alex Elder committed May 2, 2013
1 parent 81b36be commit 5522ae0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/linux/ceph/osd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ struct ceph_osd_client {
struct workqueue_struct *notify_wq;
};

extern int ceph_osdc_setup(void);
extern void ceph_osdc_cleanup(void);

extern int ceph_osdc_init(struct ceph_osd_client *osdc,
struct ceph_client *client);
extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
Expand Down
7 changes: 7 additions & 0 deletions net/ceph/ceph_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,17 @@ static int __init init_ceph_lib(void)
if (ret < 0)
goto out_crypto;

ret = ceph_osdc_setup();
if (ret < 0)
goto out_msgr;

pr_info("loaded (mon/osd proto %d/%d)\n",
CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL);

return 0;

out_msgr:
ceph_msgr_exit();
out_crypto:
ceph_crypto_shutdown();
out_debugfs:
Expand All @@ -622,6 +628,7 @@ static int __init init_ceph_lib(void)
static void __exit exit_ceph_lib(void)
{
dout("exit_ceph_lib\n");
ceph_osdc_cleanup();
ceph_msgr_exit();
ceph_crypto_shutdown();
ceph_debugfs_cleanup();
Expand Down
27 changes: 25 additions & 2 deletions net/ceph/osd_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define OSD_OP_FRONT_LEN 4096
#define OSD_OPREPLY_FRONT_LEN 512

static struct kmem_cache *ceph_osd_request_cache;

static const struct ceph_connection_operations osd_con_ops;

static void __send_queued(struct ceph_osd_client *osdc);
Expand Down Expand Up @@ -315,7 +317,8 @@ void ceph_osdc_release_request(struct kref *kref)
if (req->r_mempool)
mempool_free(req, req->r_osdc->req_mempool);
else
kfree(req);
kmem_cache_free(ceph_osd_request_cache, req);

}
EXPORT_SYMBOL(ceph_osdc_release_request);

Expand Down Expand Up @@ -346,7 +349,7 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
req = mempool_alloc(osdc->req_mempool, gfp_flags);
memset(req, 0, sizeof(*req));
} else {
req = kzalloc(sizeof(*req), gfp_flags);
req = kmem_cache_zalloc(ceph_osd_request_cache, gfp_flags);
}
if (req == NULL)
return NULL;
Expand Down Expand Up @@ -2365,6 +2368,26 @@ int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
}
EXPORT_SYMBOL(ceph_osdc_writepages);

int ceph_osdc_setup(void)
{
BUG_ON(ceph_osd_request_cache);
ceph_osd_request_cache = kmem_cache_create("ceph_osd_request",
sizeof (struct ceph_osd_request),
__alignof__(struct ceph_osd_request),
0, NULL);

return ceph_osd_request_cache ? 0 : -ENOMEM;
}
EXPORT_SYMBOL(ceph_osdc_setup);

void ceph_osdc_cleanup(void)
{
BUG_ON(!ceph_osd_request_cache);
kmem_cache_destroy(ceph_osd_request_cache);
ceph_osd_request_cache = NULL;
}
EXPORT_SYMBOL(ceph_osdc_cleanup);

/*
* handle incoming message
*/
Expand Down

0 comments on commit 5522ae0

Please sign in to comment.