aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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/*