config: Define minimum memory requirement

Introduce a constant for minimum memory requirement
in virtcontainers package, that can be used in config.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2019-10-02 14:08:34 -07:00
parent 8405b56e6f
commit 09129c1c13
3 changed files with 9 additions and 2 deletions

View File

@ -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
}

View File

@ -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.

View File

@ -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)
}