Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-08 Thread Andi Kleen
> Sure, it probably is a non issue, but I'm afraid that non issues of today > might become issues of tomorrow. Where does it say that we can never put a > task struct in a movable zone. Task structs are not movable, so they by definition do not belong in movable zones. > memory local to it, and

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-08 Thread Steven Rostedt
On Thu, 8 Jan 2009, Andi Kleen wrote: > > What about memory hotplug as Ingo mentioned? > > > > Should that be: > > > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) > > We expect memory hotunplug to only really work in movable zones > (all others should at least have on

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Peter Zijlstra
On Wed, 2009-01-07 at 15:32 -0800, Linus Torvalds wrote: > > On Wed, 7 Jan 2009, Steven Rostedt wrote: > > > > What would be interesting is various benchmarks against all three. > > > > 1) no mutex spinning. > > 2) get_task_struct() implementation. > > 3) spin_or_sched implementation. > > One o

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Andi Kleen
> What about memory hotplug as Ingo mentioned? > > Should that be: > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) We expect memory hotunplug to only really work in movable zones (all others should at least have one kernel object somewhere that prevents unplug) and you

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Gregory Haskins
Steven Rostedt wrote: > On Wed, 7 Jan 2009, Gregory Haskins wrote: > >> In my defense, the -rt versions of the patches guarantee this is ok >> based on a little hack: >> > > The -rt versions worry about much more than what the mutex code in > mainline does. Linus is correct in his arguments

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Gregory Haskins wrote: > > In my defense, the -rt versions of the patches guarantee this is ok > based on a little hack: The -rt versions worry about much more than what the mutex code in mainline does. Linus is correct in his arguments. The adaptive mutex (as suppose to wha

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Gregory Haskins
[resend: restore CC list] >>> Linus Torvalds 01/07/09 6:33 PM >>> >On Wed, 7 Jan 2009, Steven Rostedt wrote: >> >> What would be interesting is various benchmarks against all three. >> >> 1) no mutex spinning. >> 2) get_task_struct() implementation. >> 3) spin_or_sched implementation. > >One of

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Gregory Haskins
[resend: i fat fingered the reply-to-all for a few messages] >>> Linus Torvalds 01/07/09 6:20 PM >>> >On Wed, 7 Jan 2009, Linus Torvalds wrote: >> > >> > "Is get_task_struct() really that bad?" >> >> Yes. It's an atomic access (two, in fact, since you need to release it >> too), which is a huge

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread KAMEZAWA Hiroyuki
On Wed, 7 Jan 2009 21:33:31 -0500 (EST) Steven Rostedt wrote: > > On Wed, 7 Jan 2009, Linus Torvalds wrote: > > > Should that be: > > > > > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) > > > > Well, probably CONFIG_MEMORY_HOTREMOVE, no? And I'd actually suggest that

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Linus Torvalds wrote: > > Should that be: > > > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) > > Well, probably CONFIG_MEMORY_HOTREMOVE, no? And I'd actually suggest that > unplugging should have a stop-machine if it doesn't already, just because

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread KAMEZAWA Hiroyuki
On Wed, 7 Jan 2009 15:57:06 -0800 (PST) Linus Torvalds wrote: > > > On Wed, 7 Jan 2009, Steven Rostedt wrote: > > > > Should that be: > > > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) > > Well, probably CONFIG_MEMORY_HOTREMOVE, no? And I'd actually suggest that >

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Steven Rostedt wrote: > > Should that be: > > #if defined(CONFIG_DEBUG_PAGEALLOC) || defined(CONFIG_MEMORY_HOTPLUG) Well, probably CONFIG_MEMORY_HOTREMOVE, no? And I'd actually suggest that unplugging should have a stop-machine if it doesn't already, just because it's suc

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Steven Rostedt wrote: > > On Wed, 7 Jan 2009, Steven Rostedt wrote: > > > > True. I need to keep looking at the code that is posted. In -rt, we force > > the fast path into the slowpath as soon as another task fails to get the > > lock. Without that, as you pointed out, t

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Linus Torvalds wrote: > On Wed, 7 Jan 2009, Dave Kleikamp wrote: > > > > Do you need to even do that if CONFIG_DEBUG_PAGEALLOC is unset? > > No. > > > Something like: > > > > #ifdef CONFIG_DEBUG_PAGEALLOC > > /* > > * Need to access the cpu

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Steven Rostedt wrote: > > True. I need to keep looking at the code that is posted. In -rt, we force > the fast path into the slowpath as soon as another task fails to get the > lock. Without that, as you pointed out, the code can be racy. I mean we force the fast unlock pat

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Linus Torvalds wrote: > On Wed, 7 Jan 2009, Steven Rostedt wrote: > > > > What would be interesting is various benchmarks against all three. > > > > 1) no mutex spinning. > > 2) get_task_struct() implementation. > > 3) spin_or_sched implementation. > > One of the issues is t

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Steven Rostedt wrote: > > What would be interesting is various benchmarks against all three. > > 1) no mutex spinning. > 2) get_task_struct() implementation. > 3) spin_or_sched implementation. One of the issues is that I cannot convince myself that (2) is even necessarily

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Paul E. McKenney
On Wed, Jan 07, 2009 at 05:28:12PM -0500, Gregory Haskins wrote: > Andi Kleen wrote: > >> I appreciate this is sample code, but using __get_user() on > >> non-userspace pointers messes up architectures which have separate > >> user/kernel spaces (eg the old 4G/4G split for x86-32). Do we have an >

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Linus Torvalds wrote: > > > > "Is get_task_struct() really that bad?" > > Yes. It's an atomic access (two, in fact, since you need to release it > too), which is a huge deal if we're talking about a timing-critical > section of code. There's another issue: you also need t

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Dave Kleikamp wrote: > > Do you need to even do that if CONFIG_DEBUG_PAGEALLOC is unset? No. > Something like: > > #ifdef CONFIG_DEBUG_PAGEALLOC > /* > * Need to access the cpu field knowing that > * DEBUG_PAGEALLOC could h

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Gregory Haskins wrote: > > Can I ask a simple question in light of all this discussion? > > "Is get_task_struct() really that bad?" Yes. It's an atomic access (two, in fact, since you need to release it too), which is a huge deal if we're talking about a timing-critical s

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Peter W. Morreale
On Wed, 2009-01-07 at 15:51 -0700, Peter W. Morreale wrote: > On Wed, 2009-01-07 at 23:33 +0100, Ingo Molnar wrote: > > * Gregory Haskins wrote: > > > > > Can I ask a simple question in light of all this discussion? > > > > > > "Is get_task_struct() really that bad?" > > > > it dirties a cachel

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Peter Zijlstra wrote: > > Hmm, still wouldn't the spin_on_owner() loopyness and the above need > that need_resched() check you mentioned to that it can fall into the > slow path and go to sleep? Yes, I do think that the outer loop at least should have a test for need_resche

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Gregory Haskins wrote: > Hi Ingo, > > Ingo Molnar wrote: > > * Gregory Haskins wrote: > > > > > >> Can I ask a simple question in light of all this discussion? > >> > >> "Is get_task_struct() really that bad?" > >> > > > > it dirties a cacheline and it also involves

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Dave Kleikamp
On Wed, 2009-01-07 at 13:58 -0800, Linus Torvalds wrote: > > On Wed, 7 Jan 2009, Peter Zijlstra wrote: > > > > Do we really have to re-do all that code every loop? > > No, you're right, we can just look up the cpu once. Which makes Andrew's > argument that "probe_kernel_address()" isn't in any

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Gregory Haskins
Hi Ingo, Ingo Molnar wrote: > * Gregory Haskins wrote: > > >> Can I ask a simple question in light of all this discussion? >> >> "Is get_task_struct() really that bad?" >> > > it dirties a cacheline and it also involves atomics. > Yes, understood. But we should note we are always goin

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Peter W. Morreale
On Wed, 2009-01-07 at 23:33 +0100, Ingo Molnar wrote: > * Gregory Haskins wrote: > > > Can I ask a simple question in light of all this discussion? > > > > "Is get_task_struct() really that bad?" > > it dirties a cacheline and it also involves atomics. > > Also, it's a small design cleanliness

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Ingo Molnar
* Gregory Haskins wrote: > Can I ask a simple question in light of all this discussion? > > "Is get_task_struct() really that bad?" it dirties a cacheline and it also involves atomics. Also, it's a small design cleanliness issue to me: get_task_struct() impacts the lifetime of an object - an

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Gregory Haskins
Andi Kleen wrote: >> I appreciate this is sample code, but using __get_user() on >> non-userspace pointers messes up architectures which have separate >> user/kernel spaces (eg the old 4G/4G split for x86-32). Do we have an >> appropriate function for kernel space pointers? >> > > probe_kern

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Peter Zijlstra
On Wed, 2009-01-07 at 13:58 -0800, Linus Torvalds wrote: > > On Wed, 7 Jan 2009, Peter Zijlstra wrote: > > > > Do we really have to re-do all that code every loop? > > No, you're right, we can just look up the cpu once. Which makes Andrew's > argument that "probe_kernel_address()" isn't in any

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Linus Torvalds wrote: > > We don't actually care that it only happens once: this all has _known_ > races, and the "cpu_relax()" is a barrier. I phrased that badly. It's not that it has "known races", it's really that the whole code sequence is very much written and intende

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Peter Zijlstra wrote: > > Do we really have to re-do all that code every loop? No, you're right, we can just look up the cpu once. Which makes Andrew's argument that "probe_kernel_address()" isn't in any hot path even more true. > Also, it would still need to do the funny

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Ingo Molnar
* Andrew Morton wrote: > On Wed, 7 Jan 2009 22:32:22 +0100 > Ingo Molnar wrote: > > > > We could do the whole "oldfs = get_fs(); set_fs(KERNEL_DS); .. > > > set_fs(oldfs);" crud, but it would probably be better to just add an > > > architected accessor. Especially since it's going to general

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Peter Zijlstra
On Wed, 2009-01-07 at 12:55 -0800, Linus Torvalds wrote: > /* >* Look out! "thread" is an entirely speculative pointer >* access and not reliable. >*/ > void loop_while_oncpu(struct mutex *lock, struct thread_struct *thread) > { > for (;;) {

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Andrew Morton
On Wed, 7 Jan 2009 22:32:22 +0100 Ingo Molnar wrote: > > We could do the whole "oldfs = get_fs(); set_fs(KERNEL_DS); .. > > set_fs(oldfs);" crud, but it would probably be better to just add an > > architected accessor. Especially since it's going to generally just be a > > > > #define get_

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Linus Torvalds wrote: > > We've needed that before (and yes, we've simply mis-used __get_user() on > x86 before rather than add it). Ahh, yeah, we have a really broken form of this in probe_kernel_address(), but it's disgustingly slow. And it actually does a whole lot more

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Andrew Morton
On Wed, 7 Jan 2009 22:37:40 +0100 Andi Kleen wrote: > > But we can do that with __get_user(thread_info->cpu) (very unlikely page > > fault protection due to the possibility of CONFIG_DEBUG_PAGEALLOC) and > > then validating the cpu. It it's in range, we can use it and verify > > whether cpu_rq

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Ingo Molnar
* Linus Torvalds wrote: > > > On Wed, 7 Jan 2009, Matthew Wilcox wrote: > > > > I appreciate this is sample code, but using __get_user() on > > non-userspace pointers messes up architectures which have separate > > user/kernel spaces (eg the old 4G/4G split for x86-32). Do we have an > > app

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Ingo Molnar
* Linus Torvalds wrote: > /* >* Even if the access succeeded (likely case), >* the cpu field may no longer be valid. FIXME: >* this needs to validate that we can do a >* get_cpu(

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Andi Kleen
> I appreciate this is sample code, but using __get_user() on > non-userspace pointers messes up architectures which have separate > user/kernel spaces (eg the old 4G/4G split for x86-32). Do we have an > appropriate function for kernel space pointers? probe_kernel_address(). But it's slow. -A

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Matthew Wilcox wrote: > > I appreciate this is sample code, but using __get_user() on > non-userspace pointers messes up architectures which have separate > user/kernel spaces (eg the old 4G/4G split for x86-32). Do we have an > appropriate function for kernel space pointers

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Andi Kleen
> But we can do that with __get_user(thread_info->cpu) (very unlikely page > fault protection due to the possibility of CONFIG_DEBUG_PAGEALLOC) and > then validating the cpu. It it's in range, we can use it and verify > whether cpu_rq(cpu)->curr has that thread_info. > > So we can do all that l

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Matthew Wilcox
On Wed, Jan 07, 2009 at 12:55:49PM -0800, Linus Torvalds wrote: > void loop_while_oncpu(struct mutex *lock, struct thread_struct *thread) > { > for (;;) { > unsigned cpu; > struct runqueue *rq; > > if (lock

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
On Wed, 7 Jan 2009, Steven Rostedt wrote: > > Next comes the issue to know if the owner is still running. Wouldn't we > need to do something like > > if (task_thread_info(cpu_rq(cpu)->curr) == owner) Yes. After verifying that "cpu" is in a valid range. > I understand that this should n

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Steven Rostedt
On Wed, 7 Jan 2009, Linus Torvalds wrote: > > So we can do all that locklessly and optimistically, just going back and > verifying the results later. This is why "thread_info" is actually a > better thing to use than "task_struct" - we can look up the cpu in it with > a simple dereference. We

Re: [PATCH -v5][RFC]: mutex: implement adaptive spinning

2009-01-07 Thread Linus Torvalds
Ok a few more issues. This never stops. Here's the basic spinloop: On Wed, 7 Jan 2009, Peter Zijlstra wrote: > > + for (;;) { > + struct task_struct *l_owner; > + > + /* Stop spinning when there's a pending signal. */ > + if (signal_pending_state(task->st