From ac4f986e3eff19154093e6e05b0bbbe06f50c332 Mon Sep 17 00:00:00 2001 From: Sumedh Alok Sharma Date: Fri, 15 Nov 2024 18:31:19 +0530 Subject: [PATCH] runtime: Set memory config shared=false when shared_fs=None in CLH. This commit sets memory config `shared` to false in cloud hypervisor when creating vm with shared_fs=None && hugePages = false. Currently in runtime/virtcontainers/clh.go,the memory config shared is by default set to true. As per the CLH memory document, (a) shared=true is needed in case like when using virtio_fs since virtiofs daemon runs as separate process than clh. (b) for shared_fs=none + hugespages=false, shared=false can be set to use private anonymous memory for guest (with no file backing). (c) Another memory config thp (use transparent huge pages) is always enabled by default. As per documentation, (b) + (c) can be used in combination. However, with the current CLH implementation, the above combination cannot be used since shared=true is always set. Fixes #10547 Signed-off-by: Sumedh Alok Sharma --- src/runtime/virtcontainers/clh.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 6a7ad110d8..aa16fecaeb 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -513,8 +513,14 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net // Create the VM memory config via the constructor to ensure default values are properly assigned clh.vmconfig.Memory = chclient.NewMemoryConfig(int64((utils.MemUnit(clh.config.MemorySize) * utils.MiB).ToBytes())) - // shared memory should be enabled if using vhost-user(kata uses virtiofsd) - clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(true) + // Memory config shared is to be enabled when using vhost_user backends, ex. virtio-fs + // or when using HugePages. + // If such features are disabled, turn off shared memory config. + if clh.config.SharedFS == config.NoSharedFS && !clh.config.HugePages { + clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(false) + } else { + clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(true) + } // Enable hugepages if needed clh.vmconfig.Memory.Hugepages = func(b bool) *bool { return &b }(clh.config.HugePages) if !clh.config.ConfidentialGuest {