aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph/messenger.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-05-01 13:43:04 -0400
committerAlex Elder <elder@inktank.com>2013-05-02 12:58:31 -0400
commite3d5d6380482b4a5e2e9d0d662f2ef6d56504aef (patch)
treed71655db3cb326d263e9be8b9837dcc7027d9dfd /net/ceph/messenger.c
parent78c2a44aae2950ecf0279590572b861288714946 (diff)
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 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net/ceph/messenger.c')
-rw-r--r--net/ceph/messenger.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 91dd45113c7b..bc1ba4c2605d 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -152,6 +152,10 @@ static bool con_flag_test_and_set(struct ceph_connection *con,
152 return test_and_set_bit(con_flag, &con->flags); 152 return test_and_set_bit(con_flag, &con->flags);
153} 153}
154 154
155/* Slab caches for frequently-allocated structures */
156
157static struct kmem_cache *ceph_msg_cache;
158
155/* static tag bytes (protocol control messages) */ 159/* static tag bytes (protocol control messages) */
156static char tag_msg = CEPH_MSGR_TAG_MSG; 160static char tag_msg = CEPH_MSGR_TAG_MSG;
157static char tag_ack = CEPH_MSGR_TAG_ACK; 161static char tag_ack = CEPH_MSGR_TAG_ACK;
@@ -226,6 +230,22 @@ static void encode_my_addr(struct ceph_messenger *msgr)
226 */ 230 */
227static struct workqueue_struct *ceph_msgr_wq; 231static struct workqueue_struct *ceph_msgr_wq;
228 232
233static int ceph_msgr_slab_init(void)
234{
235 BUG_ON(ceph_msg_cache);
236 ceph_msg_cache = kmem_cache_create("ceph_msg",
237 sizeof (struct ceph_msg),
238 __alignof__(struct ceph_msg), 0, NULL);
239 return ceph_msg_cache ? 0 : -ENOMEM;
240}
241
242static void ceph_msgr_slab_exit(void)
243{
244 BUG_ON(!ceph_msg_cache);
245 kmem_cache_destroy(ceph_msg_cache);
246 ceph_msg_cache = NULL;
247}
248
229static void _ceph_msgr_exit(void) 249static void _ceph_msgr_exit(void)
230{ 250{
231 if (ceph_msgr_wq) { 251 if (ceph_msgr_wq) {
@@ -233,6 +253,8 @@ static void _ceph_msgr_exit(void)
233 ceph_msgr_wq = NULL; 253 ceph_msgr_wq = NULL;
234 } 254 }
235 255
256 ceph_msgr_slab_exit();
257
236 BUG_ON(zero_page == NULL); 258 BUG_ON(zero_page == NULL);
237 kunmap(zero_page); 259 kunmap(zero_page);
238 page_cache_release(zero_page); 260 page_cache_release(zero_page);
@@ -245,6 +267,9 @@ int ceph_msgr_init(void)
245 zero_page = ZERO_PAGE(0); 267 zero_page = ZERO_PAGE(0);
246 page_cache_get(zero_page); 268 page_cache_get(zero_page);
247 269
270 if (ceph_msgr_slab_init())
271 return -ENOMEM;
272
248 ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0); 273 ceph_msgr_wq = alloc_workqueue("ceph-msgr", WQ_NON_REENTRANT, 0);
249 if (ceph_msgr_wq) 274 if (ceph_msgr_wq)
250 return 0; 275 return 0;
@@ -3068,7 +3093,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
3068{ 3093{
3069 struct ceph_msg *m; 3094 struct ceph_msg *m;
3070 3095
3071 m = kzalloc(sizeof(*m), flags); 3096 m = kmem_cache_zalloc(ceph_msg_cache, flags);
3072 if (m == NULL) 3097 if (m == NULL)
3073 goto out; 3098 goto out;
3074 3099
@@ -3215,7 +3240,7 @@ void ceph_msg_kfree(struct ceph_msg *m)
3215 vfree(m->front.iov_base); 3240 vfree(m->front.iov_base);
3216 else 3241 else
3217 kfree(m->front.iov_base); 3242 kfree(m->front.iov_base);
3218 kfree(m); 3243 kmem_cache_free(ceph_msg_cache, m);
3219} 3244}
3220 3245
3221/* 3246/*