0% found this document useful (0 votes)
5 views

Learning Journal Unit 3

Uploaded by

kuyembehj05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Learning Journal Unit 3

Uploaded by

kuyembehj05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Learning Journal Unit 3: Completely Fair Scheduler (CFS) in Linux

The Completely Fair Scheduler (CFS) is an advanced scheduling algorithm


implemented in Linux that aims to provide a fair and efficient way to manage
CPU time among processes. Introduced in Linux kernel 2.6.23, CFS replaced
the earlier O(1) scheduler, offering a more balanced and predictable
approach to process scheduling.

How CFS Operates in Linux


CFS is based on the concept of "fairness" and utilizes a scheduling algorithm
that ensures processes get CPU time proportional to their priority and
requirements. The main aspects of its operation include:
1. Virtual Runtime (vruntime):
Each process in CFS is assigned a virtual runtime, which represents the
time the process has used relative to others. Processes with smaller
vruntime values are considered to have received less CPU time and are
given higher priority.
2. Red-Black Tree Structure:
CFS maintains a red-black tree, a self-balancing binary search tree, to
organize processes based on their vruntime. The leftmost node in the
tree represents the process with the smallest vruntime and is selected
next for execution. This approach ensures that the scheduler operates
in O(log N) time complexity, where N is the number of processes.
3. Time Slices:
CFS divides CPU time into "slices" that processes can utilize. The
duration of a time slice depends on the process's weight, determined
by its niceness value. Processes with lower niceness values (higher
priority) receive larger time slices.
4. Scheduling Policy:
CFS uses the SCHED_NORMAL policy for regular tasks and supports
other policies like SCHED_BATCH for batch processes and SCHED_IDLE
for low-priority background tasks. These policies allow flexibility in
managing diverse workloads.
5. Preemption:
If a newly arrived process has a smaller vruntime than the currently
running process, preemption occurs, and the new process takes over
the CPU. This mechanism ensures fairness in allocating CPU time.

Why CFS Is Preferred for Efficient CPU Scheduling


CFS has several characteristics that make it an efficient and preferred
scheduler for modern Linux systems:
1. Fairness:
By assigning CPU time based on vruntime, CFS ensures that all
processes receive a fair share of CPU resources. This is particularly
important in multi-user and multi-tasking environments where resource
hogging can degrade system performance.
2. Efficiency:
The red-black tree structure used in CFS minimizes overhead by
keeping scheduling operations efficient and predictable, even as the
number of processes grows. This is crucial for maintaining system
responsiveness.
3. Adaptability:
CFS dynamically adjusts to different workloads, making it suitable for
systems with varied use cases. Whether managing real-time
applications, interactive tasks, or batch processes, CFS adapts its
scheduling to meet the needs of the workload.
4. Improved Interactivity:
For desktop and interactive applications, CFS ensures that user-facing
processes are given priority, reducing latency and improving
responsiveness. This enhances the overall user experience on Linux-
based systems.
5. Prevention of Starvation:
Unlike traditional schedulers, which may suffer from starvation issues,
CFS guarantees that no process is indefinitely deprived of CPU time.
Processes with higher vruntime values are eventually scheduled,
ensuring fairness over time.
6. Simplified Codebase:
CFS is designed with simplicity and clarity in mind, making it easier to
maintain and extend compared to its predecessors. This design
philosophy aligns with the principles of modern software engineering.

Applications of CFS
CFS is not limited to desktop Linux distributions but is also widely used in
servers, embedded systems, and IoT devices. Its ability to efficiently manage
diverse workloads makes it a versatile choice for various applications. For
instance, in data centers, CFS ensures equitable resource distribution among
virtual machines, while in embedded devices, it balances power efficiency
and performance.

Conclusion
The Completely Fair Scheduler represents a significant advancement in
process scheduling, balancing fairness, efficiency, and adaptability. Its
innovative use of vruntime and red-black trees ensures that all processes are
treated equitably while maximizing CPU utilization. As a result, CFS has
become a cornerstone of Linux kernel development, reflecting the evolving
needs of modern computing environments.

References
 Kalin, M. (2019, February 5). CFS: Completely fair process scheduling
in Linux. Opensource.com. Retrieved from
https://opensource.com/article/19/2/fair-scheduling-linux
 Arpaci-Dusseau, R. H., & Arpaci-Dusseau, A. C. (2018). Operating
systems: Three easy pieces. Retrieved from
https://pages.cs.wisc.edu/~remzi/OSTEP/
 CFS scheduler. (n.d.). The Linux Kernel. Retrieved from
https://www.kernel.org/doc/html/latest/scheduler/sched-design-
CFS.html

You might also like