[ZBX-9142] Incorrect available memory calculation Created: 2014 Dec 14 Updated: 2017 May 30 Resolved: 2015 Jun 04 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Agent (G) |
Affects Version/s: | 2.2.7, 2.4.2 |
Fix Version/s: | 2.5.0 |
Type: | Incident report | Priority: | Blocker |
Reporter: | Alexey Pustovalov | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 3 |
Labels: | linux, memory | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Linux with high SReclaimable |
Issue Links: |
|
Description |
Zabbix agent does not consider SReclaimable kernel option when calculate free memory. The option is like cached memory and should be considered as free memory:
https://www.kernel.org/doc/Documentation/filesystems/proc.txt |
Comments |
Comment by Aleksandrs Saveljevs [ 2015 May 07 ] |
Currently, we calculate "vm.memory.size[available]" as follows (written in terms of /proc/meminfo): MemFree + Buffers + Cached The proposal in the issue description does not define the solution precisely, but one attempt at taking SReclaimable into account would be to calculate "vm.memory.size[available]" as follows: MemFree + Buffers + Cached + SReclaimable This seems to be how Monit does it: see https://bitbucket.org/tildeslash/monit/src/bbf3e4a22918774b58ff0366b9ca6b1ab57572d0/src/process/sysdep_LINUX.c?at=master#cl-333 for source code and https://bitbucket.org/tildeslash/monit/issue/71/ for a similar ticket. The problem seems to be that this calculation is different from MemAvailable, as quoted in the issue. Consider the following example: $ cat /proc/meminfo MemTotal: 8066548 kB MemFree: 2967140 kB MemAvailable: 4909836 kB Buffers: 268648 kB Cached: 2098364 kB ... SReclaimable: 221116 kB Calculation: 2967140 (MemFree) + 268648 (Buffers) + 2098364 (Cached) + 221116 (SReclaimable) = 5555268 This is different from MemAvailable, which is 4909836. So, since we are reading /proc/meminfo for "vm.memory.size[available]" anyway, I wonder whether we can just take MemAvailable, because it is a system's native estimate. Note that, from the quote in the issue description, "The estimate takes into account that the system needs some page cache to function well, and that not all reclaimable slab will be reclaimable, due to items being in use". Therefore, it seems that just adding SReclaimable to our current "vm.memory.size[available]" will not be correct. |
Comment by Aleksandrs Saveljevs [ 2015 May 14 ] |
So it was decided to fix the issue in trunk by taking "MemAvailable" from /proc/meminfo, if possible. Otherwise, we do the calculation as before, because simply adding "SReclaimable" to our current algorithm is not exactly correct. In addition to the link in the issue description, useful reading regarding "MemAvailable" can be found on http://blog.famzah.net/2014/09/24/memavailable-metric-for-linux-kernels-before-3-14-in-procmeminfo/ (a nice, summarizing blog post), https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 (commit that introduces "MemAvailable" in Linux 3.14), and https://github.com/famzah/linux-memavailable-procfs (a script by the author of the blog post to emulate "MemAvailable" on Linux kernels prior to 3.14, which we might theoretically use in the future). Quoting Linux commit message here, because it is a nice explanation of why we should use "MemAvailable" for vm.memory.size[available]:
Another useful link is https://bugzilla.kernel.org/show_bug.cgi?id=77141 , which explains why "MemFree" can be higher than "MemAvailable". |
Comment by Aleksandrs Saveljevs [ 2015 May 15 ] |
Using "MemAvailable" (when possible) is implemented in development branch svn://svn.zabbix.com/branches/dev/ZBX-9142-trunk . The fix improves function byte_value_from_proc_file() in such a way that we can read either "MemAvailable" or "Cached" (exactly one of which is required for "vm.memory.size[available]") in one go, without the need to open "/proc/meminfo" two times. |
Comment by Andris Zeila [ 2015 May 22 ] |
Successfully tested |
Comment by Aleksandrs Saveljevs [ 2015 May 27 ] |
Available in pre-2.5.0 (trunk) r53807. |
Comment by Aleksandrs Saveljevs [ 2015 May 27 ] |
Documented at the following locations:
sasha CLOSED |