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

Similar documents
Scheduling. Don Porter CSE 306

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

238P: Operating Systems. Lecture 14: Process scheduling

Scheduling, part 2. Don Porter CSE 506

W4118: advanced scheduling

Native POSIX Thread Library (NPTL) CSE 506 Don Porter

Course Syllabus. Operating Systems

Context Switching & CPU Scheduling

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

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

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

Example: CPU-bound process that would run for 100 quanta continuously 1, 2, 4, 8, 16, 32, 64 (only 37 required for last run) Needs only 7 swaps

Fall 2014:: CSE 506:: Section 2 (PhD) Threading. Nima Honarmand (Based on slides by Don Porter and Mike Ferdman)

PROCESS SCHEDULING Operating Systems Design Euiseong Seo

8: Scheduling. Scheduling. Mark Handley

CS 326: Operating Systems. CPU Scheduling. Lecture 6

Scheduling. Monday, November 22, 2004

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

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Scheduling. Scheduling 1/51

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

EECS 750: Advanced Operating Systems. 01/29 /2014 Heechul Yun

Scheduling Mar. 19, 2018

Scheduling in the Supermarket

Scheduling. Scheduling 1/51

Operating Systems. Process scheduling. Thomas Ropars.

CS2506 Quick Revision

LECTURE 3:CPU SCHEDULING

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

SFO The Linux Kernel Scheduler. Viresh Kumar (PMWG)

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Process management. Scheduling

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Multi-Level Feedback Queues

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.

SMD149 - Operating Systems

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

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

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

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 21

PROCESS SCHEDULING II. CS124 Operating Systems Fall , Lecture 13

Scalable Linux Scheduling (Paper # 9)

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Interactive Scheduling

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

Advanced Operating Systems (CS 202) Scheduling (1)

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Scheduling. Today. Next Time Process interaction & communication

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

CSE 120 Principles of Operating Systems Spring 2017

CS370 Operating Systems

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

Analysis of the BFS Scheduler in FreeBSD

Processes and Threads

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

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

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

CS3733: Operating Systems

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

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Operating Systems. Scheduling

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)

Computer Systems Laboratory Sungkyunkwan University

Operating Systems ECE344. Ding Yuan

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

Chapter 5 Scheduling

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

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)

The Art and Science of Memory Allocation

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Computer Science 4500 Operating Systems

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

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Advanced Operating Systems (CS 202) Scheduling (2)

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Lecture 4: Memory Management & The Programming Interface

CS Computer Systems. Lecture 6: Process Scheduling

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

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)

Linux Scheduler. OS 323 (Spring 2013)

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

CSL373: Lecture 6 CPU Scheduling

Chapter 5: CPU Scheduling

Implementing Scheduling Algorithms. Real-Time and Embedded Systems (M) Lecture 9

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

Unix SVR4 (Open Solaris and illumos distributions) CPU 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)

Networks and Operating Systems ( ) Chapter 3: Scheduling

Lecture 2 Process Management

Frequently asked questions from the previous class survey

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

COSC243 Part 2: Operating Systems

Process behavior. Categories of scheduling algorithms.

Enhancing Linux Scheduler Scalability

Kernel Korner What's New in the 2.6 Scheduler

Lecture 3: Processes. CMPUT 379, Section A1, Winter 2014 January 13, 15 and 17

Transcription:

Last time We went through the high-level theory of scheduling algorithms Scheduling Today: View into how Linux makes its scheduling decisions Don Porter CSE 306 Lecture goals Understand low-level building blocks of a scheduler Understand competing policy goals Understand the O(1) scheduler CFS next lecture Familiarity with standard Unix scheduling APIs (Linux) Terminology Review mm_struct represents an address space in kernel task represents a thread in the kernel A task points to 0 or 1 mm_structs Kernel threads just borrow previous task s mm, as they only execute in kernel address space Many tasks can point to the same mm_struct Multi-threading Quantum CPU timeslice Outline Policy goals Policy goals (review) O(1) Scheduler Scheduling interfaces Fairness everything gets a fair share of the CPU Real-time deadlines CPU time before a deadline more valuable than time after Latency vs Throughput: Timeslice length matters! GUI programs should feel responsive CPU-bound jobs want long timeslices, better throughput User priorities Virus scanning is nice, but I don t want it slowing things down 1

