]> arthur.barton.de Git - netdata.git/blobdiff - src/sys_fs_cgroup.c
lower the memory footprint of dimensions by 1.5KB
[netdata.git] / src / sys_fs_cgroup.c
index 21cd9a5e7a657a2adb40f06d81b1529e2afb7e37..d4ef28a9e02a13dde0f320c666ce36b53dbeca99 100644 (file)
@@ -49,92 +49,20 @@ static SIMPLE_PATTERN *enabled_cgroup_paths = NULL;
 static SIMPLE_PATTERN *enabled_cgroup_renames = NULL;
 static SIMPLE_PATTERN *systemd_services_cgroups = NULL;
 
-static char *cgroups_rename_script = PLUGINS_DIR "/cgroup-name.sh";
+static char *cgroups_rename_script = NULL;
 
 static uint32_t Read_hash = 0;
 static uint32_t Write_hash = 0;
-static uint32_t Sync_hash = 0;
-static uint32_t Async_hash = 0;
-static uint32_t Total_hash = 0;
 static uint32_t user_hash = 0;
 static uint32_t system_hash = 0;
-static uint32_t cache_hash = 0;
-static uint32_t rss_hash = 0;
-static uint32_t rss_huge_hash = 0;
-static uint32_t mapped_file_hash = 0;
-static uint32_t writeback_hash = 0;
-static uint32_t dirty_hash = 0;
-static uint32_t swap_hash = 0;
-static uint32_t pgpgin_hash = 0;
-static uint32_t pgpgout_hash = 0;
-static uint32_t pgfault_hash = 0;
-static uint32_t pgmajfault_hash = 0;
-static uint32_t inactive_anon_hash = 0;
-static uint32_t active_anon_hash = 0;
-static uint32_t inactive_file_hash = 0;
-static uint32_t active_file_hash = 0;
-static uint32_t unevictable_hash = 0;
-static uint32_t hierarchical_memory_limit_hash = 0;
-static uint32_t total_cache_hash = 0;
-static uint32_t total_rss_hash = 0;
-static uint32_t total_rss_huge_hash = 0;
-static uint32_t total_mapped_file_hash = 0;
-static uint32_t total_writeback_hash = 0;
-static uint32_t total_dirty_hash = 0;
-static uint32_t total_swap_hash = 0;
-static uint32_t total_pgpgin_hash = 0;
-static uint32_t total_pgpgout_hash = 0;
-static uint32_t total_pgfault_hash = 0;
-static uint32_t total_pgmajfault_hash = 0;
-static uint32_t total_inactive_anon_hash = 0;
-static uint32_t total_active_anon_hash = 0;
-static uint32_t total_inactive_file_hash = 0;
-static uint32_t total_active_file_hash = 0;
-static uint32_t total_unevictable_hash = 0;
 
 void read_cgroup_plugin_configuration() {
     system_page_size = sysconf(_SC_PAGESIZE);
 
     Read_hash = simple_hash("Read");
     Write_hash = simple_hash("Write");
-    Sync_hash = simple_hash("Sync");
-    Async_hash = simple_hash("Async");
-    Total_hash = simple_hash("Total");
     user_hash = simple_hash("user");
     system_hash = simple_hash("system");
-    cache_hash = simple_hash("cache");
-    rss_hash = simple_hash("rss");
-    rss_huge_hash = simple_hash("rss_huge");
-    mapped_file_hash = simple_hash("mapped_file");
-    writeback_hash = simple_hash("writeback");
-    dirty_hash = simple_hash("dirty");
-    swap_hash = simple_hash("swap");
-    pgpgin_hash = simple_hash("pgpgin");
-    pgpgout_hash = simple_hash("pgpgout");
-    pgfault_hash = simple_hash("pgfault");
-    pgmajfault_hash = simple_hash("pgmajfault");
-    inactive_anon_hash = simple_hash("inactive_anon");
-    active_anon_hash = simple_hash("active_anon");
-    inactive_file_hash = simple_hash("inactive_file");
-    active_file_hash = simple_hash("active_file");
-    unevictable_hash = simple_hash("unevictable");
-    hierarchical_memory_limit_hash = simple_hash("hierarchical_memory_limit");
-    total_cache_hash = simple_hash("total_cache");
-    total_rss_hash = simple_hash("total_rss");
-    total_rss_huge_hash = simple_hash("total_rss_huge");
-    total_mapped_file_hash = simple_hash("total_mapped_file");
-    total_writeback_hash = simple_hash("total_writeback");
-    total_dirty_hash = simple_hash("total_dirty");
-    total_swap_hash = simple_hash("total_swap");
-    total_pgpgin_hash = simple_hash("total_pgpgin");
-    total_pgpgout_hash = simple_hash("total_pgpgout");
-    total_pgfault_hash = simple_hash("total_pgfault");
-    total_pgmajfault_hash = simple_hash("total_pgmajfault");
-    total_inactive_anon_hash = simple_hash("total_inactive_anon");
-    total_active_anon_hash = simple_hash("total_active_anon");
-    total_inactive_file_hash = simple_hash("total_inactive_file");
-    total_active_file_hash = simple_hash("total_active_file");
-    total_unevictable_hash = simple_hash("total_unevictable");
 
     cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", rrd_update_every);
     if(cgroup_update_every < rrd_update_every)
@@ -177,7 +105,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/cpuacct";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
@@ -187,7 +115,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/blkio";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
@@ -197,7 +125,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/memory";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "devices");
@@ -207,7 +135,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/devices";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_devices_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/devices", filename);
 
     cgroup_root_max = (int)config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
