erigon-pulse/erigon-lib/mmap/total_memory.go
2023-11-11 15:04:18 +03:00

23 lines
430 B
Go

package mmap
import (
"runtime/debug"
"github.com/ledgerwatch/erigon-lib/common/cmp"
"github.com/pbnjay/memory"
)
func TotalMemory() uint64 {
mem := memory.TotalMemory()
if cgroupsMemLimit, err := cgroupsMemoryLimit(); (err == nil) && (cgroupsMemLimit > 0) {
mem = cmp.Min(mem, cgroupsMemLimit)
}
if goMemLimit := debug.SetMemoryLimit(-1); goMemLimit > 0 {
mem = cmp.Min(mem, uint64(goMemLimit))
}
return mem
}