Too many threads?
[Posted August 13, 2003 by corbet]
In a discussion of problems in the current
request_firmware()
interface (
discussed here last May), it was
noted that firmware loads sometimes happen too slowly as a result of
latency in the workqueue mechanism. The firmware interface uses the
default workqueue, meaning that its tasks can wait an unknown amount of
time behind other users of that queue. In some situations, at least, it
seems that this delay can be too long. So a patch was posted which sets up
a dedicated workqueue for firmware loading.
Creating one's own work queue can help with the latency problems, but it
also loads the system with another kernel thread for each processor. And
some people are starting to get a little unhappy with the number of such
threads in 2.6. They are proliferating a bit; a quick check on your
editor's mighty dual Pentium 450 system (running -test3) shows some 21
of them:
2 ? SW 0:00 [migration/0]
3 ? SWN 0:00 [ksoftirqd/0]
4 ? SW 0:00 [migration/1]
5 ? SWN 0:02 [ksoftirqd/1]
6 ? SW< 0:00 [events/0]
7 ? SW< 0:00 [events/1]
8 ? SW< 0:00 [kblockd/0]
9 ? SW< 0:01 [kblockd/1]
10 ? SW 0:00 [khubd]
11 ? SW 0:00 [kirqd]
12 ? SW 0:00 [pdflush]
13 ? SW 0:07 [pdflush]
14 ? SW 0:17 [kswapd0]
15 ? SW< 0:00 [aio/0]
16 ? SW< 0:00 [aio/1]
17 ? SW 0:00 [scsi_eh_0]
18 ? SW 0:00 [ahc_dv_0]
19 ? SW 0:00 [kseriod]
142 ? SW 0:01 [kjournald]
143 ? SW 0:00 [kjournald]
144 ? SW 0:05 [kjournald]
Kernel threads are not that expensive, but they do take up some kernel
memory and clutter up ps listings. Imagine what the listing would
look like on a system with a large number of processors. More to the
point, many of these threads are likely to be unnecessary, and that bugs
kernel hackers.
As a result, there will probably be a rework of the workqueue mechanism at
some point, when somebody feels motivated to do it. One possible change
would be to turn the default workqueue into a thread pool of sorts; if no
thread is available when schedule_work() is called, a new one is
created to handle the task. Some sort of timeout mechanism would trim the
threads down when the load drops. It has also been noted that many users
of workqueues don't really need a thread for every processor; a single
thread would be adequate for the job. An interface change allowing the
creator to specify whether per-CPU threads are needed could cut down on the
number of threads considerably.
Implementing changes of this nature would not be particularly difficult.
Whether a rework of something as fundamental is the workqueue interface is
appropriate at this stage of development is another question, however.
(
Log in to post comments)