From 2184e90d2e7cdb582f9a5b706b47015e56707e4d Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 22 Jun 2022 00:00:00 -0500 Subject: [PATCH] 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 --- proc/meminfo.c | 2 +- proc/meminfo.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proc/meminfo.c b/proc/meminfo.c index 3f949450..719ad3e7 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -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; diff --git a/proc/meminfo.h b/proc/meminfo.h index 0f3d0076..1913abd1 100644 --- a/proc/meminfo.h +++ b/proc/meminfo.h @@ -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 "