Fix memory reporting for linux systems

/proc/meminfo reports memory in KiloBytes and so needs a multiplier of
1024 instead of 1000.
The kernel reports in terms of pages and the proc filesystem is left
shifting by 2 for 4KB pages to get KB. Since this is a binary shift,
Bytes will need to shift by 10 and so get multiplied by 1024.

From the kernel code. PAGE_SHIFT = 12 for 4KB pages
"MemTotal:       %8lu kB\n", K(i.totalram)

Thanks to @subhachandrachandra!
pull/64/head
Cameron Sparr 10 years ago
parent 0d7ff2eb40
commit ce70817f55

@ -30,17 +30,17 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
} }
switch key { switch key {
case "MemTotal": case "MemTotal":
ret.Total = t * 1000 ret.Total = t * 1024
case "MemFree": case "MemFree":
ret.Free = t * 1000 ret.Free = t * 1024
case "Buffers": case "Buffers":
ret.Buffers = t * 1000 ret.Buffers = t * 1024
case "Cached": case "Cached":
ret.Cached = t * 1000 ret.Cached = t * 1024
case "Active": case "Active":
ret.Active = t * 1000 ret.Active = t * 1024
case "Inactive": case "Inactive":
ret.Inactive = t * 1000 ret.Inactive = t * 1024
} }
} }
ret.Available = ret.Free + ret.Buffers + ret.Cached ret.Available = ret.Free + ret.Buffers + ret.Cached

Loading…
Cancel
Save