Implement shared memory support on the PCP platform

Uses the mem.util.shared metric (Shmem from meminfo).
This commit is contained in:
Nathan Scott 2021-03-17 09:54:15 +11:00
parent d3af4e670d
commit b424a5b137
3 changed files with 16 additions and 14 deletions

View File

@ -1,7 +1,7 @@
/* /*
htop - PCPProcessList.c htop - PCPProcessList.c
(C) 2014 Hisham H. Muhammad (C) 2014 Hisham H. Muhammad
(C) 2020 htop dev team (C) 2020-2021 htop dev team
(C) 2020-2021 Red Hat, Inc. All Rights Reserved. (C) 2020-2021 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
@ -584,12 +584,13 @@ static void PCPProcessList_updateMemoryInfo(ProcessList* super) {
super->buffersMem = value.ull; super->buffersMem = value.ull;
if (Metric_values(PCP_MEM_SRECLAIM, &value, 1, PM_TYPE_U64) != NULL) if (Metric_values(PCP_MEM_SRECLAIM, &value, 1, PM_TYPE_U64) != NULL)
sreclaimableMem = value.ull; 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) { if (Metric_values(PCP_MEM_CACHED, &value, 1, PM_TYPE_U64) != NULL) {
super->cachedMem = value.ull; super->cachedMem = value.ull;
super->cachedMem += sreclaimableMem; super->cachedMem += sreclaimableMem;
} }
unsigned long long int usedDiff; const memory_t usedDiff = freeMem + super->cachedMem + sreclaimableMem + super->buffersMem + super->sharedMem;
usedDiff = freeMem + super->cachedMem + super->buffersMem;
super->usedMem = (super->totalMem >= usedDiff) ? super->usedMem = (super->totalMem >= usedDiff) ?
super->totalMem - usedDiff : super->totalMem - freeMem; super->totalMem - usedDiff : super->totalMem - freeMem;
if (Metric_values(PCP_MEM_AVAILABLE, &value, 1, PM_TYPE_U64) != NULL) if (Metric_values(PCP_MEM_AVAILABLE, &value, 1, PM_TYPE_U64) != NULL)

View File

@ -1,7 +1,7 @@
/* /*
htop - linux/Platform.c htop - linux/Platform.c
(C) 2014 Hisham H. Muhammad (C) 2014 Hisham H. Muhammad
(C) 2020 htop dev team (C) 2020-2021 htop dev team
(C) 2020-2021 Red Hat, Inc. All Rights Reserved. (C) 2020-2021 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
@ -152,6 +152,7 @@ static const char *Platform_metricNames[] = {
[PCP_MEM_AVAILABLE] = "mem.util.available", [PCP_MEM_AVAILABLE] = "mem.util.available",
[PCP_MEM_BUFFERS] = "mem.util.bufmem", [PCP_MEM_BUFFERS] = "mem.util.bufmem",
[PCP_MEM_CACHED] = "mem.util.cached", [PCP_MEM_CACHED] = "mem.util.cached",
[PCP_MEM_SHARED] = "mem.util.shared",
[PCP_MEM_SRECLAIM] = "mem.util.slabReclaimable", [PCP_MEM_SRECLAIM] = "mem.util.slabReclaimable",
[PCP_MEM_SWAPCACHED] = "mem.util.swapCached", [PCP_MEM_SWAPCACHED] = "mem.util.swapCached",
[PCP_MEM_SWAPTOTAL] = "mem.util.swapTotal", [PCP_MEM_SWAPTOTAL] = "mem.util.swapTotal",
@ -587,18 +588,17 @@ double Platform_setCPUValues(Meter* this, int cpu) {
void Platform_setMemoryValues(Meter* this) { void Platform_setMemoryValues(Meter* this) {
const ProcessList* pl = this->pl; const ProcessList* pl = this->pl;
const PCPProcessList* ppl = (const PCPProcessList*) pl; const PCPProcessList* ppl = (const PCPProcessList*) pl;
long int usedMem = pl->usedMem;
long int buffersMem = pl->buffersMem; this->total = pl->totalMem;
long int cachedMem = pl->cachedMem; this->values[0] = pl->usedMem;
usedMem -= buffersMem + cachedMem; this->values[1] = pl->buffersMem;
this->total = pl->totalMem; this->values[2] = pl->sharedMem;
this->values[0] = usedMem; this->values[3] = pl->cachedMem;
this->values[1] = buffersMem; this->values[4] = pl->availableMem;
this->values[2] = cachedMem;
if (ppl->zfs.enabled != 0) { if (ppl->zfs.enabled != 0) {
this->values[0] -= ppl->zfs.size; this->values[0] -= ppl->zfs.size;
this->values[2] += ppl->zfs.size; this->values[3] += ppl->zfs.size;
} }
} }

View File

@ -3,7 +3,7 @@
/* /*
htop - pcp/Platform.h htop - pcp/Platform.h
(C) 2014 Hisham H. Muhammad (C) 2014 Hisham H. Muhammad
(C) 2020 htop dev team (C) 2020-2021 htop dev team
(C) 2020-2021 Red Hat, Inc. All Rights Reserved. (C) 2020-2021 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
@ -125,6 +125,7 @@ typedef enum Metric_ {
PCP_MEM_FREE, /* mem.util.free */ PCP_MEM_FREE, /* mem.util.free */
PCP_MEM_BUFFERS, /* mem.util.bufmem */ PCP_MEM_BUFFERS, /* mem.util.bufmem */
PCP_MEM_CACHED, /* mem.util.cached */ PCP_MEM_CACHED, /* mem.util.cached */
PCP_MEM_SHARED, /* mem.util.shared */
PCP_MEM_AVAILABLE, /* mem.util.available */ PCP_MEM_AVAILABLE, /* mem.util.available */
PCP_MEM_SRECLAIM, /* mem.util.slabReclaimable */ PCP_MEM_SRECLAIM, /* mem.util.slabReclaimable */
PCP_MEM_SWAPCACHED, /* mem.util.swapCached */ PCP_MEM_SWAPCACHED, /* mem.util.swapCached */