CSL373: Lecture 7 Advanced Scheduling

Similar documents
CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2002

Last Class: Processes

CSL373: Lecture 6 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)

Page 1. CS162 Operating Systems and Systems Programming Lecture 6. Synchronization. Goals for Today

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)

CS 326: Operating Systems. CPU Scheduling. Lecture 6

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.

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)

Multi-Level Feedback Queues

8: Scheduling. Scheduling. Mark Handley

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

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

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)

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

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

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

CS162 Operating Systems and Systems Programming Lecture 6. Synchronization. Review: ThreadFork(): Create a New Thread

Operating Systems. Scheduling

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

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

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

CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)

Operating Systems. Process scheduling. Thomas Ropars.

Scheduling. Today. Next Time Process interaction & communication

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

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

CS Computer Systems. Lecture 6: Process Scheduling

Process Scheduling. Copyright : University of Illinois CS 241 Staff

1 Textbook scheduling. 2 Priority scheduling. 3 Advanced scheduling topics 1 / What goals should we have for a scheduling algorithm?

CS3733: Operating Systems

1 Textbook scheduling. 2 Priority scheduling. 3 Advanced scheduling topics. - What goals should we have for a scheduling algorithm?

Scheduling Mar. 19, 2018

Page 1. Review: Execution Stack Example" Review: Execution Stack Example" Review: Execution Stack Example"

Scheduling in the Supermarket

CS 318 Principles of Operating Systems

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02).

Chapter 9. Uniprocessor Scheduling

Course Syllabus. Operating Systems

VIRTUAL MEMORY READING: CHAPTER 9

Uniprocessor Scheduling

Properties of Processes

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

The different Unix contexts

September 21 st, 2015 Prof. John Kubiatowicz

Job Scheduling. CS170 Fall 2018

LECTURE 3:CPU SCHEDULING

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

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

Scheduling of processes

Midterm Exam March 3, 1999 CS162 Operating Systems

CHAPTER III SCHEDULING. Jehan-François Pâris

Operating Systems ECE344. Ding Yuan

Page 1. Goals for Today" Why Processes & Threads?" Putting it together: Process" CS162 Operating Systems and Systems Programming Lecture 3

Recap. Run to completion in order of arrival Pros: simple, low overhead, good for batch jobs Cons: short jobs can stuck behind the long ones

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

CS370 Operating Systems

Operating System Review Part

Computer Systems Laboratory Sungkyunkwan University

CPU Scheduling: Objectives

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

Announcements/Reminders

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

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

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

W4118: advanced scheduling

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

Start of Lecture: February 10, Chapter 6: Scheduling

May 19, Answer pieces in italics were not required to receive full points.

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

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

CS140 Operating Systems Midterm Review. Feb. 5 th, 2009 Derrick Isaacson

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Scheduling. Don Porter CSE 306

238P: Operating Systems. Lecture 14: Process scheduling

Interactive Scheduling

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

Practice Exercises 305

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

Advanced Operating Systems (CS 202) Scheduling (2)

Frequently asked questions from the previous class survey

Administrivia. - Show up to lecture for free extension to midnight - SCPD can just watch lecture before midnight

Scheduling. Scheduling 1/51

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory

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

CS162 Operating Systems and Systems Programming Lecture 7. Concurrency (Continued), Synchronization

Computer Systems Assignment 4: Scheduling and I/O

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

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

Scheduling. Scheduling 1/51

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

Opera&ng Systems ECE344

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Advanced Operating Systems (CS 202) Scheduling (1)

Operating Systems. CPU Scheduling ENCE 360

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Today s class. Scheduling. Informationsteknologi. Tuesday, October 9, 2007 Computer Systems/Operating Systems - Class 14 1

Transcription:

CSL373: Lecture 7 Advanced Scheduling

Today Multi-level feedback in the real world UNIX Lottery scheduling: Clever use of randomness to get simplicity Retro-perspectives on scheduling Reading: Chapter 5

