---
title: "CFS and Real-Time Process Scheduling"
description: "An in-depth guide to the Completely Fair Scheduler and real-time process scheduling on Linux"
keywords: ["linux", "kernel", "scheduler", "real-time", "cfs"]
category: "linux"
---

The Completely Fair Scheduler (CFS) is the default CPU scheduler in the Linux kernel since version 2.6.23. CFS aims to provide a fair distribution of CPU time to all runnable processes, based on their "virtual runtime" or vruntime. The vruntime of a process increases proportionally to the time it has been running, with the goal of ensuring that all processes receive an equal share of CPU time over the long run. Processes with a lower vruntime are prioritized for execution, and the vruntime is adjusted based on a process's "nice" value, which can range from -20 (highest priority) to 19 (lowest priority).

The SCHED_FIFO and SCHED_RR real-time scheduling policies in Linux provide a different approach to CPU scheduling. These policies do not use the CFS vruntime mechanism, but instead schedule processes based on their static priority. SCHED_FIFO ensures that the highest-priority runnable process is always scheduled, while SCHED_RR uses a round-robin approach to give each process in a priority group a time slice before moving on to the next group. Real-time processes scheduled using these policies have higher priority than normal CFS-scheduled processes.

CPU affinity can be used to bind a process to a specific CPU or set of CPUs using the `taskset` command. This can be useful for isolating critical real-time processes from interference by other workloads. The `isolcpus` kernel parameter can also be used to reserve specific CPUs for real-time or high-priority tasks, effectively creating a dedicated real-time execution environment.

The `NO_HZ_FULL` kernel parameter can be used to disable periodic timer interrupts on specific CPUs, reducing overhead and improving the performance of real-time workloads. The `schedtool` utility provides additional control over process scheduling, allowing you to set the scheduling policy, priority, and CPU affinity of a process.

Cgroups provide a way to limit the CPU resources available to a group of processes using the `cpu.max` parameter. This can be used to enforce CPU bandwidth limits for real-time or high-priority workloads, ensuring that they receive the necessary CPU resources while preventing them from consuming too much of the system's overall CPU capacity.The CFS scheduler in the Linux kernel uses the concept of "nice" values to adjust the priority of processes. The nice value ranges from -20 (highest priority) to 19 (lowest priority), with the default value being 0. Processes with a lower nice value are given a higher priority by the CFS scheduler, meaning they will receive a larger share of the available CPU time. The nice value can be set using the `nice` command or the `setpriority` system call.

Real-time processes in Linux are scheduled using the SCHED_FIFO and SCHED_RR policies, which take precedence over the CFS scheduler. SCHED_FIFO ensures that the highest-priority runnable real-time process is always scheduled, while SCHED_RR uses a round-robin approach to give each real-time process in a priority group a time slice before moving on to the next group. Real-time processes have a static priority that is higher than the dynamic priority used by the CFS scheduler, allowing them to preempt normal, non-real-time processes.

The `taskset` command can be used to bind a process to a specific CPU or set of CPUs, effectively isolating it from interference by other workloads. This can be particularly useful for real-time or high-priority processes that require consistent access to CPU resources. The `isolcpus` kernel parameter provides an alternative way to reserve specific CPUs for real-time or high-priority tasks, creating a dedicated execution environment for these workloads.

The `NO_HZ_FULL` kernel parameter can be used to disable periodic timer interrupts on specific CPUs, reducing overhead and improving the performance of real-time workloads. This feature, also known as "tickless idle," can help to minimize the latency and jitter experienced by real-time processes by reducing the frequency of context switches and other scheduler-related interruptions.

The `schedtool` utility provides additional control over process scheduling, allowing you to set the scheduling policy, priority, and CPU affinity of a process. This can be useful for fine-tuning the behavior of real-time or high-priority workloads, ensuring that they receive the necessary CPU resources and are isolated from interference by other tasks.

