mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
ef7e2af8f5
Update GOMAXPROCS to limits set via cgroups. This should reduce CPU trashing and reduce memory usage for cases when VictoriaMetrics components run in containers with CPU limits. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/685
26 lines
626 B
Go
26 lines
626 B
Go
package memory
|
|
|
|
import (
|
|
"syscall"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
|
"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 := maxInt
|
|
if uint64(maxInt)/uint64(si.Totalram) > uint64(si.Unit) {
|
|
totalMem = int(uint64(si.Totalram) * uint64(si.Unit))
|
|
}
|
|
mem := cgroup.GetMemoryLimit()
|
|
if mem <= 0 || int64(int(mem)) != mem || int(mem) > totalMem {
|
|
return totalMem
|
|
}
|
|
return int(mem)
|
|
}
|