Scheduling policy. Reference: ULK3e 7.1. Scheduling in Linux 1 / 20

Similar documents
Computer Systems Laboratory Sungkyunkwan University

Scalable Linux Scheduling (Paper # 9)

High level scheduling: Medium level scheduling: Low level scheduling. Scheduling 0 : Levels

Scheduling: Case Studies. CS 161: Lecture 5 2/14/17

238P: Operating Systems. Lecture 14: Process scheduling

Course Syllabus. Operating Systems

Scheduling - Overview

ò mm_struct represents an address space in kernel ò task represents a thread in the kernel ò A task points to 0 or 1 mm_structs

W4118: advanced scheduling

Scheduling. Don Porter CSE 306

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

Linux Scheduler. OS 323 (Spring 2013)

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

8: Scheduling. Scheduling. Mark Handley

Interactive Scheduling

Two Level Scheduling. Interactive Scheduling. Our Earlier Example. Round Robin Scheduling. Round Robin Schedule. Round Robin Schedule

Chapter 5: CPU Scheduling

Operating Systems 16 - CS 323 Assignment #2

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Properties of Processes

Process management. Scheduling

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

CS 378 (Spring 2003)

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Scheduling Bits & Pieces

ò Paper reading assigned for next Tuesday ò Understand low-level building blocks of a scheduler User Kernel ò Understand competing policy goals

Operating Systems. Scheduling

PROCESS SCHEDULING Operating Systems Design Euiseong Seo

SMP Scheduling RT Scheduling Examples. December Winter Term 2008/09 Gerd Liefländer

1.1 CPU I/O Burst Cycle

Scheduling II. Today. Next Time. ! Proportional-share scheduling! Multilevel-feedback queue! Multiprocessor scheduling. !

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

CHAPTER 2: PROCESS MANAGEMENT

Chapter 10: Case Studies. So what happens in a real operating system?

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Scheduling. The Basics

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Scheduling in the Supermarket

Chapter 6: CPU Scheduling

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems, 3rd edition. Uses content with permission from Assoc. Prof. Florin Fortis, PhD

COSC243 Part 2: Operating Systems

CS3733: Operating Systems

CSE 120 Principles of Operating Systems Spring 2017

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Learning Outcomes. Scheduling. Is scheduling important? What is Scheduling? Application Behaviour. Is scheduling important?

Scheduling. CS 161: Lecture 4 2/9/17

Ch 4 : CPU scheduling

SMD149 - Operating Systems

Operating System Concepts Ch. 5: Scheduling

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 21

CS 322 Operating Systems Practice Midterm Questions

Lecture 2 Process Management

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

CS 318 Principles of Operating Systems

Uniprocessor Scheduling. Chapter 9

Operating Systems ECE344. Ding Yuan

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Chapter 5: CPU Scheduling

Operating System Review Part

Project No. 2: Process Scheduling in Linux Submission due: April 12, 2013, 11:59pm

Scheduling II. q q q q. Proportional-share scheduling Multilevel-feedback queue Multiprocessor scheduling Next Time: Memory management

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Chapter 5 Scheduling

Scheduling. Today. Next Time Process interaction & communication

Enhancing Linux Scheduler Scalability

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Chapter 5: Process Scheduling

Scheduling of processes

SFO The Linux Kernel Scheduler. Viresh Kumar (PMWG)

Chapter 5: CPU Scheduling

Operating Systems. CPU Scheduling ENCE 360

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Operating Systems. Process scheduling. Thomas Ropars.

Linux Linux #! "! Linux

Class average is Undergraduates are performing better. Working with low-level microcontroller timers

CS2506 Quick Revision

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

CPU Scheduling Algorithms

CIS233J Java Programming II. Threads

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Chapter 5 CPU scheduling

Scheduling. Scheduling 1/51

Scheduling II. ! Multilevel queue scheduling. ! Multiprocessor scheduling issues. ! Real-time scheduling. ! Linux scheduling

Round Robin (RR) ACSC 271 Operating Systems. RR Example. RR Scheduling. Lecture 9: Scheduling Algorithms

Unix SVR4 (Open Solaris and illumos distributions) CPU Scheduling

Transcription:

Scheduling policy Reference: ULK3e 7.1. Goals fast process response time good throughput for background jobs avoidance of process starvation reconciliation of needs of low- and high-priority processes Scheduling in Linux 1 / 20

Scheduling policy. Reference: ULK2e 11.1 Scheduling policy is based on a combination of Multi-level queues different queues for real-time and conventional processes Priority scheduling low numbers high priority priorities are dynamic (change with time) implicitly uses aging priority of waiting process increases.. priority of processes running for a long time decreases Round robin scheduling process preempted on expiry of quantum but duration of quantum typically varies from process to process FCFS: only for breaking ties Scheduling in Linux 2 / 20

Scheduling policy (contd.) Scheduling policy is preemptive When a process enters the TASK RUNNING state, kernel checks priority If priority of new task is greater than priority of current process, scheduler is invoked Scheduling in Linux 3 / 20

2.4 Scheduler Scheduling in Linux 4 / 20

Priorities Static priority (rt priority) assigned to real-time processes only ranges from 1 to 99; 0 for conventional processes never changed by the scheduler Dynamic priority applies only to conventional processes dynamic priority of conventional process is always less than static priority of real-time process Scheduling in Linux 5 / 20

Scheduling algorithm. Reference: ULK2e 11.2 CPU time is divided into epochs In each epoch, every process gets a specified time quantum quantum = maximum CPU time assigned to the process in that epoch duration of quantum computed when epoch begins different processes may have different time quantum durations when process forks, remainder of parent s quantum is split / shared between parent and child Epoch ends when all runnable processes have exhausted their quanta At end of epoch, scheduler algorithm recomputes the time-quantum durations of all processes; new epoch begins Scheduling in Linux 6 / 20

Implementation Scheduling related fields in proc structure counter: contains quantum alloted to a process when new epoch begins decremented for current process by 1 at every tick nice: contains values ranging between -20 and +19 negative values high priority processes positive values low priority processes 0 (default value) normal processes. Scheduling in Linux 7 / 20

Scheduling algorithm Process selection: c = -1000; list_for_each(tmp, &runqueue_head) { } p = list_entry(tmp, struct task_struct, run_list); if (p->cpus_runnable & p->cpus_allowed & (1 << this_cpu)) { } int weight = goodness(p, this_cpu, prev->active_mm); if (weight > c) c = weight, next = p; // break ties using FCFS Best candidate may be the current process c == 0 new epoch begins for_each_task(p) // all EXISTING processes p->counter = (p->counter >> 1) + (20 - p->nice) / 4 + 1; Scheduling in Linux 8 / 20

goodness() Case I: Case II: p is a conventional process that has exhausted its quantum (p->counter is zero) weight = 0 p is a conventional process that has not exhausted its quantum weight = p->counter + 20 - p->nice; if (p->processor == this_cpu) weight +=15; if (p->mm == this_mm!p->mm) weight += 1; /* 2 <= weight <= 77 */ Case III: p is a real-time process weight = p->counter + 1000 // weight >= 1000 Scheduling in Linux 9 / 20

Limitations Reference: ULK2e 11.2.3. Scalability: if # of existing/runnable processes is large inefficient to recompute all dynamic priorities I/O bound processes are boosted only at the end of an epoch interactive applications have longer response time if number of runnable processes is large I/O-bound process boosting strategy: batch programs with almost no user interaction may be I/O-bound e.g. database search engine, network application that collects data from a remote host on a slow link Scheduling in Linux 10 / 20

2.6 Scheduler Scheduling in Linux 11 / 20

Ingredients Static priority: inherited from parent Dynamic priority: function of static priority average sleep time Nature of process: interactive or batch Scheduling in Linux 12 / 20

Priorities. Static priority (static prio) low value high priority 0 99: real-time processes Reference: ULK3e 7.2 100 139: conventional process default value is 120 may be changed via nice() new process inherits static priority of its parent Base time quantum time (ms) allocated to a process when it has exhausted its previous time quantum if (static_prio < 120) base = (140-static_prio) * 20; else if (static_prio >= 120) base = (140-static_prio)*5; Scheduling in Linux 13 / 20

Priorities Average sleep time: depends on roughly, user input whether process is sleeping in TASK.INTERRUPTIBLE state. whether process is sleeping in TASK.UNINTERRUPTIBLE state. decreases while a process is running maximum value = 1 second Dynamic priority (prio) roughly, disk I/O Used by scheduler when selecting new process to run prio = MAX(100, MIN(static prio - bonus + 5, 139)) where bonus = MIN(sleep avg. / 100, 10). interactive tasks receive a prio bonus CPU bound tasks receive a prio penalty Scheduling in Linux 14 / 20

Active vs. expired processes Active processes: runnable processes that have not yet exhausted their time quantum Expired processes: runnable processes that have exhausted their time quantum Time quantum is recalculated on expiry (cf. base time quantum) Active batch processes that finish time quantum expire Active interactive processes that finish time quantum: if the eldest expired process has already waited for a long time, or if an expired process has higher static priority than the interactive process expire otherwise, time quantum is refilled and process remains in the set of active processes Process is interactive if bonus - 5 >= static prio / 4-28 Scheduling in Linux 15 / 20

Data structures. Reference: ULK3e 7.3 Bitmap keeps track of which process lists are non-empty Scheduling in Linux 16 / 20

scheduler tick() Invoked once every tick Steps 1. Decrease the ticks left in the allocated time of the process. (p->counter (2.4), or p->time_slice (2.6)) 2. Update dynamic priority using sleep avg. 3. If necessary, refill the time allocation for the process with the base quantum. 4. Insert process in expired queue / active queue based on (a) whether the task is interactive, (b) whether the expired tasks are starving, (c) relative priority of the process w.r.t. expired processes. Scheduling in Linux 17 / 20

Real-time processes Scheduling in Linux 18 / 20

Preemptible kernel 2.6 Non-premptible kernel (e.g., 2.4): scheduler can only interrupt process running in user mode ready to run high-priority process may be blocked for long periods of time by a low-priority process inside a slow system call Pre-emptible kernel: scheduler can interrupt all processes Scheduling in Linux 19 / 20

Scheduling classes SCHED FIFO 1. Pick highest priority SCHED FIFO queue that is non-empty. 2. Schedule first process on this queue. 3. Preempted only if higher priority real-time process becomes runnable. SCHED RR: process is preempted on expiry of time quantum if there are other ready processes with same priority SCHED NORMAL or SCHED OTHER: conventional processes May be set using sched setscheduler() system call, or from command line using chrt Scheduling in Linux 20 / 20