An introduction to the credit scheduler in Xen
Credit scheduler provides automatic load balancing of virtual CPUs across physical CPUs on an SMP host. The scheduler awards credit to each VM periodically and charges each VM to run on the CPU.
To be specific, there are four main components: a virtual CPU pool, a physical CPU pool, a credit calculator and a credit scheduler (illustrated in the figure). The credit calculator calculates and updates the credit for every domain per 10ms. The scheduler dispatches the vCPU to a pCPU every 30ms according to their states, i.e., priorities.
There are 3 priorities:
- over state joining at the tail of the scheduling queue.
- under state allowed to run before any that are out of credit.
- boost state to give mostly idle vCPUs a chance to run without accumulating too much credit.
In all, the scheduling queue is ordered: BOOST, UNDER, OVER from head to tail.
It contains 2 key parameters weight and cap:
- weight represents the signi cance of a vCPU. I.e., the higher weight a vCPU has, the more pCPU it can consume.
- cap representsthe maximum amount of pCPU a domain will be able to consume. (Caution: it use an integrity to illustrate percentage. E.g., 100 = 1 pCPU)
Risks for credit1:
- Too much overhead of context switch for a vCPU running IO-intensive applications. it is because that these vCPU spends much time on IO while a little time computing.
- Malicious accumulation of credit. In another words, a malicious vCPU can accumulate plenty of credit through staying in idle for a period and then occupy most of the computing resource with purpose of holding back the victim.
Credit2 can solve the problems of credit1. It adds 3 extra mechanisms:
- ratelimite combats this problem by de ning the minimum number of microseconds a VM would be allowed to run uninterrupted before being context switched with the default being 1ms.
- timeslice allows for tweaking the scheduler. I.e., it can change the scheduling time, which is 30ms by default.
- a new credit reset condition prevents any VM from accumulating too much credit.
ratelimit and timeslice can be configured with tool xl sched_credit [option]