@@ -217,6 +145,7 @@ void read_cgroup_plugin_configuration() {
 
     enabled_cgroup_patterns = simple_pattern_create(
             config_get("plugin:cgroups", "enable by default cgroups matching",
+                    " /system.slice/docker-*.scope "
                     " !*.mount "
                     " !*.partition "
                     " !*.scope "
@@ -248,10 +177,13 @@ void read_cgroup_plugin_configuration() {
                     " * "
             ), SIMPLE_PATTERN_EXACT);
 
-    cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", cgroups_rename_script);
+    snprintfz(filename, FILENAME_MAX, "%s/cgroup-name.sh", netdata_configured_plugins_dir);
+    cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", filename);
 
     enabled_cgroup_renames = simple_pattern_create(
             config_get("plugin:cgroups", "run script to rename cgroups matching",
+                    " *docker* "
+                    " *lxc* "
                     " !/ "
                     " !*.mount "
                     " !*.partition "
@@ -295,6 +227,10 @@ struct blkio {
 
 // https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
 struct memory {
+    ARL_BASE *arl_base;
+    ARL_ENTRY *arl_dirty;
+    ARL_ENTRY *arl_swap;
+
     int updated_detailed;
     int updated_usage_in_bytes;
     int updated_msw_usage_in_bytes;
@@ -438,8 +374,6 @@ struct cgroup {
     RRDDIM *rd_mem_detailed_rss;
     RRDDIM *rd_mem_detailed_mapped;
     RRDDIM *rd_mem_detailed_writeback;
-    RRDDIM *rd_mem_detailed_dirty;
-    RRDDIM *rd_mem_detailed_swap;
     RRDDIM *rd_mem_detailed_pgpgin;
     RRDDIM *rd_mem_detailed_pgpgout;
     RRDDIM *rd_mem_detailed_pgfault;
@@ -494,15 +428,11 @@ static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) {
             char *s = procfile_lineword(ff, i, 0);
             uint32_t hash = simple_hash(s);
 
-            if(unlikely(hash == user_hash && !strcmp(s, "user"))) {
-                cp->user = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+            if(unlikely(hash == user_hash && !strcmp(s, "user")))
+                cp->user = str2ull(procfile_lineword(ff, i, 1));
 
-            if(unlikely(hash == system_hash && !strcmp(s, "system"))) {
-                cp->system = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+            else if(unlikely(hash == system_hash && !strcmp(s, "system")))
+                cp->system = str2ull(procfile_lineword(ff, i, 1));
         }
 
         cp->updated = 1;
@@ -529,7 +459,7 @@ static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
         }
 
         if(unlikely(procfile_lines(ff) < 1)) {
-            error("File '%s' should have 1+ lines but has %u.", ca->filename, procfile_lines(ff));
+            error("File '%s' should have 1+ lines but has %zu.", ca->filename, procfile_lines(ff));
             ca->updated = 0;
             return;
         }
@@ -555,7 +485,7 @@ static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
 
         unsigned long long total = 0;
         for(i = 0; i < ca->cpus ;i++) {
-            unsigned long long n = strtoull(procfile_lineword(ff, 0, i), NULL, 10);
+            unsigned long long n = str2ull(procfile_lineword(ff, 0, i));
             ca->cpu_percpu[i] = n;
             total += n;
         }
@@ -608,31 +538,21 @@ static inline void cgroup_read_blkio(struct blkio *io) {
             char *s = procfile_lineword(ff, i, 1);
             uint32_t hash = simple_hash(s);
 
-            if(unlikely(hash == Read_hash && !strcmp(s, "Read"))) {
-                io->Read += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
-                continue;
-            }
+            if(unlikely(hash == Read_hash && !strcmp(s, "Read")))
+                io->Read += str2ull(procfile_lineword(ff, i, 2));
 
-            if(unlikely(hash == Write_hash && !strcmp(s, "Write"))) {
-                io->Write += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
-                continue;
-            }
+            else if(unlikely(hash == Write_hash && !strcmp(s, "Write")))
+                io->Write += str2ull(procfile_lineword(ff, i, 2));
 
 /*
-            if(hash == Sync_hash && !strcmp(s, "Sync")) {
-                io->Sync += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
-                continue;
-            }
+            else if(unlikely(hash == Sync_hash && !strcmp(s, "Sync")))
+                io->Sync += str2ull(procfile_lineword(ff, i, 2));
 
-            if(hash == Async_hash && !strcmp(s, "Async")) {
-                io->Async += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
-                continue;
-            }
+            else if(unlikely(hash == Async_hash && !strcmp(s, "Async")))
+                io->Async += str2ull(procfile_lineword(ff, i, 2));
 
-            if(hash == Total_hash && !strcmp(s, "Total")) {
-                io->Total += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
-                continue;
-            }
+            else if(unlikely(hash == Total_hash && !strcmp(s, "Total")))
+                io->Total += str2ull(procfile_lineword(ff, i, 2));
 */
         }
 
@@ -677,179 +597,35 @@ static inline void cgroup_read_memory(struct memory *mem) {
             goto memory_next;
         }
 
-        for(i = 0; i < lines ; i++) {
-            char *s = procfile_lineword(ff, i, 0);
-            uint32_t hash = simple_hash(s);
-
-            if(unlikely(hash == cache_hash && !strcmp(s, "cache"))) {
-                mem->cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == rss_hash && !strcmp(s, "rss"))) {
-                mem->rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == rss_huge_hash && !strcmp(s, "rss_huge"))) {
-                mem->rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == mapped_file_hash && !strcmp(s, "mapped_file"))) {
-                mem->mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == writeback_hash && !strcmp(s, "writeback"))) {
-                mem->writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+        if(unlikely(!mem->arl_base)) {
+            mem->arl_base = arl_create("cgroup/memory", NULL, 60);
 
-            if(unlikely(hash == dirty_hash && !strcmp(s, "dirty"))) {
-                mem->dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                mem->detailed_has_dirty = 1;
-                continue;
-            }
-
-            if(unlikely(hash == swap_hash && !strcmp(s, "swap"))) {
-                mem->swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                mem->detailed_has_swap = 1;
-                continue;
-            }
-
-            if(unlikely(hash == pgpgin_hash && !strcmp(s, "pgpgin"))) {
-                mem->pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == pgpgout_hash && !strcmp(s, "pgpgout"))) {
-                mem->pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == pgfault_hash && !strcmp(s, "pgfault"))) {
-                mem->pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == pgmajfault_hash && !strcmp(s, "pgmajfault"))) {
-                mem->pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-/*
-            if(unlikely(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))) {
-                mem->inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == active_anon_hash && !strcmp(s, "active_anon"))) {
-                mem->active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == inactive_file_hash && !strcmp(s, "inactive_file"))) {
-                mem->inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == active_file_hash && !strcmp(s, "active_file"))) {
-                mem->active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == unevictable_hash && !strcmp(s, "unevictable"))) {
-                mem->unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit"))) {
-                mem->hierarchical_memory_limit = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_cache_hash && !strcmp(s, "total_cache"))) {
-                mem->total_cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_rss_hash && !strcmp(s, "total_rss"))) {
-                mem->total_rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge"))) {
-                mem->total_rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file"))) {
-                mem->total_mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_writeback_hash && !strcmp(s, "total_writeback"))) {
-                mem->total_writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_dirty_hash && !strcmp(s, "total_dirty"))) {
-                mem->total_dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_swap_hash && !strcmp(s, "total_swap"))) {
-                mem->total_swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin"))) {
-                mem->total_pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout"))) {
-                mem->total_pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_pgfault_hash && !strcmp(s, "total_pgfault"))) {
-                mem->total_pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault"))) {
-                mem->total_pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-
-            if(unlikely(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon"))) {
-                mem->total_inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+            arl_expect(mem->arl_base, "cache", &mem->cache);
+            arl_expect(mem->arl_base, "rss", &mem->rss);
+            arl_expect(mem->arl_base, "rss_huge", &mem->rss_huge);
+            arl_expect(mem->arl_base, "mapped_file", &mem->mapped_file);
+            arl_expect(mem->arl_base, "writeback", &mem->writeback);
+            mem->arl_dirty = arl_expect(mem->arl_base, "dirty", &mem->dirty);
+            mem->arl_swap  = arl_expect(mem->arl_base, "swap", &mem->swap);
+            arl_expect(mem->arl_base, "pgpgin", &mem->pgpgin);
+            arl_expect(mem->arl_base, "pgpgout", &mem->pgpgout);
+            arl_expect(mem->arl_base, "pgfault", &mem->pgfault);
+            arl_expect(mem->arl_base, "pgmajfault", &mem->pgmajfault);
+        }
 
-            if(unlikely(hash == total_active_anon_hash && !strcmp(s, "total_active_anon"))) {
-                mem->total_active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+        arl_begin(mem->arl_base);
 
-            if(unlikely(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file"))) {
-                mem->total_inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+        for(i = 0; i < lines ; i++) {
+            if(arl_check(mem->arl_base,
+                    procfile_lineword(ff, i, 0),
+                    procfile_lineword(ff, i, 1))) break;
+        }
 
-            if(unlikely(hash == total_active_file_hash && !strcmp(s, "total_active_file"))) {
-                mem->total_active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
+        if(unlikely(mem->arl_dirty->flags & ARL_ENTRY_FLAG_FOUND))
+            mem->detailed_has_dirty = 1;
 
-            if(unlikely(hash == total_unevictable_hash && !strcmp(s, "total_unevictable"))) {
-                mem->total_unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
-                continue;
-            }
-*/
-        }
+        if(unlikely(mem->arl_swap->flags & ARL_ENTRY_FLAG_FOUND))
+            mem->detailed_has_swap = 1;
 
         // 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);
 
@@ -1110,6 +886,7 @@ static inline void cgroup_free(struct cgroup *cg) {
     freez(cg->cpuacct_stat.filename);
     freez(cg->cpuacct_usage.filename);
 
+    arl_free(cg->memory.arl_base);
     freez(cg->memory.filename_detailed);
     freez(cg->memory.filename_failcnt);
     freez(cg->memory.filename_usage_in_bytes);
@@ -1759,134 +1536,134 @@ void update_services_charts(int update_every,
 
         if(likely(do_cpu && cg->cpuacct_stat.updated)) {
             if(unlikely(!cg->rd_cpu))
-                cg->rd_cpu = rrddim_add(st_cpu, cg->chart_id, cg->chart_title, 100, hz, RRDDIM_INCREMENTAL);
+                cg->rd_cpu = rrddim_add(st_cpu, cg->chart_id, cg->chart_title, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_cpu, cg->rd_cpu, cg->cpuacct_stat.user + cg->cpuacct_stat.system);
         }
 
         if(likely(do_mem_usage && cg->memory.updated_usage_in_bytes)) {
             if(unlikely(!cg->rd_mem_usage))
-                cg->rd_mem_usage = rrddim_add(st_mem_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_mem_usage = rrddim_add(st_mem_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
 
             rrddim_set_by_pointer(st_mem_usage, cg->rd_mem_usage, cg->memory.usage_in_bytes - ((cgroup_used_memory_without_cache)?cg->memory.cache:0));
         }
 
         if(likely(do_mem_detailed && cg->memory.updated_detailed)) {
             if(unlikely(!cg->rd_mem_detailed_rss))
-                cg->rd_mem_detailed_rss = rrddim_add(st_mem_detailed_rss, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_mem_detailed_rss = rrddim_add(st_mem_detailed_rss, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             rrddim_set_by_pointer(st_mem_detailed_rss, cg->rd_mem_detailed_rss, cg->memory.rss + cg->memory.rss_huge);
 
             if(unlikely(!cg->rd_mem_detailed_mapped))
-                cg->rd_mem_detailed_mapped = rrddim_add(st_mem_detailed_mapped, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_mem_detailed_mapped = rrddim_add(st_mem_detailed_mapped, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             rrddim_set_by_pointer(st_mem_detailed_mapped, cg->rd_mem_detailed_mapped, cg->memory.mapped_file);
 
             if(unlikely(!cg->rd_mem_detailed_cache))
-                cg->rd_mem_detailed_cache = rrddim_add(st_mem_detailed_cache, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_mem_detailed_cache = rrddim_add(st_mem_detailed_cache, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             rrddim_set_by_pointer(st_mem_detailed_cache, cg->rd_mem_detailed_cache, cg->memory.cache);
 
             if(unlikely(!cg->rd_mem_detailed_writeback))
-                cg->rd_mem_detailed_writeback = rrddim_add(st_mem_detailed_writeback, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_mem_detailed_writeback = rrddim_add(st_mem_detailed_writeback, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             rrddim_set_by_pointer(st_mem_detailed_writeback, cg->rd_mem_detailed_writeback, cg->memory.writeback);
 
             if(unlikely(!cg->rd_mem_detailed_pgfault))
-                cg->rd_mem_detailed_pgfault = rrddim_add(st_mem_detailed_pgfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                cg->rd_mem_detailed_pgfault = rrddim_add(st_mem_detailed_pgfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             rrddim_set_by_pointer(st_mem_detailed_pgfault, cg->rd_mem_detailed_pgfault, cg->memory.pgfault);
 
             if(unlikely(!cg->rd_mem_detailed_pgmajfault))
-                cg->rd_mem_detailed_pgmajfault = rrddim_add(st_mem_detailed_pgmajfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                cg->rd_mem_detailed_pgmajfault = rrddim_add(st_mem_detailed_pgmajfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             rrddim_set_by_pointer(st_mem_detailed_pgmajfault, cg->rd_mem_detailed_pgmajfault, cg->memory.pgmajfault);
 
             if(unlikely(!cg->rd_mem_detailed_pgpgin))
-                cg->rd_mem_detailed_pgpgin = rrddim_add(st_mem_detailed_pgpgin, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                cg->rd_mem_detailed_pgpgin = rrddim_add(st_mem_detailed_pgpgin, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             rrddim_set_by_pointer(st_mem_detailed_pgpgin, cg->rd_mem_detailed_pgpgin, cg->memory.pgpgin);
 
             if(unlikely(!cg->rd_mem_detailed_pgpgout))
-                cg->rd_mem_detailed_pgpgout = rrddim_add(st_mem_detailed_pgpgout, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                cg->rd_mem_detailed_pgpgout = rrddim_add(st_mem_detailed_pgpgout, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             rrddim_set_by_pointer(st_mem_detailed_pgpgout, cg->rd_mem_detailed_pgpgout, cg->memory.pgpgout);
         }
 
         if(likely(do_mem_failcnt && cg->memory.updated_failcnt)) {
             if(unlikely(!cg->rd_mem_failcnt))
-                cg->rd_mem_failcnt = rrddim_add(st_mem_failcnt, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_mem_failcnt = rrddim_add(st_mem_failcnt, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_mem_failcnt, cg->rd_mem_failcnt, cg->memory.failcnt);
         }
 
         if(likely(do_swap_usage && cg->memory.updated_msw_usage_in_bytes)) {
             if(unlikely(!cg->rd_swap_usage))
-                cg->rd_swap_usage = rrddim_add(st_swap_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                cg->rd_swap_usage = rrddim_add(st_swap_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
 
             rrddim_set_by_pointer(st_swap_usage, cg->rd_swap_usage, cg->memory.msw_usage_in_bytes);
         }
 
         if(likely(do_io && cg->io_service_bytes.updated)) {
             if(unlikely(!cg->rd_io_service_bytes_read))
-                cg->rd_io_service_bytes_read = rrddim_add(st_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_INCREMENTAL);
+                cg->rd_io_service_bytes_read = rrddim_add(st_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_io_read, cg->rd_io_service_bytes_read, cg->io_service_bytes.Read);
 
             if(unlikely(!cg->rd_io_service_bytes_write))
-                cg->rd_io_service_bytes_write = rrddim_add(st_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_INCREMENTAL);
+                cg->rd_io_service_bytes_write = rrddim_add(st_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_io_write, cg->rd_io_service_bytes_write, cg->io_service_bytes.Write);
         }
 
         if(likely(do_io_ops && cg->io_serviced.updated)) {
             if(unlikely(!cg->rd_io_serviced_read))
-                cg->rd_io_serviced_read = rrddim_add(st_io_serviced_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_serviced_read = rrddim_add(st_io_serviced_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_io_serviced_read, cg->rd_io_serviced_read, cg->io_serviced.Read);
 
             if(unlikely(!cg->rd_io_serviced_write))
-                cg->rd_io_serviced_write = rrddim_add(st_io_serviced_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_serviced_write = rrddim_add(st_io_serviced_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_io_serviced_write, cg->rd_io_serviced_write, cg->io_serviced.Write);
         }
 
         if(likely(do_throttle_io && cg->throttle_io_service_bytes.updated)) {
             if(unlikely(!cg->rd_throttle_io_read))
-                cg->rd_throttle_io_read = rrddim_add(st_throttle_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_INCREMENTAL);
+                cg->rd_throttle_io_read = rrddim_add(st_throttle_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_throttle_io_read, cg->rd_throttle_io_read, cg->throttle_io_service_bytes.Read);
 
             if(unlikely(!cg->rd_throttle_io_write))
-                cg->rd_throttle_io_write = rrddim_add(st_throttle_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_INCREMENTAL);
+                cg->rd_throttle_io_write = rrddim_add(st_throttle_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_throttle_io_write, cg->rd_throttle_io_write, cg->throttle_io_service_bytes.Write);
         }
 
         if(likely(do_throttle_ops && cg->throttle_io_serviced.updated)) {
             if(unlikely(!cg->rd_throttle_io_serviced_read))
-                cg->rd_throttle_io_serviced_read = rrddim_add(st_throttle_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_throttle_io_serviced_read = rrddim_add(st_throttle_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_throttle_ops_read, cg->rd_throttle_io_serviced_read, cg->throttle_io_serviced.Read);
 
             if(unlikely(!cg->rd_throttle_io_serviced_write))
-                cg->rd_throttle_io_serviced_write = rrddim_add(st_throttle_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_throttle_io_serviced_write = rrddim_add(st_throttle_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_throttle_ops_write, cg->rd_throttle_io_serviced_write, cg->throttle_io_serviced.Write);
         }
 
         if(likely(do_queued_ops && cg->io_queued.updated)) {
             if(unlikely(!cg->rd_io_queued_read))
-                cg->rd_io_queued_read = rrddim_add(st_queued_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_queued_read = rrddim_add(st_queued_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_queued_ops_read, cg->rd_io_queued_read, cg->io_queued.Read);
 
             if(unlikely(!cg->rd_io_queued_write))
-                cg->rd_io_queued_write = rrddim_add(st_queued_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_queued_write = rrddim_add(st_queued_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_queued_ops_write, cg->rd_io_queued_write, cg->io_queued.Write);
         }
 
         if(likely(do_merged_ops && cg->io_merged.updated)) {
             if(unlikely(!cg->rd_io_merged_read))
-                cg->rd_io_merged_read = rrddim_add(st_merged_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_merged_read = rrddim_add(st_merged_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_merged_ops_read, cg->rd_io_merged_read, cg->io_merged.Read);
 
             if(unlikely(!cg->rd_io_merged_write))
-                cg->rd_io_merged_write = rrddim_add(st_merged_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_INCREMENTAL);
+                cg->rd_io_merged_write = rrddim_add(st_merged_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
 
             rrddim_set_by_pointer(st_merged_ops_write, cg->rd_io_merged_write, cg->io_merged.Write);
         }
@@ -2008,8 +1785,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "CPU Usage (%d%% = %d core%s) for cgroup %s", (processors * 100), processors, (processors > 1) ? "s" : "", cg->chart_title);
                     cg->st_cpu = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", CHART_PRIORITY_CONTAINERS, update_every, RRDSET_TYPE_STACKED);
                 }
-                rrddim_add(cg->st_cpu, "user", NULL, 100, hz, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_cpu, "system", NULL, 100, hz, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_cpu, "user", NULL, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_cpu, "system", NULL, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_cpu);
@@ -2031,7 +1808,7 @@ void update_cgroup_charts(int update_every) {
                 }
                 for(i = 0; i < cg->cpuacct_usage.cpus; i++) {
                     snprintfz(id, CHART_TITLE_MAX, "cpu%u", i);
-                    rrddim_add(cg->st_cpu_per_core, id, NULL, 100, 1000000000, RRDDIM_INCREMENTAL);
+                    rrddim_add(cg->st_cpu_per_core, id, NULL, 100, 1000000000, RRDDIM_ALGORITHM_INCREMENTAL);
                 }
             }
             else
@@ -2052,12 +1829,12 @@ void update_cgroup_charts(int update_every) {
                     cg->st_mem = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", CHART_PRIORITY_CONTAINERS + 210, update_every, RRDSET_TYPE_STACKED);
                 }
 
-                rrddim_add(cg->st_mem, "cache", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_mem, "rss", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                rrddim_add(cg->st_mem, "cache", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_mem, "rss", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
                 if(cg->memory.detailed_has_swap)
-                    rrddim_add(cg->st_mem, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_mem, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_mem, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                    rrddim_add(cg->st_mem, "swap", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_mem, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_mem, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             }
             else
                 rrdset_next(cg->st_mem);
@@ -2078,8 +1855,8 @@ void update_cgroup_charts(int update_every) {
                 }
 
                 if(cg->memory.detailed_has_dirty)
-                    rrddim_add(cg->st_writeback, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_writeback, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                    rrddim_add(cg->st_writeback, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_writeback, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             }
             else
                 rrdset_next(cg->st_writeback);
@@ -2095,8 +1872,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
                     cg->st_mem_activity = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s", CHART_PRIORITY_CONTAINERS + 400, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_mem_activity, "pgpgin", "in", system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_mem_activity, "pgpgout", "out", -system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_mem_activity, "pgpgin", "in", system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_mem_activity, "pgpgout", "out", -system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_mem_activity);
@@ -2111,8 +1888,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
                     cg->st_pgfaults = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", CHART_PRIORITY_CONTAINERS + 500, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_pgfaults, "pgfault", NULL, system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_pgfaults, "pgmajfault", "swap", -system_page_size, 1024 * 1024, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_pgfaults, "pgfault", NULL, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_pgfaults, "pgmajfault", "swap", -system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_pgfaults);
@@ -2129,8 +1906,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Used Memory %sfor cgroup %s", (cgroup_used_memory_without_cache && cg->memory.updated_detailed)?"without Cache ":"", cg->chart_title);
                     cg->st_mem_usage = rrdset_create(type, "mem_usage", NULL, "mem", "cgroup.mem_usage", title, "MB", CHART_PRIORITY_CONTAINERS + 200, update_every, RRDSET_TYPE_STACKED);
                 }
-                rrddim_add(cg->st_mem_usage, "ram", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_mem_usage, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
+                rrddim_add(cg->st_mem_usage, "ram", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_mem_usage, "swap", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
             }
             else
                 rrdset_next(cg->st_mem_usage);
@@ -2147,7 +1924,7 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Memory Limit Failures for cgroup %s", cg->chart_title);
                     cg->st_mem_failcnt = rrdset_create(type, "mem_failcnt", NULL, "mem", "cgroup.mem_failcnt", title, "count", CHART_PRIORITY_CONTAINERS + 250, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_mem_failcnt, "failures", NULL, 1, 1, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_mem_failcnt, "failures", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_mem_failcnt);
@@ -2163,8 +1940,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
                     cg->st_io = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_AREA);
                 }
-                rrddim_add(cg->st_io, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_io, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_io, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_io, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_io);
@@ -2181,8 +1958,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
                     cg->st_serviced_ops = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_serviced_ops, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_serviced_ops, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_serviced_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_serviced_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_serviced_ops);
@@ -2199,8 +1976,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
                     cg->st_throttle_io = rrdset_create(type, "throttle_io", NULL, "disk", "cgroup.throttle_io", title, "KB/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_AREA);
                 }
-                rrddim_add(cg->st_throttle_io, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_throttle_io, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_throttle_io, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_throttle_io, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_throttle_io);
@@ -2217,8 +1994,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
                     cg->st_throttle_serviced_ops = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_throttle_serviced_ops, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_throttle_serviced_ops, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_throttle_serviced_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_throttle_serviced_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_throttle_serviced_ops);
@@ -2235,8 +2012,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
                     cg->st_queued_ops = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", CHART_PRIORITY_CONTAINERS + 2000, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_queued_ops, "read", NULL, 1, 1, RRDDIM_ABSOLUTE);
-                rrddim_add(cg->st_queued_ops, "write", NULL, -1, 1, RRDDIM_ABSOLUTE);
+                rrddim_add(cg->st_queued_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
+                rrddim_add(cg->st_queued_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
             }
             else
                 rrdset_next(cg->st_queued_ops);
@@ -2253,8 +2030,8 @@ void update_cgroup_charts(int update_every) {
                     snprintfz(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
                     cg->st_merged_ops = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 2100, update_every, RRDSET_TYPE_LINE);
                 }
-                rrddim_add(cg->st_merged_ops, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
-                rrddim_add(cg->st_merged_ops, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
+                rrddim_add(cg->st_merged_ops, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(cg->st_merged_ops, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(cg->st_merged_ops);
@@ -2306,24 +2083,20 @@ void *cgroups_main(void *ptr) {
 
     RRDSET *stcpu_thread = NULL;
 
+    heartbeat_t hb;
+    heartbeat_init(&hb);
     usec_t step = cgroup_update_every * USEC_PER_SEC;
-    usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_next = 0;
+    usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_dt = 0;
     for(;;) {
-        usec_t now = now_monotonic_usec();
-        usec_t next = now - (now % step) + step;
-
-        while(now < next) {
-            sleep_usec(next - now);
-            now = now_monotonic_usec();
-        }
-
+        usec_t hb_dt = heartbeat_next(&hb, step);
         if(unlikely(netdata_exit)) break;
 
         // BEGIN -- the job to be done
 
-        if(unlikely(now >= find_next)) {
+        find_dt += hb_dt;
+        if(unlikely(find_dt >= find_every)) {
             find_all_cgroups();
-            find_next = now + find_every;
+            find_dt = 0;
         }
 
         read_all_cgroups(cgroup_root);
@@ -2341,8 +2114,8 @@ void *cgroups_main(void *ptr) {
                 if(unlikely(!stcpu_thread))
                     stcpu_thread = rrdset_create("netdata", "plugin_cgroups_cpu", NULL, "cgroups", NULL, "NetData CGroups Plugin CPU usage", "milliseconds/s", 132000, cgroup_update_every, RRDSET_TYPE_STACKED);
 
-                rrddim_add(stcpu_thread, "user",  NULL,  1, 1000, RRDDIM_INCREMENTAL);
-                rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
+                rrddim_add(stcpu_thread, "user",  NULL,  1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
+                rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
             }
             else
                 rrdset_next(stcpu_thread);