Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
1  
Its based on the number of cores the physical device has. –  Ramhound Oct 17 '11 at 12:52
    
The same question has been answered here –  Nasreddine Oct 17 '11 at 13:42
    
@Nacereddine but I'm not talking about how many threads you can create for a process. That would be user threads right? I'm asking about how many kernel threads (that is operated and scheduled by the OS kernel) –  starcorn Oct 17 '11 at 15:34
    
@starcorn Sorry for my mistake –  Nasreddine Oct 17 '11 at 17:25
add comment

1 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)

share|improve this answer
    
that does not sound right, or maybe I got it wrong? Kernel threads are costly and not as easy created as user threads. User threads are supported by using APIs such as Java threads and POSIX you mention. Kernel thread are not the same thing as it. Kernel thread process these user threads. Actually kernel threads sees threads in a process as a single unit although if the process contains alot of threads. So still my question is not answered I think. –  starcorn Oct 17 '11 at 20:45
1  
"kernel threads are part of kernel, which gets executed by linux scheduler like a real(userland) thread." - kerneltrap.org/node/20903 –  RedGrittyBrick Oct 17 '11 at 21:11
    
@starcom: see updated answer. Hope that helps. –  RedGrittyBrick Oct 17 '11 at 22:14
    
Current Linux kernels (and corresponding glibc) create a kernel task for each user thread. Internally the kernel uses several tasks for handling events asynchronously, those don't ever run in userspace. The "kernel threads" could mean the later, or just the kernel's view of an userspace thread (some systems, notably older Solaris, created user threads ("lightweight processes"), and then mapped several of those to a kernel thread (somewhat like the pure userland threads implementations Linux used in the beginning). Murky naming ;-) –  vonbrand Jan 16 '13 at 14:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.