Scheduling Review FIFO: run in arrival order, until exit or block run + simple - Short jobs get stuck behind long ones; poor I/O RR: run in cycle, until exit, block or time slice expires add + better for short jobs - poor when jobs are the same length add STCF: run shortest jobs first run + optimal (avg. response time, avg. time-to-completion) - Hard to predict the future. Unfair. Possible starvation

Understanding scheduling You add the nth process to the system When will it run at ~1/n of speed of CPU? > 1/n? < 1/n? n Scheduling in real world Where RR used? FIFO? SJF? Hybrids? Why so much FIFO? When priorities? Time slicing? What s common cswitch overhead? Real world scheduling not covered by RR, FIFO, STCF?

Multi-level UNIX (SysV, BSD) 0..3 4..7 8..11... 124..127 Priorities go from 0..127 (0 = highest priority) 32 run queues, 4 priority levels each Run highest priority job always (even if just ran) Favor jobs that haven t run recently

Multi-level in real world: Unix SVR3 Keep history of recent CPU usage for each process Give highest priority to process that has used the least CPU time recently Every process has two fields: p_cpu field to track usage usr_pri field to track priority (lower value => higher priority) Every clock tick (how frequent?) Increment current job s p_cpu by 1 Every second, recompute every job s priority and usage p_cpu = p_cpu / 2 (escape tyranny of past!) P_priority = p_cpu/4 + PUSER + 2*nice What happens: To interactive jobs? CPU jobs? Under high system load?

Some UNIX scheduling problems How does the priority scheme scale with number of processes? How to give a process a given percentage of CPU?

Lottery scheduling: random simplicity Problem: this whole priority thing is really ad hoc. How to ensure that processes will be equally penalized under load? That system doesn t have a bad case where most processes suffer? Lottery scheduling! Dirt simple: Give each process some number of tickets Each scheduling event, randomly pick ticket Run winning process to give P n% of CPU, give it (total tickets) * n% How to use? Approximate priority: low-priority, give few tickets, highpriority give many Approximate STCF: give short jobs more tickets, long jobs fewer. Key: If job has at least 1, will not starve

Grace under load change Add or delete jobs (and their tickets): Affect all proportionally Example: give all jobs 1/n of cpu? 4 jobs, 1 ticket each 1 1 1 1 each gets (on average) 25% of CPU. Delete one job: 1 1 1 automatically adjusts to 33% of CPU! Easy priority donation: Donate tickets to process you re waiting on. Its CPU% scales with tickets on all waiters.

Changing Assumptions Real time: processes are not time insensitive missed deadline = incorrect behavior soft real time: display video frame every 30 th of sec hard real time: apply-breaks process in your car Scheduling more than one thing: memory, network bandwidth, CPU all at once Distributed systems: System not contained in 1 room: How to track load in system of 1000 nodes? Migrate jobs from one node to another? Migration cost nontrivial: must be factored into scheduling So far: assumed past = one process invocation gcc behaves pretty much the same from run to run. Research: How to exploit?

A less simplistic view of context switching Brute cswitch cost: saving and restoring: registers, control block, page table, Less obvious: lose cache(s). Can give 2-10x slowdown P P CPU cache Another CPU (or over time) File/Page cache

Context switch cost aware scheduling Two level scheduling: If process swapped out to disk, then context-switching very very expensive: must fault in many pages from disk. One disk access costs ~10ms. On 500Mhz machine, 10ms = 5 million cycles! So run in core subset for a while, then move some between disk and memory. (How to pick subset?) Multi-processor: processor affinity given choice, run process on processor last ran on cpu1 cpu2... cpun cpu1 cpu2... cpun

Parallel systems: gang scheduling N independent processes: load-balance run process on next CPU (with some affinity) N cooperating processes: run at same time cluster into groups, schedule as unit can be much faster Share caches No context switching to communicate cpu1 cpu2... cpu2 cpu1 cpu2 cpu3... cpu4

