princeton-sns / firecracker-tools

5 stars 5 forks source link

Allocate CPU share and number of vCPUs proportional to VM memory size #27

Closed LedgeDash closed 5 years ago

LedgeDash commented 5 years ago

I'm creating this PR against workload branch because I mistakenly branched it off of workload instead of master. sorry...

Here's a summary:

  1. I'm reserving a fixed 4GB memory for other processes in the cluster. So the maximum total amount of memory VMs can get is total_machine_memory - 4GB.
  2. VmAppConfig now has a vcpu_count field in additional to the cpu_share field that was originally there. vcpu_count is passed into VmConfig to set the number of vCPUs, whereas cpu_share is passed into cgroup to control cpu share of the VM process.
  3. cpu_share is calculated as VM_mem_size / 128MB. For example, a 256MB VM's cpu_share is 2.
  4. vcpu_count is calculated as ceil(VM_mem_size / one_hyperthread_mem_size), where one_hyperthread_mem_size = (total_machine_memory - 4GB) / num_of_hyperthreads.