Linux process scheduling notes (a)

Is focused on the case of a single-core CPU, some of the ideas and algorithms for scheduling. Discussions are carried out under conditions of single-core CPU-based.

In memory, no matter how many processes for the user, but when the CPU is running, always only perform only one process. There are many ways the process of scheduling, the traditional algorithm FIFO, SJF (shortest job first), multi-level feedback queue scheduling. However, due to the emergence of multi-process, certainly not the case of using a single process performed sequentially, so now the CPU is running multiple processes at the same time, the time allocated to each process, so that, for the user, you can feel the illusion of multiple processes in parallel.

When the CPU is apportioned for each process, each time a program is run, using the concept of a time slice, i.e., the time when the CPU runs this program lengths. When the kernel scheduling, and scheduling is selected to control the dynamic time slice calculation.

In general, the process can be divided into two categories, the classification process is necessary, different processes due to the different needs of its resources, it can be divided into two types of IO consumption and processor consumption. To differentiate between the two processes can effectively avoid the waste of CPU resources, IO IO consumption may in time or wait for user input a little more time, then the CPU time they need to calculate the contrast is small, this classification can effectively avoid the waste of resources.

The core scheduling strategy is to carry out the operation and effect of the system as much as possible utilization CPU, do the tradeoff between throughput.

Process because of their different effects, have different respective importance. For different processes, we can divide a different priority for higher priority processes to run first, but after running low priority programs. For the same priority process, we can, in turn follow a round robin manner. Thus forming a multi-level priority, round robin scheduling algorithm.

The most basic scheduling is now mainly used in Kernel is completely fair scheduler (CFS) algorithm scheduling program. And there is no concept of time slices, the only program of wait time. That is how long the program waits in the ready queue.

For the same priority process, we should spend time each process to ensure uniform as possible. That is as much resources used by each process. In an ideal world, we can divide time into infinitesimal quantity, each process running the same infinitesimal quantity, then between processes do not cost the process of switching, so that we can put the resources spent on average each process on. But the real difficulty is that during the process of switching times, there is often a cost of existence, at the same time, cpu cache of cache will also be affected.

CFS approach is to run for a period of time each process, and then choose the least run the process as the next process. For each process should run long it relied on the difference between the proportion of its importance in the process of running the total time corresponding. That is the more important of course, the more time available. At the same time, each process is running, always have a minimum size of operation, not only can avoid starvation, but also to avoid large cost due to frequent schedule.

Guess you like

Origin www.cnblogs.com/wAther/p/12210086.html