Three mapping models
How user level tasks map to kernel threads comes in three shapes:
- One to one maps each user thread to one kernel thread. Simple, but the kernel manages every thread.
- Many to one maps many user threads onto a single kernel thread. Cheap switches, but no real parallelism and one block stalls all.
- N to M, also called many to many, maps N user level tasks onto M kernel threads where M is smaller.
Why N to M is appealing
N to M aims to combine the best of both. The runtime schedules cheap user tasks in user space, while the M kernel threads let several tasks run in parallel across cores. You get lightweight switching and true multicore use at once.
The hard part
The trouble is coordination. When a user task makes a blocking kernel call, the runtime ideally moves other ready tasks to a different kernel thread so the core is not wasted. Doing this well needs cooperation between the user scheduler and the kernel, which is complex. Several systems tried and later simplified, but the model underlies many modern runtimes.
Key idea
N to M threading maps many cheap user tasks onto fewer kernel threads to get both lightweight switching and multicore parallelism, but balancing tasks across kernel threads on blocking is hard.