Download Linux Scheduling

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Linux Scheduling
Tanenbaum Ch. 10.3
Silberschatz Ch.21.5
cs431-cotter
1
Linux Scheduling Background
• Basic structure results from compliance with
POSIX standard
• 3 tiered system
• As a process ran, its priority decreased.
• When all processes were no longer
runnable, their priorities were recalculated.
• Approach did not scale well.
cs431-cotter
2
Linux Schedule Re-design
Objectives
•
•
•
•
•
Implement fully O(1) scheduling
Implement SMP scalability
Improve SMP affinity
Improve interactive performance
Optimize for 1-2 runnable processes, yet
scale well.
cs431-cotter
3
Kernel Scheduling vs. Process
Scheduling ???
• Kernel Scheduling
– Running process requests a system call
– Device driver, etc. generates a hardware interrupt
– Requires careful synchronization of data structure
access
– Kernel is preemptive (as of version 2.5)
• Process Scheduling
– Time-sharing algorithm designed for fair
preemptive scheduling among multiple processes
– Schedules for real-time tasks where absolute
priorities are more important than fairness.
cs431-cotter
4
Scheduling in Linux
Three classes of threads for scheduling purposes:



Real-time FIFO
Real-time round robin
Timesharing (for all non real-time processes)
cs431-cotter
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
5
Process Priorities
• Determined by priority and counter
• Static
– Used for real-time processes
– Priorities 0 - 99
• Dynamic
– Used for conventional processes
– Priorities 100-139
– Adjusted based on time run and priority class
cs431-cotter
6
Process Priority
• Based on original “nice” level of process.
– Default 0, range -20 to +19 (lower is better)
• I/O bound processes get higher priority.
• CPU bound processes get lower priority.
• Process characteristics adjusted
dynamically (range of ± 5)
• Highest runnable process is always
selected
cs431-cotter
7
Process Timeslice
• On creation, child process gets ½ of
parent process timeslice
• Higher priority also gets longer timeslice
– Low priority / less interactive ~ 10 ms
– Default ~ 150 ms
– High priority / more interactive ~ 300 ms
• When timeslice  0, process has expired
cs431-cotter
8
Runqueues
• Process scheduling implemented through
runqueues
– One per processor
– Includes array of lists for all priorities
• Runqueue struct:
–
–
–
–
# of runnable processes
Active priority array
Expired priority array
…
• Non-runnable processes that still have timeslice
and are blocked are managed in waitqueues
(waiting on whatever event is blocking them).
cs431-cotter
9
Scheduling in Linux
Figure 10-10. Illustration of Linux runqueue and priority arrays.
cs431-cotter
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
10
Load balancing in SMP
• Load balancing done to improve overall system
performance
– Called every 1 ms when processor is idle, otherwise
every 200 ms.
• If subject processor is more than 25% less than
busiest processor, processes are moved
– Prefer expired processes
– Prefer high priority processes
– Prefer “cache cold” processes
cs431-cotter
11
Scheduling System Calls
• nice ( ); (command line function)
•
•
•
•
sched_getscheduler( ); sched_setscheduler( );
sched_getparam( ); sched_setparam( );
sched_yield( );
sched_get_priority_min( );
sched_get_priority_max( );
• sched_getaffinity(); sched_setaffinity();
• sched_rr_get_interval();
cs431-cotter
12
Interrupt protection Levels
Top-half Interrupt Handlers
Highest priority
Bottom-half Interrupt Handlers
Kernel-system service routines
User-mode programs
cs431-cotter
Lowest Priority
13
Scheduler Performance
• Advantages
– Self-contained and easy to follow
– Adapts to a wide range of environments
– O(1) performance !!!
– Real-time performance good (although not
engineered for hard real-time systems)
– Optimized for I/O bound processes
(interactive users)
cs431-cotter
14
More Recent Schedulers
• Anticipatory Scheduler
– Linux Kernel Versions 2.6.0 through 2.6.18
– Optimized disk I/O by waiting a short time
after each read to see if another read from the
same file was coming.
– Big improvement for some services (Apache
Web server), but uneven effects elsewhere.
cs431-cotter
15
More Recent Schedulers
• Completely Fair Scheduler
– Linux kernel version 2.6.23 - ?
– Schedules processes based on which
process has used the least of its time
quantum.
– Stores processes in a tree (red-black)
structure to facilitate picking the lowest user.
– O(log N) performance.
cs431-cotter
16
Summary
• Kernel is preemptive.
• Linux supports 3 schedulers:
– FIFO for real-time processes
– RR for interactive, I/O bound real-time processes
– OTHER for regular processes
• User processes use a priority queue
mechanism.
– Process priority is dynamic based on base
priority and time remaining in time quantum.
Each priority class runs as RR
cs431-cotter
17
Questions
• How does the Linux scheduler decide which
process/thread to run when it schedules a new
process/thread for the CPU?
• How does Linux ensure that real-time processes
always run before any other processes?
• What timeslice values do real-time processes
use?
• How does Linux dynamically adjust the
scheduling for I/O intensive processes (giving
them a higher priority)?
• Once all runnable processes have exhausted
their timeslices, how does the scheduler
recalculate/ restart those processes?
cs431-cotter
18