Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
config: Define minimum memory requirement
Browse files Browse the repository at this point in the history
Introduce a constant for minimum memory requirement
in virtcontainers package, that can be used in config.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Oct 3, 2019
1 parent 8405b56 commit 09129c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 09129c1

Please sign in to comment.