Distributed system load balancing Large system of independent nodes Want: run job on lightly loaded node Querying each node too expensive Instead randomly pick one (used by lots of internet servers) Mitzenmacher: Then randomly pick one more! Send job to shortest run queue Result? Really close to optimal (with a few assumptions ;-) Exponential convergence: picking 3 doesn t get you much

The universality of scheduling Used to let m requests share n resources Issues same: fairness, prioritizing, optimization Disk arm: which read/write request to do next? Opt: close requests = faster Fair: don t starve far requests Memory scheduling: who to take page from? Opt: past=future? Take away from least-recently-used Fair: equal share of memory Printer: what job to print? People = fairness paramount: uses FIFO rather than SJF. admission control to combat long jobs

Unfair = speed Unfair in scheduling STCF: *must* be unfair to be optimal Favor I/O jobs? Penalize CPU. Other way, devices idle Favor recent jobs over older ones = better cache performance LRU cache replacement Rather than give each process 1/nth of cache, evict most useless entries. Traffic light: Rather than RR at the car granularity (fair), coarsen, and schedule at the lane granularity. Reduces context switch overhead, but may make recent cars wait

Adaptation = speed Multilevel feedback is an adaptive technique system feedback = better decisions at static policies Why? more information = better decisions = speed Lock acquisition: using dynamic information lets us get within 2x of optimal Ethernet transmission Sending a message on a busy ethernet causes collision Rather than wait fixed amount, backoff randomly and retry. If collide again, backoff further, repeat Buffer cache replacement: eject least-recently-used (LRU) memory page rather than give each process 1/n of memory

How to allocate resources? time sharing (terminals CPU, disk arm locks) (seats, profs rooms) (disk blocks, Pages, Cache blocks) Space sharing Space sharing (sometimes): split up. When to stop? Time-sharing (always): how long do you give out piece? Pre-emptible (CPU, memory) vs non-preemptible (locks, files, terminals)

Postscript In principle, scheduling decisions can be arbitrary since the system should produce the same results in any event Good: rare that the best process can be calculated Unfortunately, algorithms have strong effects on system s overhead, efficiency and response time The best schemes are adaptive. To do absolutely best we d have to predict the future. Scheduling has gotten *increasingly* ad hoc over the years. 1960s papers very math heavy, now mostly tweak and see

Event-Driven vs. Shared Memory -or- Multiprocessing vs. Multithreading

ATM Bank Server ATM server problem: Service a set of requests Do so without corrupting database Don t hand out too much money

ATM bank server example Suppose we wanted to implement a server process to handle requests from an ATM network: BankServer() { while (TRUE) { ReceiveRequest(&op, &acctid, &amount); ProcessRequest(op, acctid, amount); } } ProcessRequest(op, acctid, amount) { if (op == deposit) Deposit(acctId, amount); else if } Deposit(acctId, amount) { acct = GetAccount(acctId); /* may use disk I/O */ acct->balance += amount; StoreAccount(acct); /* Involves disk I/O */ } How could we speed this up? More than one request being processed at once Event driven (overlap computation and I/O) Multiple threads (multi-proc, or overlap comp and I/O)

Event Driven Version of ATM server Suppose we only had one CPU Still like to overlap I/O with computation Without threads, we would have to rewrite in eventdriven style Example BankServer() { while(true) { event = WaitForNextEvent(); if (event == ATMRequest) StartOnRequest(); else if (event == AcctAvail) ContinueRequest(); else if (event == AcctStored) FinishRequest(); } } What if we missed a blocking I/O step? What if we have to split code into hundreds of pieces which could be blocking? This technique is used for graphical programming

Can Threads Make This Easier? Threads yield overlapped I/O and computation without deconstructing code into non-blocking fragments One thread per request Requests proceeds to completion, blocking as required: Deposit(acctId, amount) { acct = GetAccount(actId); /* May use disk I/O */ acct->balance += amount; StoreAccount(acct); /* Involves disk I/O */ } Unfortunately, shared state is complicated too! Thread 1 Thread 2 load r1, acct->balance load r1, acct->balance add r1, amount2 store r1, acct->balance add r1, amount1 store r1, acct->balance