library: modify calculation of 'MEMINFO_MEM_USED' item

In an effort to more accurately reflect 'used' memory,
we will now rely on the kernel's estimate of available
memory. Thus, 'MEMINFO_MEM_USED' will be calculated as
just 'MEMINFO_MEM_TOTAL' less 'MEMINFO_MEM_AVAILABLE'.

Reference(s):
. thread leading to agreed upon change
https://www.freelists.org/post/procps/free-regression-due-to-a-different-calculation-of-Used-memory
. where consensus reached
https://www.freelists.org/post/procps/free-regression-due-to-a-different-calculation-of-Used-memory,11
https://www.freelists.org/post/procps/free-regression-due-to-a-different-calculation-of-Used-memory,12

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2022-06-22 00:00:00 -05:00 committed by Craig Small
parent 3c7f8199f7
commit 2184e90d2e
2 changed files with 2 additions and 2 deletions

View File

@ -699,7 +699,7 @@ static int meminfo_read_failed (
such values will be dramatically distorted over those of the host. */
if (mHr(MemAvailable) > mHr(MemTotal))
mHr(MemAvailable) = mHr(MemFree);
mem_used = mHr(MemTotal) - mHr(MemFree) - mHr(derived_mem_cached) - mHr(Buffers);
mem_used = mHr(MemTotal) - mHr(MemAvailable);
if (mem_used < 0)
mem_used = mHr(MemTotal) - mHr(MemFree);
mHr(derived_mem_used) = (unsigned long)mem_used;

View File

@ -89,7 +89,7 @@ enum meminfo_item {
MEMINFO_MEM_SLAB_UNRECLAIM, // ul_int "
MEMINFO_MEM_TOTAL, // ul_int "
MEMINFO_MEM_UNEVICTABLE, // ul_int "
MEMINFO_MEM_USED, // ul_int derived from MEM_TOTAL - MEM_BUFFERS - MEM_CACHED_ALL - MEM_FREE
MEMINFO_MEM_USED, // ul_int derived from MEM_TOTAL - MEM_AVAILABLE
MEMINFO_MEM_VM_ALLOC_CHUNK, // ul_int /proc/meminfo
MEMINFO_MEM_VM_ALLOC_TOTAL, // ul_int "
MEMINFO_MEM_VM_ALLOC_USED, // ul_int "