Scheduler: Allocate CPU processors to processes over time
- Allow multiprogramming (multiple program executing on a same core)
- CPU Utilization: 1 - % of time CPU is idle
- Throughput: Work completed per unit time
Scheduler Metrics: Evaluate performance (throughput) and fairness
Short-term Scheduler / Dispatcher: Switch between ready and running threads
Process Lifecycle
Process typically alternate between CPU and I/O
- CPU-Bound: Threads with long CPU bursts and low I/O bursts
- I/O-Bound: Threads with short CPU bursts and frequent I/O bursts
Scheduling Goals
- Fairness, Avoid starvation, Policy enforcement, Balanced (all resources should be busy)
Batch Systems: Maximize throughput, minimize turnaround time, keep CPU busy
Interactive Systems: Response time (prioritize IO), proportionality (simple tasks run quickly)
Real-time Systems: Meet response deadlines, predictability
Non-preemptive Policies
Preemptive: CPU can be involuntarily taken away from a process
First-come First-serve: Always pop the thread at queue top and run to completion
- No starvation, but fair??
- Con: Convoy effect - shorter jobs waiting for one really long job
Shorter Job First: Always pop the thread with the shortest (estimated) time
- Optimal average wait time
- Con: Time estimate is inaccurate, can lead to starvation (long job waiting forever)
Preemptive Policies
Round Robin: Each process run for an equal time quantum q before switching.
- If q = ∞, same as first-come first-serve
- If q = 0, overhead of context switching wastes useful time
Priority Scheduling
Priority Scheduling: Select highest-priority job from ready queue
- Starvation: Low-P tasks may never get to run
- Priority Inversion: Low-P tasks may prevent high-P tasks from progressing
- Priority Inheritance: Tasks holding a mutex inherit the priority of task waiting on it
Single-queue: Have a ready queue sorted by priority
- Con: Sorting have too much overhead
Multi-level Queue: One ready queue per priority level
- Permanently assign priority to each process (bad)
- Each queue have its own scheduling algorithm
ML Feedback Queue: MLQ but adjust priority based on history
- Adjust priority
- Boost aging threads waiting too long (prevent starvation)
- Boost short threads that don’t use full quantum
- Boost priority after user-input event
- Lower priority for long CPU-intensive processes
- Always choose to run highest-P jobs in round-robin fashion
- High-P tasks should be shorter: IO / Interactive jobs
- Jobs start at high-P queue (increase response time)
Proportional Share Scheduling
Proportional Share: Each user gets proportional CPU time regardless of number of processes
Lottery Scheduling: Each user assigned equal “tickets,” hold a lottery to find next process
Linux Scheduling
Linux 2.6
- 140 priorities (0-99 for real-time, 100-139 for time sharing)
- O(1) scheduling
- Initial priority 120, increase priority if average sleep time is high
- Higher priority threads have longer time slice
Linux Completely Fair Scheduler