Linux2.6 Process Scheduling

Source: Internet
Author: User

I. Features of linux2.6 Scheduling Algorithm

1. Select the process to be run within a fixed period of time. This time will not increase because the number of processes that can be run increases.

2. Each CPU has its own runable queue

3. better solve the problem of distinguishing between interactive process and Batch Process

2. Process classification by scheduling type

1. sched_fifo: first-in-first-out real-time process

If there are no other real-time processes with a higher priority (must be higher) that can run (normal processes have a higher priority than real-time processes), they can run on the ground.

For such a process, the length of time is meaningless.

2. sched_rr: Real-time process of time slice Rotation

All sched_rr with the same priority (and the highest priority in the current situation) are allocated with a fair CPU in the form of time slice rotation.

3. sched_normal: common process of time slice Rotation

After the time slice is used up, it becomes an expired process. After all processes become process processes, the expired processes are changed to active processes.

1 and 2 will never become expired Processes

Iii. Relationship between process types and priorities

  Static Priority Dynamic Priority Real-time priority
FIFO None None (1) (2)
Rr (2) (3) None (1)
Normal (2) (3) (4) (1) (5) None

Note:

(1) It determines the position of the running queue, that is, the scheduling determines which process is selected as the new process.

(2) You can change the value of Nice () or setpriority ().

(3) The initial value is inherited from the parent process and determines the basic length of the time slice. The smaller the value, the longer the Basic time slice.

(4) there is an impact on Dynamic Priority values

(5) It depends on the average sleep time in the past. The average sleep time (tend to interactive processes) has a higher priority and the average sleep time (tend to batch processing processes) has a lower priority.

4. Update the process time slice

1. FIFO: meaningless

2. RR: decrease the time slice. If the time slice is used up, perform the following operations:

(1) refill in the number of time slices of the process

(2) set the tif_need_resched flag of the process and forcibly call schedule () to switch the process.

(3) Move the process descriptor to the tail of the running queue activity linked list corresponding to the current process priority.

3. Normal: decrease the time slice. If the time slice is used up, perform the following operations:

(1) Delete the process from the Active Queue

(2) set the tif_need_resched flag of the process and forcibly call schedule () to switch the process.

(3) calculate a new dynamic priority

(4) refill the time slice

(5) Add the process to the expired queue

5. Scheduling only occurs in the following two scenarios:

1. Direct call: when a process is blocked because it cannot obtain resources, it directly calls schedule ()

2. Indirect call: Check the tif_need_resched flag before restoring the kernel state to the user State. If it is set to a bit, call schedule ()

Perform the following operations to set the tif_need_resched flag

(1) process used up time slice

(2) A wake-up process has a higher priority than a new process.

(3) issuing system calls for Process Scheduling

Vi. scheduling function schedule ()

0. Schedule () -----> scheduling function

(1) kernel preemption and local interruption prohibited

(2) If the prev is not runable, delete it from the running queue.

(3) If there are processes in the local runable queue, call dependent_sleeper () to select a process (see figure 1)

If no running queue exists locally, migrate some processes that can run to the local load_balance ()

If the migration fails, select the Swapper process as the next

(4) load the first part of task_struct in the hardware cache.

(5) reducing the average sleep time of Prev

(6) If Prev and Next are the same process, no switchover is performed.

(7) Create an address space for next

(8) switch_to () (see linux2.6 process switching) (see figure 2)

(9) enable local interrupt and enable kernel preemption

1. dependent_sleeper () -----> select a process

(1) Check the runable queue. If there is no activity, all expired processes will be active.

(2) Search for a runable process from the active queue as the next

(3) increase the sleep time of the process (see figure 3)

2. About switch_to ()

The subsequent command after the switch_to macro is called is not executed immediately by the next process, but is executed by the prev when the scheduler selects the prev execution.

However, the prev at that time points not to the replaced process in Schedule (), but to the process replaced by the prev when the prev is scheduled.

3. "Increase Process sleep time"

The scheduler separates the processes awakened by the interrupt handler and the delayable function from those Awakened by system calling service programs and kernel threads.

For the former, increase the waiting time for all running queues

For the latter, only the waiting time is added.

Because the interaction process is more likely to be awakened by asynchronous events rather than synchronous events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.