1 / 16

Linux Kernel Development

Linux Kernel Development. Chapter 4. Process Scheduling Kim, Byung-Chul. Overview Policy I/O-Bound Versus Processor-Bound Processes Policy Priority Timeslice Process Preemption The Scheduling Policy in Action The Linux Scheduling Algorithm Runqueues The Priority Arrays

biana
Download Presentation

Linux Kernel Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Kernel Development Chapter 4. Process Scheduling Kim, Byung-Chul

  2. Overview Policy I/O-Bound Versus Processor-Bound Processes Policy Priority Timeslice Process Preemption The Scheduling Policy in Action The Linux Scheduling Algorithm Runqueues The Priority Arrays Recalculating Timeslices Schedule() Calculating Priority and Timeslice Sleeping and Waking up The Load Balancer Preemption and Context Switching User Preemption Kernel Preemption Real-Time Scheduler-Related System Calls Scheduling Policy and Priority-Related System Calls Process Affinity System Calls Yielding Processor Time Scheduler Finale Contents Ch. 4. Processing Scheduling

  3. Overview • Process Scheduler by deciding whch process to run next • Best utilizing the system • Giving the impression that multiple processes are executing simultaneously • Multi-tasking Operating System • Cooperative multi-tasking • Preemptive multi-tasking • This Chapter • The fundamentals of scheduler design • How they apply to the new O(1) scheduler Ch. 4. Processing Scheduling

  4. Policy • The Type of Processes • I/O-Bound Processes: spend much of their time submitting and waiting on I/O requests • Processor-Bound Processes: spend much of their time executing code • Process Priority • Process with a higher priority run before those with a lower priority. • Dynamic priority-based scheduling • Priority Range implemented by Linux • Nice value • Real-time priority Ch. 4. Processing Scheduling

  5. Timeslice • The numeric value that represents how long a task can run until it is preempted. • A process does not have to use all its timeslice at once. • When a process’s timeslice runs out, the process is not eligible to run until all other processes have exhausted their timeslices. • Process Preemption • When a process with the higher priority than the priority of the currently executing process enters the TASK_RUNNING state. • When a process’s timeslice reaches zero. Ch. 4. Processing Scheduling

  6. The Scheduling Policy in Action Text-Editor Video-Encoder I/O-bound process More interactive High priority Larger timeslice Processor-bound process Less interactive Low priority Fewer timeslice Ch. 4. Processing Scheduling

  7. The Linux Scheduling Algorithm • The new scheduler was designed to accomplish specific goals from the 2.5 linux kernel: • Implement fully O(1) scheduling. • Implement perfect SMP scalability. • Implement improved SMP affinity. • Provide good interactive performance. • Provide fairness. • Optimize for the common case of only one or two runnable processes, yet scale well to multiple processors, each with many processes. Ch. 4. Processing Scheduling

  8. Runqueues • The list of runnable processes on a given processor. • Refer struct runqueue on the page 45 for the detailed elements. • Before a runqueue can be manipulated, it must be locked. • The Priority Arrays • The Linux scheduler maintains two priority arrays • The active and the expired array. • Priority arrays are the data structures that provide O(1) scheduling. Ch. 4. Processing Scheduling

  9. schedule() schedule_find_first_set() Bit 0 priority 0 Bit 7 priority 7 List of all runnable tasks, by priority 140-bit priority array Bit 139 priority 139 List of runnable tasks for priority 7 Run the first process in the list Ch. 4. Processing Scheduling

  10. Calculating Priority & Timeslice • Dynamic Priority for Priority • To get whether a process is interactive, Linux keeps a running tab on how much time a process is spent sleeping versus how much time the process spends in a runnable state. • Static Priority for Timeslice • When a process is first created, the new child and the parent split the parent’s remaining timeslice. • After a task’s timeslice is exhausted, it is recalculated based on the task’s static priority. Ch. 4. Processing Scheduling

  11. Sleeping and Waking Up • The sleeping task marks itself as sleeping, puts itself on a wait queue1), removes itself from the runqueue, and calls schedule() to select a new process to execute. • The waking task is set as runnable, removed from the wait queue, and added back to the runqueue. 1) wait queue: a simple list of process waiting for an event to occur Ch. 4. Processing Scheduling

  12. The Load Balancer Process 1 Process 1 Process 2 load_balance() Process 3 Process 4 Process 5 Pull process from one runqueue To another to relieve imbalance Processor 1’s Runqueue Total process: 5 Processor 2’s Runqueue Total process: 1 Ch. 4. Processing Scheduling

  13. Preemption & Context Switching • Context Switching • Calls switch_mm() to switch the virtual memory mapping from the previous process’s to that of the new process. • Calls switch_to() to switch the processor state from the previous process’s to the current’s. • Preemption • User Preemption • When returning to user-space from a system call • When returning to user-space from an interrupt handler • Kernel Preemption • When an interrupt handler exists, before returning to kernel-space • When kernel code becomes preemptible again • If a task in the kernel explicitly calls schedule() • If a task in the kernel blocks Ch. 4. Processing Scheduling

  14. Run-Time • Real-time Scheduling Policy1) • SCHED_FIFO: implements a simple first-in, first-out scheduling algorithm without timeslices. • SCHED_RR: identical to SCHED_FIFO except that each process can run only until it exhausts a predetermined timeslice. • Real-Time Behavior • Soft Real-Time • Hard Real-Time: not supported by linux 1) Real-time scheduling policy implements static priorities. The kernel does not calculate dynamic priority values. Ch. 4. Processing Scheduling

  15. Schedule-Related System Calls • Scheduling Policy and Priority-Related System Calls • Processor Affinity System Calls • Yielding Processor Time Ch. 4. Processing Scheduling

  16. Scheduler Finale • The process scheduler is an important part of the kernel, but controlling the demands of process scheduling are non-trivial. • A large number of runnable processes • scalability concerns • tradeoffs between latency and throughput • the demands of various workloads • This Chapter • Theory behind process scheduling, and the specific implementation, algorithms, and interfaces used by the current Linux kernel. Ch. 4. Processing Scheduling

More Related