This commit adds support for reading the `AnonHugePages` field from `/proc/meminfo`.
The values in this field allow monitoring the [THP](https://www.kernel.org/doc/Documentation/vm/transhuge.txt) usage by systems that use this type of memory
manual available memory calculation should be done if only memavail is false
Manual Available Memory calculation under kernel 3.14
accurate manaul available memory calculation
Used memory was calculated as Total - Available.
For newer kernels (3.14+), available memory is taken from /proc/meminfo,
whereas for older kernels it is computed as free+buffered+cached.
This commit changes that behavior. Available memory is still taken from
/proc/meminfo, if available, but used memory is always computed as
total-free-buffered-cached.
This way, it matches the output of `free` for used memory (in the -/+
buffers/cache line) and other tools.
Prior to this change, I'd see a reported used memory of 600MiB whereas
free, htop and other tools would report a used memory of 1.8GiB. And
adding used, cached, buffered and free memory would leave ~1.2GiB
unaccounted for.
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!