From b29b33ebb9ae80a95e7d09eb537e0fccc5043d68 Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Tue, 27 Dec 2022 04:57:52 +0400 Subject: {Memory,Swap}Meter: add "compressed memory" metrics For now, the semantics are mostly fit for Linux zswap subsystem. For instance, we add the third swap usage metric that indicates the amount of memory that is accounted to swap but in fact stored elsewhere. This exactly matches the definition of frontswap/zswap, and is probably of little use to all other platforms. --- SwapMeter.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'SwapMeter.c') diff --git a/SwapMeter.c b/SwapMeter.c index fea8e88b..84e58a26 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -20,7 +20,8 @@ in the source distribution for its full text. static const int SwapMeter_attributes[] = { SWAP, - SWAP_CACHE + SWAP_CACHE, + SWAP_FRONTSWAP, }; static void SwapMeter_updateValues(Meter* this) { @@ -29,6 +30,7 @@ static void SwapMeter_updateValues(Meter* this) { int written; this->values[SWAP_METER_CACHE] = NAN; /* 'cached' not present on all platforms */ + this->values[SWAP_METER_FRONTSWAP] = NAN; /* 'frontswap' not present on all platforms */ Platform_setSwapValues(this); written = Meter_humanUnit(buffer, this->values[SWAP_METER_USED], size); @@ -54,6 +56,12 @@ static void SwapMeter_display(const Object* cast, RichString* out) { RichString_appendAscii(out, CRT_colors[METER_TEXT], " cache:"); RichString_appendAscii(out, CRT_colors[SWAP_CACHE], buffer); } + + if (!isnan(this->values[SWAP_METER_FRONTSWAP])) { + Meter_humanUnit(buffer, this->values[SWAP_METER_FRONTSWAP], sizeof(buffer)); + RichString_appendAscii(out, CRT_colors[METER_TEXT], " frontswap:"); + RichString_appendAscii(out, CRT_colors[SWAP_FRONTSWAP], buffer); + } } const MeterClass SwapMeter_class = { -- cgit v1.2.3