The new Linux scheduler extends scheduling capabilities by introducing scheduling classes and also simplifies debugging by improving schedule statistics. Completely Fair Scheduler (CFS) is getting good reviews when tested for thread-intensive applications including 3D games. CFS handles CPU resource allocation for executing processes, and aims to maximize overall CPU utilization while maximizing interactive performance. CFS considered as the first implementation of a fair queuing process scheduler in a widely used general-purpose operating system.
The Linux 2.6.23 kernel comes with a modular scheduler core and a CFS, which is implemented as a scheduling module. In this article, get acquainted with the major features of the CFS, see how it works, and look ahead to some of the expected changes for the 2.6.24 release.
=> Introducing the CFS for Linux
Iâ€™ve already wrote about setting processor affinity for a certain task or process using taskset command using Linux scheduler utilities. Now Linux gets completely fair scheduler (CFS):
The new CPU scheduler includes a pluggable framework that completely replaces Molnar’s earlier O(1) scheduler, and is described to ‘model an “ideal, precise multi-tasking CPU” on real hardware. 80% of CFS’s design can be summed up in a single sentence: CFS basically models an ‘ideal, precise multi-tasking CPU’ on real hardware.
Please note that scheduler matters more for Linux servers and not for your desktop system. However it is belived that CFS may help improve the situation for poorly written X driver.
Read more (via Slashdot)
When you are using SMP (Symmetric MultiProcessing) you might want to override the kernel’s process scheduling and bind a certain process to a specific CPU(s).
But what is CPU affinity?
CPU affinity is nothing but a scheduler property that “bonds” a process to a given set of CPUs on the SMP system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU affinity:
The scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications. For example, application such as Oracle (ERP apps) use # of cpusÃ‚ per instance licensed. You can bound Oracle to specific CPU to avoid license problem. This is a really useful on large server having 4 or 8 CPUS
Setting processor affinity for a certain task or process using taskset command
taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. However taskset is not installed by default. You need to install schedutils (Linux scheduler utilities) package.
# apt-get install schedutils
Red Hat Enterprise Linux:
# up2date schedutils
# rpm -ivh schedutils*
Under latest version of Debian / Ubuntu Linux taskset is installed by default using util-linux package.
The CPU affinity is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. For example:
- 0x00000001 is processor #0 (1st processor)
- 0x00000003 is processors #0 and #1
- 0x00000004 is processors #2 (3rd processor)
To set the processor affinity of process 13545 to processor #0 (1st processor) type following command:
# taskset 0x00000001 -p 13545
If you find a bitmask hard to use, then you can specify a numerical list of processors instead of a bitmask using -c flag:
# taskset -c 1 -p 13545
# taskset -c 3,4 -p 13545
- -p : Operate on an existing PID and not launch a new task (default is to launch a new task)
UPDATED for accuracy.