Linux Scheduling.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Operating Systems Process Scheduling (Ch 3.2, )
Abdulrahman Idlbi COE, KFUPM Jan. 17, Past Schedulers: 1.2 & : circular queue with round-robin policy. Simple and minimal. Not focused on.
CSE506: Operating Systems Scheduling. CSE506: Operating Systems Undergrad Review What is cooperative multitasking? – Processes voluntarily yield CPU when.
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
Operating System Process Scheduling (Ch 4.2, )
Operating System I Process Scheduling. Schedulers F Short-Term –“Which process gets the CPU?” –Fast, since once per 100 ms F Long-Term (batch) –“Which.
Processes CSCI 444/544 Operating Systems Fall 2008.
Project 2 – solution code
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Operating Systems Process Scheduling (Ch 4.2, )
1 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
Operating System Process Scheduling (Ch 4.2, )
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
CPU Scheduling Chapter 6 Chapter 6.
Linux Scheduling CS Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.
Operating System Examples - Scheduling
CE Operating Systems Lecture 11 Windows – Object manager and process management.
4.1 Advanced Operating Systems Desktop Scheduling You are running some long simulations. In the mean time, why not watch an illegally downloaded Simpsons.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
2.5 Scheduling Given a multiprogramming system. Given a multiprogramming system. Many times when more than 1 process is waiting for the CPU (in the ready.
LINUX SCHEDULING Evolution in the 2.6 Kernel Kevin Lambert Maulik Mistry Cesar Davila Jeremy Taylor.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Lecture 6 Page 1 CS 111 Online Preemptive Scheduling Again in the context of CPU scheduling A thread or process is chosen to run It runs until either it.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
CS333 Intro to Operating Systems Jonathan Walpole.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
Operating System Examples - Scheduling. References r er/ch10.html r bangalore.org/blug/meetings/200401/scheduler-
Lecture 6 The Rest of Scheduling Algorithms and The Beginning of Memory Management.
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
Tutorial 2: Homework 1 and Project 1
UNIT–II: Process Management
Processes and threads.
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Linux Scheduler.
Lecture 12: Real-Time Scheduling
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Networks and Operating Systems: Exercise Session 2
This lecture is heavily based on the material developed by Don Porter
Chapter 8 Multi-Level Feedback Queue
Intro to Processes CSSE 332 Operating Systems
The Linux “Completely Fair Scheduler”
Chapter 2.2 : Process Scheduling
Main Memory Management
CS 3204 Operating Systems Lecture 14 Godmar Back.
Lecture 2: Processes Part 1
A Comparison Study of Process Scheduling in FreeBSD, Linux and Win2k
Operating System Concepts
Process & its States Lecture 5.
Chapter 2: The Linux System Part 3
Scheduling Adapted from:
Scheduling.
Operating systems Process scheduling.
CPU SCHEDULING.
Process Scheduling Decide which process should run and for how long
Process Description and Control
Chapter 3: Processes.
Scheduling of Regular Tasks in Linux
Linux Scheduler © DJ Foreman 3/8/2009.
CSE 153 Design of Operating Systems Winter 2019
Linux Scheduling CSE 2431: Introduction to Operating Systems
Scheduling of Regular Tasks in Linux
CPU Scheduling David Ferry CSCI 3500 – Operating Systems
Presentation transcript:

Linux Scheduling

Real World Scheduling Select process to run next Must handle… Priorities Forking – where does child go? What about if you only use part of your quantum? E.g., blocking I/O

Linux 2.4 Linux scheduler had a single list of tasks Scanned entire list looking for best task to run Applied a goodness function to each task Generated a priority metric to compare tasks with O(n) Linear complexity (n = number of tasks) Time broken into epochs Each process had a window of time in epoch If time wasn’t used: half of left over time saved for next epoch

Linux O(1) Scheduler (2.6) runqueue: a list of runnable processes Blocked processes are not on any runqueue A runqueue belongs to a specific CPU Each task is on exactly one runqueue Task only scheduled on runqueue’s CPU unless migrated 2 *40 * #CPUs = # of runqueues 40 dynamic priority levels (more on this later) 2 sets of runqueues – one active and one expired

Run Queues

Approach Take first task from lowest runqueue on active set Lower priority value means higher priority When done, put it on runqueue on expired set On empty active, swap active and expired runqueues Constant time Fixed number of queues to check Only take first item from non-empty queue

Example

Blocking What if a program blocks on I/O? Still has part of its quantum left Has nothing to execute Removed from active and expired runqueues Need a wait queue for each blocking event Disk, lock, pipe, network socket, etc…

Wait Queues

Wait Queues Blocked tasks are stored on wait queues Disk example: Moved back when event happens No longer on any active or expired queue! Disk example: I/O completes IRQ handler moves task from wait queue to active runqueue

Time Slices A process blocks and then becomes runnable How much time did it have left? Each task tracks time left in ‘time_slice’ field On each clock period: current->time_slice-- If time slice goes to zero, move to expired queue Refill time slice Schedule someone else An unblocked task can use balance of time slice Forking halves time slice with child

Priorities Based on “nice” levels 100 = highest priority “nice” value: user-specified adjustment to base priority 100 = highest priority 139 = lowest priority 120 = base priority Selfish (not nice) = -20 (I want to go first) Really nice = +19 (I will go last)

Time Slice assignment Priority < 120 Priority >= 120 Time slice = (140 – priority) * 20ms Priority >= 120 Time slice = (140 – priority) * 5ms “Higher” priority tasks get longer time slices And run first

Interactive Tasks Most GUI programs are I/O bound on the user Unlikely to use entire time slice Users care about interactivity Latency or responsiveness to user events Typically Keyboard/Mouse events Scheduler tries to give UI programs a priority boost Move to front of line, run briefly, block on I/O again Scheduler must somehow identify interactive tasks

Heuristic based classification I/O bound applications wait on I/O Don’t need much CPU time Scheduler monitors I/O wait time Infer which programs are GUI (and disk intensive) Processes that do a lot of I/O get a priority boost Note that this behavior can be dynamic GUI does something compute intensive E.g. image rendering Scheduling should match program phases

Dynamic Priorities Real Priority = static priority − bonus + 5; floor(100) && ceil(139) Bonus is calculated based on sleep time Dynamic priority determines a tasks’ runqueue Balance throughput and latency with infrequent I/O May not be optimal Heuristically driven Seems to work, but is pretty ugly Edge cases can cause it to break

Dynamic Priorities Runqueue determined by the dynamic priority Not the static priority Dynamic priority mostly based on time spent waiting To boost UI responsiveness and “fairness” to I/O intensive apps “nice” values influence static priority Can’t boost dynamic priority without being in wait queue! No matter how “nice” you are (or aren’t)

Setting static priorities int setpriority(int which, int who, int prio); int getpriority(int which, int who); which: process, process group, or user id who: PID, PGID, or UID prio: nice value (-20 to +19) int nice(int inc); Historical interface (backwards compatible) Equivalent to: setpriority(PRIO_PROCESS, getpid(), niceval)

CFS Scheduler (later 2.6) O(1) scheduler is complicated Heuristics for various issues makes it more complicated Heuristics can end up working at cross-purposes Desire for something simpler and elegant Based on a simple list of tasks (conceptually) Ordered by how much time they’ve used Always pick the “neediest” task to run Until it is no longer neediest Then re-insert old task in the timeline Schedule the new neediest Implements a form of Weighted Fair Queueing

Fairness 50 tasks, each should get 2% of CPU time Do we really want this? What about priorities? Interactive vs. batch jobs? Per-user fairness? Alice has 1 task and Bob has 49; Why should Bob get 98% of CPU?

CFS

CFS

CFS details CPU time is allotted based on the tick allocations Global virtual clock: ticks at a fraction of real time Fraction is number of total tasks Each task accumulates time in proportion to total # of tasks Stores accumulated time as a variable Accumulated time subtracted as task runs Example: 4 tasks Global vclock ticks once every 4 real ticks Each task allocated one real tick Tasks stored in a red-black tree sorted based on their allocation of ticks struct rbtree; Generic kernel data structure Task with largest allocation of ticks is scheduled next CPU time is allotted based on the tick allocations Messing with the tick allocations allows flexibility

Priorities Priorities allow scheduler to be unfair In CFS, priorities determine the ticks allocated to a task Example: For a high-priority task 10 real clock ticks may be allocated per global virtual tick For a low-priority task A virtual, task-local tick may only last for 1 actual clock tick Higher-priority tasks run longer Low-priority tasks make some progress

Weighted Fair Queueing GUI programs are I/O bound We want them to be responsive to user input Need to be scheduled as soon as input is available Will only run for a short time CFS blocked tasks removed from RB-tree Just like O(1) scheduler Virtual clock keeps ticking while tasks are blocked Increasingly large deficit between task and global vclock When a GUI task is runnable, goes to the front Dramatically lower vclock value than CPU-bound jobs

Grouping Per group or user scheduling Controlled by real to virtual tick ratio Function of number of global and user’s/group’s tasks Can group processes in multiple ways Can support group hierarchies Scheduler doesn’t operate on tasks, threads or processes Uses a generic “sched_entity” structure Sched entity can refer to anything that can run Can also refer to a set of “sched_entities” Allows recursiveness in the scheduler Easily extendable to support “cgroups” Basis for containerization