diff --git a/pkg/compute/models/skus.go b/pkg/compute/models/skus.go index f940aaff8b3..2cf98487a99 100644 --- a/pkg/compute/models/skus.go +++ b/pkg/compute/models/skus.go @@ -317,8 +317,8 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred return input, httperrors.NewOutOfRangeError("cpu_core_count should be range of 1~256") } - if input.MemorySizeMB < 512 || input.MemorySizeMB > 1024*512 { - return input, httperrors.NewOutOfRangeError("memory_size_mb, shoud be range of 512~%d", 1024*512) + if input.MemorySizeMB < 512 || input.MemorySizeMB > 1024*1024 { + return input, httperrors.NewOutOfRangeError("memory_size_mb, shoud be range of 512~%d", 1024*1024) } if len(input.InstanceTypeCategory) == 0 { diff --git a/pkg/hostman/guestman/qemu/qemu.go b/pkg/hostman/guestman/qemu/qemu.go index 465b373f04f..08c56d64e30 100644 --- a/pkg/hostman/guestman/qemu/qemu.go +++ b/pkg/hostman/guestman/qemu/qemu.go @@ -433,7 +433,11 @@ func (o baseOptions_x86_64) SMP(cpus uint) string { } func (o baseOptions_x86_64) Memory(sizeMB uint64) string { - return fmt.Sprintf("-m %dM,slots=4,maxmem=524288M", sizeMB) + maxMem := options.HostOptions.MaxMemorySizeMb + if maxMem == 0 { + maxMem = 524288 + } + return fmt.Sprintf("-m %dM,slots=4,maxmem=%dM", sizeMB, maxMem) } func (o baseOptions_x86_64) Cdrom(cdromPath string, osName string, isQ35 bool, disksLen int) []string { @@ -542,7 +546,11 @@ func (o baseOptions_aarch64) SMP(cpus uint) string { } func (o baseOptions_aarch64) Memory(sizeMB uint64) string { - return fmt.Sprintf("-m %dM,slots=4,maxmem=262144M", sizeMB) + maxMem := options.HostOptions.MaxMemorySizeMb + if maxMem == 0 { + maxMem = 262144 + } + return fmt.Sprintf("-m %dM,slots=4,maxmem=%dM", sizeMB, maxMem) } func (o baseOptions_aarch64) Cdrom(cdromPath string, osName string, isQ35 bool, disksLen int) []string { diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 43e6621b13a..9aa3675f537 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -31,7 +31,9 @@ type SHostBaseOptions struct { HostCpuPassthrough bool `default:"true" help:"if it is true, set qemu cpu type as -cpu host, otherwise, qemu64. default is true"` LiveMigrateCpuThrottleMax int64 `default:"99" help:"live migrate auto converge cpu throttle max"` - DefaultQemuVersion string `help:"Default qemu version" default:"4.2.0"` + DefaultQemuVersion string `help:"Default qemu version" default:"4.2.0"` + MaxMemorySizeMb int64 `help:"Max memory size mb"` + MaxHotplugVCpuCount int `help:"maximal possible vCPU count that the platform kvm supports"` } type SHostOptions struct { @@ -187,8 +189,6 @@ type SHostOptions struct { LocalBackupTempPath string `help:"the local temporary directory for backup" default:"/opt/cloud/workspace/run/backups"` BinaryMemcleanPath string `help:"execute binary memclean path" default:"/opt/yunion/bin/memclean"` - - MaxHotplugVCpuCount int `help:"maximal possible vCPU count that the platform kvm supports"` } var (