diff --git a/Action.c b/Action.c index a67233cca..18c990e0b 100644 --- a/Action.c +++ b/Action.c @@ -674,10 +674,11 @@ static Htop_Reaction actionHelp(State* st) { mvaddstr(line++, 0, "Memory bar: "); addattrstr(CRT_colors[BAR_BORDER], "["); addbartext(CRT_colors[MEMORY_USED], "", "used"); + addbartext(CRT_colors[MEMORY_COMPRESSED], "/", "compressed"); addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers"); addbartext(CRT_colors[MEMORY_SHARED], "/", "shared"); addbartext(CRT_colors[MEMORY_CACHE], "/", "cache"); - addbartext(CRT_colors[BAR_SHADOW], " ", "used"); + addbartext(CRT_colors[BAR_SHADOW], " ", "used"); addbartext(CRT_colors[BAR_SHADOW], "/", "total"); addattrstr(CRT_colors[BAR_BORDER], "]"); @@ -687,10 +688,11 @@ static Htop_Reaction actionHelp(State* st) { addbartext(CRT_colors[SWAP], "", "used"); #ifdef HTOP_LINUX addbartext(CRT_colors[SWAP_CACHE], "/", "cache"); + addbartext(CRT_colors[SWAP_FRONTSWAP], "/", "frontswap"); #else addbartext(CRT_colors[SWAP_CACHE], " ", ""); #endif - addbartext(CRT_colors[BAR_SHADOW], " ", "used"); + addbartext(CRT_colors[BAR_SHADOW], " ", "used"); addbartext(CRT_colors[BAR_SHADOW], "/", "total"); addattrstr(CRT_colors[BAR_BORDER], "]"); diff --git a/CRT.c b/CRT.c index 85a381159..a82fc8c1b 100644 --- a/CRT.c +++ b/CRT.c @@ -163,6 +163,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = A_BOLD | ColorPairGrayBlack, [SWAP] = ColorPair(Red, Black), [SWAP_CACHE] = ColorPair(Yellow, Black), + [SWAP_FRONTSWAP] = A_BOLD | ColorPairGrayBlack, [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), [GRAPH_2] = ColorPair(Cyan, Black), [MEMORY_USED] = ColorPair(Green, Black), @@ -170,6 +171,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), [MEMORY_CACHE] = ColorPair(Yellow, Black), [MEMORY_SHARED] = ColorPair(Magenta, Black), + [MEMORY_COMPRESSED] = A_BOLD | ColorPairGrayBlack, [HUGEPAGE_1] = ColorPair(Green, Black), [HUGEPAGE_2] = ColorPair(Yellow, Black), [HUGEPAGE_3] = ColorPair(Red, Black), @@ -274,6 +276,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = A_DIM, [SWAP] = A_BOLD, [SWAP_CACHE] = A_NORMAL, + [SWAP_FRONTSWAP] = A_DIM, [GRAPH_1] = A_BOLD, [GRAPH_2] = A_NORMAL, [MEMORY_USED] = A_BOLD, @@ -281,6 +284,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = A_NORMAL, [MEMORY_CACHE] = A_NORMAL, [MEMORY_SHARED] = A_NORMAL, + [MEMORY_COMPRESSED] = A_DIM, [HUGEPAGE_1] = A_BOLD, [HUGEPAGE_2] = A_NORMAL, [HUGEPAGE_3] = A_REVERSE | A_BOLD, @@ -385,6 +389,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = ColorPair(Black, White), [SWAP] = ColorPair(Red, White), [SWAP_CACHE] = ColorPair(Yellow, White), + [SWAP_FRONTSWAP] = A_BOLD | ColorPair(Black, White), [GRAPH_1] = A_BOLD | ColorPair(Blue, White), [GRAPH_2] = ColorPair(Blue, White), [MEMORY_USED] = ColorPair(Green, White), @@ -392,6 +397,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White), [MEMORY_CACHE] = ColorPair(Yellow, White), [MEMORY_SHARED] = ColorPair(Magenta, White), + [MEMORY_COMPRESSED] = A_BOLD | ColorPair(Black, White), [HUGEPAGE_1] = ColorPair(Green, White), [HUGEPAGE_2] = ColorPair(Yellow, White), [HUGEPAGE_3] = ColorPair(Red, White), @@ -496,6 +502,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = ColorPairGrayBlack, [SWAP] = ColorPair(Red, Black), [SWAP_CACHE] = ColorPair(Yellow, Black), + [SWAP_FRONTSWAP] = ColorPairGrayBlack, [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), [GRAPH_2] = ColorPair(Cyan, Black), [MEMORY_USED] = ColorPair(Green, Black), @@ -503,6 +510,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black), [MEMORY_CACHE] = ColorPair(Yellow, Black), [MEMORY_SHARED] = ColorPair(Magenta, Black), + [MEMORY_COMPRESSED] = ColorPairGrayBlack, [HUGEPAGE_1] = ColorPair(Green, Black), [HUGEPAGE_2] = ColorPair(Yellow, Black), [HUGEPAGE_3] = ColorPair(Red, Black), @@ -607,6 +615,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = ColorPair(Cyan, Blue), [SWAP] = ColorPair(Red, Blue), [SWAP_CACHE] = A_BOLD | ColorPair(Yellow, Blue), + [SWAP_FRONTSWAP] = A_BOLD | ColorPair(Black, Blue), [GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue), [GRAPH_2] = ColorPair(Cyan, Blue), [MEMORY_USED] = A_BOLD | ColorPair(Green, Blue), @@ -614,6 +623,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue), [MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue), [MEMORY_SHARED] = A_BOLD | ColorPair(Magenta, Blue), + [MEMORY_COMPRESSED] = A_BOLD | ColorPair(Black, Blue), [HUGEPAGE_1] = A_BOLD | ColorPair(Green, Blue), [HUGEPAGE_2] = A_BOLD | ColorPair(Yellow, Blue), [HUGEPAGE_3] = A_BOLD | ColorPair(Red, Blue), @@ -718,6 +728,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [BAR_SHADOW] = ColorPair(Cyan, Black), [SWAP] = ColorPair(Red, Black), [SWAP_CACHE] = ColorPair(Yellow, Black), + [SWAP_FRONTSWAP] = ColorPair(Yellow, Black), [GRAPH_1] = A_BOLD | ColorPair(Green, Black), [GRAPH_2] = ColorPair(Green, Black), [MEMORY_USED] = ColorPair(Green, Black), @@ -725,6 +736,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), [MEMORY_CACHE] = ColorPair(Yellow, Black), [MEMORY_SHARED] = ColorPair(Magenta, Black), + [MEMORY_COMPRESSED] = ColorPair(Yellow, Black), [HUGEPAGE_1] = ColorPair(Green, Black), [HUGEPAGE_2] = ColorPair(Yellow, Black), [HUGEPAGE_3] = ColorPair(Red, Black), diff --git a/CRT.h b/CRT.h index 278c1e815..ae78c9c50 100644 --- a/CRT.h +++ b/CRT.h @@ -68,6 +68,7 @@ typedef enum ColorElements_ { TASKS_RUNNING, SWAP, SWAP_CACHE, + SWAP_FRONTSWAP, PROCESS, PROCESS_SHADOW, PROCESS_TAG, @@ -95,6 +96,7 @@ typedef enum ColorElements_ { MEMORY_BUFFERS_TEXT, MEMORY_CACHE, MEMORY_SHARED, + MEMORY_COMPRESSED, HUGEPAGE_1, HUGEPAGE_2, HUGEPAGE_3, diff --git a/MemoryMeter.c b/MemoryMeter.c index 1dad1356d..28c0be277 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -20,6 +20,7 @@ static const int MemoryMeter_attributes[] = { MEMORY_USED, MEMORY_BUFFERS, MEMORY_SHARED, + MEMORY_COMPRESSED, MEMORY_CACHE }; @@ -28,8 +29,9 @@ static void MemoryMeter_updateValues(Meter* this) { size_t size = sizeof(this->txtBuffer); int written; - /* shared and available memory are not supported on all platforms */ + /* shared, compressed and available memory are not supported on all platforms */ this->values[MEMORY_METER_SHARED] = NAN; + this->values[MEMORY_METER_COMPRESSED] = NAN; this->values[MEMORY_METER_AVAILABLE] = NAN; Platform_setMemoryValues(this); @@ -38,7 +40,13 @@ static void MemoryMeter_updateValues(Meter* this) { "MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues"); this->curItems = MEMORY_METER_AVAILABLE; - written = Meter_humanUnit(buffer, this->values[MEMORY_METER_USED], size); + /* we actually want to show "used + compressed" */ + double used = this->values[MEMORY_METER_USED]; + if (!isnan(this->values[MEMORY_METER_COMPRESSED])) { + used += this->values[MEMORY_METER_COMPRESSED]; + } + + written = Meter_humanUnit(buffer, used, size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, '/'); @@ -69,6 +77,13 @@ static void MemoryMeter_display(const Object* cast, RichString* out) { RichString_appendAscii(out, CRT_colors[MEMORY_SHARED], buffer); } + /* compressed memory is not supported on all platforms */ + if (!isnan(this->values[MEMORY_METER_COMPRESSED])) { + Meter_humanUnit(buffer, this->values[MEMORY_METER_COMPRESSED], sizeof(buffer)); + RichString_appendAscii(out, CRT_colors[METER_TEXT], " compressed:"); + RichString_appendAscii(out, CRT_colors[MEMORY_COMPRESSED], buffer); + } + Meter_humanUnit(buffer, this->values[MEMORY_METER_CACHE], sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " cache:"); RichString_appendAscii(out, CRT_colors[MEMORY_CACHE], buffer); diff --git a/MemoryMeter.h b/MemoryMeter.h index d8f5fdbc9..b6568afca 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -13,9 +13,10 @@ typedef enum { MEMORY_METER_USED = 0, MEMORY_METER_BUFFERS = 1, MEMORY_METER_SHARED = 2, - MEMORY_METER_CACHE = 3, - MEMORY_METER_AVAILABLE = 4, - MEMORY_METER_ITEMCOUNT = 5, // number of entries in this enum + MEMORY_METER_COMPRESSED = 3, + MEMORY_METER_CACHE = 4, + MEMORY_METER_AVAILABLE = 5, + MEMORY_METER_ITEMCOUNT = 6, // number of entries in this enum } MemoryMeterValues; extern const MeterClass MemoryMeter_class; diff --git a/SwapMeter.c b/SwapMeter.c index fea8e88b5..84e58a26e 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 = { diff --git a/SwapMeter.h b/SwapMeter.h index 162897fb7..94b8dc859 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -12,7 +12,8 @@ in the source distribution for its full text. typedef enum { SWAP_METER_USED = 0, SWAP_METER_CACHE = 1, - SWAP_METER_ITEMCOUNT = 2, // number of entries in this enum + SWAP_METER_FRONTSWAP = 2, + SWAP_METER_ITEMCOUNT = 3, // number of entries in this enum } SwapMeterValues; extern const MeterClass SwapMeter_class; diff --git a/darwin/Platform.c b/darwin/Platform.c index deba7abb2..20bfec26e 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -294,6 +294,7 @@ void Platform_setMemoryValues(Meter* mtr) { mtr->values[MEMORY_METER_USED] = (double)(vm->active_count + vm->wire_count) * page_K; mtr->values[MEMORY_METER_BUFFERS] = (double)vm->purgeable_count * page_K; // mtr->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" mtr->values[MEMORY_METER_CACHE] = (double)vm->inactive_count * page_K; // mtr->values[MEMORY_METER_AVAILABLE] = "available memory" } @@ -306,6 +307,8 @@ void Platform_setSwapValues(Meter* mtr) { mtr->total = swapused.xsu_total / 1024; mtr->values[SWAP_METER_USED] = swapused.xsu_used / 1024; + // mtr->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // mtr->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } void Platform_setZfsArcValues(Meter* this) { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index ab21d3650..995276421 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -215,6 +215,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // mtr->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" } @@ -223,7 +224,8 @@ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; - this->values[SWAP_METER_CACHE] = NAN; + // mtr->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // mtr->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } char* Platform_getProcessEnv(pid_t pid) { diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 618ed6b42..cab80929b 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -236,6 +236,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; this->values[MEMORY_METER_SHARED] = pl->sharedMem; + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" @@ -254,7 +255,8 @@ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; - this->values[SWAP_METER_CACHE] = NAN; + // this->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } void Platform_setZfsArcValues(Meter* this) { diff --git a/linux/Platform.c b/linux/Platform.c index c14736bbf..45fee3927 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -359,6 +359,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; this->values[MEMORY_METER_SHARED] = pl->sharedMem; + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; this->values[MEMORY_METER_AVAILABLE] = pl->availableMem; diff --git a/netbsd/Platform.c b/netbsd/Platform.c index 9c9546fec..1cf160670 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -274,6 +274,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" } @@ -282,7 +283,8 @@ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; - this->values[SWAP_METER_CACHE] = NAN; + // this->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } char* Platform_getProcessEnv(pid_t pid) { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index e49a0f817..707d21068 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -231,6 +231,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = usedMem; this->values[MEMORY_METER_BUFFERS] = buffersMem; // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" } @@ -239,7 +240,8 @@ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; - this->values[SWAP_METER_CACHE] = NAN; + // this->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } char* Platform_getProcessEnv(pid_t pid) { diff --git a/pcp/Platform.c b/pcp/Platform.c index 22963dda3..87de2c2f7 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -537,6 +537,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; this->values[MEMORY_METER_SHARED] = pl->sharedMem; + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; this->values[MEMORY_METER_AVAILABLE] = pl->availableMem; @@ -556,6 +557,7 @@ void Platform_setSwapValues(Meter* this) { this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; this->values[SWAP_METER_CACHE] = pl->cachedSwap; + // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } void Platform_setZramValues(Meter* this) { diff --git a/solaris/Platform.c b/solaris/Platform.c index f7ab65585..79b6a9ead 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -240,6 +240,7 @@ void Platform_setMemoryValues(Meter* this) { this->values[MEMORY_METER_USED] = pl->usedMem; this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + // this->values[MEMORY_METER_COMPRESSED] = "compressed memory, like zswap on linux" this->values[MEMORY_METER_CACHE] = pl->cachedMem; // this->values[MEMORY_METER_AVAILABLE] = "available memory" } @@ -248,7 +249,8 @@ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; this->values[SWAP_METER_USED] = pl->usedSwap; - this->values[SWAP_METER_CACHE] = NAN; + // this->values[SWAP_METER_CACHE] = "pages that are both in swap and RAM, like SwapCached on linux" + // this->values[SWAP_METER_FRONTSWAP] = "pages that are accounted to swap but stored elsewhere, like frontswap on linux" } void Platform_setZfsArcValues(Meter* this) {