Completely Fair Scheduler Alireza Heidari. Introduction The Completely Fair Scheduler (CFS) is a process scheduler. Merged into the 2.6.23 release of.

Slides:



Advertisements
Similar presentations
Chapter 13. Red-Black Trees
Advertisements

1 Always want to have CPU (or CPU’s) working Usually many processes in ready queue –Ready to run on CPU –Focus on a single CPU here Need strategies for.
Lecture 11: Operating System Services. What is an Operating System? An operating system is an event driven program which acts as an interface between.
Abdulrahman Idlbi COE, KFUPM Jan. 17, Past Schedulers: 1.2 & : circular queue with round-robin policy. Simple and minimal. Not focused on.
Chapter 4: Trees Part II - AVL Tree
CS 484. Discrete Optimization Problems A discrete optimization problem can be expressed as (S, f) S is the set of all feasible solutions f is the cost.
BFS: Brain F*ck Scheduler Jacob Chan. Objectives  Brain F*ck Scheduling  What it is  How it works  Features  Scalability  Limitations  Definition.
Outline Scapegoat Trees ( O(log n) amortized time)
November 5, Algorithms and Data Structures Lecture VIII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
ITEC200 Week 11 Self-Balancing Search Trees. 2 Learning Objectives Week 11 (ch 11) To understand the impact that balance has on.
Discussion #36 Spanning Trees
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
Chapter 2: Processes Topics –Processes –Threads –Process Scheduling –Inter Process Communication (IPC) Reference: Operating Systems Design and Implementation.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 47 Red Black Trees.
Trees and Red-Black Trees Gordon College Prof. Brinton.
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
Self-Balancing Search Trees Chapter 11. Chapter 11: Self-Balancing Search Trees2 Chapter Objectives To understand the impact that balance has on the performance.
Self-Balancing Search Trees Chapter 11. Chapter Objectives  To understand the impact that balance has on the performance of binary search trees  To.
GRANULARITY OF LOCKS IN SHARED DATA BASE J.N. Gray, R.A. Lorie and G.R. Putzolu.
David Luebke 1 7/2/2015 ITCS 6114 Red-Black Trees.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
CS 61B Data Structures and Programming Methodology Aug 11, 2008 David Sun.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
The Linux “Completely Fair Scheduler”
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Copyright © Wondershare Software Introduction to Data Structures Prepared by: Eng. Ahmed & Mohamed Taha.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
ICS 220 – Data Structures and Algorithms Week 7 Dr. Ken Cosh.
ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 6.
Ch 4. Process Scheduling. Overview (1) The process scheduler is the component of the kernel that selects which process to run next  Can be viewed as.
Linux Scheduling CS Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.
Windows 2000 Scheduling Computing Department, Lancaster University, UK.
Self stabilizing Linux Kernel Mechanism Doron Mishali, Alex Plits Supervisors: Prof. Shlomi Dolev Dr. Reuven Yagel.
CHP-4 QUEUE.
David Luebke 1 9/18/2015 CS 332: Algorithms Red-Black Trees.
Heaps, Heapsort, Priority Queues. Sorting So Far Heap: Data structure and associated algorithms, Not garbage collection context.
Balanced Search Trees Chapter 27 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Ch 4. Process Scheduling. Overview (1) The process scheduler is the component of the kernel that selects which process to run next  Can be viewed as.
CS-2851 Dr. Mark L. Hornick 1 Okasaki’s Insertion Method for Red/Black balancing A step-by-step procedure for maintaining balance through application of.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
1 Red-Black Trees By Mary Hudachek-Buswell Red Black Tree Properties Rotate Red Black Trees Insertion Red Black Trees.
Data Structures Balanced Trees 1CSCI Outline  Balanced Search Trees 2-3 Trees Trees Red-Black Trees 2CSCI 3110.
Lecture 10 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
Red-Black trees Binary search trees with additional conditions. These conditions ensure that the trees are fairly well balanced. In this way we obtain.
LINUX SCHEDULING Evolution in the 2.6 Kernel Kevin Lambert Maulik Mistry Cesar Davila Jeremy Taylor.
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
Periodic scheduler for Linux OS
Red-Black Trees. Review: Binary Search Trees ● Binary Search Trees (BSTs) are an important data structure for dynamic sets ● In addition to satellite.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
Red-Black Tree Insertion Start with binary search insertion, coloring the new node red NIL l Insert 18 NIL l NIL l 1315 NIL l
Linux Process Management. Linux Implementation of Threads Threads enable concurrent programming / true parallelism Linux implementation of threads.
1 Algorithms CSCI 235, Fall 2015 Lecture 24 Red Black Trees.
CSC 213 – Large Scale Programming. Priority Queue ADT  Prioritizes Entry s using their keys  For Entry s with equal priorities, order not specified.
Keeping Binary Trees Sorted. Search trees Searching a binary tree is easy; it’s just a preorder traversal public BinaryTree findNode(BinaryTree node,
CSC317 1 x y γ β α x y γ β x β What did we leave untouched? α y x β.
Lecture 6 The Rest of Scheduling Algorithms and The Beginning of Memory Management.
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Linux Scheduler.
Process Management Process Concept Why only the global variables?
Chapter 5a: CPU Scheduling
Red Black Trees
FLIPPED CLASSROOM ACTIVITY CONSTRUCTOR – USING EXISTING CONTENT
The Linux “Completely Fair Scheduler”
Red-Black Trees Motivations
Lecture 9 Algorithm Analysis
Virtual-Time Round-Robin: An O(1) Proportional Share Scheduler
2-3-4 Trees Red-Black Trees
CPU Scheduling David Ferry CSCI 3500 – Operating Systems
Presentation transcript:

Completely Fair Scheduler Alireza Heidari

Introduction The Completely Fair Scheduler (CFS) is a process scheduler. Merged into the release of the Linux kernel and is the default scheduler. Maximize overall CPU utilization while also maximizing interactive performance CFS does not use the old data structures for the runqueues, but it uses a time-ordered red black tree to build a "timeline" of future task execution

Introduction CFS basically models an "ideal, precise multi-tasking CPU" on real hardware. "Ideal multi-tasking CPU" is a (non-existent :-)) CPU that has 100% physical power and which can run each task at precise equal speed, in parallel, each at 1/nr_running speed. For example: if there are 2 tasks running, then it runs each at 50% physical power i.e., actually in parallel.

