views:

1264

answers:

4

Explained in your own words, what is preemption and what does it mean to a (linux) kernel?

What are advantages and disadvantages in having a preemptible kernel?

A: 

You should really use the term "preemptive." There are different kinds of preemption. Essentially, it is very simple and you probably understand this by another name. A preemptive operating system can switch contexts between user mode threads without any special programming in the preempted application. This allows for multitasking. An OS can switch away and back to a process and this switching is essentially trasnparent. There is also such a thing as preemptive kernel, which allows kernel mode threads to be preempted (most operating systems do not allow this but it is required for certain applications such as in real time systems). Note, this is a very simplified explanation.

BobbyShaftoe
+4  A: 

Preemptive multitasking - Running several processes/threads on a single processor, creating the illusion that they run concurrently when actually each is allocated small multiplexed time slices to run in. A process is "preempted" when it is scheduled out of execution and waits for the next time slice to run in.

A preemptive kernel is one that can be interrupted in the middle of a executing code - for instance in response for a system call - to do other things and run other threads, possible that are not in the kernel.
The main advantage in a preemptive kernel is that sys-calls do not block the entire system. if a sys-call takes a long time to finish then it doesn't mean the kernel can't do anything else in this time.
The main disadvantage is that this introduces more complexity to the kernel code, having to handle more end-cases, perform more fine grained locking or use lock-less structures and algorithms.

shoosh
This is why when a filesystem goes bad, particularly a network filesystem, you might find yourself with a process that can't be killed. Its sitting around waiting for a sys call to read the filesystem to return, but it never will and it can't be interrupted.
Schwern
A: 

Preemption means the OS supports multiple tasks (a separate, stand-alone piece of code) and will switch between tasks on a schedule. When a task is interrupted, it is called "preempting". Modern OS support this - but it's not required for simple embedded systems, for example. The overhead of supporting task switching is not always worth it.

Jeff
A: 

Others have adequately explained what a preemptible kernel is.

What is it good for?

Mostly the benefits are:

  • Lower latency on non-SMP systems - typically used in realtime systems or for other things where latency is important (audio, video apps perhaps)
  • Teaching kernel developers who don't have SMP systems how to write correct code for SMP

With a non-preemptible kernel, on a single processor system it is possible for kernel developers to be lazy and get away without any locking most of the time - of course this is a big FAIL on SMP. Preemptible kernels allow them to get this pain without more cores.

MarkR