Re: [htop-general] [PATCH] Report dirty (modified) cached memory
Brought to you by:
loderunner
From: Seth <ht...@se...> - 2013-02-06 13:54:09
|
I've been running with the patch for some time now. Quite simply, it works as advertised, I think. On the functional side of things, I haven't found out what the "Dirty" measure is useful for, for me. I can imagine (as you state) that particular brand of sysadmin tasks (virtualization hosts) might have a user for this. On my workstation, and under the most extreme of loads I could think of, the most I've seen reported 'Dirty" is 11MiB. In this light, I'd prefer this to be a switchable option (one more 'memory bar' display setting, or perhaps a command line option). I feel the distinction buffers/cache is more meaningful, mainly because the numbers aren't nearly as volatile. For my IO metering needs I use the IO* fields or usually vmstat Is there anything I'm missing? Cheers, Seth On 01/30/2013 09:05 PM, Richard Braun wrote: > Monitoring the amount of dirty memory helps understanding how memory and > I/O behave depending on the workload. This can in turn be used (mostly > by system administrators and advanced users) to tune some VM parameters, > such as vm.dirty_background_ratio and vm.dirty_ratio. > > The new "dirty" value reported in the memory meter actually includes > both the Dirty (waiting to be written back) and Writeback (being written > back) counters of the meminfo procfs file. In order to avoid consuming > too much screen space, the previous "buffers" and "cache" values are > merged in the latter, which now stands for clean cached memory. Total > memory is then divided between "used", "dirty", "cached" (clean), and > unused. > --- > CRT.c | 14 +++++++------- > CRT.h | 2 +- > MemoryMeter.c | 19 ++++++++++--------- > ProcessList.c | 10 ++++++++++ > ProcessList.h | 2 ++ > htop.c | 2 +- > 6 files changed, 31 insertions(+), 18 deletions(-) > > diff --git a/CRT.c b/CRT.c > index 3a1eb91..00e95f2 100644 > --- a/CRT.c > +++ b/CRT.c > @@ -83,7 +83,7 @@ typedef enum ColorElements_ { > GRAPH_8, > GRAPH_9, > MEMORY_USED, > - MEMORY_BUFFERS, > + MEMORY_DIRTY, > MEMORY_CACHE, > LOAD, > LOAD_AVERAGE_FIFTEEN, > @@ -281,7 +281,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = A_DIM; > CRT_colors[GRAPH_9] = A_DIM; > CRT_colors[MEMORY_USED] = A_BOLD; > - CRT_colors[MEMORY_BUFFERS] = A_NORMAL; > + CRT_colors[MEMORY_DIRTY] = A_NORMAL; > CRT_colors[MEMORY_CACHE] = A_NORMAL; > CRT_colors[LOAD_AVERAGE_FIFTEEN] = A_DIM; > CRT_colors[LOAD_AVERAGE_FIVE] = A_NORMAL; > @@ -342,7 +342,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = ColorPair(Yellow,White); > CRT_colors[GRAPH_9] = ColorPair(Yellow,White); > CRT_colors[MEMORY_USED] = ColorPair(Green,White); > - CRT_colors[MEMORY_BUFFERS] = ColorPair(Cyan,White); > + CRT_colors[MEMORY_DIRTY] = ColorPair(Cyan,White); > CRT_colors[MEMORY_CACHE] = ColorPair(Yellow,White); > CRT_colors[LOAD_AVERAGE_FIFTEEN] = ColorPair(Black,White); > CRT_colors[LOAD_AVERAGE_FIVE] = ColorPair(Black,White); > @@ -403,7 +403,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = ColorPair(Yellow,Black); > CRT_colors[GRAPH_9] = ColorPair(Yellow,Black); > CRT_colors[MEMORY_USED] = ColorPair(Green,Black); > - CRT_colors[MEMORY_BUFFERS] = ColorPair(Cyan,Black); > + CRT_colors[MEMORY_DIRTY] = ColorPair(Cyan,Black); > CRT_colors[MEMORY_CACHE] = ColorPair(Yellow,Black); > CRT_colors[LOAD_AVERAGE_FIFTEEN] = ColorPair(Black,Black); > CRT_colors[LOAD_AVERAGE_FIVE] = ColorPair(Black,Black); > @@ -464,7 +464,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = A_BOLD | ColorPair(Yellow,Blue); > CRT_colors[GRAPH_9] = A_BOLD | ColorPair(Yellow,Blue); > CRT_colors[MEMORY_USED] = A_BOLD | ColorPair(Green,Blue); > - CRT_colors[MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan,Blue); > + CRT_colors[MEMORY_DIRTY] = A_BOLD | ColorPair(Cyan,Blue); > CRT_colors[MEMORY_CACHE] = A_BOLD | ColorPair(Yellow,Blue); > CRT_colors[LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black,Blue); > CRT_colors[LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White,Blue); > @@ -525,7 +525,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = ColorPair(Blue,Black); > CRT_colors[GRAPH_9] = A_BOLD | ColorPair(Black,Black); > CRT_colors[MEMORY_USED] = ColorPair(Green,Black); > - CRT_colors[MEMORY_BUFFERS] = ColorPair(Blue,Black); > + CRT_colors[MEMORY_DIRTY] = ColorPair(Blue,Black); > CRT_colors[MEMORY_CACHE] = ColorPair(Yellow,Black); > CRT_colors[LOAD_AVERAGE_FIFTEEN] = ColorPair(Green,Black); > CRT_colors[LOAD_AVERAGE_FIVE] = ColorPair(Green,Black); > @@ -587,7 +587,7 @@ void CRT_setColors(int colorScheme) { > CRT_colors[GRAPH_8] = ColorPair(Blue,Black); > CRT_colors[GRAPH_9] = A_BOLD | ColorPair(Black,Black); > CRT_colors[MEMORY_USED] = ColorPair(Green,Black); > - CRT_colors[MEMORY_BUFFERS] = ColorPair(Blue,Black); > + CRT_colors[MEMORY_DIRTY] = ColorPair(Blue,Black); > CRT_colors[MEMORY_CACHE] = ColorPair(Yellow,Black); > CRT_colors[LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black,Black); > CRT_colors[LOAD_AVERAGE_FIVE] = A_NORMAL; > diff --git a/CRT.h b/CRT.h > index f7d4d72..22125e2 100644 > --- a/CRT.h > +++ b/CRT.h > @@ -75,7 +75,7 @@ typedef enum ColorElements_ { > GRAPH_8, > GRAPH_9, > MEMORY_USED, > - MEMORY_BUFFERS, > + MEMORY_DIRTY, > MEMORY_CACHE, > LOAD, > LOAD_AVERAGE_FIFTEEN, > diff --git a/MemoryMeter.c b/MemoryMeter.c > index eca0442..0f59808 100644 > --- a/MemoryMeter.c > +++ b/MemoryMeter.c > @@ -22,17 +22,18 @@ in the source distribution for its full text. > }*/ > > int MemoryMeter_attributes[] = { > - MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE > + MEMORY_USED, MEMORY_DIRTY, MEMORY_CACHE > }; > > static void MemoryMeter_setValues(Meter* this, char* buffer, int size) { > long int usedMem = this->pl->usedMem; > - long int buffersMem = this->pl->buffersMem; > - long int cachedMem = this->pl->cachedMem; > - usedMem -= buffersMem + cachedMem; > + long int dirtyMem = this->pl->dirtyMem + this->pl->writebackMem; > + long int cachedMem = this->pl->buffersMem + this->pl->cachedMem; > + usedMem -= cachedMem; > + cachedMem -= dirtyMem; > this->total = this->pl->totalMem; > this->values[0] = usedMem; > - this->values[1] = buffersMem; > + this->values[1] = dirtyMem; > this->values[2] = cachedMem; > snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024); > } > @@ -43,7 +44,7 @@ static void MemoryMeter_display(Object* cast, RichString* out) { > int k = 1024; const char* format = "%ldM "; > long int totalMem = this->total / k; > long int usedMem = this->values[0] / k; > - long int buffersMem = this->values[1] / k; > + long int dirtyMem = this->values[1] / k; > long int cachedMem = this->values[2] / k; > RichString_write(out, CRT_colors[METER_TEXT], ":"); > sprintf(buffer, format, totalMem); > @@ -51,9 +52,9 @@ static void MemoryMeter_display(Object* cast, RichString* out) { > sprintf(buffer, format, usedMem); > RichString_append(out, CRT_colors[METER_TEXT], "used:"); > RichString_append(out, CRT_colors[MEMORY_USED], buffer); > - sprintf(buffer, format, buffersMem); > - RichString_append(out, CRT_colors[METER_TEXT], "buffers:"); > - RichString_append(out, CRT_colors[MEMORY_BUFFERS], buffer); > + sprintf(buffer, format, dirtyMem); > + RichString_append(out, CRT_colors[METER_TEXT], "dirty:"); > + RichString_append(out, CRT_colors[MEMORY_DIRTY], buffer); > sprintf(buffer, format, cachedMem); > RichString_append(out, CRT_colors[METER_TEXT], "cache:"); > RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); > diff --git a/ProcessList.c b/ProcessList.c > index 99a6512..94a9a5e 100644 > --- a/ProcessList.c > +++ b/ProcessList.c > @@ -127,6 +127,8 @@ typedef struct ProcessList_ { > unsigned long long int sharedMem; > unsigned long long int buffersMem; > unsigned long long int cachedMem; > + unsigned long long int dirtyMem; > + unsigned long long int writebackMem; > unsigned long long int totalSwap; > unsigned long long int usedSwap; > unsigned long long int freeSwap; > @@ -788,6 +790,14 @@ void ProcessList_scan(ProcessList* this) { > if (String_startsWith(buffer, "Cached:")) > sscanf(buffer, "Cached: %llu kB", &this->cachedMem); > break; > + case 'D': > + if (String_startsWith(buffer, "Dirty:")) > + sscanf(buffer, "Dirty: %llu kB", &this->dirtyMem); > + break; > + case 'W': > + if (String_startsWith(buffer, "Writeback:")) > + sscanf(buffer, "Writeback: %llu kB", &this->writebackMem); > + break; > case 'S': > if (String_startsWith(buffer, "SwapTotal:")) > sscanf(buffer, "SwapTotal: %llu kB", &this->totalSwap); > diff --git a/ProcessList.h b/ProcessList.h > index e410ae2..cdc4c4e 100644 > --- a/ProcessList.h > +++ b/ProcessList.h > @@ -110,6 +110,8 @@ typedef struct ProcessList_ { > unsigned long long int sharedMem; > unsigned long long int buffersMem; > unsigned long long int cachedMem; > + unsigned long long int dirtyMem; > + unsigned long long int writebackMem; > unsigned long long int totalSwap; > unsigned long long int usedSwap; > unsigned long long int freeSwap; > diff --git a/htop.c b/htop.c > index cdee8ee..220aa8e 100644 > --- a/htop.c > +++ b/htop.c > @@ -102,7 +102,7 @@ static void showHelp(ProcessList* pl) { > mvaddstr(4, 0, "Memory bar: "); > addattrstr(CRT_colors[BAR_BORDER], "["); > addattrstr(CRT_colors[MEMORY_USED], "used"); addstr("/"); > - addattrstr(CRT_colors[MEMORY_BUFFERS], "buffers"); addstr("/"); > + addattrstr(CRT_colors[MEMORY_DIRTY], "dirty"); addstr("/"); > addattrstr(CRT_colors[MEMORY_CACHE], "cache"); > addattrstr(CRT_colors[BAR_SHADOW], " used/total"); > addattrstr(CRT_colors[BAR_BORDER], "]"); |