100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is the Completely Fair Scheduler (CFS)?

Learn how the Linux Completely Fair Scheduler works — vruntime, the red-black tree, and nice values — with an interview question answered.

hardQ32 of 234 in Operating Systems Est. time: 6 minsLast updated:
Open Code Lab
32 / 234

Expected Interview Answer

The Completely Fair Scheduler (CFS) is the default Linux process scheduler that tracks each runnable task’s virtual runtime and always picks the task with the least accumulated virtual runtime to run next, approximating an ideal system where every task gets a perfectly equal, continuous share of the CPU.

CFS maintains runnable tasks in a red-black tree keyed by virtual runtime (vruntime), a measure of how much CPU time a task has consumed, weighted by its nice value so higher-priority tasks accumulate vruntime more slowly. The scheduler always dispatches the leftmost node in the tree, meaning the task with the smallest vruntime so far — the one that has, proportionally, received the least CPU time. As that task runs, its vruntime increases, and once it exceeds another task’s vruntime, that other task becomes the new leftmost node and gets scheduled next, which naturally interleaves tasks in proportion to their weight without needing fixed time quanta or discrete priority queues. Nice values (from -20 to 19) scale the weight applied to vruntime accumulation, so a higher-priority task’s vruntime grows more slowly relative to a lower-priority one’s, giving it a proportionally larger CPU share, and CFS uses an adaptive scheduling latency target combined with a minimum granularity to decide how often it re-evaluates rather than a fixed time-slice per task.

  • Approximates perfectly fair, proportional CPU sharing in O(log n) via a red-black tree
  • No fixed time quantum — scheduling decisions scale with the number of runnable tasks
  • Nice values smoothly scale CPU share instead of using rigid priority queues
  • Default scheduler for normal (non-real-time) tasks in the Linux kernel

AI Mentor Explanation

CFS is like a nets facility that tracks each batter’s total minutes of practice so far and always calls up whichever batter has had the least practice time relative to their assigned weighting. A batter who has barely practiced gets called next, and as soon as they start batting their tallied minutes rise until someone else has a lower tally, at which point that batter is called instead. A senior batter with a higher weighting accumulates tracked minutes more slowly per minute actually spent, so they end up getting a proportionally larger share of net time over the session, all without anyone assigning fixed turn lengths.

Step-by-Step Explanation

  1. Step 1

    Track vruntime

    Each runnable task accumulates virtual runtime, weighted by its nice value, as it consumes CPU time.

  2. Step 2

    Maintain the tree

    Runnable tasks are kept in a red-black tree ordered by vruntime, so the smallest-vruntime task is always the leftmost node.

  3. Step 3

    Pick the leftmost task

    The scheduler dispatches the leftmost (least-vruntime) task, giving it CPU time next.

  4. Step 4

    Re-evaluate

    As the running task’s vruntime grows past another task’s, that other task becomes leftmost and is scheduled in, bounded by the scheduling latency target and minimum granularity.

What Interviewer Expects

  • Understanding of vruntime as the core fairness metric
  • Knowledge that CFS uses a red-black tree keyed by vruntime, not fixed queues
  • Explanation of how nice values scale vruntime accumulation to change CPU share
  • Awareness that CFS is the default Linux scheduler for normal (non-real-time) tasks

Common Mistakes

  • Confusing CFS with round robin (CFS has no fixed time quantum per task)
  • Thinking nice values map to fixed priority queues rather than vruntime weighting
  • Forgetting that CFS picks the leftmost (smallest vruntime) node, not a random or FIFO choice
  • Not knowing CFS is specific to normal Linux scheduling, separate from real-time scheduling classes

Best Answer (HR Friendly)

The Completely Fair Scheduler is the default Linux scheduler, and its core idea is tracking how much CPU time each task has effectively received so far, then always running whichever task has received the least. It uses an efficient tree structure to always find that task quickly, and it lets you weight tasks so some get proportionally more CPU without needing rigid, fixed time slices.

Code Example

Simplified CFS vruntime update and pick-next logic
struct task {
    long vruntime;   /* weighted accumulated CPU time */
    int  weight;     /* derived from the task’s nice value */
    struct task *left, *right;  /* conceptual red-black tree links */
};

void update_vruntime(struct task *t, long time_ran) {
    /* higher weight (higher priority) accumulates vruntime more slowly */
    t->vruntime += (time_ran * NICE_0_WEIGHT) / t->weight;
}

