Professional Linux Kernel Architecture 2.6.3 section 疑问

在Professional Linux Kernel Architecture 2.6.3 section 中作者对CFS 的place_entity 中sched_entity 的vruntime 更新提到:

However, if the sleeper has accumulated a large unfairness as indicated by a large se_vruntime value, the kernel must honor this. If se->vruntime is larger than the previously computed difference, it is kept as the vruntime of the process, which leads to a leftward placement on the red-black tree — recall that large vruntime values are good to schedule early!

这个就奇怪了,明明vruntime 越大,对应在rb tree 中的位置就越右,怎么还越左,然后越早scheduler.

再反过来看place_entity 这段代码: version linux kernel 3.4.10 in kernel/sched/fair.c

static void
place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
{
	u64 vruntime = cfs_rq->min_vruntime;

	/*
	 * The 'current' period is already promised to the current tasks,
	 * however the extra weight of the new task will slow them down a
	 * little, place the new task so that it fits in the slot that
	 * stays open at the end.
	 */
	if (initial && sched_feat(START_DEBIT))
		vruntime += sched_vslice(cfs_rq, se);

	/* sleeps up to a single latency don't count. */
	if (!initial) {
		unsigned long thresh = sysctl_sched_latency;

		/*
		 * Halve their sleep time's effect, to allow
		 * for a gentler effect of sleepers:
		 */
		if (sched_feat(GENTLE_FAIR_SLEEPERS))
			thresh >>= 1;

		vruntime -= thresh;
	}

	/* ensure we never gain time by being placed backwards. */
	vruntime = max_vruntime(se->vruntime, vruntime);

	se->vruntime = vruntime;
}
 


--------------------------------------------------------------------------------------------------------------------------
/* ensure we never gain time by being placed backwards. */
vruntime = max_vruntime(se->vruntime, vruntime);

作者当时的用意应当是防止vruntime 出现倒流的情况; 反过来,我们考察两种case.
1. process 短暂sleep ,这时se->vruntime 一般比min_vruntime 要大,选择se->vruntime 无可厚非。
2. process 长时间sleep, 这时se->vruntime 已经要比min_vruntime 要小很多,通过在min_vruntime 削掉sysctl_sched_latency 可保证插入rb tree 时,位置越往左,从而这个进程即越早被sched 到。 这可让长时间sleep 的process 尽早执行,也算一种奖励把。

至于书上写到的,真的怪怪的。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值