summaryrefslogtreecommitdiffstats
path: root/pcp
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-11-20 15:59:41 +1100
committerNathan Scott <nathans@redhat.com>2023-11-20 15:59:41 +1100
commit452244dc06270aff4872a3c3d9559e7da5f34ad6 (patch)
tree198c178d126253d53dfbf06a7d0d6d8cc29785a8 /pcp
parente49a40ad82c7ce122f30b0056a2fc2cdb1a208b0 (diff)
PCP platform implementation of frontswap and zswap accounting
Diffstat (limited to 'pcp')
-rw-r--r--pcp/Metric.h3
-rw-r--r--pcp/PCPMachine.c14
-rw-r--r--pcp/PCPMachine.h5
-rw-r--r--pcp/Platform.c27
4 files changed, 46 insertions, 3 deletions
diff --git a/pcp/Metric.h b/pcp/Metric.h
index 789ef4b2..914d7d65 100644
--- a/pcp/Metric.h
+++ b/pcp/Metric.h
@@ -93,6 +93,9 @@ typedef enum Metric_ {
PCP_ZRAM_CAPACITY, /* zram.capacity */
PCP_ZRAM_ORIGINAL, /* zram.mm_stat.data_size.original */
PCP_ZRAM_COMPRESSED, /* zram.mm_stat.data_size.compressed */
+ PCP_ZSWAP_MAX_POOL_PERCENT, /* sysfs.module.zswap.max_pool_percent */
+ PCP_MEM_ZSWAP, /* mem.util.zswap */
+ PCP_MEM_ZSWAPPED, /* mem.util.zswapped */
PCP_VFS_FILES_COUNT, /* vfs.files.count */
PCP_VFS_FILES_MAX, /* vfs.files.max */
diff --git a/pcp/PCPMachine.c b/pcp/PCPMachine.c
index 5f24a284..faf3ae96 100644
--- a/pcp/PCPMachine.c
+++ b/pcp/PCPMachine.c
@@ -178,6 +178,19 @@ static void PCPMachine_updatePerCPUReal(PCPMachine* this, Metric metric, CPUMetr
this->percpu[i][cpumetric].d = this->values[i].d;
}
+static inline void PCPMachine_scanZswapInfo(PCPMachine* this) {
+ const Machine* host = &this->super;
+ pmAtomValue value;
+
+ memset(&this->zswap, 0, sizeof(ZswapStats));
+ if (Metric_values(PCP_ZSWAP_MAX_POOL_PERCENT, &value, 1, PM_TYPE_U64))
+ this->zswap.totalZswapPool = host->totalMem * value.ull / 100;
+ if (Metric_values(PCP_MEM_ZSWAP, &value, 1, PM_TYPE_U64))
+ this->zswap.usedZswapComp = value.ull;
+ if (Metric_values(PCP_MEM_ZSWAPPED, &value, 1, PM_TYPE_U64))
+ this->zswap.usedZswapOrig = value.ull;
+}
+
static inline void PCPMachine_scanZfsArcstats(PCPMachine* this) {
unsigned long long int dbufSize = 0;
unsigned long long int dnodeSize = 0;
@@ -251,6 +264,7 @@ static void PCPMachine_scan(PCPMachine* this) {
PCPMachine_updatePerCPUReal(this, PCP_HINV_CPUCLOCK, CPU_FREQUENCY);
PCPMachine_scanZfsArcstats(this);
+ PCPMachine_scanZswapInfo(this);
}
void Machine_scan(Machine* super) {
diff --git a/pcp/PCPMachine.h b/pcp/PCPMachine.h
index faca8efc..fe6c503f 100644
--- a/pcp/PCPMachine.h
+++ b/pcp/PCPMachine.h
@@ -17,6 +17,7 @@ in the source distribution for its full text.
#include "UsersTable.h"
#include "pcp/Platform.h"
+#include "linux/ZswapStats.h"
#include "zfs/ZfsArcStats.h"
@@ -59,10 +60,14 @@ typedef struct PCPMachine_ {
int smaps_flag;
double period;
double timestamp; /* previous sample timestamp */
+
pmAtomValue* cpu; /* aggregate values for each metric */
pmAtomValue** percpu; /* per-processor values for each metric */
pmAtomValue* values; /* per-processor buffer for just one metric */
+
ZfsArcStats zfs;
+ /*ZramStats zram; -- not needed, calculated in-line in Platform.c */
+ ZswapStats zswap;
} PCPMachine;
#endif
diff --git a/pcp/Platform.c b/pcp/Platform.c
index 9fb3770e..402276ae 100644
--- a/pcp/Platform.c
+++ b/pcp/Platform.c
@@ -197,6 +197,9 @@ static const char* Platform_metricNames[] = {
[PCP_ZRAM_CAPACITY] = "zram.capacity",
[PCP_ZRAM_ORIGINAL] = "zram.mm_stat.data_size.original",
[PCP_ZRAM_COMPRESSED] = "zram.mm_stat.data_size.compressed",
+ [PCP_ZSWAP_MAX_POOL_PERCENT] = "sysfs.module.zswap.max_pool_percent",
+ [PCP_MEM_ZSWAP] = "mem.util.zswap",
+ [PCP_MEM_ZSWAPPED] = "mem.util.zswapped",
[PCP_VFS_FILES_COUNT] = "vfs.files.count",
[PCP_VFS_FILES_MAX] = "vfs.files.max",
@@ -549,9 +552,9 @@ void Platform_setMemoryValues(Meter* this) {
this->total = host->totalMem;
this->values[MEMORY_METER_USED] = host->usedMem;
- this->values[MEMORY_METER_BUFFERS] = host->buffersMem;
this->values[MEMORY_METER_SHARED] = host->sharedMem;
- // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux"
+ this->values[MEMORY_METER_COMPRESSED] = 0;
+ this->values[MEMORY_METER_BUFFERS] = host->buffersMem;
this->values[MEMORY_METER_CACHE] = host->cachedMem;
this->values[MEMORY_METER_AVAILABLE] = host->availableMem;
@@ -564,14 +567,32 @@ void Platform_setMemoryValues(Meter* this) {
this->values[MEMORY_METER_CACHE] += shrinkableSize;
this->values[MEMORY_METER_AVAILABLE] += shrinkableSize;
}
+
+ if (phost->zswap.usedZswapOrig > 0 || phost->zswap.usedZswapComp > 0) {
+ this->values[MEMORY_METER_USED] -= phost->zswap.usedZswapComp;
+ this->values[MEMORY_METER_COMPRESSED] += phost->zswap.usedZswapComp;
+ }
}
void Platform_setSwapValues(Meter* this) {
const Machine* host = this->host;
+ const PCPMachine* phost = (const PCPMachine*) host;
+
this->total = host->totalSwap;
this->values[SWAP_METER_USED] = host->usedSwap;
this->values[SWAP_METER_CACHE] = host->cachedSwap;
- // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux"
+ this->values[SWAP_METER_FRONTSWAP] = 0; /* frontswap -- memory that is accounted to swap but resides elsewhere */
+
+ if (phost->zswap.usedZswapOrig > 0 || phost->zswap.usedZswapComp > 0) {
+ /* refer to linux/Platform.c::Platform_setSwapValues for details */
+ this->values[SWAP_METER_USED] -= phost->zswap.usedZswapOrig;
+ if (this->values[SWAP_METER_USED] < 0) {
+ /* subtract the overflow from SwapCached */
+ this->values[SWAP_METER_CACHE] += this->values[SWAP_METER_USED];
+ this->values[SWAP_METER_USED] = 0;
+ }
+ this->values[SWAP_METER_FRONTSWAP] += phost->zswap.usedZswapOrig;
+ }
}
void Platform_setZramValues(Meter* this) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy