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,
vruntime
is actually normalized. But the documentation does not go into detail.How is it actually done?
Normalization happens by means of a
min_vruntime
value. Thismin_vruntime
value is recorded in the CFS runqueue (struct cfs_rq
). Themin_vruntime
value is the smallestvruntime
of 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()
howvruntime
andmin_vruntime
are kept updated:The actual update to
min_vruntime
happens in the aptly namedupdate_min_vruntime()
function:By ensuring that
min_vruntime
is properly updated, it follows that normalization based onmin_vruntime
stays consistent. (You can see more examples of where normalization based onmin_vruntime
occurs by grepping for "normalize" or "min_vruntime" infair.c
.)So in simple terms, all CFS tasks'
vruntime
values are normalized based on the currentmin_vruntime
, which ensures that in your example, the newer task'svruntime
will rapidly approach equilibrium with the older task'svruntime
. (We know this because the documentation states thatmin_vruntime
is monotonically increasing.)