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