No perfect solution Outline Optimizing multiple variables Like memory allocation, this is best-effort Some workloads prefer some scheduling strategies Nonetheless, some solutions are generally better than others Policy goals O(1) Scheduler Scheduling interfaces O(1) scheduler O(1) Bookkeeping Goal: decide who to run next, independent of number of processes in system Still maintain ability to prioritize tasks, handle partially unused quanta, etc 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 runqueues 40 dynamic priority levels (more later) 2 sets of runqueues one active and one expired O(1) Data Structures O(1) Intuition Take the first task off the lowest-numbered runqueue on active set Confusingly: a lower priority value means higher priority When done, put it on appropriate runqueue on expired set Once active is completely empty, swap which set of runqueues is active and expired Constant time, since fixed number of queues to check; only take first item from non-empty queue 2

O(1) Example What now? Pick first, highest priority task to run Move to expired queue when quantum expires Blocked Tasks What if a program blocks on I/O, say for the disk? Blocking Example Disk It still has part of its quantum left Not runnable, so don t waste time putting it on the active or expired runqueues We need a wait queue associated with each blockable event Disk, lock, pipe, network socket, etc Block on disk! Process goes on disk wait queue Blocked Tasks, cont Time slice tracking A blocked task is moved to a wait queue until the expected event happens No longer on any active or expired queue! Disk example: After I/O completes, interrupt handler moves task back to active runqueue If a process blocks and then becomes runnable, how do we know how much time it had left? Each task tracks ticks left in time_slice field On each clock tick: 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 3

More on priorities = highest priority = lowest priority 120 = base priority nice value: user-specified adjustment to base priority Selfish (not nice) = -20 (I want to go first) Really nice = +19 (I will go last) Base time slice # % (140 prio)* 20ms prio <120 time = $ % (140 prio)* 5ms prio 120 & Higher priority tasks get longer time slices And run first Goal: Responsive UIs Idea: Infer from sleep time Most GUI programs are I/O bound on the user Unlikely to use entire time slice Users get annoyed when they type a key and it takes a long time to appear Idea: give UI programs a priority boost Go to front of line, run briefly, block on I/O again Which ones are the UI programs? By definition, I/O bound applications spend most of their time waiting on I/O We can monitor I/O wait time and infer which programs are GUI (and disk intensive) Give these applications a priority boost Note that this behavior can be dynamic Ex: GUI configures DVD ripping, then it is CPU-bound Scheduling should match program phases Dynamic priority dynamic priority = max (, min ( static priority bonus + 5, ) ) Bonus is calculated based on sleep time Dynamic priority determines a tasks runqueue This is a heuristic to balance competing goals of CPU throughput and latency in dealing with infrequent I/O May not be optimal Dynamic Priority in O(1) Scheduler Important: The runqueue a process goes in is determined by the dynamic priority, not the static priority Dynamic priority is mostly determined by time spent waiting, to boost UI responsiveness Nice values influence static priority No matter how nice you are (or aren t), you can t boost your dynamic priority without blocking on a wait queue! 4

Rebalancing tasks Rebalancing As described, once a task ends up in one CPU s runqueue, it stays on that CPU forever CPU 0 CPU 1 CPU 1 Needs More Work! Rebalancing tasks Idea: Idle CPUs rebalance As described, once a task ends up in one CPU s runqueue, it stays on that CPU forever What if all the processes on CPU 0 exit, and all of the processes on CPU 1 fork more children? We need to periodically rebalance Balance overheads against benefits Figuring out where to move tasks isn t free If a CPU is out of runnable tasks, it should take load from busy CPUs Busy CPUs shouldn t lose time finding idle CPUs to take their work if possible There may not be any idle CPUs Overhead to figure out whether other idle CPUs exist Just have busy CPUs rebalance much less frequently Average load Rebalancing strategy How do we measure how busy a CPU is? Average number of runnable tasks over time Available in /proc/loadavg Read the loadavg of each CPU Find the one with the highest loadavg (Hand waving) Figure out how many tasks we could take If worth it, lock the CPU s runqueues and take them If not, try again later 5

Outline Setting priorities Policy goals O(1) Scheduler Scheduling interfaces setpriority(which, who, niceval) and getpriority() Which: process, process group, or user id PID, PGID, or UID Niceval: -20 to +19 (recall earlier) nice(niceval) Historical interface (backwards compatible) Equivalent to: setpriority(prio_process, getpid(), niceval) Scheduler Affinity yield sched_setaffinity and sched_getaffinity Can specify a bitmap of CPUs on which this can be scheduled Better not be 0! Useful for benchmarking: ensure each thread on a dedicated CPU Moves a runnable task to the expired runqueue Unless real-time (more later), then just move to the end of the active runqueue Several other real-time related APIs Summary Understand competing scheduling goals Understand O(1) scheduler + rebalancing Scheduling system calls 6