struct task *pick_next(struct task *tree_root) {
    struct task *node = tree_root;
    while (node->left != NULL) {
        node = node->left;       /* leftmost node has the smallest vruntime */
    }
    return node;
}

Follow-up Questions

  • How does a nice value affect a task’s vruntime accumulation rate?
  • Why does CFS use a red-black tree instead of a simple sorted list?
  • What is scheduling latency and minimum granularity in CFS?
  • How does CFS differ from Linux’s real-time scheduling classes like SCHED_FIFO?

MCQ Practice

1. What does CFS use to decide which task runs next?

CFS always dispatches the runnable task with the least vruntime so far, approximating perfectly fair proportional CPU sharing.

2. What data structure does CFS use to track runnable tasks?

CFS keeps runnable tasks in a red-black tree ordered by vruntime, letting it find the least-vruntime task in O(log n).

3. How does a lower nice value (higher priority) affect a task in CFS?

A higher-priority (lower nice value) task’s vruntime accumulates more slowly relative to CPU time consumed, so it ends up with a proportionally larger CPU share.

Flash Cards

What is CFS?The default Linux scheduler for normal tasks, which always runs the runnable task with the smallest accumulated vruntime.

What data structure backs CFS?A red-black tree keyed by vruntime, giving O(log n) selection of the next task.

How do nice values affect CFS?They scale how fast a task’s vruntime grows, changing its proportional CPU share.

Does CFS use fixed time quanta?No — it uses an adaptive scheduling latency target and minimum granularity instead of per-task fixed slices.

1 / 4
32 / 234

Continue Learning

Frequently Asked Questions

21 categories · pick one to explore