Red–black tree Properties A node is either red or black. The root is black. (This rule is sometimes omitted. Since the root can always be changed from red to black, but not necessarily vice-versa, this rule has little effect on analysis.) All leaves (NIL) are black. (All leaves are same color as the root.) Every red node must have two black child nodes. Every path from a given node to any of its descendant leaves contains the same number of black nodes.

Red–black tree Properties

CFS On real hardware, we can run only a single task at once, so we have to introduce the concept of "virtual runtime." The virtual runtime of a task specifies when its next timeslice would start execution on the ideal multi-tasking CPU described above. In practice, the virtual runtime of a task is its actual runtime normalized to the total number of running tasks.

CFS In CFS the virtual runtime is expressed and tracked via the per-task p->se.vruntime (nanosec-unit) value. This way, it's possible to accurately timestamp and measure the "expected CPU time" a task should have gotten. On "ideal" hardware, at any time all tasks would have the same p- >se.vruntime value i.e., tasks would execute simultaneously and no task would ever get "out of balance" from the "ideal" share of CPU time.

CFS CFS's task picking logic is based on this p->se.vruntime value It always tries to run the task with the smallest p->se.vruntime value (i.e., the task which executed least so far). The total number of running tasks in the runqueue is accounted through the rq->cfs.load value, which is the sum of the weights of the tasks queued on the runqueue.

CFS All runnable tasks are sorted by the p->se.vruntime key. CFS picks the "leftmost" task from the tree. the executed tasks are put into the tree more and more to the right, slowly but surely giving a chance for every task to become the "leftmost task" and thus get on the CPU within a deterministic amount of time.

Summing up 1. It runs a task a bit. 2. When the task schedules (or a scheduler tick happens) the task's CPU usage is "accounted for“. 3. The (small) time it just spent using the physical CPU is added to p->se.vruntime. 4. Once p->se.vruntime gets high enough so that another task becomes the "leftmost task" of the time-ordered rbtree it maintains ("granularity" ) 5. The new leftmost task is picked and the current task is preempted.

CFS detail The left most node of the scheduling tree is chosen (as it will have the lowest spent execution time), and sent for execution. If the process simply completes execution, it is removed from the system and scheduling tree. If the process reaches its maximum execution time or is otherwise stopped (voluntarily or via interrupt) it is reinserted into the scheduling tree based on its new spent execution time. The new left-most node will then be selected from the tree, repeating the iteration.

SCHEDULING CLASSES enqueue_task(...) Called when a task enters a runnable state.It puts the scheduling entity (task) into the red-black tree and increments the nr_running variable. dequeue_task(...) When a task is no longer runnable, this function is called to keep the corresponding scheduling entity out of the red-black tree.It decrements the nr_running variable.

SCHEDULING CLASSES check_preempt_curr(...) This function checks if a task that entered the runnable state should preempt the currently running task. pick_next_task(...) This function chooses the most appropriate task eligible to run next. set_curr_task(...) This function is called when a task changes its scheduling class or changes its task group. task_tick(...) This function is mostly called from time tick functions; it might lead to process switch. This drives the running preemption.

Question?