What is voluntary preemption? I only know that it's a concept in scheduling.
preemptive means when a new process is ready to run, the cpu will be allocated to the new process, it doesn't need the running process be co-operative and give up the cpu.
The various preemption models are kernel specific. In principle, user space programs are always preemptible. Preemption of a running task is performed by the scheduler. This action can be triggered by a kernel interaction like a system call or an asynchronous event like an interrupt.
Kernel Preemption The Linux kernel, unlike most other Unix variants and many other operating systems, is a fully preemptive kernel.
PREEMPT: Enabling CONFIG_PREEMPT reduces the kernel latency by making low-priority processes involuntarily preempt themselves. Preemption is disabled only at critical locations where the kernel must protect data from concurrency.
It depends a little bit on the OS.
In some RTOS (real time operatiing system), voluntary preemption means that the running process declares points where it can be preempted (where otherwise it would run until completion). Another way to think of this variant is that of a yield in a coroutine. This is in contrast to most desktop OS where the kernel determines preemption. Keep in mind that some RTOS do not have the concept of a "user mode".
In Linux (at least), "voluntary preemption" is a bit of a misnomer:
Traditionally (no forced preemption), when a user process was making a system call (in kernel mode), it would block until completion. Only user mode code could be preempted.
The preemptive kernel is such that kernel code itself can be preempted. That sounds redundant but it's worth noting that we mean the kernel is preemptible, not that "the kernel supports preemption". Forced/involuntary preemption means that even while servicing a system call, an interrupt for a high priority user process can "force" the kernel to context switch so that it will now run (technically it's not really a context switch, but it has the same effect). This decreases the latency of a user process "seeing" a change in hardware state.
Voluntary preemption is where the kernel periodically checks to see if it should reschedule processes "while doing kernel things". That is, instead of only scheduling/rescheduling user processes at preemption points, it does it periodically while handling things such as I/O. So, where normally a high priority user process might still have to wait for a low priority process to finish its slice, the high prioirty process might now get run "early" as the kernel is checking more frequently if it's to run. This decreases the latency of a user process moving from a suspended state to a running state (at the expense of overall system throughput).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With