Where can I practice technical interview questions for free in India?
SkillVeris offers a free interview questions section with readiness scoring, so you can practice technical interview questions at no cost from anywhere in India or worldwide. Questions span AI/ML, programming, web development, DevOps, cloud and security. Combine them with Code Lab for hands-on coding practice and the AI Mentor for instant explanations whenever an answer confuses you.
How do I prepare for a coding interview if I am a complete beginner?
Start by learning one language well, then practice small problems daily before attempting interview questions. On SkillVeris you can take a free structured programming course with 24–40 lessons, write code in the in-browser Code Lab across 6 languages, and then move to the interview questions bank with readiness scoring to measure how prepared you actually are.
What is interview readiness scoring and how does it work?
Interview readiness scoring measures how prepared you are for a technical interview based on your performance across practice questions. On SkillVeris, as you answer interview questions, your readiness score updates so you can see weak topics before the real interview. It turns vague confidence into a concrete signal, telling you which areas need more revision and which are already strong.
How long does it take to get interview ready for a developer job?
Most beginners need a few months of consistent practice to feel interview ready, though timelines vary with background and daily study time. A practical route is finishing a structured SkillVeris course, which includes 24–40 lessons, module assessments and a final exam at an 80 percent pass mark, then drilling the free interview questions until your readiness score is consistently strong.
What are the most common technical interview topics for freshers?
Freshers are commonly tested on programming fundamentals, data structures, problem solving, databases, and basics of the role's stack such as web development or cloud. SkillVeris covers these through 37 free courses, a glossary of around 2,000 terms for quick definitions, cheat sheets for revision, and interview questions with readiness scoring so you can practise exactly what interviewers usually ask.
Can I practice coding interview prep without installing anything?
Yes, SkillVeris Code Lab runs entirely in your browser, so you can practice coding interview prep without installing compilers or editors. It supports 6 languages across 15 categories of exercises. Pair Code Lab sessions with the interview questions bank and readiness scoring, and you have a complete free preparation setup that works on any machine with an internet connection.
How do I explain technical concepts clearly in an interview?
Practice explaining each concept through a simple analogy first, then add the technical detail, because interviewers value clarity over jargon. SkillVeris teaches with its Learn Through Hobbies method, explaining concepts through cricket, music, gaming, cooking and eight more domains. Learning a topic through an analogy gives you a ready-made, memorable way to explain it when an interviewer asks.
Are there free mock interview resources for software engineers?
SkillVeris provides free interview questions with readiness scoring, which works like a self-paced mock interview you can repeat any time. You answer real-style technical questions, get scored, and see where you stand. The AI Mentor is available 24/7 to explain any answer at Quick, Detailed or Deep-dive depth, acting like an always-available interviewer who never gets tired.
How should I prepare for an AI or machine learning interview?
Cover ML fundamentals, Python, and modern topics like LLMs and RAG, then practise explaining projects clearly. SkillVeris has free AI/ML courses including Python for AI and ML, Large Language Models and Retrieval-Augmented Generation, each with 24–40 lessons and assessments. After finishing, use the interview questions bank and readiness scoring to confirm you can answer under pressure.
What should I revise the night before a technical interview?
Revise concise summaries rather than learning anything new: core definitions, common patterns, and your own project stories. SkillVeris cheat sheets and study notes are built exactly for this kind of quick revision, and the glossary of around 2,000 terms lets you verify any definition fast. A short readiness-score check on the interview questions bank confirms nothing critical is shaky.
How do I prepare for a DevOps interview with no work experience?
Build demonstrable knowledge through structured learning and hands-on practice, since you cannot point to job experience. SkillVeris offers free DevOps, Docker and Kubernetes related courses within its 37-course catalog and a DevOps Engineer learning path. Complete the courses, earn certificates by passing the final exams, then use the interview questions section to rehearse common DevOps scenarios.
Do certificates help in clearing technical interviews?
Certificates alone do not clear interviews, but they signal structured learning and give interviewers a starting point for questions. SkillVeris awards certificates when you pass a course final exam at 80 percent, after 24–40 lessons and module assessments, so the certificate reflects genuine effort. Pair it with practised interview answers and Code Lab projects to make a stronger impression.
How can I improve my problem solving speed for coding interviews?
Speed comes from repetition on progressively harder problems, not from rushing. Practise daily in SkillVeris Code Lab, which offers in-browser coding in 6 languages across 15 categories, and time yourself on interview questions. Review every mistake with the AI Mentor, which explains solutions 24/7 at Quick, Detailed or Deep-dive depth, so each session genuinely improves your pattern recognition.
What questions are asked in a Python technical interview?
Python interviews typically cover data types, functions, comprehensions, OOP, error handling and libraries relevant to the role, such as ML packages for AI positions. SkillVeris interview questions include Python topics, and its free Python for AI and ML course builds the underlying knowledge across 24–40 lessons. Readiness scoring then shows whether your Python answers are interview grade.
How do I handle interview questions I don't know the answer to?
Say what you do know, reason aloud toward an approach, and be honest about the gap, because interviewers value thinking over bluffing. Reduce how often this happens by broadening fundamentals: SkillVeris study notes, cheat sheets and the roughly 2,000-term glossary fill knowledge gaps quickly, and readiness scoring highlights weak areas before an interviewer ever finds them.
Is there a free way to check my interview readiness before applying for jobs?
Yes, SkillVeris interview questions come with readiness scoring, all completely free, so you can measure preparation before applying. Once your score looks solid, browse the SkillVeris Jobs page, which aggregates live roles across India, UK, USA, Germany and Remote with salary and experience filters, and apply knowing your technical preparation has been objectively tested.
How do I prepare for web developer interview questions?
Focus on JavaScript fundamentals, your framework of choice, HTTP basics, and building things you can discuss. SkillVeris offers free web development courses among its 37-course catalog, plus a Full Stack Java Developer learning path. After the courses, drill the interview questions bank, practise coding tasks in Code Lab, and use readiness scoring to verify you cover typical frontend and backend topics.
Can the AI Mentor help me practice interview answers?
Yes, the SkillVeris AI Mentor answers questions 24/7 and can explain any concept at Quick, Detailed or Deep-dive depth, which makes it useful for rehearsing interview explanations. Ask it to clarify a topic, then try explaining it back in your own words. Combined with the interview questions bank and readiness scoring, it becomes a free, always-available practice partner.
What is the best free platform for technical interview prep in 2026?
SkillVeris is a strong free option because it combines structured learning with dedicated interview preparation in one place. You get 37 free courses, interview questions with readiness scoring, an in-browser Code Lab for hands-on practice, cheat sheets and study notes for revision, and a 24/7 AI Mentor. Everything is free, which matters for learners in India and worldwide.
How do I stay calm and confident during a technical interview?
Confidence comes from evidence of preparation, so build that evidence deliberately. Complete a SkillVeris course, pass its final exam at the 80 percent bar, and watch your readiness score climb on the interview questions bank. Knowing you have explained concepts through analogies, coded in Code Lab, and scored well on practice questions gives you genuine, grounded calm on the day.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse