From: Jamie Lokier <jamie@shareable.org>
To: Davide Libenzi <davidel@xmailserver.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [patch] futex API cleanups, futex-api-cleanup-2.5.69-A2
Date: Tue, 20 May 2003 18:59:22 +0100 [thread overview]
Message-ID: <20030520175922.GA19094@mail.jlokier.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.55.0305200947460.3636@bigblue.dev.mcafeelabs.com>
Davide Libenzi wrote:
> > Yes, they do and it should work (I haven't tried, though).
> >
> > There is a practical problem when waiting on a futex in multiple
> > threads using epoll: you need a separate fd per waiter, rather than an
> > fd per waited-on futex. This is because some uses of futexes depend
> > on waiters being woken in the exact order that they were queued.
>
> Not really Jamie. See a Futex event is not much different from a network
> one. When the event shows up, one thread will pick it up (epoll_wait) and
> will handle it. A futex event will very likely be a green light for some
> sort of resource usage that whatever thread can pick up and handle.
That is true when a futex represents some item of work to do, or
readiness such as data coming in or going it. Then it is quite
reasonable to think of it like a pollable fd.
But futexes are also used to represent contention for shared
resources, and the properties needed for this are quite different.
See futex_up_fair() in Rusty's futex-2.2 library. That depends
crucially on getting exactly the right number of wakeup tokens passed,
and in the order the waiters blocked.
To pick an example, consider a dynamic web server which is
occasionally asked to render complex images, but where most of the
content is easily generated. You might have 30 concurrent page
serving threads, but want to limit the number of threads which are
generating a particularly complex response to 3 at a time because of
memory constraints.
You cannot program this as putting things on a work queue and having
arbitrary threads pick them off, unless you are prepared to represent
the problem as an explicit state machine, where the intermediate
states can be represented as a data structure. If the state is too
complex for that, which is often a reason for using threads in the
first place, that is not an option.
So it is important that _those_ kind of waiting threads are woken in
something approximating the order they went to sleep. Otherwise there
is a danger of certain requests being starved unfairly.
To implement this you can use a simple futex, or a significantly more
complex, and slower, queue structure.
Using the futex, you either need an fd per waiter to get this
fairness, when the waiters are using epoll to listen for more than one
event, _or_ you need epoll to be clever and preserve the sleep-to-wake
ordering over a single futex. I favour that last solution.
-- Jamie
next prev parent reply other threads:[~2003-05-20 17:46 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-19 9:31 [patch] futex requeueing feature, futex-requeue-2.5.69-D3 Ingo Molnar
2003-05-19 10:10 ` Christoph Hellwig
2003-05-19 10:16 ` Ingo Molnar
2003-05-19 11:49 ` Christoph Hellwig
2003-05-19 12:33 ` [patch] futex API cleanups, futex-api-cleanup-2.5.69-A2 Ingo Molnar
2003-05-19 12:51 ` Ingo Molnar
2003-05-19 14:47 ` bert hubert
2003-05-19 16:02 ` Ingo Molnar
2003-05-19 15:18 ` Linus Torvalds
2003-05-19 16:06 ` Ingo Molnar
2003-05-19 23:33 ` Jamie Lokier
2003-05-20 0:39 ` Rusty Russell
2003-05-20 1:14 ` Davide Libenzi
2003-05-20 1:44 ` Jamie Lokier
2003-05-20 16:54 ` Davide Libenzi
2003-05-20 17:59 ` Jamie Lokier [this message]
2003-05-21 23:56 ` Davide Libenzi
2003-05-20 1:50 ` Jamie Lokier
2003-05-20 0:15 ` Rusty Russell
2003-05-20 0:08 ` [patch] futex requeueing feature, futex-requeue-2.5.69-D3 Rusty Russell
2003-05-20 0:31 ` Valdis.Kletnieks
2003-05-19 10:23 ` Andrew Morton
2003-05-19 10:30 ` [patch] futex requeueing feature, futex-requeue-2.5.69-D4 Ingo Molnar
2003-05-20 0:04 ` [patch] futex requeueing feature, futex-requeue-2.5.69-D3 Rusty Russell
2003-05-20 0:40 ` Ulrich Drepper
2003-05-20 1:46 ` Rusty Russell
2003-05-20 2:11 ` Ulrich Drepper
2003-05-20 6:27 ` Ingo Molnar
2003-05-20 6:56 ` Christoph Hellwig
2003-05-20 8:57 ` Rusty Russell
2003-05-20 9:03 ` Ingo Molnar
2003-05-20 9:51 ` Christoph Hellwig
2003-05-20 12:56 ` [patch] futex patches, futex-2.5.69-A2 Ingo Molnar
2003-05-20 14:08 ` Christoph Hellwig
2003-05-20 16:02 ` Ingo Molnar
2003-05-20 19:55 ` Christoph Hellwig
2003-05-21 5:06 ` Martin Schlemmer
2003-05-21 6:31 ` Christoph Hellwig
2003-05-20 15:46 ` [patch] futex requeueing feature, futex-requeue-2.5.69-D3 Linus Torvalds
2003-05-20 9:12 ` Ingo Oeser
2003-05-20 15:41 ` Linus Torvalds
2003-05-20 8:55 ` Rusty Russell
2003-05-20 6:19 ` Ingo Molnar
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=20030520175922.GA19094@mail.jlokier.co.uk \
--to=jamie@shareable.org \
--cc=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®