From: Hannes Reinecke <hare@suse.de>
To: Coly Li <colyli@suse.de>, linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, mlyle@lyle.org, tang.junhui@zte.com.cn
Subject: Re: [PATCH v1 02/10] bcache: set task properly in allocator_wait()
Date: Mon, 8 Jan 2018 08:10:49 +0100 [thread overview]
Message-ID: <49532f67-d6dc-805a-efe6-16dc3afcb34f@suse.de> (raw)
In-Reply-To: <20180103140325.63175-3-colyli@suse.de>
On 01/03/2018 03:03 PM, Coly Li wrote:
> Kernel thread routine bch_allocator_thread() references macro
> allocator_wait() to wait for a condition or quit to do_exit()
> when kthread_should_stop() is true.
>
> Macro allocator_wait() has 2 issues in setting task state, let's
> see its code piece,
>
> 284 while (1) { \
> 285 set_current_state(TASK_INTERRUPTIBLE); \
> 286 if (cond) \
> 287 break; \
> 288 \
> 289 mutex_unlock(&(ca)->set->bucket_lock); \
> 290 if (kthread_should_stop()) \
> 291 return 0; \
> 292 \
> 293 schedule(); \
> 294 mutex_lock(&(ca)->set->bucket_lock); \
> 295 } \
> 296 __set_current_state(TASK_RUNNING); \
>
> 1) At line 285, task state is set to TASK_INTERRUPTIBLE, if at line 290
> kthread_should_stop() is true, the kernel thread will terminate and return
> to kernel/kthread.s:kthread(), then calls do_exit() with TASK_INTERRUPTIBLE
> state. This is not a suggested behavior and a warning message will be
> reported by might_sleep() in do_exit() code path: "WARNING: do not call
> blocking ops when !TASK_RUNNING; state=1 set at [xxxx]".
>
> 2) Because task state is set to TASK_INTERRUPTIBLE at line 285, when break
> while-loop the task state has to be set back to TASK_RUNNING at line 296.
> Indeed it is unncessary, if task state is set to TASK_INTERRUPTIBLE before
> calling schedule() at line 293, we don't need to set the state back to
> TASK_RUNNING at line 296 anymore. The reason is, allocator kthread is only
> woken up by wake_up_process(), this routine makes sure the task state of
> allocator kthread will be TASK_RUNNING after it returns from schedule() at
> line 294 (see kernel/sched/core.c:try_to_wake_up() for more detailed
> information).
>
> This patch fixes the above 2 issues by,
> 1) Setting TASK_INTERRUPTIBLE state just before calling schedule().
> 2) Then setting TASK_RUNNING at line 296 is unnecessary, remove it.
>
> Signed-off-by: Coly Li <colyli@suse.de>
> ---
> drivers/md/bcache/alloc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
> index a0cc1bc6d884..48c002faf08d 100644
> --- a/drivers/md/bcache/alloc.c
> +++ b/drivers/md/bcache/alloc.c
> @@ -282,7 +282,6 @@ static void invalidate_buckets(struct cache *ca)
> #define allocator_wait(ca, cond) \
> do { \
> while (1) { \
> - set_current_state(TASK_INTERRUPTIBLE); \
> if (cond) \
> break; \
> \
> @@ -290,10 +289,10 @@ do { \
> if (kthread_should_stop()) \
> return 0; \
> \
> + set_current_state(TASK_INTERRUPTIBLE); \
> schedule(); \
> mutex_lock(&(ca)->set->bucket_lock); \
> } \
> - __set_current_state(TASK_RUNNING); \
> } while (0)
>
> static int bch_allocator_push(struct cache *ca, long bucket)
>
Same as with the previous patch; why not simply set it to TASK_RUNNING
before 'return 0' ?
Cheers,
Hannes
--
Dr. Hannes Reinecke Teamlead Storage & Networking
hare@suse.de +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
next prev parent reply other threads:[~2018-01-08 7:10 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-03 14:03 [PATCH v1 00/10] cache device failure handling improvement Coly Li
2018-01-03 14:03 ` [PATCH v1 01/10] bcache: exit bch_writeback_thread() with proper task state Coly Li
2018-01-03 17:08 ` Michael Lyle
2018-01-05 17:05 ` Coly Li
2018-01-05 17:09 ` Michael Lyle
2018-01-08 7:09 ` Hannes Reinecke
2018-01-08 13:50 ` Coly Li
2018-01-03 14:03 ` [PATCH v1 02/10] bcache: set task properly in allocator_wait() Coly Li
2018-01-03 17:09 ` Michael Lyle
2018-01-05 17:11 ` Coly Li
2018-01-08 7:10 ` Hannes Reinecke [this message]
2018-01-03 14:03 ` [PATCH v1 03/10] bcache: reduce cache_set devices iteration by devices_max_used Coly Li
2018-01-03 17:11 ` Michael Lyle
2018-01-08 7:12 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 04/10] bcache: fix cached_dev->count usage for bch_cache_set_error() Coly Li
2018-01-08 7:16 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 05/10] bcache: stop dc->writeback_rate_update if cache set is stopping Coly Li
2018-01-08 7:22 ` Hannes Reinecke
2018-01-08 16:01 ` Coly Li
2018-01-03 14:03 ` [PATCH v1 06/10] bcache: stop dc->writeback_rate_update, dc->writeback_thread earlier Coly Li
2018-01-08 7:25 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 07/10] bcache: set error_limit correctly Coly Li
2018-01-08 7:26 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 08/10] bcache: fix misleading error message in bch_count_io_errors() Coly Li
2018-01-03 17:14 ` Michael Lyle
2018-01-08 7:27 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 09/10] bcache: add io_disable to struct cache_set Coly Li
2018-01-08 7:30 ` Hannes Reinecke
2018-01-03 14:03 ` [PATCH v1 10/10] bcache: stop all attached bcache devices for a retired cache set Coly Li
2018-01-08 7:31 ` Hannes Reinecke
2018-01-03 17:07 ` [PATCH v1 00/10] cache device failure handling improvement Michael Lyle
2018-01-04 2:20 ` Coly Li
2018-01-04 17:46 ` Michael Lyle
2018-01-05 4:04 ` Coly Li
-- strict thread matches above, loose matches on Subject: below --
2018-01-03 18:29 [PATCH v1 02/10] bcache: set task properly in allocator_wait() tang.junhui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49532f67-d6dc-805a-efe6-16dc3afcb34f@suse.de \
--to=hare@suse.de \
--cc=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=mlyle@lyle.org \
--cc=tang.junhui@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox