libceph: use slab caches in messenger and osd osd client
cover libceph: use slab caches in messenger and osd osd client
This series adds slab caches to some frequently-allocated data structures in the messenger and the osd client.
-Alex
[PATCH 1/3] libceph: allocate ceph messages with a slab allocator [PATCH 2/3] libceph: allocate ceph message data with a slab [PATCH 3/3] libceph: use slab cache for osd client requests
PATCH 1/3 libceph: allocate ceph messages with a slab allocator
Create a slab cache to manage ceph_msg structure allocation.
This is part of:
http://tracker.ceph.com/issues/3926
--- net/ceph/messenger.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
net/ceph/messenger.c +0 -0
@@ -152,6 +152,10 @@ static bool con_flag_test_and_set(struct
ceph_connection *con,
return test_and_set_bit(con_flag, &con->flags);
}
+/* Slab caches for frequently-allocated structures */
+
+static struct kmem_cache *ceph_msg_cache;
+
/* static tag bytes (protocol control messages) */
static char tag_msg = CEPH_MSGR_TAG_MSG;
static char tag_ack = CEPH_MSGR_TAG_ACK;
@@ -226,6 +230,22 @@ static void encode_my_addr(struct ceph_messenger *msgr)
*/
static struct workqueue_struct *ceph_msgr_wq;
+static int ceph_msgr_slab_init(void)
+{
+ BUG_ON(ceph_msg_cache);
+ ceph_msg_cache = kmem_cache_create("ceph_msg",
+ sizeof (struct ceph_msg),
+ __alignof__(struct ceph_msg), 0, NULL);
+ return ceph_msg_cache ? 0 : -ENOMEM;
+}
+
+static void ceph_msgr_slab_exit(void)
+{
+ BUG_ON(!ceph_msg_cache);
+ kmem_cache_destroy(ceph_msg_cache);
+ ceph_msg_cache = NULL;
+}
+
static void _ceph_msgr_exit(void)
{
if (ceph_msgr_wq) {
@@ -233,6 +253,8 @@ static void _ceph_msgr_exit(void)
ceph_msgr_wq = NULL;
}
+ ceph_msgr_slab_exit();
+
BUG_ON(zero_page == NULL);
kunmap(zero_page);
page_cache_release(zero_page);
@@ -245,6 +267,9 @@ int ceph_msgr_init(void)
zero_page = ZERO_PAGE(0);
page_cache_get(zero_page);
+ if (ceph_msgr_slab_init())
+ return -ENOMEM;
+
ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); if (ceph_msgr_wq)
return 0;
@@ -3068,7 +3093,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
{
struct ceph_msg *m;
- m = kzalloc(sizeof(*m), flags);
+ m = kmem_cache_zalloc(ceph_msg_cache, flags);
if (m == NULL)
goto out;
@@ -3215,7 +3240,7 @@ void ceph_msg_kfree(struct ceph_msg *m)
vfree(m->front.iov_base);
else
kfree(m->front.iov_base);
- kfree(m);
+ kmem_cache_free(ceph_msg_cache, m);
}
/*
Signature · 1 line
1.7.9.5
PATCH 2/3 libceph: allocate ceph message data with a slab
In reply to Alex ElderCreate a slab cache to manage ceph_msg_data structure allocation.
This is part of:
http://tracker.ceph.com/issues/3926
--- net/ceph/messenger.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
net/ceph/messenger.c +0 -0
@@ -155,6 +155,7 @@ static bool con_flag_test_and_set(struct
ceph_connection *con,
/* Slab caches for frequently-allocated structures */
static struct kmem_cache *ceph_msg_cache;
+static struct kmem_cache *ceph_msg_data_cache;
/* static tag bytes (protocol control messages) */
static char tag_msg = CEPH_MSGR_TAG_MSG;
@@ -236,11 +237,30 @@ static int ceph_msgr_slab_init(void)
ceph_msg_cache = kmem_cache_create("ceph_msg",
sizeof (struct ceph_msg), __alignof__(struct ceph_msg), 0, NULL);
- return ceph_msg_cache ? 0 : -ENOMEM;
+
+ if (!ceph_msg_cache)
+ return -ENOMEM;
+
+ BUG_ON(ceph_msg_data_cache);
+ ceph_msg_data_cache = kmem_cache_create("ceph_msg_data",
+ sizeof (struct ceph_msg_data),
+ __alignof__(struct ceph_msg_data),
+ 0, NULL);
+ if (ceph_msg_data_cache)
+ return 0;
+
+ kmem_cache_destroy(ceph_msg_cache);
+ ceph_msg_cache = NULL;
+
+ return -ENOMEM;
}
static void ceph_msgr_slab_exit(void)
{
+ BUG_ON(!ceph_msg_data_cache);
+ kmem_cache_destroy(ceph_msg_data_cache);
+ ceph_msg_data_cache = NULL;
+
BUG_ON(!ceph_msg_cache); kmem_cache_destroy(ceph_msg_cache); ceph_msg_cache = NULL;
@@ -3008,7 +3028,7 @@ static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type)
if (WARN_ON(!ceph_msg_data_type_valid(type)))
return NULL;
- data = kzalloc(sizeof (*data), GFP_NOFS);
+ data = kmem_cache_zalloc(ceph_msg_data_cache, GFP_NOFS);
if (data)
data->type = type;
INIT_LIST_HEAD(&data->links);
@@ -3026,7 +3046,7 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data)
ceph_pagelist_release(data->pagelist); kfree(data->pagelist);
}
- kfree(data);
+ kmem_cache_free(ceph_msg_data_cache, data);
}
void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
Signature · 1 line
1.7.9.5
PATCH 3/3 libceph: use slab cache for osd client requests
In reply to Alex ElderCreate a slab cache to manage allocation of ceph_osdc_request structures.
This resolves:
http://tracker.ceph.com/issues/3926
--- include/linux/ceph/osd_client.h | 3 +++ net/ceph/ceph_common.c | 7 +++++++ net/ceph/osd_client.c | 27 +++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-)
(quoted diff) +0 -0
b/include/linux/ceph/osd_client.h
index 4191cd2..186db0b 100644
include/linux/ceph/osd_client.h +3 -0
@@ -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);
net/ceph/ceph_common.c +7 -0
@@ -601,11 +601,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:
@@ -617,6 +623,7 @@ out: static void __exit exit_ceph_lib(void) {dout ("exit_ceph_lib\n" ); +ceph_osdc_cleanup ();ceph_msgr_exit ();ceph_crypto_shutdown ();ceph_debugfs_cleanup ();
net/ceph/osd_client.c +4 -1
@@ -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);
@@ -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);
@@ -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;
@@ -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
*/
Signature · 1 line
1.7.9.5
Quoted 8 lines · Alex Elder
This series adds slab caches to some frequently-allocated data structures in the messenger and the osd client.
-Alex
[PATCH 1/3] libceph: allocate ceph messages with a slab allocator [PATCH 2/3] libceph: allocate ceph message data with a slab [PATCH 3/3] libceph: use slab cache for osd client requests
These all look good.