Cgroups provide a way to limit the CPU resources available to a group of processes using the `cpu.max` parameter. This can be used to enforce CPU bandwidth limits for real-time or high-priority workloads, ensuring that they receive the necessary CPU resources while preventing them from consuming too much of the system's overall CPU capacity. By setting appropriate `cpu.max` values, you can guarantee a minimum level of CPU bandwidth for critical real-time tasks while still allowing other, lower-priority processes to utilize any remaining CPU cycles.The Completely Fair Scheduler (CFS) in the Linux kernel uses a concept called "virtual runtime" or "vruntime" to ensure fair distribution of CPU time among all runnable processes. The vruntime of a process increases proportionally to the time it has been running, with the goal of ensuring that all processes receive an equal share of CPU time over the long run. Processes with a lower vruntime are prioritized for execution, and the vruntime is adjusted based on a process's "nice" value, which can range from -20 (highest priority) to 19 (lowest priority).

The `isolcpus` kernel parameter can be used to reserve specific CPUs for real-time or high-priority tasks, effectively creating a dedicated real-time execution environment. This can be particularly useful in systems with multiple CPU cores, as it allows you to isolate critical real-time workloads from interference by other, less time-sensitive tasks. By reserving specific CPUs for real-time use, you can ensure that these processes have consistent access to the resources they require, reducing latency and improving overall system responsiveness.

The `schedtool` utility provides a powerful way to control the scheduling behavior of individual processes on a Linux system. With `schedtool`, you can set the scheduling policy (e.g., SCHED_FIFO, SCHED_RR), priority, and CPU affinity of a process. This can be especially useful for tuning the performance of real-time or high-priority workloads, ensuring that they receive the necessary CPU resources and are isolated from interference by other tasks. The `schedtool` command-line tool can be used to apply these settings directly, or you can integrate it into your application or system management scripts to automate the process.

Cgroups, or control groups, provide a way to limit the CPU resources available to a group of processes using the `cpu.max` parameter. This can be used to enforce CPU bandwidth limits for real-time or high-priority workloads, ensuring that they receive the necessary CPU resources while preventing them from consuming too much of the system's overall CPU capacity. By setting appropriate `cpu.max` values, you can guarantee a minimum level of CPU bandwidth for critical real-time tasks while still allowing other, lower-priority processes to utilize any remaining CPU cycles. This can be particularly useful in systems with limited CPU resources or where it's important to maintain a balance between real-time and non-real-time workloads.The `NO_HZ_FULL` kernel parameter is a feature that can be used to disable periodic timer interrupts on specific CPUs, reducing overhead and improving the performance of real-time workloads. This "tickless idle" mode can help to minimize the latency and jitter experienced by real-time processes by reducing the frequency of context switches and other scheduler-related interruptions. By disabling timer interrupts on CPUs dedicated to real-time tasks, the system can avoid the overhead associated with these interrupts, allowing the real-time processes to execute more efficiently and with lower latency.

The `cpu.max` parameter in cgroups provides a way to limit the CPU resources available to a group of processes. This can be particularly useful for managing the resource allocation between real-time and non-real-time workloads on a system. By setting appropriate `cpu.max` values for the cgroups containing your real-time processes, you can ensure that they receive a guaranteed minimum level of CPU bandwidth, while still allowing other, lower-priority tasks to utilize any remaining CPU cycles. This can help to prevent real-time processes from being starved of CPU resources, ensuring that they can meet their latency and responsiveness requirements.

In addition to the `taskset` command, which can be used to bind a process to a specific CPU or set of CPUs, the Linux kernel also provides the `isolcpus` parameter. This parameter allows you to reserve specific CPUs for use by real-time or high-priority tasks, effectively creating a dedicated execution environment for these workloads. By isolating real-time processes on a subset of the available CPUs, you can protect them from interference by other, less time-sensitive tasks, helping to ensure consistent performance and low latency.

The `schedtool` utility is a powerful tool for controlling the scheduling behavior of individual processes on a Linux system. With `schedtool`, you can set the scheduling policy (e.g., SCHED_FIFO, SCHED_RR), priority, and CPU affinity of a process. This can be especially useful for tuning the performance of real-time or high-priority workloads, ensuring that they receive the necessary CPU resources and are isolated from interference by other tasks. The `schedtool` command-line tool can be used to apply these settings directly, or you can integrate it into your application or system management scripts to automate the process.