Skip to content

macOS: idle VM burns a full host core while the Kubernetes cluster is running (0.2.2) #989

Done

Description

@ChasLui

Kiri version and system

Kiri 0.2.2 (engine 0.2.2), macOS 27.2.1, Apple M1 Max (10 cores, 64 GB), Apple silicon.
Guest: Linux 6.18.58 (Kiri's own kernel). VM: {"cpus":6,"memory_mib":24576}.

KIRI_NO_BALLOON=1 is set — that's the workaround for #646/#891, which is why Balloon below reads 0. To keep balloon out of the picture: with the balloon disabled, the burn still appears and disappears with the cluster alone (kiri k8s stop → 0.1–0.3%, kiri k8s start → back), so it tracks the cluster rather than the balloon setting, and this is not a recurrence of the #646/#988 balloon loop. I have not measured with the balloon enabled.

Nothing else is running: the only container is Kiri's own kiri-k8s (rancher/k3s:v1.37.1-k3s1), the cluster is empty apart from kube-system, pods total 8m CPU and kubectl top node reports 82m.

What you did

kiri k8s start                      # "Kubernetes is ready in 2 s"
# leave it completely idle, then sample the Virtualization VM process:
ps -o time= -p <vm pid>; sleep 8; ps -o time= -p <vm pid>      # 8 s window, %CPU = delta/8

A/B with the same VM process pid:

kiri k8s stop                       # VM process drops to 0.1–0.3%
docker run -d --name probe busybox sleep 300    # stays at 0.2% while the cluster is off
kiri k8s start                      # the burn comes back

What happened

With the cluster up and nothing running, com.apple.Virtualization.VirtualMachine holds 88–107% of one core indefinitely (8 s ps -o time deltas, repeated over about two hours: 88.0, 93.6, 98.1, 101.4, 103.3, 104.0, 106.8, 107.5).

  • kiri k8s stop → 0.1–0.3% within seconds; the container is Exited (0) and stays that way across daemon restarts (RestartPolicy is unless-stopped).
  • kiri k8s start → it ramps back: 12.5% over an 8 s window right after start, then ~100% after a few minutes. So "start and measure immediately" under-reports it.
  • An ordinary long-running container does not trigger it (docker run -d busybox sleep 300 with the cluster stopped: 0.2%).
  • The daemon itself is 0% in steady state (verified with ps -o time deltas; ps %cpu is a lifetime average and misleading here).
  • It survives launchctl kickstart -k of the daemon and VM sleep/wake, so it isn't a macOS: engine API deadlocks after a daemon restart: create/info/exec hang forever behind a VmLink request with no reply #948-style leftover.

Where the CPU goes, with the cluster up and idle:

  • Guest /proc/stat: ~10–11% busy across the 6 vCPUs, spread out per CPU (2–34%) — no vCPU is accounted busy.
  • Guest /proc/softirqs, deltas over 6 s: TIMER +719, SCHED +3109, RCU +2579, NET_RX +413, NET_TX 0. No interrupt or softirq storm.
  • Guest /proc/interrupts: 0 lines (the shipped kernel does no per-IRQ accounting), so I couldn't attribute it to an IRQ.
  • No cpuidle driver: /sys/devices/system/cpu/cpu0/cpuidle does not exist and /sys/devices/system/cpu/cpuidle/current_driver is empty.
  • On the host, sample of the VM process puts 1371 of 1473 samples of com.apple.virtualization.thread.cpu-0 in hv_trap / Hv::Vcpu::run(): the guest really is executing instructions, while Linux counts that time as idle.

My reading is that a vCPU keeps taking exits in the guest's idle path only while the cluster is up (k3s brings a lot of netns/veth/iptables/conntrack and timers with it). That part is an inference, not a measurement — the counters above can't attribute it to a process or an IRQ.

What you expected instead

An idle VM sits near 0% on the host, the way it does with the cluster stopped (kiri k8s stop gives 0.1–0.3%), and the way it does with any other container running.

Anything else

Reproducible every time on this machine. I first noticed it on 0.2.2, after setting {"cpus":4,"memory_mib":16384}; it also shows at 6 vCPUs / 24 GiB. I have no 0.2.1 measurement to compare against.

Workaround for now: kiri k8s stop when the cluster isn't needed (it starts again in 1–2 s, ~20 s cold). That's fine for me, but it means a cluster left on all day costs a whole core.

Happy to run a build from a branch and send whatever measurements help. A kernel with per-IRQ accounting (/proc/interrupts) or perf in the guest would make this attributable, if you want it narrowed to the vGIC/vtimer vs virtio-net side before touching anything.

Activity

  1. libracoder commented on Nov 27, 2026

    @libracoder
    Owner

    Fixed in #996 (31cca962):

    1. Stopped watching /Users and /Volumes on kiri-k8s: Excluded the dev.kiri.k8s node container from mac_bind_sources() (and wsl_bind_sources() on Windows) so kiri-k8s's /Users and /Volumes hostPath mounts no longer open a 50 ms FSEvents stream across the entire Mac filesystem or wake vCPU 0 on host background file writes.
    2. Coalesced k3s background tickers (timerslack_ns = 10 ms): Applied 10 ms timer coalescing to kiri-k8s across execve, coalescing k3s's dozens of staggered 100 ms watch_progress / kine / cAdvisor timers and cutting arch_timer and cross-vCPU IPI1 interrupts by 60–72% (especially impactful on Apple Silicon software-emulated vGIC).
    3. Event-driven LoadBalancer service watch: Replaced the 3-second kubectl get svc -A polling spawn loop with a persistent kubectl get svc -A --watch-only stream.

    This will ship in the upcoming 0.2.3 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions