Skip to content

Commit

Permalink
virtcontainers/qemu: reduce memory footprint
Browse files Browse the repository at this point in the history
There is a relation between the maximum number of vCPUs and the
memory footprint, if QEMU maxcpus option and kernel nr_cpus
cmdline argument are big, then memory footprint is big, this
issue only occurs if CPU hotplug support is enabled in the kernel,
might be because of kernel needs to allocate resources to watch all
sockets waiting for a CPU to be connected (ACPI event).

For example

```
+---------------+-------------------------+
|               | Memory Footprint (KB)   |
+---------------+-------------------------+
| NR_CPUS=240   | 186501                  |
+---------------+-------------------------+
| NR_CPUS=8     | 110684                  |
+---------------+-------------------------+
```

In order to do not affect CPU hotplug and allow to users to have containers
with the same number of physical CPUs, this patch tries to mitigate the
big memory footprint by using the actual number of physical CPUs as the
maximum number of vCPUs for each container.

Before this patch a container with 256MB of RAM

```
              total        used        free      shared  buff/cache   available
Mem:           195M         40M        113M         26M         41M        112M
Swap:            0B          0B          0B
```

With this patch

```
              total        used        free      shared  buff/cache   available
Mem:           236M         11M        188M         26M         36M        186M
Swap:            0B          0B          0B
```

fixes kata-containers#295

Signed-off-by: Julio Montes <julio.montes@intel.com>
  • Loading branch information
Julio Montes committed May 9, 2018
1 parent 48e9494 commit 063f4f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const defaultConsole = "console.sock"
var defaultKernelParameters = []Param{
{"panic", "1"},
{"initcall_debug", ""},
{"nr_cpus", fmt.Sprintf("%d", maxQemuVCPUs())},
}

type operation int
Expand Down
3 changes: 2 additions & 1 deletion virtcontainers/qemu_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package virtcontainers
import (
"fmt"
"os"
"runtime"
"strconv"

govmmQemu "github.com/intel/govmm/qemu"
Expand Down Expand Up @@ -73,7 +74,7 @@ var supportedQemuMachines = []govmmQemu.Machine{

// returns the maximum number of vCPUs supported
func maxQemuVCPUs() uint32 {
return uint32(240)
return uint32(runtime.NumCPU())
}

func newQemuArch(config HypervisorConfig) qemuArch {
Expand Down

0 comments on commit 063f4f4

Please sign in to comment.