linux CFS调度器如何防止一个vruntime非常小的任务使处理器挨饿?

时间:2021-12-08 02:10:20

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,

因此,当一个任务耗尽它的时间片后,它将被重新插入到红黑树中。如果该任务之前已经休眠了很长时间,与运行队列中的其他任务相比,它将导致一个非常小的vruntime,那么它将被重复地重新插入到红黑树中最左边的节点,对吗?因此,它将永远作为下一个要运行的任务被获取吗?我已经在core中检查了源代码。c和公平。c,我没看到有什么地方可以把这个任务交给其他的任务。尽管在pick_next_entity()函数中,我确实看到了一些任务,比如cfs_rq->,cfs_rq->last等。哪个可能有更高的运行优先级,我认为这不是防止vruntime非常小的任务占用处理器太长时间的正确地方,对吧?有人知道吗?谢谢,

1 个解决方案

#1


3  

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.

我找到了答案。出列从运行队列的任务时,这将被称为:se - > vruntime - = cfs_rq - > min_vruntime再次排队到运行队列的任务时,这将被称为:se - > vruntime + = cfs_rq - > min_vruntime实际上只有抵消vruntime将存储在任务睡眠和偏移量将再次醒来的时候。

#1


3  

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.

我找到了答案。出列从运行队列的任务时,这将被称为:se - > vruntime - = cfs_rq - > min_vruntime再次排队到运行队列的任务时,这将被称为:se - > vruntime + = cfs_rq - > min_vruntime实际上只有抵消vruntime将存储在任务睡眠和偏移量将再次醒来的时候。