added dirty and swap to cgroup
Costa Tsaousis (ktsaou) committed
Apr 24, 2016 at 22:30 UTC
4f70e286e364acf64a5cea254652938b4a81f392
1 file changed
+47
-5
src/sys_fs_cgroup.c
+47
-5
@@ -77,16 +77,21 @@ struct memory {
77
78
char *filename;
79
80
+ int has_dirty_swap;
81
+
82
unsigned long long cache;
83
unsigned long long rss;
84
unsigned long long rss_huge;
85
unsigned long long mapped_file;
86
unsigned long long writeback;
87
+ unsigned long long dirty;
88
+ unsigned long long swap;
89
unsigned long long pgpgin;
90
unsigned long long pgpgout;
91
unsigned long long pgfault;
92
unsigned long long pgmajfault;
89
-/* unsigned long long inactive_anon;
93
+/*
94
+ unsigned long long inactive_anon;
95
unsigned long long active_anon;
96
unsigned long long inactive_file;
97
unsigned long long active_file;
@@ -97,6 +102,8 @@ struct memory {
102
unsigned long long total_rss_huge;
103
unsigned long long total_mapped_file;
104
unsigned long long total_writeback;
105
+ unsigned long long total_dirty;
106
+ unsigned long long total_swap;
107
unsigned long long total_pgpgin;
108
unsigned long long total_pgpgout;
109
unsigned long long total_pgfault;
@@ -317,11 +324,14 @@ void cgroup_read_memory(struct memory *mem) {
324
static uint32_t rss_huge_hash = 0;
325
static uint32_t mapped_file_hash = 0;
326
static uint32_t writeback_hash = 0;
327
+ static uint32_t dirty_hash = 0;
328
+ static uint32_t swap_hash = 0;
329
static uint32_t pgpgin_hash = 0;
330
static uint32_t pgpgout_hash = 0;
331
static uint32_t pgfault_hash = 0;
332
static uint32_t pgmajfault_hash = 0;
324
-/* static uint32_t inactive_anon_hash = 0;
333
+/*
334
+ static uint32_t inactive_anon_hash = 0;
335
static uint32_t active_anon_hash = 0;
336
static uint32_t inactive_file_hash = 0;
337
static uint32_t active_file_hash = 0;
@@ -332,6 +342,8 @@ void cgroup_read_memory(struct memory *mem) {
342
static uint32_t total_rss_huge_hash = 0;
343
static uint32_t total_mapped_file_hash = 0;
344
static uint32_t total_writeback_hash = 0;
345
+ static uint32_t total_dirty_hash = 0;
346
+ static uint32_t total_swap_hash = 0;
347
static uint32_t total_pgpgin_hash = 0;
348
static uint32_t total_pgpgout_hash = 0;
349
static uint32_t total_pgfault_hash = 0;
@@ -348,11 +360,14 @@ void cgroup_read_memory(struct memory *mem) {
360
rss_huge_hash = simple_hash("rss_huge");
361
mapped_file_hash = simple_hash("mapped_file");
362
writeback_hash = simple_hash("writeback");
363
+ dirty_hash = simple_hash("dirty");
364
+ swap_hash = simple_hash("swap");
365
pgpgin_hash = simple_hash("pgpgin");
366
pgpgout_hash = simple_hash("pgpgout");
367
pgfault_hash = simple_hash("pgfault");
368
pgmajfault_hash = simple_hash("pgmajfault");
355
-/* inactive_anon_hash = simple_hash("inactive_anon");
369
+/*
370
+ inactive_anon_hash = simple_hash("inactive_anon");
371
active_anon_hash = simple_hash("active_anon");
372
inactive_file_hash = simple_hash("inactive_file");
373
active_file_hash = simple_hash("active_file");
@@ -363,6 +378,8 @@ void cgroup_read_memory(struct memory *mem) {
378
total_rss_huge_hash = simple_hash("total_rss_huge");
379
total_mapped_file_hash = simple_hash("total_mapped_file");
380
total_writeback_hash = simple_hash("total_writeback");
381
+ total_dirty_hash = simple_hash("total_dirty");
382
+ total_swap_hash = simple_hash("total_swap");
383
total_pgpgin_hash = simple_hash("total_pgpgin");
384
total_pgpgout_hash = simple_hash("total_pgpgout");
385
total_pgfault_hash = simple_hash("total_pgfault");
@@ -409,6 +426,16 @@ void cgroup_read_memory(struct memory *mem) {
426
else if(hash == writeback_hash && !strcmp(s, "writeback"))
427
mem->writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
428
429
+ else if(hash == dirty_hash && !strcmp(s, "dirty")) {
430
+ mem->dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
431
+ mem->has_dirty_swap = 1;
432
+ }
433
+
434
+ else if(hash == swap_hash && !strcmp(s, "swap")) {
435
+ mem->swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
436
+ mem->has_dirty_swap = 1;
437
+ }
438
+
439
else if(hash == pgpgin_hash && !strcmp(s, "pgpgin"))
440
mem->pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
441
@@ -421,7 +448,8 @@ void cgroup_read_memory(struct memory *mem) {
448
else if(hash == pgmajfault_hash && !strcmp(s, "pgmajfault"))
449
mem->pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
450
424
-/* else if(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))
451
+/*
452
+ else if(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))
453
mem->inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
454
455
else if(hash == active_anon_hash && !strcmp(s, "active_anon"))
@@ -454,6 +482,12 @@ void cgroup_read_memory(struct memory *mem) {
482
else if(hash == total_writeback_hash && !strcmp(s, "total_writeback"))
483
mem->total_writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
484
485
+ else if(hash == total_dirty_hash && !strcmp(s, "total_dirty"))
486
+ mem->total_dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
487
+
488
+ else if(hash == total_swap_hash && !strcmp(s, "total_swap"))
489
+ mem->total_swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
490
+
491
else if(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin"))
492
mem->total_pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
493
@@ -483,7 +517,7 @@ void cgroup_read_memory(struct memory *mem) {
517
*/
518
}
519
486
- // fprintf(stderr, "READ: '%s', cache: %llu, rss: %llu, rss_huge: %llu, mapped_file: %llu, writeback: %llu, pgpgin: %llu, pgpgout: %llu, pgfault: %llu, pgmajfault: %llu, inactive_anon: %llu, active_anon: %llu, inactive_file: %llu, active_file: %llu, unevictable: %llu, hierarchical_memory_limit: %llu, total_cache: %llu, total_rss: %llu, total_rss_huge: %llu, total_mapped_file: %llu, total_writeback: %llu, total_pgpgin: %llu, total_pgpgout: %llu, total_pgfault: %llu, total_pgmajfault: %llu, total_inactive_anon: %llu, total_active_anon: %llu, total_inactive_file: %llu, total_active_file: %llu, total_unevictable: %llu\n", mem->filename, mem->cache, mem->rss, mem->rss_huge, mem->mapped_file, mem->writeback, mem->pgpgin, mem->pgpgout, mem->pgfault, mem->pgmajfault, mem->inactive_anon, mem->active_anon, mem->inactive_file, mem->active_file, mem->unevictable, mem->hierarchical_memory_limit, mem->total_cache, mem->total_rss, mem->total_rss_huge, mem->total_mapped_file, mem->total_writeback, mem->total_pgpgin, mem->total_pgpgout, mem->total_pgfault, mem->total_pgmajfault, mem->total_inactive_anon, mem->total_active_anon, mem->total_inactive_file, mem->total_active_file, mem->total_unevictable);
520
+ // fprintf(stderr, "READ: '%s', cache: %llu, rss: %llu, rss_huge: %llu, mapped_file: %llu, writeback: %llu, dirty: %llu, swap: %llu, pgpgin: %llu, pgpgout: %llu, pgfault: %llu, pgmajfault: %llu, inactive_anon: %llu, active_anon: %llu, inactive_file: %llu, active_file: %llu, unevictable: %llu, hierarchical_memory_limit: %llu, total_cache: %llu, total_rss: %llu, total_rss_huge: %llu, total_mapped_file: %llu, total_writeback: %llu, total_dirty: %llu, total_swap: %llu, total_pgpgin: %llu, total_pgpgout: %llu, total_pgfault: %llu, total_pgmajfault: %llu, total_inactive_anon: %llu, total_active_anon: %llu, total_inactive_file: %llu, total_active_file: %llu, total_unevictable: %llu\n", mem->filename, mem->cache, mem->rss, mem->rss_huge, mem->mapped_file, mem->writeback, mem->dirty, mem->swap, mem->pgpgin, mem->pgpgout, mem->pgfault, mem->pgmajfault, mem->inactive_anon, mem->active_anon, mem->inactive_file, mem->active_file, mem->unevictable, mem->hierarchical_memory_limit, mem->total_cache, mem->total_rss, mem->total_rss_huge, mem->total_mapped_file, mem->total_writeback, mem->total_dirty, mem->total_swap, mem->total_pgpgin, mem->total_pgpgout, mem->total_pgfault, mem->total_pgmajfault, mem->total_inactive_anon, mem->total_active_anon, mem->total_inactive_file, mem->total_active_file, mem->total_unevictable);
521
522
mem->updated = 1;
523
}
@@ -829,6 +863,8 @@ void update_cgroup_charts(int update_every) {
863
864
rrddim_add(st, "cache", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
865
rrddim_add(st, "rss", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
866
+ if(cg->memory.has_dirty_swap)
867
+ rrddim_add(st, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
868
rrddim_add(st, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
869
rrddim_add(st, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
870
}
@@ -836,6 +872,8 @@ void update_cgroup_charts(int update_every) {
872
873
rrddim_set(st, "cache", cg->memory.cache);
874
rrddim_set(st, "rss", cg->memory.rss);
875
+ if(cg->memory.has_dirty_swap)
876
+ rrddim_set(st, "swap", cg->memory.swap);
877
rrddim_set(st, "rss_huge", cg->memory.rss_huge);
878
rrddim_set(st, "mapped_file", cg->memory.mapped_file);
879
rrdset_done(st);
@@ -847,10 +885,14 @@ void update_cgroup_charts(int update_every) {
885
st = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", 40300,
886
update_every, RRDSET_TYPE_AREA);
887
888
+ if(cg->memory.has_dirty_swap)
889
+ rrddim_add(st, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
890
rrddim_add(st, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
891
}
892
else rrdset_next(st);
893
894
+ if(cg->memory.has_dirty_swap)
895
+ rrddim_set(st, "dirty", cg->memory.dirty);
896
rrddim_set(st, "writeback", cg->memory.writeback);
897
rrdset_done(st);
898