linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Shaohua Li <shli@fb.com>, linux-raid@vger.kernel.org
Cc: Kernel-team@fb.com, songliubraving@fb.com
Subject: Re: [PATCH 1/2] raid5-cache: suspend reclaim thread instead of shutdown
Date: Wed, 23 Nov 2016 13:41:45 +1100	[thread overview]
Message-ID: <87twayc3yu.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <598ff2610261ffa745b682c311d5300fefeb2fcc.1479751751.git.shli@fb.com>

[-- Attachment #1: Type: text/plain, Size: 2625 bytes --]

On Tue, Nov 22 2016, Shaohua Li wrote:

> There is mechanism to suspend a kernel thread. Use it instead of playing
> create/destroy game.

Good idea!

>
> Signed-off-by: Shaohua Li <shli@fb.com>
> ---
>  drivers/md/md.c          |  4 +++-
>  drivers/md/raid5-cache.c | 18 +++++-------------
>  2 files changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index d3cef77..f548469 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -7136,10 +7136,12 @@ static int md_thread(void *arg)
>  		wait_event_interruptible_timeout
>  			(thread->wqueue,
>  			 test_bit(THREAD_WAKEUP, &thread->flags)
> -			 || kthread_should_stop(),
> +			 || kthread_should_stop() || kthread_should_park(),
>  			 thread->timeout);
>  
>  		clear_bit(THREAD_WAKEUP, &thread->flags);
> +		if (kthread_should_park())
> +			kthread_parkme();
>  		if (!kthread_should_stop())
>  			thread->run(thread);
>  	}
> diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
> index 8cb79fc..5f817bd 100644
> --- a/drivers/md/raid5-cache.c
> +++ b/drivers/md/raid5-cache.c
> @@ -19,6 +19,7 @@
>  #include <linux/raid/md_p.h>
>  #include <linux/crc32c.h>
>  #include <linux/random.h>
> +#include <linux/kthread.h>
>  #include "md.h"
>  #include "raid5.h"
>  #include "bitmap.h"
> @@ -1437,23 +1438,14 @@ void r5l_quiesce(struct r5l_log *log, int state)
>  	struct mddev *mddev;
>  	if (!log || state == 2)
>  		return;
> -	if (state == 0) {
> -		/*
> -		 * This is a special case for hotadd. In suspend, the array has
> -		 * no journal. In resume, journal is initialized as well as the
> -		 * reclaim thread.
> -		 */
> -		if (log->reclaim_thread)
> -			return;
> -		log->reclaim_thread = md_register_thread(r5l_reclaim_thread,
> -					log->rdev->mddev, "reclaim");
> -		log->reclaim_thread->timeout = R5C_RECLAIM_WAKEUP_INTERVAL;
> -	} else if (state == 1) {
> +	if (state == 0)
> +		kthread_unpark(log->reclaim_thread->tsk);

The old code tested for log->reclaim_thread being NULL.  This new
version will just crash.


> +	else if (state == 1) {
>  		/* make sure r5l_write_super_and_discard_space exits */
>  		mddev = log->rdev->mddev;
>  		wake_up(&mddev->sb_wait);
> +		kthread_park(log->reclaim_thread->tsk);

r5l_do_reclaim has a wait loop internally.  I think you need that to
abort when kthread_should_park(), else this will block indefinitely.

Thanks,
NeilBrown


>  		r5l_wake_reclaim(log, MaxSector);
> -		md_unregister_thread(&log->reclaim_thread);
>  		r5l_do_reclaim(log);
>  	}
>  }
> -- 
> 2.9.3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

  parent reply	other threads:[~2016-11-23  2:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-21 18:29 [PATCH 1/2] raid5-cache: suspend reclaim thread instead of shutdown Shaohua Li
2016-11-21 18:29 ` [PATCH 2/2] md: stop write should stop journal reclaim Shaohua Li
2016-11-23  2:41 ` NeilBrown [this message]
2016-11-23  6:30   ` [PATCH 1/2] raid5-cache: suspend reclaim thread instead of shutdown Shaohua Li
2016-11-24  0:00     ` NeilBrown
2016-11-24  0:56       ` Shaohua Li
2016-11-24  3:13         ` NeilBrown

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=87twayc3yu.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=Kernel-team@fb.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=shli@fb.com \
    --cc=songliubraving@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).