How aws firecracker handles vcpu?

11/23/2019

I have issued below command in aws firecracker to configure the VM. I have only 8 vcpu in my host machine.

curl --unix-socket /tmp/firecracker.socket -i  \
    -X PUT 'http://localhost/machine-config' \
    -H 'Accept: application/json'            \
    -H 'Content-Type: application/json'      \
    -d '{
        "vcpu_count": 20,
        "mem_size_mib": 1024,
        "ht_enabled": false
    }'

In Kubernetes, if we tried to configure a pod with vcpu more than max vcpu in host it will move to the pending state. but firecracker not showed any error or warning it just started the vm.

Anyone kindly explain how firecracker handling the vcpu?

--
firecracker
kata-containers
kubernetes
linux

2 Answers

11/23/2019

Firecracker is a VMM, and vCPUs are just a thread running on the host system.

I wouldn't mix up Kubernetes resource management with how VMMs behave -- they are orthogonal. Firecracker starts virtual machines, not pods.

If you were to use an OCI runtime in Kubernetes that utilizes Firecracker for isolation, the number of requests/limits for the resulting pod would be restricted by Kubernetes (scheduler/kubelet). Again, this is orthogonal to how the VMM behaves.

-- egernst
Source: StackOverflow

11/26/2019

In Firecracker vCPUs are implemented as threads.

At instance start Firecracker will create a thread for each of the vCPUs configured.

For example a running microvm with 4 vCPUs configured has 6 threads: main thread (handles device emulation), api thread(fc_api) and 4 vCPU threads.

ubuntu@ip-172-31-20-103:~$ ps H -o 'tid comm' 571
  TID COMMAND
  571 firecracker
  572 fc_api
  730 fc_vcpu3
  731 fc_vcpu2
  734 fc_vcpu1
  735 fc_vcpu0

With Firecracker you can oversubscribe both CPU and Memory so the amount of guest memory and number of vCPUs can be much higher than the actual physical CPUs and RAM.

Things are different with Kubernetes as it will prevent you from oversubscribing both memory and cpu when you specify cpu and memory limits in your pod definitions.

-- Andrei Sandu
Source: StackOverflow