This change changes and documents the (previously undocumented) behavior of Used
to "RAM used by programs".
We also remove the undocumented and unused Shared field of that struct.
So with this change in place, the VirtualMemoryStruct contains:
* three human-consumable fields for Total, Used and Available memory
* one human-consumable UsedPercentage field
* a number of kernel specific fields
Before this change we used to exec() various binaries to find out memory
information.
While this worked, it was awfully slow.
And if somebody would want to compute how many percent of available memory all
PIDs on the system uses, that would take almost ten seconds on my laptop with
the previous implementation.
This implementation fares a lot better, and is smaller.
Package common wasn't used for public functions. Place it in an
internal directory to prevent other packages from using.
Remove the distributed references to "HOST_PROC" and "HOST_SYS"
consts and combine into a common function. This also helps so that
if a env var is defined with a trailing slash all will continue to
work as expected.
Fixes#100
Added the ability to fetch an alternative location for /proc via an
environment variable. If the env var is not set it will return /proc as
the default value.
/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!