Skip to content

Commit

Permalink
Incorporate shared memory in bar text
Browse files Browse the repository at this point in the history
Shared memory is claimed, and as significant a part of the memory load
as the "used" memory. Since "shared" was separated from the "used"
value, the basic "used/total" display in the bar text has become less
meaningful for Linux, as it only reflects a subset of the claimed
memory. The difference often isn't huge, but it can become so if tmpfs
is heavily used.

Improve the situation by adding used and shared for that text,
making it "claimed/total".
  • Loading branch information
kjbracey2 committed Jul 15, 2023
1 parent 3633ed5 commit 12be9e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ static Htop_Reaction actionHelp(State* st) {
addbartext(CRT_colors[MEMORY_COMPRESSED], "/", "compressed");
addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers");
addbartext(CRT_colors[MEMORY_CACHE], "/", "cache");
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
addbartext(CRT_colors[BAR_SHADOW], " ", "claimed");
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
addattrstr(CRT_colors[BAR_BORDER], "]");

Expand Down
11 changes: 7 additions & 4 deletions MemoryMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ static void MemoryMeter_updateValues(Meter* this) {
"MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues");
this->curItems = MEMORY_METER_AVAILABLE;

/* we actually want to show "used + compressed" */
double used = this->values[MEMORY_METER_USED];
/* we actually want to show "used + shared + compressed" */
double claimed = this->values[MEMORY_METER_USED];
if (!isnan(this->values[MEMORY_METER_SHARED])) {
claimed += this->values[MEMORY_METER_SHARED];
}
if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
used += this->values[MEMORY_METER_COMPRESSED];
claimed += this->values[MEMORY_METER_COMPRESSED];
}

written = Meter_humanUnit(buffer, used, size);
written = Meter_humanUnit(buffer, claimed, size);
METER_BUFFER_CHECK(buffer, size, written);

METER_BUFFER_APPEND_CHR(buffer, size, '/');
Expand Down

0 comments on commit 12be9e1

Please sign in to comment.