If vruntime is counted since creation of a process how come such a process even gets a processor if it is competing with a newly created processor-bound process which is younger let say by days?
As I've read the rule is simple: pick the leftmost leaf which is a process with the lowest runtime.
Thanks!
The kernel documentation for CFS kind of glosses over what would be the answer to your question, but mentions it briefly:
So,
vruntimeis actually normalized. But the documentation does not go into detail.How is it actually done?
Normalization happens by means of a
min_vruntimevalue. Thismin_vruntimevalue is recorded in the CFS runqueue (struct cfs_rq). Themin_vruntimevalue is the smallestvruntimeof all tasks in the rbtree. The value is also used to track all the work done by thecfs_rq.You can observe an example of normalization being performed in CFS'
enqueue_entity()code:You can also observe in
update_curr()howvruntimeandmin_vruntimeare kept updated:The actual update to
min_vruntimehappens in the aptly namedupdate_min_vruntime()function:By ensuring that
min_vruntimeis properly updated, it follows that normalization based onmin_vruntimestays consistent. (You can see more examples of where normalization based onmin_vruntimeoccurs by grepping for "normalize" or "min_vruntime" infair.c.)So in simple terms, all CFS tasks'
vruntimevalues are normalized based on the currentmin_vruntime, which ensures that in your example, the newer task'svruntimewill rapidly approach equilibrium with the older task'svruntime. (We know this because the documentation states thatmin_vruntimeis monotonically increasing.)