How is kbmemused calculated in sar?
Environment
- Red Hat Enterprise Linux 10
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 7
- sysstat-12.5.4-5.el9
Issue
- Explanation of
kbmemusedinman sarhas changed in RHEL9. - How is the value calculated? What is the difference compared with the older version?
RHEL8 and older version
# man sar
...
kbmemused
Amount of used memory in kilobytes. This does not take into account memory used by the kernel
itself.
RHEL9 and RHEL10
# man sar
...
kbmemused
Amount of used memory in kilobytes (calculated as total installed memory - kbmemfree - kb‐
buffers - kbcached - kbslab).
Resolution
kbmemused is calculated in the following method:
RHEL9 and RHEL10 (11.7.4 and newer version)
kbmemused = total installed memory - kbmemfree - kbbuffer - kbcached - kbslab
RHEL8 and RHEL7 (older version than 11.7.4)
kbmemused = total installed memory - kbmemfree
Root Cause
- As per the change log, the calculation method of
kbmemusedhas changed since the upstream version 11.7.4.
2018/06/01: Version 11.7.4 - Sebastien Godard (sysstat <at> orange.fr)
...
* sar: Change how used memory (kbmemused) is calculated to be
consistent with free(1) and top(1)'s output [11.6.4] [11.4.10].
...
- Here is a source code of
sysstat-12.5.4-5.el9.
rndr_stats.c
...
767 nousedmem = smc->frmkb + smc->bufkb + smc->camkb + smc->slabkb;
768 if (nousedmem > smc->tlmkb) {
769 nousedmem = smc->tlmkb;
770 }
...
780 render(isdb, pre, PT_USEINT,
781 "-\tkbmemused", NULL, NULL,
782 smc->tlmkb - nousedmem, DNOVAL, NULL);
- As the following source code shows,
kbmemusedis calculated intotal installed memory - kbmemfree.
sysstat-11.7.3-9.el8
rndr_stats.c
...
753 render(isdb, pre, PT_USEINT,
754 "-\tkbmemfree", NULL, NULL,
755 smc->frmkb, DNOVAL, NULL);
...
761 render(isdb, pre, PT_USEINT,
762 "-\tkbmemused", NULL, NULL,
763 smc->tlmkb - smc->frmkb, DNOVAL, NULL); <<<---
pidstat.c
69 unsigned long tlmkb; /* Total memory in kB */
Diagnostic Steps
- Check the
sysstatversion andman sar.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments