Number of kernel threads = cores

kernel

I wonder whether or not a systems max kernel threads are determined by how many cores your CPU has. Or is it decided in another way?

Best Answer

No, you can set the maximum kernel threads to very high numbers.

Note that the word "threads" is used for many different things:

It may be that Intels use causes confusion.


Update re kernel threads

Here are some Linux kernel threads running in CoLinux under Vista on AMD Athlon 64 X2 dual-core.

$ ps -eLf
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
root         1     0     1  0    1 17:24 ?        00:00:00 init [2]
root         2     0     2  0    1 17:24 ?        00:00:00 [kthreadd]
root         3     2     3  0    1 17:24 ?        00:00:00 [ksoftirqd/0]
root         4     2     4  0    1 17:24 ?        00:00:00 [events/0]
root         5     2     5  0    1 17:24 ?        00:00:00 [khelper]
root        21     2    21  0    1 17:24 ?        00:00:00 [kblockd/0]
root        22     2    22  0    1 17:24 ?        00:00:00 [kseriod]
root        41     2    41  0    1 17:24 ?        00:00:00 [pdflush]
root        42     2    42  0    1 17:24 ?        00:00:00 [pdflush]
root        43     2    43  0    1 17:24 ?        00:00:00 [kswapd0]
root        44     2    44  0    1 17:24 ?        00:00:00 [aio/0]
root       727     2   727  0    1 17:24 ?        00:00:00 [kjournald]

LWP is the thread ID.

(See man ps: "-L Show threads, possibly with LWP and NLWP columns" … "LWP lwp (light weight process, or thread) ID of the lwp being reported. (alias spid, tid)")

kthreadd is the kernel thread daemon, I believe is is responsible for all the other kernel threads. Note I am not showing daemons like klogd which do not execute in ring 0 (as far as I know).

Number of kernel threads != number of CPU cores. (ref title of question)


Kernel threads consist of a set of registers, a stack, and a few corresponding kernel data structures.

The purported advantage of kernel threads over processes is faster creation and context switching compared with processes.

Kernel threads are considered “lightweight,” and one would expect the number of threads to only be limited by address space and processor time

In particular, operating system kernels tend to see kernel threads as a special kind of process rather than a unique entity. For example, in the Solaris kernel threads are called “light weight processes” (LWP’s). Linux actually creates kernel threads using a special variation of fork called “clone,” and until recently gave each thread a separate process ID. Because of this heritage, in practice kernel threads tend to be closer in memory and time cost to processes than user-level threads,

(Multiple Flows of Control in Migratable Parallel Programs 2006)

Related Question