linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: kbuild test robot <lkp@intel.com>,
	kbuild-all@01.org, Andrew Morton <akpm@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>, Tejun Heo <tj@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jiri Kosina <jkosina@suse.cz>, Borislav Petkov <bp@suse.de>,
	Michal Hocko <mhocko@suse.cz>,
	linux-mm@kvack.org, Vlastimil Babka <vbabka@suse.cz>,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 08/20] kthread: Allow to cancel kthread work
Date: Fri, 26 Feb 2016 16:38:18 +0100	[thread overview]
Message-ID: <20160226153818.GI3305@pathway.suse.cz> (raw)
In-Reply-To: <20160225125932.GI6357@twins.programming.kicks-ass.net>

On Thu 2016-02-25 13:59:32, Peter Zijlstra wrote:
> On Wed, Feb 24, 2016 at 05:18:05PM +0100, Petr Mladek wrote:
> > @@ -770,7 +782,22 @@ void delayed_kthread_work_timer_fn(unsigned long __data)
> >  	if (WARN_ON_ONCE(!worker))
> >  		return;
> >  
> > -	spin_lock(&worker->lock);
> > +	/*
> > +	 * We might be unable to take the lock if someone is trying to
> > +	 * cancel this work and calls del_timer_sync() when this callback
> > +	 * has already been removed from the timer list.
> > +	 */
> > +	while (!spin_trylock(&worker->lock)) {
> > +		/*
> > +		 * Busy wait with spin_is_locked() to avoid cache bouncing.
> > +		 * Break when canceling is set to avoid a deadlock.
> > +		 */
> > +		do {
> > +			if (work->canceling)
> > +				return;
> > +			cpu_relax();
> > +		} while (spin_is_locked(&worker->lock));
> > +	}
> >  	/* Work must not be used with more workers, see queue_kthread_work(). */
> >  	WARN_ON_ONCE(work->worker != worker);
> >  
> 
> This is pretty vile; why can't you drop the lock over del_timer_sync() ?

We would need to take the lock later and check if nobody has set the timer
again in the meantime.

Now, timer_active() check is not reliable. It does not check if the
timer handler is running at the moment. I tried to implement
a safe timer_active()[1] but nobody was keen to take it.

Even if we have that timer_active() check, we would need to add
some relock/check/try_again stuff around the del_timer_sync().
So, it would just move the complexity somewhere else.

I think that the current solution is quite elegant after all.
Thanks a lot Tejun for the idea.

Reference:
[1] http://thread.gmane.org/gmane.linux.kernel.mm/144964/focus=144965


Thanks a lot for review,
Petr

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-02-26 15:38 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 14:56 [PATCH v5 00/20] kthread: Use kthread worker API more widely Petr Mladek
2016-02-22 14:56 ` [PATCH v5 01/20] kthread/smpboot: Do not park in kthread_create_on_cpu() Petr Mladek
2016-02-22 14:56 ` [PATCH v5 02/20] kthread: Allow to call __kthread_create_on_node() with va_list args Petr Mladek
2016-02-22 14:56 ` [PATCH v5 03/20] kthread: Add create_kthread_worker*() Petr Mladek
2016-02-22 15:48   ` kbuild test robot
2016-02-24 15:56     ` Petr Mladek
2016-02-22 14:56 ` [PATCH v5 04/20] kthread: Add drain_kthread_worker() Petr Mladek
2016-02-25 12:35   ` Peter Zijlstra
2016-02-26 15:23     ` Petr Mladek
2016-02-27 15:18       ` Peter Zijlstra
2016-02-22 14:56 ` [PATCH v5 05/20] kthread: Add destroy_kthread_worker() Petr Mladek
2016-02-25 12:36   ` Peter Zijlstra
2016-02-26 15:15     ` Petr Mladek
2016-02-22 14:56 ` [PATCH v5 06/20] kthread: Detect when a kthread work is used by more workers Petr Mladek
2016-02-22 14:56 ` [PATCH v5 07/20] kthread: Initial support for delayed kthread work Petr Mladek
2016-02-22 16:06   ` kbuild test robot
2016-02-24 16:09     ` Petr Mladek
2016-02-22 14:56 ` [PATCH v5 08/20] kthread: Allow to cancel " Petr Mladek
2016-02-22 16:50   ` kbuild test robot
2016-02-24 16:18     ` Petr Mladek
2016-02-25 12:59       ` Peter Zijlstra
2016-02-26 15:38         ` Petr Mladek [this message]
2016-02-26 16:25           ` Peter Zijlstra
2016-02-26 17:00             ` Petr Mladek
2016-02-27 15:16               ` Peter Zijlstra
2016-02-22 14:56 ` [PATCH v5 09/20] kthread: Allow to modify delayed " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 10/20] kthread: Better support freezable kthread workers Petr Mladek
2016-02-22 17:33   ` kbuild test robot
2016-02-24 16:25     ` Petr Mladek
2016-02-25 13:01   ` Peter Zijlstra
2016-02-26 15:43     ` Petr Mladek
2016-02-22 14:57 ` [PATCH v5 11/20] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek
2016-02-22 14:57 ` [PATCH v5 12/20] ring_buffer: Convert benchmark kthreads " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 13/20] hung_task: Convert hungtaskd " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 14/20] kmemleak: Convert kmemleak kthread " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 15/20] ipmi: Convert kipmi " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 16/20] IB/fmr_pool: Convert the cleanup thread " Petr Mladek
2016-02-22 14:57 ` [PATCH v5 17/20] memstick/r592: Better synchronize debug messages in r592_io kthread Petr Mladek
2016-02-22 14:57 ` [PATCH v5 18/20] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek
2016-02-22 14:57 ` [PATCH v5 19/20] thermal/intel_powerclamp: Remove duplicated code that starts the kthread Petr Mladek
2016-02-22 14:57 ` [PATCH v5 20/20] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek

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=20160226153818.GI3305@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@suse.de \
    --cc=jkosina@suse.cz \
    --cc=josh@joshtriplett.org \
    --cc=kbuild-all@01.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=mhocko@suse.cz \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /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).