From 1755c9f628c2a9f240c1d78765c4d4dd74c46e99 Mon Sep 17 00:00:00 2001 From: Alexander Boyko Date: Wed, 3 Aug 2016 11:12:19 +0300 Subject: [PATCH] LU-8475 target: use slab allocation The patch adds kmem slabs for target threads and session info to improve allocation and better accounting. Signed-off-by: Alexander Boyko Signed-off-by: Alexey Lyashkov Change-Id: Ia0a93d410618c5d7724f2dcc86f1bcb9ae32e572 Seagate-bug-id: MRP-2836 Reviewed-on: https://review.whamcloud.com/21654 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Alexey Lyashkov Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- lustre/target/tgt_main.c | 61 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/lustre/target/tgt_main.c b/lustre/target/tgt_main.c index 4d39237..ef85c9c 100644 --- a/lustre/target/tgt_main.c +++ b/lustre/target/tgt_main.c @@ -338,8 +338,37 @@ void tgt_fini(const struct lu_env *env, struct lu_target *lut) } EXPORT_SYMBOL(tgt_fini); +static struct kmem_cache *tgt_thread_kmem; +static struct kmem_cache *tgt_session_kmem; +static struct lu_kmem_descr tgt_caches[] = { + { + .ckd_cache = &tgt_thread_kmem, + .ckd_name = "tgt_thread_kmem", + .ckd_size = sizeof(struct tgt_thread_info), + }, + { + .ckd_cache = &tgt_session_kmem, + .ckd_name = "tgt_session_kmem", + .ckd_size = sizeof(struct tgt_session_info) + }, + { + .ckd_cache = NULL + } +}; + + /* context key constructor/destructor: tg_key_init, tg_key_fini */ -LU_KEY_INIT(tgt, struct tgt_thread_info); +static void *tgt_key_init(const struct lu_context *ctx, + struct lu_context_key *key) +{ + struct tgt_thread_info *thread; + + OBD_SLAB_ALLOC_PTR_GFP(thread, tgt_thread_kmem, GFP_NOFS); + if (thread == NULL) + return ERR_PTR(-ENOMEM); + + return thread; +} static void tgt_key_fini(const struct lu_context *ctx, struct lu_context_key *key, void *data) @@ -356,7 +385,7 @@ static void tgt_key_fini(const struct lu_context *ctx, if (args->ta_args != NULL) OBD_FREE(args->ta_args, sizeof(args->ta_args[0]) * args->ta_alloc_args); - OBD_FREE_PTR(info); + OBD_SLAB_FREE_PTR(info, tgt_thread_kmem); } static void tgt_key_exit(const struct lu_context *ctx, @@ -378,8 +407,25 @@ struct lu_context_key tgt_thread_key = { LU_KEY_INIT_GENERIC(tgt); -/* context key constructor/destructor: tgt_ses_key_init, tgt_ses_key_fini */ -LU_KEY_INIT_FINI(tgt_ses, struct tgt_session_info); +static void *tgt_ses_key_init(const struct lu_context *ctx, + struct lu_context_key *key) +{ + struct tgt_session_info *session; + + OBD_SLAB_ALLOC_PTR_GFP(session, tgt_session_kmem, GFP_NOFS); + if (session == NULL) + return ERR_PTR(-ENOMEM); + + return session; +} + +static void tgt_ses_key_fini(const struct lu_context *ctx, + struct lu_context_key *key, void *data) +{ + struct tgt_session_info *session = data; + + OBD_SLAB_FREE_PTR(session, tgt_session_kmem); +} /* context key: tgt_session_key */ struct lu_context_key tgt_session_key = { @@ -402,8 +448,13 @@ struct page *tgt_page_to_corrupt; int tgt_mod_init(void) { + int result; ENTRY; + result = lu_kmem_init(tgt_caches); + if (result != 0) + RETURN(result); + tgt_page_to_corrupt = alloc_page(GFP_KERNEL); tgt_key_init_generic(&tgt_thread_key, NULL); @@ -427,5 +478,7 @@ void tgt_mod_exit(void) lu_context_key_degister(&tgt_thread_key); lu_context_key_degister(&tgt_session_key); update_info_fini(); + + lu_kmem_fini(tgt_caches); } -- 1.8.3.1