Plain UNIX-linux cfs a comment

Source: Internet
Author: User

This series is called Naïve Unix, but also includes the details of various Unix-like systems, this series of articles collated from my years of study notes, focusing on the implementation of UNIX, Unix-like ideas and sentiment.
This article is relatively short, just analyze a Linux CFS scheduler in one detail.
Is it just the process of removing the lower left corner of the red and black tree while the process is looking for the next process to be run? In fact, the simplest implementation is, but given the optimization, it's not that simple. Consider the utilization of CPU cache, that is, if a process a preemption process B, in the context of a process, pick next is to select Process B, or choose the lower left corner of the red and black tree process? In addition, if process A has just been awakened, attempting to preempt process B, but not successful, is the next option to select the lower left corner of the red-black tree or process a? Yes, these are the questions.
Let's take a look at the implementation of pick Next:

Static struct sched_entity *pick_next_entity (STRUCT&NBSP;CFS_RQ&NBSP;*CFS_RQ) {     struct sched_entity *se = __pick_next_entity (CFS_RQ);     struct sched_entity *left = se;    if  (cfs_rq->next & & wakeup_preempt_entity (cfs_rq->next, left)  < 1)          se = cfs_rq->next;    /*     *  Prefer last buddy, try to return the CPU to a  preempted task.     */    if  (cfs_rq->last  && wakeup_preempt_entity (cfs_rq->last, left)  < 1)          se = cfs_rq->last;    clear_buddies (CFS_RQ,&NBSP;SE);     return se;} 

Obviously, to the red and black tree The bottom left of the process and the other two processes, namely next and last, the next is to seize the failure of the process, and last is to seize the success of the process of being preempted, which of the three processes is the optimal next process? The decision conditions for Linux CFS implementations are:
1. As much as possible to meet the need for the processes that have just been awakened to preempt other processes;
2. Minimize the impact of the cache refresh that this preemption brings.
How does the Linux CFS implementation work? Linux holds two variables, that is, the process of preemption and the preemption of a successful preemption, and in the tradeoff, the order of preference is:
The process that was preempted after preemption succeeded > preempted the failed process > The bottom left corner of the red and black tree

In the end can choose the first two processes, it is wakeup_preempt_entity function to decide, code too much useless, look at the following diagram:


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4C/43/wKioL1Q6FC6T364aAACwP_f2avU972.jpg "title=" wake Next.jpg "alt=" Wkiol1q6fc6t364aaacwp_f2avu972.jpg "/>


The details of this CFS were not implemented when the Linux 2.6.23 originally implemented CFS. So from the simplest of times, you can gradually understand the ins and outs of the details, to see Changelog is good. It must be said that reading history makes people wise.


Plain UNIX-linux cfs a comment

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.