diff options
author | Alex Elder <elder@inktank.com> | 2013-05-01 13:43:04 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2013-05-02 12:58:31 -0400 |
commit | e3d5d6380482b4a5e2e9d0d662f2ef6d56504aef (patch) | |
tree | d71655db3cb326d263e9be8b9837dcc7027d9dfd /net/ceph/messenger.c | |
parent | 78c2a44aae2950ecf0279590572b861288714946 (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.c | 29 |
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 | |||
157 | static struct kmem_cache *ceph_msg_cache; | ||
158 | |||
155 | /* static tag bytes (protocol control messages) */ | 159 | /* static tag bytes (protocol control messages) */ |
156 | static char tag_msg = CEPH_MSGR_TAG_MSG; | 160 | static char tag_msg = CEPH_MSGR_TAG_MSG; |
157 | static char tag_ack = CEPH_MSGR_TAG_ACK; | 161 | static char tag_ack = CEPH_MSGR_TAG_ACK; |
@@ -226,6 +230,22 @@ static void encode_my_addr(struct ceph_messenger *msgr) | |||
226 | */ | 230 | */ |
227 | static struct workqueue_struct *ceph_msgr_wq; | 231 | static struct workqueue_struct *ceph_msgr_wq; |
228 | 232 | ||
233 | static 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 | |||
242 | static 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 | |||
229 | static void _ceph_msgr_exit(void) | 249 | static 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 | /* |