After the introduction of MemAvailable in the kernel v3.14 one can
estimate how much RAM memory is being "used" by how much it is left
before the system starts swapping.
That is the reason why I want to monitor memory usage, to know
how close the system is to swapping. Therefore I propose to
use MemAvailable to compute the percentage of "used" memory.
Theoretically, after this patch a 100% memory usage is a more
accurate description of "yeah, we need to swap from now on".
See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
The reason is the same as in the analogous patch for wmwifi
in commit 1e34ea7f980; it improves considerably the efficiency.
Keeping the 'interval' unchanged (set to 1 sec), with this change
the number of wakeups as measured by powertop goes from around 14 wakeups/sec
to around 2 wakeup/sec.
Avoid the following compiler warning:
mem_linux.c: In function ‘mem_init’:
mem_linux.c:52:40: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
if (version == 2 && patchlevel >= 5 && sublevel >= 1 || \
^
Avoid multiple compiler warnings such as the following:
main.c: In function ‘update’:
main.c:157:4: warning: pointer targets in passing argument 1 of ‘mem_getusage’ differ in signedness [-Wpointer-sign]
mem_getusage(&mem_usage, &swap_usage, &mem_opts);
^
In file included from main.c:29:0:
mem.h:16:6: note: expected ‘int *’ but argument is of type ‘unsigned int *’
void mem_getusage(int *per_mem, int *per_swap, const struct mem_options *opts);
^
Avoid the following compiler warning:
dockapp.c: In function ‘dockapp_open_window’:
dockapp.c:51:16: warning: variable ‘stat’ set but not used [-Wunused-but-set-variable]
Status stat;
^
Previously, kvm_read was used to get the memory usage in FreeBSD. However,
this has been deprecated in favor of sysctl. This patch implements this
change.
Some work had previously been done in this direction, as could be seen in
the file src/mem_freebsd_sysctl.c. Since this file is no longer needed, it
has been removed.
Additionally, some formatting has been done on the remaining older code for
a more consistent style.