mirror of https://github.com/xzeldon/htop.git
Linux: Add SwapCached to the swap meter
According to the Linux kernel documentation, "SwapCached" tracks "memory that once was swapped out, is swapped back in but still also is in the swapfile (if memory is needed it doesn't need to be swapped out AGAIN because it is already in the swapfile. This saves I/O)."
This commit is contained in:
parent
f4404effa4
commit
37e186fd66
6
Action.c
6
Action.c
|
@ -528,7 +528,13 @@ static Htop_Reaction actionHelp(State* st) {
|
|||
mvaddstr(line++, 0, "Swap bar: ");
|
||||
addattrstr(CRT_colors[BAR_BORDER], "[");
|
||||
addattrstr(CRT_colors[SWAP], "used");
|
||||
#ifdef HTOP_LINUX
|
||||
addattrstr(CRT_colors[BAR_SHADOW], "/");
|
||||
addattrstr(CRT_colors[SWAP_CACHE], "cache");
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
#else
|
||||
addattrstr(CRT_colors[BAR_SHADOW], " used/total");
|
||||
#endif
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
mvaddstr(line++, 0, "Type and layout of header meters are configurable in the setup screen.");
|
||||
|
|
6
CRT.c
6
CRT.c
|
@ -144,6 +144,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = A_BOLD,
|
||||
[BAR_SHADOW] = A_BOLD | ColorPairGrayBlack,
|
||||
[SWAP] = ColorPair(Red, Black),
|
||||
[SWAP_CACHE] = ColorPair(Yellow, Black),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
|
||||
[GRAPH_2] = ColorPair(Cyan, Black),
|
||||
[MEMORY_USED] = ColorPair(Green, Black),
|
||||
|
@ -229,6 +230,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = A_BOLD,
|
||||
[BAR_SHADOW] = A_DIM,
|
||||
[SWAP] = A_BOLD,
|
||||
[SWAP_CACHE] = A_NORMAL,
|
||||
[GRAPH_1] = A_BOLD,
|
||||
[GRAPH_2] = A_NORMAL,
|
||||
[MEMORY_USED] = A_BOLD,
|
||||
|
@ -314,6 +316,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = ColorPair(Blue, White),
|
||||
[BAR_SHADOW] = ColorPair(Black, White),
|
||||
[SWAP] = ColorPair(Red, White),
|
||||
[SWAP_CACHE] = ColorPair(Yellow, White),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Blue, White),
|
||||
[GRAPH_2] = ColorPair(Blue, White),
|
||||
[MEMORY_USED] = ColorPair(Green, White),
|
||||
|
@ -399,6 +402,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = ColorPair(Blue, Black),
|
||||
[BAR_SHADOW] = ColorPairGrayBlack,
|
||||
[SWAP] = ColorPair(Red, Black),
|
||||
[SWAP_CACHE] = ColorPair(Yellow, Black),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
|
||||
[GRAPH_2] = ColorPair(Cyan, Black),
|
||||
[MEMORY_USED] = ColorPair(Green, Black),
|
||||
|
@ -484,6 +488,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue),
|
||||
[BAR_SHADOW] = ColorPair(Cyan, Blue),
|
||||
[SWAP] = ColorPair(Red, Blue),
|
||||
[SWAP_CACHE] = A_BOLD | ColorPair(Yellow, Blue),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue),
|
||||
[GRAPH_2] = ColorPair(Cyan, Blue),
|
||||
[MEMORY_USED] = A_BOLD | ColorPair(Green, Blue),
|
||||
|
@ -569,6 +574,7 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
|
|||
[BAR_BORDER] = A_BOLD | ColorPair(Green, Black),
|
||||
[BAR_SHADOW] = ColorPair(Cyan, Black),
|
||||
[SWAP] = ColorPair(Red, Black),
|
||||
[SWAP_CACHE] = ColorPair(Yellow, Black),
|
||||
[GRAPH_1] = A_BOLD | ColorPair(Green, Black),
|
||||
[GRAPH_2] = ColorPair(Green, Black),
|
||||
[MEMORY_USED] = ColorPair(Green, Black),
|
||||
|
|
1
CRT.h
1
CRT.h
|
@ -65,6 +65,7 @@ typedef enum ColorElements_ {
|
|||
BATTERY,
|
||||
TASKS_RUNNING,
|
||||
SWAP,
|
||||
SWAP_CACHE,
|
||||
PROCESS,
|
||||
PROCESS_SHADOW,
|
||||
PROCESS_TAG,
|
||||
|
|
|
@ -65,9 +65,10 @@ typedef struct ProcessList_ {
|
|||
unsigned long long int usedMem;
|
||||
unsigned long long int buffersMem;
|
||||
unsigned long long int cachedMem;
|
||||
|
||||
unsigned long long int totalSwap;
|
||||
unsigned long long int usedSwap;
|
||||
unsigned long long int freeSwap;
|
||||
unsigned long long int cachedSwap;
|
||||
|
||||
int cpuCount;
|
||||
|
||||
|
|
11
SwapMeter.c
11
SwapMeter.c
|
@ -14,7 +14,8 @@ in the source distribution for its full text.
|
|||
|
||||
|
||||
static const int SwapMeter_attributes[] = {
|
||||
SWAP
|
||||
SWAP,
|
||||
SWAP_CACHE
|
||||
};
|
||||
|
||||
static void SwapMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
||||
|
@ -38,6 +39,12 @@ static void SwapMeter_display(const Object* cast, RichString* out) {
|
|||
Meter_humanUnit(buffer, this->values[0], sizeof(buffer));
|
||||
RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:");
|
||||
RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
|
||||
|
||||
#ifdef HTOP_LINUX
|
||||
Meter_humanUnit(buffer, this->values[1], sizeof(buffer));
|
||||
RichString_appendAscii(out, CRT_colors[METER_TEXT], " cache:");
|
||||
RichString_appendAscii(out, CRT_colors[SWAP_CACHE], buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
const MeterClass SwapMeter_class = {
|
||||
|
@ -48,7 +55,7 @@ const MeterClass SwapMeter_class = {
|
|||
},
|
||||
.updateValues = SwapMeter_updateValues,
|
||||
.defaultMode = BAR_METERMODE,
|
||||
.maxItems = 1,
|
||||
.maxItems = 2,
|
||||
.total = 100.0,
|
||||
.attributes = SwapMeter_attributes,
|
||||
.name = "Swap",
|
||||
|
|
|
@ -205,6 +205,7 @@ void Platform_setSwapValues(Meter* this) {
|
|||
const ProcessList* pl = this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
this->values[1] = NAN;
|
||||
}
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
|
|
|
@ -225,6 +225,7 @@ void Platform_setSwapValues(Meter* this) {
|
|||
const ProcessList* pl = this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
this->values[1] = NAN;
|
||||
}
|
||||
|
||||
void Platform_setZfsArcValues(Meter* this) {
|
||||
|
|
|
@ -1508,6 +1508,7 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
|
|||
switch (buffer[1]) {
|
||||
case 'w':
|
||||
tryRead("SwapTotal:", &this->totalSwap);
|
||||
tryRead("SwapCached:", &this->cachedSwap);
|
||||
tryRead("SwapFree:", &swapFree);
|
||||
break;
|
||||
case 'h':
|
||||
|
@ -1524,7 +1525,7 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
|
|||
|
||||
this->usedMem = this->totalMem - freeMem;
|
||||
this->cachedMem = this->cachedMem + sreclaimable - shmem;
|
||||
this->usedSwap = this->totalSwap - swapFree;
|
||||
this->usedSwap = this->totalSwap - swapFree - this->cachedSwap;
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -301,6 +301,7 @@ void Platform_setSwapValues(Meter* this) {
|
|||
const ProcessList* pl = this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
this->values[1] = pl->cachedSwap;
|
||||
}
|
||||
|
||||
void Platform_setZramValues(Meter* this) {
|
||||
|
|
|
@ -213,6 +213,7 @@ void Platform_setSwapValues(Meter* this) {
|
|||
const ProcessList* pl = this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
this->values[1] = NAN;
|
||||
}
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
|
|
|
@ -223,6 +223,7 @@ void Platform_setSwapValues(Meter* this) {
|
|||
const ProcessList* pl = this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
this->values[1] = NAN;
|
||||
}
|
||||
|
||||
void Platform_setZfsArcValues(Meter* this) {
|
||||
|
|
Loading…
Reference in New Issue