From e2fe73121dcc49aa2c5c5c3a6686d7ca38fc3a99 Mon Sep 17 00:00:00 2001 From: Sebastien Godard Date: Sat, 18 Dec 2010 16:17:15 +0100 Subject: [PATCH] Added two new metrics (amount of active and inactive memory) to sar -r. This patch adds two new metrics (kbactive and kbinact) to sar -r. Also update sar manual page and DTD and XSD documents. --- CHANGES | 2 ++ activity.c | 2 +- man/sar.in | 11 +++++++++++ pr_stats.c | 36 ++++++++++++++++++++++-------------- rd_stats.c | 8 ++++++++ rd_stats.h | 2 ++ rndr_stats.c | 10 +++++++++- xml/sysstat.dtd | 4 +++- xml/sysstat.xsd | 2 ++ xml_stats.c | 8 +++++++- 10 files changed, 67 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index bc7cc87..8506ce9 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat orange.fr) activities. * Added a new metric (number of tasks waiting for I/O) to sar -q. + * Added two new metrics (amount of active and inactive + memory) to sar -r. * [Ivana Varekova]: Fix segfaults on bogus localtime input. * Fixed bogus CPU statistics output, which happened when CPU user value from /proc/stat wasn't incremented whereas diff --git a/activity.c b/activity.c index ac4d0b1..e622e96 100644 --- a/activity.c +++ b/activity.c @@ -264,7 +264,7 @@ struct activity memory_act = { .f_render = render_memory_stats, .f_xml_print = xml_print_memory_stats, .hdr_line = "frmpg/s;bufpg/s;campg/s|" - "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit|" + "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact|" "kbswpfree;kbswpused;%swpused;kbswpcad;%swpcad", .name = "A_MEMORY", #endif diff --git a/man/sar.in b/man/sar.in index 08e23a9..8eee9de 100644 --- a/man/sar.in +++ b/man/sar.in @@ -1688,7 +1688,18 @@ RAM/swap is needed to guarantee that there never is out of memory. .RS Percentage of memory needed for current workload in relation to the total amount of memory (RAM+swap). This number may be greater than 100% because the kernel usually overcommits memory. +.RE +.B kbactive +.RS +Amount of active memory in kilobytes (memory that has been used more recently +and usually not reclaimed unless absolutely necessary). +.RE + +.B kbinact +.RS +Amount of inactive memory in kilobytes (memory which has been less recently +used. It is more eligible to be reclaimed for other purposes). .RE .RE .IP -R diff --git a/pr_stats.c b/pr_stats.c index 73f7085..28b55a9 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -390,10 +390,12 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, *smc = (struct stats_memory *) a->buf[curr], *smp = (struct stats_memory *) a->buf[prev]; static unsigned long long - avg_frmkb = 0, - avg_bufkb = 0, - avg_camkb = 0, - avg_comkb = 0; + avg_frmkb = 0, + avg_bufkb = 0, + avg_camkb = 0, + avg_comkb = 0, + avg_activekb = 0, + avg_inactkb = 0; static unsigned long long avg_frskb = 0, avg_tlskb = 0, @@ -414,12 +416,12 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, if (DISPLAY_MEM_AMT(a->opt_flags)) { if (dis) { printf("\n%-11s kbmemfree kbmemused %%memused kbbuffers kbcached" - " kbcommit %%commit\n", timestamp[!curr]); + " kbcommit %%commit kbactive kbinact\n", timestamp[!curr]); } if (!dispavg) { /* Display instantaneous values */ - printf("%-11s %9lu %9lu %6.2f %9lu %9lu %9lu %7.2f\n", + printf("%-11s %9lu %9lu %6.2f %9lu %9lu %9lu %7.2f %9lu %9lu\n", timestamp[curr], smc->frmkb, smc->tlmkb - smc->frmkb, @@ -429,21 +431,25 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, smc->camkb, smc->comkb, (smc->tlmkb + smc->tlskb) ? - SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0); + SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0, + smc->activekb, + smc->inactkb); /* * Will be used to compute the average. * We assume that the total amount of memory installed can not vary * during the interval given on the command line. */ - avg_frmkb += smc->frmkb; - avg_bufkb += smc->bufkb; - avg_camkb += smc->camkb; - avg_comkb += smc->comkb; + avg_frmkb += smc->frmkb; + avg_bufkb += smc->bufkb; + avg_camkb += smc->camkb; + avg_comkb += smc->comkb; + avg_activekb += smc->activekb; + avg_inactkb += smc->inactkb; } else { /* Display average values */ - printf("%-11s %9.0f %9.0f %6.2f %9.0f %9.0f %9.0f %7.2f\n", + printf("%-11s %9.0f %9.0f %6.2f %9.0f %9.0f %9.0f %7.2f %9.0f %9.0f\n", timestamp[curr], (double) avg_frmkb / avg_count, (double) smc->tlmkb - ((double) avg_frmkb / avg_count), @@ -456,11 +462,13 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr, (double) avg_comkb / avg_count, (smc->tlmkb + smc->tlskb) ? SP_VALUE(0.0, (double) (avg_comkb / avg_count), - smc->tlmkb + smc->tlskb) : - 0.0); + smc->tlmkb + smc->tlskb) : 0.0, + (double) avg_activekb / avg_count, + (double) avg_inactkb / avg_count); /* Reset average counters */ avg_frmkb = avg_bufkb = avg_camkb = avg_comkb = 0; + avg_activekb = avg_inactkb = 0; } } diff --git a/rd_stats.c b/rd_stats.c index 9d78c63..9a1ad5f 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -335,6 +335,14 @@ void read_meminfo(struct stats_memory *st_memory) /* Read the amount of cached swap in kB */ sscanf(line + 11, "%lu", &st_memory->caskb); } + else if (!strncmp(line, "Active:", 7)) { + /* Read the amount of active memory in kB */ + sscanf(line + 7, "%lu", &st_memory->activekb); + } + else if (!strncmp(line, "Inactive:", 9)) { + /* Read the amount of inactive memory in kB */ + sscanf(line + 9, "%lu", &st_memory->inactkb); + } else if (!strncmp(line, "SwapTotal:", 10)) { /* Read the total amount of swap memory in kB */ sscanf(line + 10, "%lu", &st_memory->tlskb); diff --git a/rd_stats.h b/rd_stats.h index 90c224a..ff34359 100644 --- a/rd_stats.h +++ b/rd_stats.h @@ -152,6 +152,8 @@ struct stats_memory { unsigned long tlskb __attribute__ ((aligned (8))); unsigned long caskb __attribute__ ((aligned (8))); unsigned long comkb __attribute__ ((aligned (8))); + unsigned long activekb __attribute__ ((aligned (8))); + unsigned long inactkb __attribute__ ((aligned (8))); }; #define STATS_MEMORY_SIZE (sizeof(struct stats_memory)) diff --git a/rndr_stats.c b/rndr_stats.c index 33e8e58..866eff7 100644 --- a/rndr_stats.c +++ b/rndr_stats.c @@ -688,11 +688,19 @@ __print_funct_t render_memory_stats(struct activity *a, int isdb, char *pre, "-\tkbcommit", NULL, NULL, smc->comkb, DNOVAL); - render(isdb, pre, pt_newlin, + render(isdb, pre, PT_NOFLAG, "-\t%%commit", NULL, NULL, NOVAL, (smc->tlmkb + smc->tlskb) ? SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0); + + render(isdb, pre, PT_USEINT, + "-\tkbactive", NULL, NULL, + smc->activekb, DNOVAL); + + render(isdb, pre, PT_USEINT | pt_newlin, + "-\tkbinact", NULL, NULL, + smc->inactkb, DNOVAL); } if (DISPLAY_SWAP(a->opt_flags)) { diff --git a/xml/sysstat.dtd b/xml/sysstat.dtd index ad21c56..db1e44c 100644 --- a/xml/sysstat.dtd +++ b/xml/sysstat.dtd @@ -17,6 +17,8 @@ + + - + + + diff --git a/xml_stats.c b/xml_stats.c index 2b6dc9b..dade9c8 100644 --- a/xml_stats.c +++ b/xml_stats.c @@ -507,10 +507,16 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab, xprintf(tab, "%lu", smc->comkb); - xprintf(tab--, "%.2f", + xprintf(tab, "%.2f", (smc->tlmkb + smc->tlskb) ? SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0); + + xprintf(tab, "%lu", + smc->activekb); + + xprintf(tab--, "%lu", + smc->inactkb); } if (DISPLAY_SWAP(a->opt_flags)) { -- 2.40.0