github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/utils/memory/memory_linux.go (about) 1 //go:build linux 2 // +build linux 3 4 package memory 5 6 import "syscall" 7 8 func sysTotalMemory() uint64 { 9 in := &syscall.Sysinfo_t{} 10 err := syscall.Sysinfo(in) 11 if err != nil { 12 return 0 13 } 14 // If this is a 32-bit system, then these fields are 15 // uint32 instead of uint64. 16 // So we always convert to uint64 to match signature. 17 return uint64(in.Totalram) * uint64(in.Unit) 18 } 19 20 func sysFreeMemory() uint64 { 21 in := &syscall.Sysinfo_t{} 22 err := syscall.Sysinfo(in) 23 if err != nil { 24 return 0 25 } 26 // If this is a 32-bit system, then these fields are 27 // uint32 instead of uint64. 28 // So we always convert to uint64 to match signature. 29 return uint64(in.Freeram) * uint64(in.Unit) 30 }