public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: PROT_SEM + FUTEX
@ 2002-11-11 22:31 Perez-Gonzalez, Inaky
  2002-11-11 23:08 ` Mark Mielke
  0 siblings, 1 reply; 6+ messages in thread
From: Perez-Gonzalez, Inaky @ 2002-11-11 22:31 UTC (permalink / raw)
  To: 'Mark Mielke'; +Cc: linux-kernel


> hoping that
> > > PROT_SEM is not required, as I intend to scatter the 
> words throughout
> > > memory, and it would be a real pain to mprotect(PROT_SEM) 
> each page
> > > that contains a FUTEX word.
> >
> > Still you want to group them as much as possible - each 
> time you lock
> > a futex you are pinning the containing page into physical 
> memory, that
> > would cause that if you have, for example, 4000 futexes 
> locked in 4000 
> > different pages, there is going to be 4 MB of memory locked 
> in ... it
> > helps to have an allocator that ties them together.
> 
> This is not necessarily correct for a high-capacity, low-latency
> application (i.e. a poorly designed thread architecture might suffer
> from this problem -- but a poorly designed thread architecture suffers
> from more problems than pinned pages).

Too much thinking about the general case - you are absolutely right, but
only as long as you are sure that the contention rate across the many
futexes you have is going to be _really_ low; that, or if your applications
are always mlocked in memory, then you are ok.

I keep thinking about multi-thousand threads and their locks, so spare me, I
forget about the well-designed cases.

> As far as I understand - PROT_SEM has no effect on the behaviour of
> FUTEX operations. I think it should be removed.

Rusty (Russel) declared that Linus declared that platforms that don't
implement a sane cache architecture can not implement futexes ... so I guess
this means we can forget about PROT_SEM for futexes.

> As long as the person attempting to manipulate the FUTEX word succeeds
> (i.e. 0 -> 1, or 0 -> -1, or whatever), futex_wait() need not 
> be issued.
> futex_wake() only pins the page for a brief period of time.

Define brief - remember that if the futex is locked, the page is already
pinned, futex_wake() is just making sure it is there while it uses it - and
again, as you said before, this is completely application specific; the
kernel cannot count on any specific behaviour on the user side.

> same cache line. Also, if the memory word is used to synchronize
> access to a smaller data structure (<128 bytes), it is actually
> optimal to include the memory word used to synchronize access to the
> data, and the data itself, in the same cache line.

Sure, this makes full sense; if you are using the futexes straight off from
the kernel for synchronization; however, when used by something like NGPT's
mutex system, the story changes, because you cannot assume anything, you
have to be generic - and there is my bias. 

Lucky you that don't need to worry about that :)

Inaky Perez-Gonzalez -- Not speaking for Intel - opinions are my own [or my
fault]


^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: PROT_SEM + FUTEX
@ 2002-11-12  0:31 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 6+ messages in thread
From: Perez-Gonzalez, Inaky @ 2002-11-12  0:31 UTC (permalink / raw)
  To: 'Mark Mielke'; +Cc: linux-kernel


> frequently. I would find any application that needed to actively wait
> on 4000 futex objects to be either incorrectly designed, or under
> enough load that I think an investment in a few more CPU's would be
> worthwhile... :-)

Not really; well, yeah really, but on other side; the case 
I am talking about is threaded applications with thousands of threads 
[no  kidding], where for example, 2K are producers and 4K are consumers;
there you have a rough 50% rate of contention for each lock [assume
each producer has a lock that the two consumers need to acquire]; the
contention might not be very bad, but as an average you might have
around 1000 futexes locked, that would add up to, in worst case, 1000
pages locked ...

However, if you do some thousand threads, you better have more memory
so that 1000 pages locked does not really mind :]

Inaky Perez-Gonzalez -- Not speaking for Intel - opinions are my own [or my
fault]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* RE: PROT_SEM + FUTEX
@ 2002-11-11 20:28 Perez-Gonzalez, Inaky
  2002-11-11 21:46 ` Mark Mielke
  0 siblings, 1 reply; 6+ messages in thread
From: Perez-Gonzalez, Inaky @ 2002-11-11 20:28 UTC (permalink / raw)
  To: 'Mark Mielke', linux-kernel


> I am beginning to play with the FUTEX system call. I am hoping that
> PROT_SEM is not required, as I intend to scatter the words throughout
> memory, and it would be a real pain to mprotect(PROT_SEM) each page
> that contains a FUTEX word.

Still you want to group them as much as possible - each time you lock
a futex you are pinning the containing page into physical memory, that
would cause that if you have, for example, 4000 futexes locked in 4000 
different pages, there is going to be 4 MB of memory locked in ... it
helps to have an allocator that ties them together.

Cheers,

Inaky Perez-Gonzalez -- Not speaking for Intel - opinions are my own [or my
fault]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* PROT_SEM + FUTEX
@ 2002-11-11  6:12 Mark Mielke
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Mielke @ 2002-11-11  6:12 UTC (permalink / raw)
  To: linux-kernel

Is PROT_SEM necessary anymore? 2.5.46 does not seem to include any
references to it that adjust behaviour for pages. Would it be
reasonable to remove it, or #define PROT_SEM to (0) to avoid
confusion?

I am beginning to play with the FUTEX system call. I am hoping that
PROT_SEM is not required, as I intend to scatter the words throughout
memory, and it would be a real pain to mprotect(PROT_SEM) each page
that contains a FUTEX word.

For systems that do not support the FUTEX system call (2.4.x?),
is sched_yield() the best alternative?

Thanks,
mark

-- 
mark@mielke.cc/markm@ncf.ca/markm@nortelnetworks.com __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-11-12  0:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-11 22:31 PROT_SEM + FUTEX Perez-Gonzalez, Inaky
2002-11-11 23:08 ` Mark Mielke
  -- strict thread matches above, loose matches on Subject: below --
2002-11-12  0:31 Perez-Gonzalez, Inaky
2002-11-11 20:28 Perez-Gonzalez, Inaky
2002-11-11 21:46 ` Mark Mielke
2002-11-11  6:12 Mark Mielke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox