Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the linux CFS scheduler prevent a task with a very small vruntime from starving the processor?

So after a task eats up its time slice, it would be re-inserted into the red-black tree. If the task has slept for a long time previously , leading to a very small vruntime compared to other tasks in the runqueue, then it will be repetitively re-inserted as the left-most node in the red-black tree, right? Consequently it will always be picked up as the next task to run? I have checked the source code in core.c and fair.c, I didn't see any place where this task should yield to other tasks. Though in the funciton pick_next_entity(), I do see some tasks such cfs_rq->next,cfs_rq->last or etc.. which might have higher running priority,I do not think this is the correct place to prevent a task with very small vruntime from taking a processor for a too long time,right? Does anyone have a clue? Thanks,

like image 456
Hao Shen Avatar asked Oct 07 '22 08:10

Hao Shen


1 Answers

I found the answer. When task is dequeue from the runqueue, this will be called: se->vruntime -= cfs_rq->min_vruntime When task is again enqueued to the runqueue, this will be called: se->vruntime += cfs_rq->min_vruntime So actually only the offset of the vruntime will be stored when the task is sleeping and the offset will be added again when it wakes up.

like image 127
Hao Shen Avatar answered Oct 12 '22 20:10

Hao Shen