术语
CFS:Completely Fair Scheduler--完全公平调度。对应的调度策略为:SCHED_NORMAL。
CFS调度下的带宽控制是:通过允许一个特点进程组在某个周期(period)下的CPU配额(quota)控制其带宽。主要有两个参数:
cpu.cfs_period_us:周期(us)
cpu.cfs_quota_us:配额(us)
此上两个配置通过cgroup文件系统配置。
原文
The bandwidth allowed for a group is specified using a quota and period. Within each given "period" (microseconds), a group is allowed to consume only up to "quota" microseconds of CPU time. When the CPU bandwidth consumption of a group exceeds this limit (for that period), the tasks belonging to its hierarchy will be throttled and are not allowed to run again until the next period.
举例
# echo 250000 > cpu.cfs_quota_us /* quota = 250ms */
# echo 250000 > cpu.cfs_period_us /* period = 250ms */此配置限制group 在250ms周期内CPU配额为250ms,也就是每隔T=250ms获取一个CPU时间;
# echo 1000000 > cpu.cfs_quota_us /* quota = 1000ms */
# echo 500000 > cpu.cfs_period_us /* period = 500ms */此配置限制group 在500ms周期内CPU配额为1000ms,也就是每隔T=500ms获得2个CPU时间。
若cfs_quota=-1,表示CPU带宽不受限。
带宽控制统计
#cat cpu.stat
nr_periods 0
nr_throttled 0
throttled_time 0nr_periods:Number of enforcement intervals that have elapsed.-- 表示过去了多少个cpu.cfs_period_us里面配置的时间周期。
nr_throttled: Number of times the group has been throttled/limited. --在上面的时间(nr_periods)内,此group被限制的次数;
throttled_time:The total time duration (in nanoseconds) for which entities of the group have been throttled.---此group内所有被限制的进程总时间。
参考
内核文档:
Documentation/scheduler/sched-bwc.txt