Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1276755

Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work

From Linus Torvalds <torvalds@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work
Date 2015-11-24 21:50 +0100
Message-ID <qysHg-4BO-1@gated-at.bofh.it> (permalink)
References <qwaYa-3sP-5@gated-at.bofh.it> <qwb7R-3wi-15@gated-at.bofh.it> <qy8fw-89o-19@gated-at.bofh.it> <qysnT-4vl-9@gated-at.bofh.it> <qysnT-4vl-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Nov 24, 2015 at 12:28 PM, Tejun Heo <tj@kernel.org> wrote:
>>
>> In general, it's very dangerous to try to cook up your own locking
>> rules. People *always* get it wrong.
>
> It's either trylock on timer side or timer active spinning trick on
> canceling side, so this seems the lesser of the two evils.

I'm not saying the approach is wrong.

I'm saying that people need to realize that locking is harder than
they think, and not cook up their own lock primitives using things
like trylock without really thinking about it a *lot*.

Basically, "trylock()" on its own should never be used in a loop. The
main use for trylock should be one of:

 - thing that you can just not do at all if you can't get the lock

 - avoiding ABBA deadlocks: if you have a A->B locking order, but you
already hold B, instead of "drop B, then take A and B in the right
order", you may decide to first "trylock(A)" - and if that fails you
then fall back on the "drop and relock in the right order".

but if what you want to create is a "get lock using trylock", you need
to be very aware of the cache coherency traffic issue at least.

It is possible that we should think about trying to introduce a new
primitive for that "loop_try_lock()" thing. But it's probably not
common enough to be worth it - we've had this issue before, but I
think it's a "once every couple of years" kind of thing rather than
anything that we need to worry about.

The "locking is hard" issue is very real, though. We've traditionally
had a *lot* of code that tried to do its own locking, and not getting
the memory ordering right etc. Things that happen to work on x86 but
don't on other architectures etc.

                       Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/22] kthread: Use kthread worker API more widely Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 22/22] thermal/intel_powerclamp: Convert the kthread to kthread worker API Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 06/22] kthread: Add destroy_kthread_worker() Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 20/22] memstick/r592: convert r592_io kthread into kthread worker API Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 18/22] IB/fmr_pool: Convert the cleanup thread into kthread worker API Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
    Re: [PATCH v3 18/22] IB/fmr_pool: Convert the cleanup thread into  kthread worker API Yuval Shaia <yuval.shaia@oracle.com> - 2015-11-19 13:50 +0100
  [PATCH v3 10/22] kthread: Allow to modify delayed kthread work Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 11/22] kthread: Better support freezable kthread workers Petr Mladek <pmladek@suse.com> - 2015-11-18 14:30 +0100
  [PATCH v3 08/22] kthread: Initial support for delayed kthread work Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
  [PATCH v3 12/22] kthread: Use try_lock_kthread_work() in flush_kthread_work() Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
  [PATCH v3 05/22] kthread: Add drain_kthread_worker() Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
  [PATCH v3 13/22] mm/huge_page: Convert khugepaged() into kthread worker API Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
  [PATCH v3 09/22] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
    Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work Tejun Heo <tj@kernel.org> - 2015-11-24 00:00 +0100
      Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work Petr Mladek <pmladek@suse.com> - 2015-11-24 11:30 +0100
      Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work Tejun Heo <tj@kernel.org> - 2015-11-24 21:30 +0100
        Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-24 21:50 +0100
      Re: [PATCH v3 09/22] kthread: Allow to cancel kthread work Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-24 21:30 +0100
  [PATCH v3 04/22] kthread: Add create_kthread_worker*() Petr Mladek <pmladek@suse.com> - 2015-11-18 14:40 +0100
  Re: [PATCH v3 00/22] kthread: Use kthread worker API more widely "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2015-11-18 15:30 +0100

csiph-web