From d00decc97dec4e7ec96399b1f127d60f2650f7ad Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Wed, 15 Sep 2021 10:43:57 -0700 Subject: [PATCH] runtime: clh: Enable hugepages support This patch adds the configuration option that allows to use hugepages with Cloud Hypervisor guests. Fixes: #2648 Signed-off-by: Bo Chen --- src/runtime/cli/config/configuration-clh.toml.in | 5 +++++ src/runtime/virtcontainers/clh.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/runtime/cli/config/configuration-clh.toml.in b/src/runtime/cli/config/configuration-clh.toml.in index 79c33feb8e..3425a22c4a 100644 --- a/src/runtime/cli/config/configuration-clh.toml.in +++ b/src/runtime/cli/config/configuration-clh.toml.in @@ -109,6 +109,11 @@ virtio_fs_cache = "@DEFVIRTIOFSCACHE@" # or nvdimm. block_device_driver = "virtio-blk" +# Enable huge pages for VM RAM, default false +# Enabling this will result in the VM memory +# being allocated using huge pages. +#enable_hugepages = true + # This option changes the default hypervisor and kernel parameters # to enable debug output where available. # diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index ebef22d85a..b117fb7e11 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -240,6 +240,8 @@ func (clh *cloudHypervisor) createSandbox(ctx context.Context, id string, networ 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) + // Enable hugepages if needed + clh.vmconfig.Memory.Hugepages = func(b bool) *bool { return &b }(clh.config.HugePages) hostMemKb, err := getHostMemorySizeKb(procMemInfo) if err != nil { return nil