From 758c5aa895d026146c66f8637d992ba6e72021a1 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 31 Mar 2020 06:41:11 -0400 Subject: [PATCH 1/3] Don't hold reference to module in thread Since stopping threads have to be done synchronusly, there is no need to keep reference to cas_cache module in each thread. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/threads.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/cas_cache/threads.c b/modules/cas_cache/threads.c index 4854782..f83f37f 100644 --- a/modules/cas_cache/threads.c +++ b/modules/cas_cache/threads.c @@ -54,7 +54,7 @@ static int _cas_io_queue_thread(void *data) wait_for_completion(&info->compl); printk(KERN_DEBUG "Thread %s stopped\n", info->name); kfree(info); - module_put_and_exit(0); + do_exit(0); return 0; } @@ -115,7 +115,7 @@ static int _cas_cleaner_thread(void *data) wait_for_completion(&info->compl); kfree(info); - module_put_and_exit(0); + do_exit(0); return 0; } @@ -149,7 +149,7 @@ static int _cas_metadata_updater_thread(void *data) wait_for_completion(&info->compl); kfree(info); - module_put_and_exit(0); + do_exit(0); return 0; } @@ -183,8 +183,6 @@ static int _cas_create_thread(struct cas_thread_info **pinfo, } info->thread = thread; - BUG_ON(!try_module_get(THIS_MODULE)); - /* Affinitize thread to core */ if (cpu != CAS_CPUS_ALL) kthread_bind(thread, cpu); From 1b3424a485e3a98c12ad081e48752f2417730979 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 31 Mar 2020 06:46:27 -0400 Subject: [PATCH 2/3] Revert "Free memory of all allocated threads." This reverts commit 4ec277433d86b73d6739c98ffb24b5535ad83bc0. --- modules/cas_cache/threads.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/modules/cas_cache/threads.c b/modules/cas_cache/threads.c index f83f37f..4bae862 100644 --- a/modules/cas_cache/threads.c +++ b/modules/cas_cache/threads.c @@ -51,10 +51,8 @@ static int _cas_io_queue_thread(void *data) /* If we get here, then thread was signalled to terminate. * So, let's free memory and exit. */ - wait_for_completion(&info->compl); printk(KERN_DEBUG "Thread %s stopped\n", info->name); kfree(info); - do_exit(0); return 0; } @@ -113,9 +111,7 @@ static int _cas_cleaner_thread(void *data) } } while (true); - wait_for_completion(&info->compl); - kfree(info); - do_exit(0); + complete_and_exit(&info->compl, 0); return 0; } @@ -147,9 +143,7 @@ static int _cas_metadata_updater_thread(void *data) atomic_read(&info->kicked)); } while (true); - wait_for_completion(&info->compl); - kfree(info); - do_exit(0); + complete_and_exit(&info->compl, 0); return 0; } @@ -205,10 +199,8 @@ static void _cas_start_thread(struct cas_thread_info *info) static void _cas_stop_thread(struct cas_thread_info *info) { if (info && info->thread) { - reinit_completion(&info->compl); atomic_set(&info->stop, 1); wake_up(&info->wq); - complete(&info->compl); } } From 664c974e03f879f2220a97f8cbb6cfa02a55e0e3 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 31 Mar 2020 06:47:37 -0400 Subject: [PATCH 3/3] Revert "Free thread memory after it is stopped." This reverts commit d483951ebe6e040e53579640a32eeb4e6fe189cf. --- modules/cas_cache/threads.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/cas_cache/threads.c b/modules/cas_cache/threads.c index 4bae862..e36504b 100644 --- a/modules/cas_cache/threads.c +++ b/modules/cas_cache/threads.c @@ -49,10 +49,9 @@ static int _cas_io_queue_thread(void *data) WARN(ocf_queue_pending_io(q), "Still pending IO requests\n"); /* If we get here, then thread was signalled to terminate. - * So, let's free memory and exit. + * So, let's complete and exit. */ - printk(KERN_DEBUG "Thread %s stopped\n", info->name); - kfree(info); + complete_and_exit(&info->compl, 0); return 0; } @@ -199,9 +198,13 @@ static void _cas_start_thread(struct cas_thread_info *info) static void _cas_stop_thread(struct cas_thread_info *info) { if (info && info->thread) { + reinit_completion(&info->compl); atomic_set(&info->stop, 1); wake_up(&info->wq); + wait_for_completion(&info->compl); + printk(KERN_DEBUG "Thread %s stopped\n", info->name); } + kfree(info); } int cas_create_queue_thread(ocf_queue_t q, int cpu)