
Linux Scheduler Descending to Reality. Philosophies Processor Scheduling Processor Affinity Basic Scheduling Algorithm The Run Queue The Highest Priority Process Calculating Linux Scheduler Timeslices Typical Quanta Dynamic Priority Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 1 / 40 Timers Descending to Reality. Linux Scheduler ■ Descending to The Linux scheduler tries to be very efficient Reality. Philosophies ■ To do that, it uses some complex data Processor Scheduling structures Processor Affinity Basic Scheduling ■ Algorithm Some of what it does actually contradicts the The Run Queue The Highest Priority schemes we’ve been discussing. Process Calculating Timeslices Typical Quanta Dynamic Priority Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 2 / 40 Timers Philosophies Linux Scheduler ■ Descending to Use large quanta for important processes Reality. Philosophies ■ Modify quanta based on CPU use Processor Scheduling ■ Bind processes to CPUs Processor Affinity Basic Scheduling ■ Algorithm Do everything in O(1) time The Run Queue The Highest Priority Process Calculating Timeslices Typical Quanta Dynamic Priority Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 3 / 40 Timers Processor Scheduling Linux Scheduler ■ Descending to Have a separate run queue for each processor Reality. Philosophies ■ Each processor only selects processes from its Processor Scheduling own queue to run Processor Affinity Basic Scheduling ■ Algorithm Yes, it’s possible for one processor to be idle The Run Queue The Highest Priority while others have jobs waiting in their run Process Calculating queues Timeslices Typical Quanta ■ Periodically, the queues are rebalanced: if one Dynamic Priority Interactive Processes processor’s run queue is too long, some Using Quanta Avoiding Indefinite processes are moved from it to another Overtaking The Priority Arrays processor’s queue Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 4 / 40 Timers Processor Affinity Linux Scheduler ■ Descending to Each process has a bitmask saying what CPUs Reality. Philosophies it can run on Processor Scheduling ■ Normally, of course, all CPUs are listed Processor Affinity Basic Scheduling ■ Algorithm Processes can change the mask The Run Queue ■ The Highest Priority The mask is inherited by child processes (and Process Calculating threads), thus tending to keep them on the Timeslices Typical Quanta same CPU Dynamic Priority Interactive Processes ■ Rebalancing does not override affinity Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 5 / 40 Timers Basic Scheduling Algorithm Linux Scheduler ■ Descending to Find the highest-priority queue with a runnable Reality. Philosophies process Processor Scheduling ■ Find the first process on that queue Processor Affinity Basic Scheduling ■ Algorithm Calculate its quantum size The Run Queue ■ The Highest Priority Let it run Process Calculating ■ When its time is up, put it on the expired list Timeslices Typical Quanta ■ Repeat Dynamic Priority Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 6 / 40 Timers The Run Queue Linux Scheduler ■ Descending to 140 separate queues, one for each priority level Reality. Philosophies ■ Actually, that number can be changed at a Processor Scheduling given site Processor Affinity Basic Scheduling ■ Algorithm Actually, two sets, active and expired The Run Queue ■ The Highest Priority Priorities 0-99 for real-time processes Process Calculating ■ Priorities 100-139 for normal processes; value Timeslices Typical Quanta set via nice() system call Dynamic Priority Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 7 / 40 Timers The Highest Priority Process Linux Scheduler ■ Descending to There is a bit map indicating which queues Reality. Philosophies have processes that are ready to run Processor Scheduling ■ Find the first bit that’s set: Processor Affinity Basic Scheduling Algorithm ◆ 140 queues ⇒ 5 integers The Run Queue The Highest Priority ◆ Only a few compares to find the first that Process Calculating Timeslices is non-zero Typical Quanta ◆ Dynamic Priority Hardware instruction to find the first 1-bit Interactive Processes ◆ Using Quanta Time depends on the number of priority Avoiding Indefinite Overtaking levels, not the number of processes The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 8 / 40 Timers Calculating Timeslices Linux Scheduler ■ Descending to Calculate Reality. Philosophies Processor Scheduling (140 − SP) × 20 if SP < 120 Processor Affinity Quantum = Basic Scheduling (140 − SP) × 5 if SP ≥ 120 Algorithm The Run Queue The Highest Priority Process where SP is the static priority Calculating Timeslices ■ Higher priority process get longer quanta Typical Quanta Dynamic Priority ■ Basic idea: important processes should run Interactive Processes Using Quanta longer Avoiding Indefinite Overtaking ■ Other mechanisms used for quick interactive The Priority Arrays Swapping Arrays response Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 9 / 40 Timers Typical Quanta Linux Scheduler Descending to Static Reality. Philosophies Pri Niceness Quantum Processor Scheduling Processor Affinity Highest Static Pri 100 20 800 ms Basic Scheduling Algorithm High Static Pri 110 -10 600 ms The Run Queue The Highest Priority Normal 120 0 100ms Process Calculating Timeslices Low Static Pri 130 +10 50 ms Typical Quanta Dynamic Priority Lowest Static Pri 139 +20 5 ms Interactive Processes Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 10 / 40 Timers Dynamic Priority Linux Scheduler ■ Descending to Dynamic priority is calculated from static Reality. Philosophies priority and average sleep time Processor Scheduling ■ When process wakes up, record how long it Processor Affinity Basic Scheduling Algorithm was sleeping, up to some maximum value The Run Queue ■ The Highest Priority When the process is running, decrease that Process Calculating value each timer tick Timeslices Typical Quanta ■ Roughly speaking, the bonus is a number in Dynamic Priority Interactive Processes [0, 10] that measures what percentage of the Using Quanta Avoiding Indefinite time the process was sleeping recently; 5 is Overtaking The Priority Arrays neutral, 10 helps priority by 5, 0 hurts priority Swapping Arrays Why Two Arrays? The Traditional by 5 Algorithm Linux is More Efficient Locking Runqueues Real-Time DP = max(100, min(SP − bonus +5, 139)) Scheduling Sleeping and Waking 11 / 40 Timers Interactive Processes Linux Scheduler ■ Descending to A process is interactive if Reality. Philosophies Processor Scheduling bonus − 5 ≥ S/4 − 28 Processor Affinity Basic Scheduling Algorithm ■ The Run Queue Low-priority processes have a hard time The Highest Priority Process becoming interactive Calculating Timeslices ■ Typical Quanta A default priority process becomes interactive Dynamic Priority Interactive Processes when its sleep time is greater than 700 ms Using Quanta Avoiding Indefinite Overtaking The Priority Arrays Swapping Arrays Why Two Arrays? The Traditional Algorithm Linux is More Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 12 / 40 Timers Using Quanta Linux Scheduler ■ Descending to At every time tick, decrease the quantum of Reality. Philosophies the current running process Processor Scheduling ■ If the time goes to zero, the process is done Processor Affinity Basic Scheduling ■ Algorithm If the process is non-interactive, put it aside on The Run Queue The Highest Priority the expired list Process Calculating ■ If the process is interactive, put it at the end Timeslices Typical Quanta of the current priority queue Dynamic Priority Interactive Processes ■ If there’s nothing else at that priority, it will Using Quanta Avoiding Indefinite run again immediately Overtaking The Priority Arrays ■ Of course, by running so much is bonus will go Swapping Arrays Why Two Arrays? The Traditional down, and so will its priority and its interative Algorithm Linux is More status Efficient Locking Runqueues Real-Time Scheduling Sleeping and Waking 13 / 40 Timers Avoiding Indefinite Overtaking Linux Scheduler ■ Descending to There are two sets of 140 queues, active and Reality. Philosophies expired Processor Scheduling ■ The system only runs processes
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages40 Page
-
File Size-