Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Commit f6da537

Browse files
author
Julio Montes
committed
config: don't exceed the number of physical cores
the maximum number of vCPUs per VM shouldn't not exceed the number of physical cores, otherwise we could face issues with KVM and other architectures fixes #1028 Signed-off-by: Julio Montes <julio.montes@intel.com>
1 parent 7067e6d commit f6da537

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

config.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,14 @@ func (h hypervisor) machineType() string {
185185
}
186186

187187
func (h hypervisor) defaultVCPUs() uint32 {
188-
if h.DefaultVCPUs < 0 {
189-
return uint32(goruntime.NumCPU())
188+
numCPUs := goruntime.NumCPU()
189+
190+
if h.DefaultVCPUs < 0 || h.DefaultVCPUs > int32(numCPUs) {
191+
return uint32(numCPUs)
190192
}
191193
if h.DefaultVCPUs == 0 { // or unspecified
192194
return defaultVCPUCount
193195
}
194-
if h.DefaultVCPUs > 255 { // qemu supports max 255
195-
return 255
196-
}
197196

198197
return uint32(h.DefaultVCPUs)
199198
}

config/configuration.toml.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ firmware = "@FIRMWAREPATH@"
3333
machine_accelerators="@MACHINEACCELERATORS@"
3434

3535
# Default number of vCPUs per POD/VM:
36-
# unspecified or 0 --> will be set to @DEFVCPUS@
37-
# < 0 --> will be set to the actual number of physical cores
38-
# > 0 <= 255 --> will be set to the specified number
39-
# > 255 --> will be set to 255
36+
# unspecified or 0 --> will be set to @DEFVCPUS@
37+
# < 0 --> will be set to the actual number of physical cores
38+
# > 0 <= number of physical cores --> will be set to the specified number
39+
# > number of physical cores --> will be set to the actual number of physical cores
4040
default_vcpus = -1
4141

4242

config_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,9 @@ func TestHypervisorDefaults(t *testing.T) {
668668
h.DefaultVCPUs = 2
669669
assert.Equal(h.defaultVCPUs(), uint32(2), "default vCPU number is wrong")
670670

671-
// qemu supports max 255
672-
h.DefaultVCPUs = 8086
673-
assert.Equal(h.defaultVCPUs(), uint32(255), "default vCPU number is wrong")
671+
numCPUs := goruntime.NumCPU()
672+
h.DefaultVCPUs = int32(numCPUs) + 1
673+
assert.Equal(h.defaultVCPUs(), uint32(numCPUs), "default vCPU number is wrong")
674674

675675
h.DefaultMemSz = 1024
676676
assert.Equal(h.defaultMemSz(), uint32(1024), "default memory size is wrong")
@@ -1017,7 +1017,7 @@ func TestUpdateRuntimeConfiguration(t *testing.T) {
10171017
func TestUpdateRuntimeConfigurationVMConfig(t *testing.T) {
10181018
assert := assert.New(t)
10191019

1020-
vcpus := uint(8)
1020+
vcpus := uint(2)
10211021
mem := uint(2048)
10221022

10231023
config := oci.RuntimeConfig{}

0 commit comments

Comments
 (0)