From 922416327353b087d5004d17d7ed30286994a9ca Mon Sep 17 00:00:00 2001 From: Sumedh Alok Sharma Date: Tue, 10 Dec 2024 14:23:35 +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. 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 1ab89a727fe3..ef412c1c112c 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -556,8 +556,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 && igvmPath == "" {