diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index 5a500eb5e8..51d2ceba4b 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -304,7 +304,7 @@ func (h hypervisor) defaultMaxVCPUs() uint32 { } func (h hypervisor) defaultMemSz() uint32 { - if h.MemorySize < 8 { + if h.MemorySize < vc.MinHypervisorMemory { return defaultMemSize // MiB } diff --git a/virtcontainers/hypervisor.go b/virtcontainers/hypervisor.go index e910f21864..4fb6a4881f 100644 --- a/virtcontainers/hypervisor.go +++ b/virtcontainers/hypervisor.go @@ -63,6 +63,9 @@ const ( // port numbers below 1024 are called privileged ports. Only a process with // CAP_NET_BIND_SERVICE capability may bind to these port numbers. vSockPort = 1024 + + // MinHypervisorMemory is the minimum memory required for a VM. + MinHypervisorMemory = 256 ) // In some architectures the maximum number of vCPUs depends on the number of physical cores. diff --git a/virtcontainers/pkg/oci/utils.go b/virtcontainers/pkg/oci/utils.go index 1143cd5df0..6619753e44 100644 --- a/virtcontainers/pkg/oci/utils.go +++ b/virtcontainers/pkg/oci/utils.go @@ -446,10 +446,14 @@ func addHypervisorConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig) func addHypervisorMemoryOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) error { if value, ok := ocispec.Annotations[vcAnnotations.DefaultMemory]; ok { memorySz, err := strconv.ParseUint(value, 10, 32) - if err != nil || memorySz < 8 { + if err != nil { return fmt.Errorf("Error encountered parsing annotation for default_memory: %v, please specify positive numeric value greater than 8", err) } + if memorySz < vc.MinHypervisorMemory { + return fmt.Errorf("Memory specified in annotation %s is less than minimum required %d, please specify a larger value", vcAnnotations.DefaultMemory, vc.MinHypervisorMemory) + } + sbConfig.HypervisorConfig.MemorySize = uint32(memorySz) }