Bash – KVM reports strange CPU usage peaks (bash infinite recursion)

bashcpukvmvirtual machine

On a KVM machine running Fedora 20 I ran ulimit -s unlimited (this removes limit on stack size) and an experimental torturing testing script. All this script does is just infinite recursion:

#!/bin/bash

fn() {
    true
    fn
}

fn

What I expected was that CPU usage would go to 100%, and after some resource depletion (which could take long time), the bash would be eventually shot down by kernel.

But what really happened is somewhat strange and I don't have the right knowledge to explain:

  • Inside the VM, top reports 100% CPU usage by this funny script. That
    makes sense.

  • But from outside, virt-manager shows 0% no CPU usage, expect for recurring
    sharp 100% peaks. And as if that was not strange enough, the delay
    observed between each consecutive peaks is growing (eventually the delay
    stops growing and becomes coinstant):

CPU usage peaks

Why is this? What is actually happening inside? Or is the usage reported by virt-manager misleading? Then what creates the pattern seen between the peaks?

Best Answer

If you use top inside the virtual machine you noticed the cpu usage about 100%, but in you physical host the virtual machine can't use the all cpu time, this is because a kvm vm is normal normal process from the kernel point of view, so kernel process scheduler share the cpu with other process

Related Question