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:36 -0400 |
commit | 81b36be4c56299ac4c4c786908cb117ad232b62e (patch) | |
tree | f1b37087eabc44310bb1a82f4246f5ca0704ebb3 /net/ceph/messenger.c | |
parent | e3d5d6380482b4a5e2e9d0d662f2ef6d56504aef (diff) |
libceph: allocate ceph message data with a slab allocator
Create a slab cache to manage ceph_msg_data 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 | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index bc1ba4c2605d..eb0a46a49bd4 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c | |||
@@ -155,6 +155,7 @@ static bool con_flag_test_and_set(struct ceph_connection *con, | |||
155 | /* Slab caches for frequently-allocated structures */ | 155 | /* Slab caches for frequently-allocated structures */ |
156 | 156 | ||
157 | static struct kmem_cache *ceph_msg_cache; | 157 | static struct kmem_cache *ceph_msg_cache; |
158 | static struct kmem_cache *ceph_msg_data_cache; | ||
158 | 159 | ||
159 | /* static tag bytes (protocol control messages) */ | 160 | /* static tag bytes (protocol control messages) */ |
160 | static char tag_msg = CEPH_MSGR_TAG_MSG; | 161 | static char tag_msg = CEPH_MSGR_TAG_MSG; |
@@ -236,11 +237,30 @@ static int ceph_msgr_slab_init(void) | |||
236 | ceph_msg_cache = kmem_cache_create("ceph_msg", | 237 | ceph_msg_cache = kmem_cache_create("ceph_msg", |
237 | sizeof (struct ceph_msg), | 238 | sizeof (struct ceph_msg), |
238 | __alignof__(struct ceph_msg), 0, NULL); | 239 | __alignof__(struct ceph_msg), 0, NULL); |
239 | return ceph_msg_cache ? 0 : -ENOMEM; | 240 | |
241 | if (!ceph_msg_cache) | ||
242 | return -ENOMEM; | ||
243 | |||
244 | BUG_ON(ceph_msg_data_cache); | ||
245 | ceph_msg_data_cache = kmem_cache_create("ceph_msg_data", | ||
246 | sizeof (struct ceph_msg_data), | ||
247 | __alignof__(struct ceph_msg_data), | ||
248 | 0, NULL); | ||
249 | if (ceph_msg_data_cache) | ||
250 | return 0; | ||
251 | |||
252 | kmem_cache_destroy(ceph_msg_cache); | ||
253 | ceph_msg_cache = NULL; | ||
254 | |||
255 | return -ENOMEM; | ||
240 | } | 256 | } |
241 | 257 | ||
242 | static void ceph_msgr_slab_exit(void) | 258 | static void ceph_msgr_slab_exit(void) |
243 | { | 259 | { |
260 | BUG_ON(!ceph_msg_data_cache); | ||
261 | kmem_cache_destroy(ceph_msg_data_cache); | ||
262 | ceph_msg_data_cache = NULL; | ||
263 | |||
244 | BUG_ON(!ceph_msg_cache); | 264 | BUG_ON(!ceph_msg_cache); |
245 | kmem_cache_destroy(ceph_msg_cache); | 265 | kmem_cache_destroy(ceph_msg_cache); |
246 | ceph_msg_cache = NULL; | 266 | ceph_msg_cache = NULL; |
@@ -3008,7 +3028,7 @@ static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type) | |||
3008 | if (WARN_ON(!ceph_msg_data_type_valid(type))) | 3028 | if (WARN_ON(!ceph_msg_data_type_valid(type))) |
3009 | return NULL; | 3029 | return NULL; |
3010 | 3030 | ||
3011 | data = kzalloc(sizeof (*data), GFP_NOFS); | 3031 | data = kmem_cache_zalloc(ceph_msg_data_cache, GFP_NOFS); |
3012 | if (data) | 3032 | if (data) |
3013 | data->type = type; | 3033 | data->type = type; |
3014 | INIT_LIST_HEAD(&data->links); | 3034 | INIT_LIST_HEAD(&data->links); |
@@ -3026,7 +3046,7 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data) | |||
3026 | ceph_pagelist_release(data->pagelist); | 3046 | ceph_pagelist_release(data->pagelist); |
3027 | kfree(data->pagelist); | 3047 | kfree(data->pagelist); |
3028 | } | 3048 | } |
3029 | kfree(data); | 3049 | kmem_cache_free(ceph_msg_data_cache, data); |
3030 | } | 3050 | } |
3031 | 3051 | ||
3032 | void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages, | 3052 | void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages, |