mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/memory: properly handle int overflow in sysTotalMemory
This should fix builds on 32-bit architectures such as arm. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/212
This commit is contained in:
parent
7d7d7a7d4e
commit
12c8afc3f2
1 changed files with 6 additions and 1 deletions
|
@ -9,12 +9,17 @@ import (
|
|||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
)
|
||||
|
||||
const maxInt = int(^uint(0) >> 1)
|
||||
|
||||
func sysTotalMemory() int {
|
||||
var si syscall.Sysinfo_t
|
||||
if err := syscall.Sysinfo(&si); err != nil {
|
||||
logger.Panicf("FATAL: error in syscall.Sysinfo: %s", err)
|
||||
}
|
||||
totalMem := int(si.Totalram) * int(si.Unit)
|
||||
totalMem := maxInt
|
||||
if uint64(maxInt)/uint64(si.Totalram) > uint64(si.Unit) {
|
||||
totalMem = int(uint64(si.Totalram) * uint64(si.Unit))
|
||||
}
|
||||
|
||||
// Try determining the amount of memory inside docker container.
|
||||
// See https://stackoverflow.com/questions/42187085/check-mem-limit-within-a-docker-container .
|
||||
|
|
Loading…
Reference in a new issue