Re: [PATCH 0/3] 64-bit futexes: Intro

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Ingo Molnar <mingo@...>
Cc: Linus Torvalds <torvalds@...>, David Howells <dhowells@...>, Ulrich Drepper <drepper@...>, Linux Kernel Mailing List <linux-kernel@...>, Andrew Morton <akpm@...>
Date: Monday, June 2, 2008 - 11:24 pm

On Tue, Jun 03, 2008 at 01:03:17AM +0200, Ingo Molnar wrote:

I think optimised our unlock_page in a way that it can do a
non-atomic unlock in the fastpath (no waiters) using 2 bits. In
practice it was still atomic but only because other page flags
operations could operate on ->flags at the same time.

I still have to get around to submitting the damn thing upstream,
but maybe if I bring it up here, I get the idea more reviewed :)

Anyway, the algorithm goes like this:

lock_page()
{
  if (test_and_set_bit_lock(PG_locked))
    lock_page_slow();
}

lock_page_slow()
{
  /* slowpath */
again:
  prepare_to_wait();
  set_bit(PG_waiters);
  if (test_and_set_bit_lock(PG_locked)) {
    schedule();
    goto again;
  }
}

wake_page_waiters()
{
  /* slowpath */
  clear_bit(PG_waiters);
  smp_mb__after_clear_bit(); /* order clear_bit store with wake_up_page load */
  wake_up_page(PG_locked);
}

unlock_page()
{
  clear_bit_unlock(PG_locked);
  if (unlikely(test_bit(PG_waiters)))
    wake_page_waiters();
}

We don't require any load/store barrier in the unlock_page fastpath
because the bits are in the same word, so cache coherency gives us a
sequential ordering anyway.

Now you notice the lock page slowpath can set bits without holding the
lock, at first glance you'd think the clear_bit to unlock has to be
atomic too then. But actually if we're careful, we can put them in seperate
parts of the word and use the sub-word operations on x86 to avoid the atomic
requirement. I'm not aware of any architecture in which operations to the
same word could be out of order.

Not only does this avoid all barriers (except acquire/release) in the
fastpaths, but it also avoids the unconditional load of the random
hash page waitqueue cacheline on unlock.

Anything applicable to your problem at hand?

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/3] 64-bit futexes: Intro, Ulrich Drepper, (Fri May 30, 9:27 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Fri May 30, 10:13 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Ulrich Drepper, (Fri May 30, 11:14 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Fri May 30, 11:44 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Ulrich Drepper, (Sat May 31, 12:04 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Sat May 31, 12:16 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Sat May 31, 12:23 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Ulrich Drepper, (Sat May 31, 12:38 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Sat May 31, 6:25 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Ingo Molnar, (Mon Jun 2, 2:54 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Mon Jun 2, 4:22 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Thu Jun 5, 9:27 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Thu Jun 5, 11:37 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Fri Jun 6, 7:53 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Fri Jun 6, 11:01 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Ingo Molnar, (Mon Jun 2, 7:03 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Mon Jun 2, 11:24 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Wed Jun 4, 3:57 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Wed Jun 4, 9:45 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Wed Jun 4, 4:38 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Wed Jun 4, 9:56 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Wed Jun 4, 11:08 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Thu Jun 5, 12:29 am)
Re: [PATCH 0/3] 64-bit futexes: Intro, Nick Piggin, (Wed Jun 4, 9:58 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Sat May 31, 6:32 pm)
Re: [PATCH 0/3] 64-bit futexes: Intro, Linus Torvalds, (Sat May 31, 12:58 am)