From d392b22ee4a644e921ae30457b819ca46653f198 Mon Sep 17 00:00:00 2001 From: Ganesh Maharaj Mahalingam Date: Mon, 17 Jun 2019 18:58:51 -0700 Subject: [PATCH] virtiofs: Allow memory hotplug with virtiofs Kata with virtio-fs fails to do memory hotplugging. This is caused by the fact that hot plugged memory is always backed by 'memory-backend-ram' while virtio-fs expects it to be backed by file and shared for it to be able to use the system the way it is intended. This chnage allows using file based memory backend for virtio-fs, hugepages or when the user prefers to use a file backed memory Fixes: #1745 Signed-off-by: Ganesh Maharaj Mahalingam --- virtcontainers/qemu.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 727bdd5469..13d1e72017 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -1355,6 +1355,9 @@ func (q *qemu) hotplugMemory(memDev *memoryDevice, op operation) (int, error) { func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) { memoryDevices, err := q.qmpMonitorCh.qmp.ExecQueryMemoryDevices(q.qmpMonitorCh.ctx) + share := false + target := "" + memoryBack := "memory-backend-ram" if err != nil { return 0, fmt.Errorf("failed to query memory devices: %v", err) } @@ -1368,7 +1371,20 @@ func (q *qemu) hotplugAddMemory(memDev *memoryDevice) (int, error) { } memDev.slot = maxSlot + 1 } - err = q.qmpMonitorCh.qmp.ExecHotplugMemory(q.qmpMonitorCh.ctx, "memory-backend-ram", "mem"+strconv.Itoa(memDev.slot), "", memDev.sizeMB, false) + if q.qemuConfig.Knobs.HugePages { + // we are setting all the bits that govmm sets when hugepages are enabled. + // https://github.com/intel/govmm/blob/master/qemu/qemu.go#L1677 + target = "/dev/hugepages" + memoryBack = "memory-backend-file" + share = true + } else if q.config.SharedFS == config.VirtioFS || q.config.FileBackedMemRootDir != "" { + target = q.qemuConfig.Memory.Path + memoryBack = "memory-backend-file" + } + if q.qemuConfig.Knobs.FileBackedMemShared { + share = true + } + err = q.qmpMonitorCh.qmp.ExecHotplugMemory(q.qmpMonitorCh.ctx, memoryBack, "mem"+strconv.Itoa(memDev.slot), target, memDev.sizeMB, share) if err != nil { q.Logger().WithError(err).Error("hotplug memory") return 0, err