From 97d9b320ad1ce3e8c505682a36ce663c59eeee1a Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 29 Jul 2021 09:44:03 +1000 Subject: [PATCH] PCP: use the correct metric for shared memory calculations --- pcp/PCPProcessList.c | 10 ++++------ pcp/Platform.c | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c index 5a02aba0..77f82095 100644 --- a/pcp/PCPProcessList.c +++ b/pcp/PCPProcessList.c @@ -431,7 +431,7 @@ static void PCPProcessList_updateMemoryInfo(ProcessList* super) { unsigned long long int swapFreeMem = 0; unsigned long long int sreclaimableMem = 0; super->totalMem = super->usedMem = super->cachedMem = 0; - super->usedSwap = super->totalSwap = 0; + super->usedSwap = super->totalSwap = super->sharedMem = 0; pmAtomValue value; if (Metric_values(PCP_MEM_TOTAL, &value, 1, PM_TYPE_U64) != NULL) @@ -444,11 +444,9 @@ static void PCPProcessList_updateMemoryInfo(ProcessList* super) { sreclaimableMem = value.ull; if (Metric_values(PCP_MEM_SHARED, &value, 1, PM_TYPE_U64) != NULL) super->sharedMem = value.ull; - if (Metric_values(PCP_MEM_CACHED, &value, 1, PM_TYPE_U64) != NULL) { - super->cachedMem = value.ull; - super->cachedMem += sreclaimableMem; - } - const memory_t usedDiff = freeMem + super->cachedMem + sreclaimableMem + super->buffersMem + super->sharedMem; + if (Metric_values(PCP_MEM_CACHED, &value, 1, PM_TYPE_U64) != NULL) + super->cachedMem = value.ull + sreclaimableMem - super->sharedMem; + const memory_t usedDiff = freeMem + super->cachedMem + sreclaimableMem + super->buffersMem; super->usedMem = (super->totalMem >= usedDiff) ? super->totalMem - usedDiff : super->totalMem - freeMem; if (Metric_values(PCP_MEM_AVAILABLE, &value, 1, PM_TYPE_U64) != NULL) diff --git a/pcp/Platform.c b/pcp/Platform.c index 082f4b5b..4ddf7e68 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -157,7 +157,7 @@ static const char* Platform_metricNames[] = { [PCP_MEM_AVAILABLE] = "mem.util.available", [PCP_MEM_BUFFERS] = "mem.util.bufmem", [PCP_MEM_CACHED] = "mem.util.cached", - [PCP_MEM_SHARED] = "mem.util.shared", + [PCP_MEM_SHARED] = "mem.util.shmem", [PCP_MEM_SRECLAIM] = "mem.util.slabReclaimable", [PCP_MEM_SWAPCACHED] = "mem.util.swapCached", [PCP_MEM_SWAPTOTAL] = "mem.util.swapTotal",