can cgroup(cpu,mem) limit qemu and obtain right usage

Michal Prívozník mprivozn at redhat.com
Wed Dec 8 15:47:37 UTC 2021


On 12/8/21 04:50, longguang.yue wrote:
> Hi, all:
>     kata runs qemu as a kubernetes pod and use cgroup to limit cpu/memory. 
> my question are :
>       1. how libvirt obtain qemu's cpu and memory usage, how about
> non-root mode cpu usage?

By parsing /proc/$qemu-pid/task/$vcpu-tid/stat, or for stats of qemu
itself just /proc/$qemu-pid/stat. We have an API that we don't like to
talk about that parses cgroups: virCgroupGetPercpuStats() and
virCgroupGetDomainTotalCpuStats().

>       2. if qemu is limited in cgroups , does that usage include
>  non-root mode cpu usage?  

What do you mean by non-root mode? Each vcpu is in its own cgroup, main
QEMU thread is in emulator/ sub-group, and so is every iothread. There's
nothing running in the "root" group.

But since you brought it up, maybe it's time for Kata to start looking
in libvirt's direction? This is all solved here ;-)

Michal




More information about the libvir-list mailing list