free.c - available mem calculation is off by 1%
-
I'm referring to: https://gitlab.com/procps-ng/procps/blob/18b1a887b781e94391909fc7a8f7021309a8ebec/proc/sysinfo.c#L780
-
This algorithm is used to calculate "available" mem when "MemAvailable:" field is not included in /proc/meminfo on kernels <3.14.
-
This was implemented like this because this commit was used as a guide: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
-
At some point, Linux changed the way "MemAvailable:" is calculated: https://github.com/torvalds/linux/commit/84ad5802a33a4964a49b8f7d24d80a214a096b19
-
So this is how avail mem is now calculated in recent kernels: https://github.com/torvalds/linux/blob/6aa303defb7454a2520c4ddcdf6b081f62a15890/mm/page_alloc.c#L4025
-
free
should do the same and do "available = free_pages - total_reserve_pages" instead of "available = free_pages - watermark_low". -
For the record, I have the same issue in psutil: https://github.com/giampaolo/psutil/issues/887 and right now I'm not sure how to retrieve "total_reserve_pages" as apparently they are not exposed into /proc/meminfo (but this is another story).