From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
To: linux-hotplug@vger.kernel.org
Subject: Re: [GIT] Experimental threaded udev
Date: Mon, 01 Jun 2009 09:29:11 +0000 [thread overview]
Message-ID: <4A239F67.3030902@tuffmail.co.uk> (raw)
In-Reply-To: <4A1EA138.10400@tuffmail.co.uk>
Kay Sievers wrote:
> On Fri, 2009-05-29 at 20:11 +0200, Kay Sievers wrote:
>
>> On Fri, May 29, 2009 at 19:53, Alan Jenkins <alan-jenkins@tuffmail.co.uk> wrote:
>>
>>
>>> Maybe just recycling the event processes would bring
>>> similar gains, with less of the risks of threads.
>>>
>> Yeah, I thought that too, without having tested anything, it could be,
>> that we just want to keep a pipe to the event process, and let the
>> event process send a signal back to the main daemon, that it has
>> handled the event, and it goes to sleep after that. The main daemon
>> can recycle a sleeping event process and push a new event over the
>> pipe to it. If no events are queued anymore, the main daemon just
>> closes the pipe, and the event process will exit.
>>
>> With that model we might be able to reduce the number of fork()s
>> significantly. And we would still have the process separation, it's
>> robustness, and the lock-free behavior for malloc, cloexec and all
>> these issues.
>>
>
> Here is a rough hack to check how it behaves. It boots my box, nothing
> else I really checked.
>
> It clones the event processes as the current version does, but the event
> process stays around to get re-used as a worker for later events.
> Further messages are send over netlink to the worker processes, and the
> worker process signals its state back with sigqueue() rt-signals. When
> the events have settled, the workers get killed after a few seconds of
> idle time.
>
> The current git version:
> $ time (udevadm trigger; udevadm settle)
> real 0m1.566s
> ...
>
> $ time /sbin/udevd.orig
> []
> user 0m0.420s
> sys 0m1.412s
>
>
> The thread-version:
> $ time (udevadm trigger -Snet; udevadm settle)
> real 0m1.336s
>
> $ time udev/udevd
> []
> user 0m0.310s
> sys 0m0.679s
>
>
> The worker-version:
> $ time (udevadm trigger; udevadm settle)
> real 0m1.171s
> ...
>
> $ time udev/udevd
> []
> user 0m0.057s
> sys 0m0.095s
>
>
> The thread- and worker-versions do not create as many COW page-faults in
> the daemon after every cloned event-process, and therefore need much
> less CPU.
>
> At least on the dual-core laptop here, the pool of workers seems to be
> faster than the threads.
>
Great, you beat me to it. It makes sense that this would be _bit_
faster than threads. As I say I tried to avoid the page faults caused
(somehow) by forking the extra thread-stack mappings, but it didn't
really work out. I'm surprised by quite how much faster it is though!
I have some thoughts which may help in bringing the code up from "rough
hack" quality :-).
Aren't signal queues unreliable? If you exceed the maximum number of
queued signals, sigqueue will fail with EAGAIN, and I don't think
there's a blocking version :-). I think a pipe would be better, or
maybe you can do something with netlink.
+ /* wait for more device messages from udevd */
+ do
+ dev = udev_monitor_receive_device(monitor);
+ while (dev = NULL);
I think this loop should finish when the signal handler sets
worker_exit? But maybe you didn't actually install a handler for
SIGTERM and it's still being reset to the default action:
/* set signal handlers */
memset(&act, 0x00, sizeof(act));
act.sa_handler = event_sig_handler;
@@ -154,66 +203,135 @@ static void event_fork(struct udev_event *event)
sigaction(SIGTERM, &act, NULL);
I'm not sure you're handling worker processes crashing, it looks like
you might leave the event in limbo if you get SIGCHLD for a worker in
state WORKER_RUNNING. I'm sure you'll test that though.
Talking of unexpected crashes. I anticipated using a
connection-oriented socketpair for passing events. Using netlink for
this means the worker threads don't get a nice notification if the
daemon dies without killing them. Unless this is covered by udevd being
the session leader, or something like that? I'll test this empirically
- maybe it's not important, but I think it's good to know what will happen.
BTW I had a go at this too, but a couple of my workers fail in about 1
run out of 20, apparently because calloc() returns NULL without setting
errno. I'm sure it's my fault but I'll try to track it down. Obviously
I'll let you know if your patch could be affected by the same problem.
Thanks
Alan
next prev parent reply other threads:[~2009-06-01 9:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-28 14:35 [GIT] Experimental threaded udev Alan Jenkins
2009-05-28 15:09 ` Kay Sievers
2009-05-28 15:39 ` Alan Jenkins
2009-05-29 17:53 ` Alan Jenkins
2009-05-29 18:11 ` Kay Sievers
2009-06-01 2:41 ` Kay Sievers
2009-06-01 9:29 ` Alan Jenkins [this message]
2009-06-01 11:32 ` Kay Sievers
2009-06-01 12:33 ` Kay Sievers
2009-06-01 13:30 ` Kay Sievers
2009-06-01 13:46 ` Alan Jenkins
2009-06-01 13:57 ` Kay Sievers
2009-06-01 16:22 ` Kay Sievers
2009-06-01 16:24 ` Alan Jenkins
2009-06-01 19:39 ` Kay Sievers
2009-06-02 4:58 ` Kay Sievers
2009-06-02 9:13 ` Alan Jenkins
2009-06-02 9:26 ` Alan Jenkins
2009-06-02 11:39 ` Kay Sievers
2009-06-02 14:05 ` Kay Sievers
2009-06-03 19:44 ` Kay Sievers
2009-06-03 20:46 ` Alan Jenkins
2009-06-03 22:20 ` Kay Sievers
2009-06-03 23:53 ` Kay Sievers
2009-06-06 14:20 ` Kay Sievers
2009-06-06 17:01 ` Bryan Kadzban
2009-06-08 11:45 ` Scott James Remnant
2009-06-08 16:29 ` Bryan Kadzban
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=4A239F67.3030902@tuffmail.co.uk \
--to=alan-jenkins@tuffmail.co.uk \
--cc=linux-hotplug@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;
as well as URLs for NNTP newsgroup(s).