Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-17415

Incorrect available memory calculation description on RHEL7 based systems

XMLWordPrintable

    • Icon: Documentation task Documentation task
    • Resolution: Fixed
    • Icon: Critical Critical
    • 5.0 (plan)
    • 3.0.30, 4.0.18, 4.4.6, 5.0.0alpha2
    • Documentation (D)
    • RHEL7-based distro's
    • Sprint 62 (Mar 2020)
    • 1

      Steps to reproduce:

      1. Install any Zabbix Agent 4.0.18/4.4.6/3.0.30/5.0;
      2. Use vm.memory.size.

      Since RHEL uses custom kernel with backported features MemAvailable is present but kernel is still 3.10+, the following check is incorrect in the /libs/zbxsysinfo/linux/memory.c:

              /* try MemAvailable (present since Linux 3.14), falling back to a calculation based on sysinfo() and Cached */
      
              if (NULL == (f = fopen("/proc/meminfo", "r")))
              {
                      SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot open /proc/meminfo: %s", zbx_strerror(errno)));
                      return SYSINFO_RET_FAIL;
              }
      
              if (FAIL == (res = byte_value_from_proc_file(f, "MemAvailable:", "Cached:", &value)))
              {
                      SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain the value of MemAvailable from /proc/meminfo."));
                      goto close;
              }
      
              if (SUCCEED == res)
              {
                      SET_UI64_RESULT(result, value);
                      ret = SYSINFO_RET_OK;
                      goto close;
              }
      

      kernel.org (procfs):

      MemAvailable: An estimate of how much memory is available for starting new
                    applications, without swapping. Calculated from MemFree,
                    SReclaimable, the size of the file LRU lists, and the low
                    watermarks in each zone.
                    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. The
                    impact of those factors will vary from system to system.
      

      Result:

      Linux c7zs1.local 3.10.0-1062.12.1.el7.x86_64 #1 SMP Tue Feb 4 23:02:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
      cat /proc/meminfo 
      MemTotal:        1010080 kB
      MemFree:           80260 kB
      MemAvailable:     336324 kB
      Buffers:               0 kB
      Cached:           398228 kB
      SwapCached:            0 kB
      
      zabbix_agentd -t vm.memory.size[available]
      vm.memory.size[available]                     [u|343908352]
      
      ### in kB: 335848
      

      Expected:
      478192 kB (466 Mb)

      MemFree:           78964 kB
      Buffers:               0 kB
      Cached:           399228 kB
      

      Meanwhile on RHEL8/CentOS 8/OEL8:

      [root@m8]# uname -a
      Linux m8.local 4.18.0-147.5.1.el8_1.x86_64 #1 SMP Wed Feb 5 02:00:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
      
      [root@m8]# head -n 7 /proc/meminfo 
      MemTotal:        2031268 kB
      MemFree:         1235676 kB
      MemAvailable:    1355472 kB
      Buffers:            3292 kB
      Cached:           240036 kB
      SwapCached:            0 kB
      Active:           538432 kB
      

      And the most confusing part:
      https://access.redhat.com/solutions/406773

            vso Vladislavs Sokurenko
            edgar.akhmetshin Edgar Akhmetshin
            Team A
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: