From 94642c2ec0cb95e1db19622b27ac0b6577bcf75d Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Thu, 17 Oct 2019 10:46:01 +0800 Subject: [PATCH] fix reserved memory is zero --- pkg/hostman/hostinfo/hostinfo.go | 3 +++ pkg/hostman/hostinfo/hostinfohelper.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 5bb4f41a1a..c6e5507bbc 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -831,6 +831,9 @@ func (h *SHostInfo) getReservedMem() int { if reserved > options.HostOptions.MaxReservedMemory { return options.HostOptions.MaxReservedMemory } + if reserved == 0 { + panic("memory reserve value is 0, need help") + } return reserved } diff --git a/pkg/hostman/hostinfo/hostinfohelper.go b/pkg/hostman/hostinfo/hostinfohelper.go index e72da00993..c5bbd36eff 100644 --- a/pkg/hostman/hostinfo/hostinfohelper.go +++ b/pkg/hostman/hostinfo/hostinfohelper.go @@ -152,6 +152,10 @@ func DetectMemoryInfo() (*SMemory, error) { return nil, err } smem.MemInfo = sysutils.ParseDMIMemInfo(strings.Split(string(ret), "\n")) + if smem.MemInfo.Total == 0 { + // in case dmidecode is not work, use gopsutil + smem.MemInfo.Total = smem.Total + } return smem, nil }