|
| 1 | +# Kata Containers with `virtio-mem` |
| 2 | + |
| 3 | +- [Introduction](#introduction) |
| 4 | +- [Requisites](#requisites) |
| 5 | +- [Run a Kata Container utilizing `virtio-mem`](#run-a-kata-container-utilizing-virtio-mem) |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +The basic idea of `virtio-mem` is to provide a flexible, cross-architecture memory hot plug and hot unplug solution that avoids many limitations imposed by existing technologies, architectures, and interfaces. |
| 10 | +More details can be found in https://lkml.org/lkml/2019/12/12/681. |
| 11 | + |
| 12 | +Kata Containers with `virtio-mem` supports memory resize. |
| 13 | + |
| 14 | +## Requisites |
| 15 | + |
| 16 | +Kata Containers with `virtio-mem` requires Linux and the QEMU that support `virtio-mem`. |
| 17 | +The Linux kernel and QEMU upstream version still not support `virtio-mem`. @davidhildenbrand is working on them. |
| 18 | +Please use following unofficial version of the Linux kernel and QEMU that support `virtio-mem` with Kata Containers. |
| 19 | + |
| 20 | +The Linux kernel is at https://github.com/davidhildenbrand/linux/tree/virtio-mem-rfc-v4. |
| 21 | +The Linux kernel config that can work with Kata Containers is at https://gist.github.com/teawater/016194ee84748c768745a163d08b0fb9. |
| 22 | + |
| 23 | +The QEMU is at https://github.com/teawater/qemu/tree/kata-virtio-mem. (The original source is at https://github.com/davidhildenbrand/qemu/tree/virtio-mem. Its base version of QEMU cannot work with Kata Containers. So merge the commit of `virtio-mem` to upstream QEMU.) |
| 24 | + |
| 25 | +Set Linux and the QEMU that support `virtio-mem` with following line in the Kata Containers QEMU configuration `configuration-qemu.toml`: |
| 26 | +```toml |
| 27 | +[hypervisor.qemu] |
| 28 | +path = "qemu-dir" |
| 29 | +kernel = "vmlinux-dir" |
| 30 | +``` |
| 31 | + |
| 32 | +Enable `virtio-mem` with following line in the Kata Containers configuration: |
| 33 | +```toml |
| 34 | +enable_virtio_mem = true |
| 35 | +``` |
| 36 | + |
| 37 | +## Run a Kata Container utilizing `virtio-mem` |
| 38 | + |
| 39 | +Use following command to enable memory overcommitment of a Linux kernel. Because QEMU `virtio-mem` device need to allocate a lot of memory. |
| 40 | +``` |
| 41 | +$ echo 1 | sudo tee /proc/sys/vm/overcommit_memory |
| 42 | +``` |
| 43 | + |
| 44 | +Use following command start a Kata Container. |
| 45 | +``` |
| 46 | +$ docker run --rm -it --runtime=kata --name test busybox |
| 47 | +``` |
| 48 | + |
| 49 | +Use following command set the memory size of test to default_memory + 512m. |
| 50 | +``` |
| 51 | +$ docker update -m 512m --memory-swap -1 test |
| 52 | +``` |
| 53 | + |
0 commit comments