]> arthur.barton.de Git - netdata.git/blobdiff - src/proc_vmstat.c
improvements identified via static code analysis with cppcheck
[netdata.git] / src / proc_vmstat.c
index 5f4e5aaddd7fb124af88c0ac0fc21be516c3f2cb..a8058398409077a2db021c43405e6794e0cc2672 100644 (file)
 #include "common.h"
 
 int do_proc_vmstat(int update_every, unsigned long long dt) {
+    (void)dt;
+
     static procfile *ff = NULL;
-    static int do_swapio = -1, do_io = -1, do_pgfaults = -1, gen_hashes = -1;
+    static int do_swapio = -1, do_io = -1, do_pgfaults = -1;
+
+    // static uint32_t hash_allocstall = 0;
+    // static uint32_t hash_compact_blocks_moved = 0;
+    // static uint32_t hash_compact_fail = 0;
+    // static uint32_t hash_compact_pagemigrate_failed = 0;
+    // static uint32_t hash_compact_pages_moved = 0;
+    // static uint32_t hash_compact_stall = 0;
+    // static uint32_t hash_compact_success = 0;
+    // static uint32_t hash_htlb_buddy_alloc_fail = 0;
+    // static uint32_t hash_htlb_buddy_alloc_success = 0;
+    // static uint32_t hash_kswapd_high_wmark_hit_quickly = 0;
+    // static uint32_t hash_kswapd_inodesteal = 0;
+    // static uint32_t hash_kswapd_low_wmark_hit_quickly = 0;
+    // static uint32_t hash_kswapd_skip_congestion_wait = 0;
+    // static uint32_t hash_nr_active_anon = 0;
+    // static uint32_t hash_nr_active_file = 0;
+    // static uint32_t hash_nr_anon_pages = 0;
+    // static uint32_t hash_nr_anon_transparent_hugepages = 0;
+    // static uint32_t hash_nr_bounce = 0;
+    // static uint32_t hash_nr_dirtied = 0;
+    // static uint32_t hash_nr_dirty = 0;
+    // static uint32_t hash_nr_dirty_background_threshold = 0;
+    // static uint32_t hash_nr_dirty_threshold = 0;
+    // static uint32_t hash_nr_file_pages = 0;
+    // static uint32_t hash_nr_free_pages = 0;
+    // static uint32_t hash_nr_inactive_anon = 0;
+    // static uint32_t hash_nr_inactive_file = 0;
+    // static uint32_t hash_nr_isolated_anon = 0;
+    // static uint32_t hash_nr_isolated_file = 0;
+    // static uint32_t hash_nr_kernel_stack = 0;
+    // static uint32_t hash_nr_mapped = 0;
+    // static uint32_t hash_nr_mlock = 0;
+    // static uint32_t hash_nr_page_table_pages = 0;
+    // static uint32_t hash_nr_shmem = 0;
+    // static uint32_t hash_nr_slab_reclaimable = 0;
+    // static uint32_t hash_nr_slab_unreclaimable = 0;
+    // static uint32_t hash_nr_unevictable = 0;
+    // static uint32_t hash_nr_unstable = 0;
+    // static uint32_t hash_nr_vmscan_immediate_reclaim = 0;
+    // static uint32_t hash_nr_vmscan_write = 0;
+    // static uint32_t hash_nr_writeback = 0;
+    // static uint32_t hash_nr_writeback_temp = 0;
+    // static uint32_t hash_nr_written = 0;
+    // static uint32_t hash_pageoutrun = 0;
+    // static uint32_t hash_pgactivate = 0;
+    // static uint32_t hash_pgalloc_dma = 0;
+    // static uint32_t hash_pgalloc_dma32 = 0;
+    // static uint32_t hash_pgalloc_movable = 0;
+    // static uint32_t hash_pgalloc_normal = 0;
+    // static uint32_t hash_pgdeactivate = 0;
+    static uint32_t hash_pgfault = 0;
+    // static uint32_t hash_pgfree = 0;
+    // static uint32_t hash_pginodesteal = 0;
+    static uint32_t hash_pgmajfault = 0;
+    static uint32_t hash_pgpgin = 0;
+    static uint32_t hash_pgpgout = 0;
+    // static uint32_t hash_pgrefill_dma = 0;
+    // static uint32_t hash_pgrefill_dma32 = 0;
+    // static uint32_t hash_pgrefill_movable = 0;
+    // static uint32_t hash_pgrefill_normal = 0;
+    // static uint32_t hash_pgrotated = 0;
+    // static uint32_t hash_pgscan_direct_dma = 0;
+    // static uint32_t hash_pgscan_direct_dma32 = 0;
+    // static uint32_t hash_pgscan_direct_movable = 0;
+    // static uint32_t hash_pgscan_direct_normal = 0;
+    // static uint32_t hash_pgscan_kswapd_dma = 0;
+    // static uint32_t hash_pgscan_kswapd_dma32 = 0;
+    // static uint32_t hash_pgscan_kswapd_movable = 0;
+    // static uint32_t hash_pgscan_kswapd_normal = 0;
+    // static uint32_t hash_pgsteal_direct_dma = 0;
+    // static uint32_t hash_pgsteal_direct_dma32 = 0;
+    // static uint32_t hash_pgsteal_direct_movable = 0;
+    // static uint32_t hash_pgsteal_direct_normal = 0;
+    // static uint32_t hash_pgsteal_kswapd_dma = 0;
+    // static uint32_t hash_pgsteal_kswapd_dma32 = 0;
+    // static uint32_t hash_pgsteal_kswapd_movable = 0;
+    // static uint32_t hash_pgsteal_kswapd_normal = 0;
+    static uint32_t hash_pswpin = 0;
+    static uint32_t hash_pswpout = 0;
+    // static uint32_t hash_slabs_scanned = 0;
+    // static uint32_t hash_thp_collapse_alloc = 0;
+    // static uint32_t hash_thp_collapse_alloc_failed = 0;
+    // static uint32_t hash_thp_fault_alloc = 0;
+    // static uint32_t hash_thp_fault_fallback = 0;
+    // static uint32_t hash_thp_split = 0;
+    // static uint32_t hash_unevictable_pgs_cleared = 0;
+    // static uint32_t hash_unevictable_pgs_culled = 0;
+    // static uint32_t hash_unevictable_pgs_mlocked = 0;
+    // static uint32_t hash_unevictable_pgs_mlockfreed = 0;
+    // static uint32_t hash_unevictable_pgs_munlocked = 0;
+    // static uint32_t hash_unevictable_pgs_rescued = 0;
+    // static uint32_t hash_unevictable_pgs_scanned = 0;
+    // static uint32_t hash_unevictable_pgs_stranded = 0;
 
-    // static uint32_t hash_allocstall = -1;
-    // static uint32_t hash_compact_blocks_moved = -1;
-    // static uint32_t hash_compact_fail = -1;
-    // static uint32_t hash_compact_pagemigrate_failed = -1;
-    // static uint32_t hash_compact_pages_moved = -1;
-    // static uint32_t hash_compact_stall = -1;
-    // static uint32_t hash_compact_success = -1;
-    // static uint32_t hash_htlb_buddy_alloc_fail = -1;
-    // static uint32_t hash_htlb_buddy_alloc_success = -1;
-    // static uint32_t hash_kswapd_high_wmark_hit_quickly = -1;
-    // static uint32_t hash_kswapd_inodesteal = -1;
-    // static uint32_t hash_kswapd_low_wmark_hit_quickly = -1;
-    // static uint32_t hash_kswapd_skip_congestion_wait = -1;
-    // static uint32_t hash_nr_active_anon = -1;
-    // static uint32_t hash_nr_active_file = -1;
-    // static uint32_t hash_nr_anon_pages = -1;
-    // static uint32_t hash_nr_anon_transparent_hugepages = -1;
-    // static uint32_t hash_nr_bounce = -1;
-    // static uint32_t hash_nr_dirtied = -1;
-    // static uint32_t hash_nr_dirty = -1;
-    // static uint32_t hash_nr_dirty_background_threshold = -1;
-    // static uint32_t hash_nr_dirty_threshold = -1;
-    // static uint32_t hash_nr_file_pages = -1;
-    // static uint32_t hash_nr_free_pages = -1;
-    // static uint32_t hash_nr_inactive_anon = -1;
-    // static uint32_t hash_nr_inactive_file = -1;
-    // static uint32_t hash_nr_isolated_anon = -1;
-    // static uint32_t hash_nr_isolated_file = -1;
-    // static uint32_t hash_nr_kernel_stack = -1;
-    // static uint32_t hash_nr_mapped = -1;
-    // static uint32_t hash_nr_mlock = -1;
-    // static uint32_t hash_nr_page_table_pages = -1;
-    // static uint32_t hash_nr_shmem = -1;
-    // static uint32_t hash_nr_slab_reclaimable = -1;
-    // static uint32_t hash_nr_slab_unreclaimable = -1;
-    // static uint32_t hash_nr_unevictable = -1;
-    // static uint32_t hash_nr_unstable = -1;
-    // static uint32_t hash_nr_vmscan_immediate_reclaim = -1;
-    // static uint32_t hash_nr_vmscan_write = -1;
-    // static uint32_t hash_nr_writeback = -1;
-    // static uint32_t hash_nr_writeback_temp = -1;
-    // static uint32_t hash_nr_written = -1;
-    // static uint32_t hash_pageoutrun = -1;
-    // static uint32_t hash_pgactivate = -1;
-    // static uint32_t hash_pgalloc_dma = -1;
-    // static uint32_t hash_pgalloc_dma32 = -1;
-    // static uint32_t hash_pgalloc_movable = -1;
-    // static uint32_t hash_pgalloc_normal = -1;
-    // static uint32_t hash_pgdeactivate = -1;
-    static uint32_t hash_pgfault = -1;
-    // static uint32_t hash_pgfree = -1;
-    // static uint32_t hash_pginodesteal = -1;
-    static uint32_t hash_pgmajfault = -1;
-    static uint32_t hash_pgpgin = -1;
-    static uint32_t hash_pgpgout = -1;
-    // static uint32_t hash_pgrefill_dma = -1;
-    // static uint32_t hash_pgrefill_dma32 = -1;
-    // static uint32_t hash_pgrefill_movable = -1;
-    // static uint32_t hash_pgrefill_normal = -1;
-    // static uint32_t hash_pgrotated = -1;
-    // static uint32_t hash_pgscan_direct_dma = -1;
-    // static uint32_t hash_pgscan_direct_dma32 = -1;
-    // static uint32_t hash_pgscan_direct_movable = -1;
-    // static uint32_t hash_pgscan_direct_normal = -1;
-    // static uint32_t hash_pgscan_kswapd_dma = -1;
-    // static uint32_t hash_pgscan_kswapd_dma32 = -1;
-    // static uint32_t hash_pgscan_kswapd_movable = -1;
-    // static uint32_t hash_pgscan_kswapd_normal = -1;
-    // static uint32_t hash_pgsteal_direct_dma = -1;
-    // static uint32_t hash_pgsteal_direct_dma32 = -1;
-    // static uint32_t hash_pgsteal_direct_movable = -1;
-    // static uint32_t hash_pgsteal_direct_normal = -1;
-    // static uint32_t hash_pgsteal_kswapd_dma = -1;
-    // static uint32_t hash_pgsteal_kswapd_dma32 = -1;
-    // static uint32_t hash_pgsteal_kswapd_movable = -1;
-    // static uint32_t hash_pgsteal_kswapd_normal = -1;
-    static uint32_t hash_pswpin = -1;
-    static uint32_t hash_pswpout = -1;
-    // static uint32_t hash_slabs_scanned = -1;
-    // static uint32_t hash_thp_collapse_alloc = -1;
-    // static uint32_t hash_thp_collapse_alloc_failed = -1;
-    // static uint32_t hash_thp_fault_alloc = -1;
-    // static uint32_t hash_thp_fault_fallback = -1;
-    // static uint32_t hash_thp_split = -1;
-    // static uint32_t hash_unevictable_pgs_cleared = -1;
-    // static uint32_t hash_unevictable_pgs_culled = -1;
-    // static uint32_t hash_unevictable_pgs_mlocked = -1;
-    // static uint32_t hash_unevictable_pgs_mlockfreed = -1;
-    // static uint32_t hash_unevictable_pgs_munlocked = -1;
-    // static uint32_t hash_unevictable_pgs_rescued = -1;
-    // static uint32_t hash_unevictable_pgs_scanned = -1;
-    // static uint32_t hash_unevictable_pgs_stranded = -1;
+    if(unlikely(do_swapio == -1)) {
+        do_swapio = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "swap i/o", CONFIG_ONDEMAND_ONDEMAND);
+        do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
+        do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
 
-    if(gen_hashes != 1) {
-        gen_hashes = 1;
         // hash_allocstall = simple_hash("allocstall");
         // hash_compact_blocks_moved = simple_hash("compact_blocks_moved");
         // hash_compact_fail = simple_hash("compact_fail");
@@ -193,24 +198,17 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
         // hash_unevictable_pgs_stranded = simple_hash("unevictable_pgs_stranded");
     }
 
-    if(do_swapio == -1)    do_swapio = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "swap i/o", CONFIG_ONDEMAND_ONDEMAND);
-    if(do_io == -1)        do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
-    if(do_pgfaults == -1)  do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
-
-    (void)dt;
-
-    if(!ff) {
+    if(unlikely(!ff)) {
         char filename[FILENAME_MAX + 1];
         snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/vmstat");
         ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
+        if(unlikely(!ff)) return 1;
     }
-    if(!ff) return 1;
 
     ff = procfile_readall(ff);
-    if(!ff) return 0; // we return 0, so that we will retry to open it next time
+    if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
 
     uint32_t lines = procfile_lines(ff), l;
-    uint32_t words;
 
     // unsigned long long allocstall = 0ULL;
     // unsigned long long compact_blocks_moved = 0ULL;
@@ -306,111 +304,111 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
     // unsigned long long unevictable_pgs_stranded = 0ULL;
 
     for(l = 0; l < lines ;l++) {
-        words = procfile_linewords(ff, l);
-        if(words < 2) {
-            if(words) error("Cannot read /proc/vmstat line %u. Expected 2 params, read %u.", l, words);
+        uint32_t words = procfile_linewords(ff, l);
+        if(unlikely(words < 2)) {
+            if(unlikely(words)) error("Cannot read /proc/vmstat line %u. Expected 2 params, read %u.", l, words);
             continue;
         }
 
         char *name = procfile_lineword(ff, l, 0);
         char * value = procfile_lineword(ff, l, 1);
-        if(!name || !*name || !value || !*value) continue;
+        if(unlikely(!name || !*name || !value || !*value)) continue;
 
         uint32_t hash = simple_hash(name);
 
-        if(0) ;
-        // else if(hash == hash_allocstall && strcmp(name, "allocstall") == 0) allocstall = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_blocks_moved && strcmp(name, "compact_blocks_moved") == 0) compact_blocks_moved = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_fail && strcmp(name, "compact_fail") == 0) compact_fail = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_pagemigrate_failed && strcmp(name, "compact_pagemigrate_failed") == 0) compact_pagemigrate_failed = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_pages_moved && strcmp(name, "compact_pages_moved") == 0) compact_pages_moved = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_stall && strcmp(name, "compact_stall") == 0) compact_stall = strtoull(value, NULL, 10);
-        // else if(hash == hash_compact_success && strcmp(name, "compact_success") == 0) compact_success = strtoull(value, NULL, 10);
-        // else if(hash == hash_htlb_buddy_alloc_fail && strcmp(name, "htlb_buddy_alloc_fail") == 0) htlb_buddy_alloc_fail = strtoull(value, NULL, 10);
-        // else if(hash == hash_htlb_buddy_alloc_success && strcmp(name, "htlb_buddy_alloc_success") == 0) htlb_buddy_alloc_success = strtoull(value, NULL, 10);
-        // else if(hash == hash_kswapd_high_wmark_hit_quickly && strcmp(name, "kswapd_high_wmark_hit_quickly") == 0) kswapd_high_wmark_hit_quickly = strtoull(value, NULL, 10);
-        // else if(hash == hash_kswapd_inodesteal && strcmp(name, "kswapd_inodesteal") == 0) kswapd_inodesteal = strtoull(value, NULL, 10);
-        // else if(hash == hash_kswapd_low_wmark_hit_quickly && strcmp(name, "kswapd_low_wmark_hit_quickly") == 0) kswapd_low_wmark_hit_quickly = strtoull(value, NULL, 10);
-        // else if(hash == hash_kswapd_skip_congestion_wait && strcmp(name, "kswapd_skip_congestion_wait") == 0) kswapd_skip_congestion_wait = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_active_anon && strcmp(name, "nr_active_anon") == 0) nr_active_anon = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_active_file && strcmp(name, "nr_active_file") == 0) nr_active_file = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_anon_pages && strcmp(name, "nr_anon_pages") == 0) nr_anon_pages = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_anon_transparent_hugepages && strcmp(name, "nr_anon_transparent_hugepages") == 0) nr_anon_transparent_hugepages = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_bounce && strcmp(name, "nr_bounce") == 0) nr_bounce = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_dirtied && strcmp(name, "nr_dirtied") == 0) nr_dirtied = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_dirty && strcmp(name, "nr_dirty") == 0) nr_dirty = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_dirty_background_threshold && strcmp(name, "nr_dirty_background_threshold") == 0) nr_dirty_background_threshold = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_dirty_threshold && strcmp(name, "nr_dirty_threshold") == 0) nr_dirty_threshold = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_file_pages && strcmp(name, "nr_file_pages") == 0) nr_file_pages = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_free_pages && strcmp(name, "nr_free_pages") == 0) nr_free_pages = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_inactive_anon && strcmp(name, "nr_inactive_anon") == 0) nr_inactive_anon = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_inactive_file && strcmp(name, "nr_inactive_file") == 0) nr_inactive_file = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_isolated_anon && strcmp(name, "nr_isolated_anon") == 0) nr_isolated_anon = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_isolated_file && strcmp(name, "nr_isolated_file") == 0) nr_isolated_file = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_kernel_stack && strcmp(name, "nr_kernel_stack") == 0) nr_kernel_stack = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_mapped && strcmp(name, "nr_mapped") == 0) nr_mapped = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_mlock && strcmp(name, "nr_mlock") == 0) nr_mlock = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_page_table_pages && strcmp(name, "nr_page_table_pages") == 0) nr_page_table_pages = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_shmem && strcmp(name, "nr_shmem") == 0) nr_shmem = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_slab_reclaimable && strcmp(name, "nr_slab_reclaimable") == 0) nr_slab_reclaimable = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_slab_unreclaimable && strcmp(name, "nr_slab_unreclaimable") == 0) nr_slab_unreclaimable = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_unevictable && strcmp(name, "nr_unevictable") == 0) nr_unevictable = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_unstable && strcmp(name, "nr_unstable") == 0) nr_unstable = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_vmscan_immediate_reclaim && strcmp(name, "nr_vmscan_immediate_reclaim") == 0) nr_vmscan_immediate_reclaim = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_vmscan_write && strcmp(name, "nr_vmscan_write") == 0) nr_vmscan_write = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_writeback && strcmp(name, "nr_writeback") == 0) nr_writeback = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_writeback_temp && strcmp(name, "nr_writeback_temp") == 0) nr_writeback_temp = strtoull(value, NULL, 10);
-        // else if(hash == hash_nr_written && strcmp(name, "nr_written") == 0) nr_written = strtoull(value, NULL, 10);
-        // else if(hash == hash_pageoutrun && strcmp(name, "pageoutrun") == 0) pageoutrun = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgactivate && strcmp(name, "pgactivate") == 0) pgactivate = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgalloc_dma && strcmp(name, "pgalloc_dma") == 0) pgalloc_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgalloc_dma32 && strcmp(name, "pgalloc_dma32") == 0) pgalloc_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgalloc_movable && strcmp(name, "pgalloc_movable") == 0) pgalloc_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgalloc_normal && strcmp(name, "pgalloc_normal") == 0) pgalloc_normal = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgdeactivate && strcmp(name, "pgdeactivate") == 0) pgdeactivate = strtoull(value, NULL, 10);
-        else if(hash == hash_pgfault && strcmp(name, "pgfault") == 0) pgfault = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgfree && strcmp(name, "pgfree") == 0) pgfree = strtoull(value, NULL, 10);
-        // else if(hash == hash_pginodesteal && strcmp(name, "pginodesteal") == 0) pginodesteal = strtoull(value, NULL, 10);
-        else if(hash == hash_pgmajfault && strcmp(name, "pgmajfault") == 0) pgmajfault = strtoull(value, NULL, 10);
-        else if(hash == hash_pgpgin && strcmp(name, "pgpgin") == 0) pgpgin = strtoull(value, NULL, 10);
-        else if(hash == hash_pgpgout && strcmp(name, "pgpgout") == 0) pgpgout = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgrefill_dma && strcmp(name, "pgrefill_dma") == 0) pgrefill_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgrefill_dma32 && strcmp(name, "pgrefill_dma32") == 0) pgrefill_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgrefill_movable && strcmp(name, "pgrefill_movable") == 0) pgrefill_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgrefill_normal && strcmp(name, "pgrefill_normal") == 0) pgrefill_normal = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgrotated && strcmp(name, "pgrotated") == 0) pgrotated = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_direct_dma && strcmp(name, "pgscan_direct_dma") == 0) pgscan_direct_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_direct_dma32 && strcmp(name, "pgscan_direct_dma32") == 0) pgscan_direct_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_direct_movable && strcmp(name, "pgscan_direct_movable") == 0) pgscan_direct_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_direct_normal && strcmp(name, "pgscan_direct_normal") == 0) pgscan_direct_normal = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_kswapd_dma && strcmp(name, "pgscan_kswapd_dma") == 0) pgscan_kswapd_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_kswapd_dma32 && strcmp(name, "pgscan_kswapd_dma32") == 0) pgscan_kswapd_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_kswapd_movable && strcmp(name, "pgscan_kswapd_movable") == 0) pgscan_kswapd_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgscan_kswapd_normal && strcmp(name, "pgscan_kswapd_normal") == 0) pgscan_kswapd_normal = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_direct_dma && strcmp(name, "pgsteal_direct_dma") == 0) pgsteal_direct_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_direct_dma32 && strcmp(name, "pgsteal_direct_dma32") == 0) pgsteal_direct_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_direct_movable && strcmp(name, "pgsteal_direct_movable") == 0) pgsteal_direct_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_direct_normal && strcmp(name, "pgsteal_direct_normal") == 0) pgsteal_direct_normal = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_kswapd_dma && strcmp(name, "pgsteal_kswapd_dma") == 0) pgsteal_kswapd_dma = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_kswapd_dma32 && strcmp(name, "pgsteal_kswapd_dma32") == 0) pgsteal_kswapd_dma32 = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_kswapd_movable && strcmp(name, "pgsteal_kswapd_movable") == 0) pgsteal_kswapd_movable = strtoull(value, NULL, 10);
-        // else if(hash == hash_pgsteal_kswapd_normal && strcmp(name, "pgsteal_kswapd_normal") == 0) pgsteal_kswapd_normal = strtoull(value, NULL, 10);
-        else if(hash == hash_pswpin && strcmp(name, "pswpin") == 0) pswpin = strtoull(value, NULL, 10);
-        else if(hash == hash_pswpout && strcmp(name, "pswpout") == 0) pswpout = strtoull(value, NULL, 10);
-        // else if(hash == hash_slabs_scanned && strcmp(name, "slabs_scanned") == 0) slabs_scanned = strtoull(value, NULL, 10);
-        // else if(hash == hash_thp_collapse_alloc && strcmp(name, "thp_collapse_alloc") == 0) thp_collapse_alloc = strtoull(value, NULL, 10);
-        // else if(hash == hash_thp_collapse_alloc_failed && strcmp(name, "thp_collapse_alloc_failed") == 0) thp_collapse_alloc_failed = strtoull(value, NULL, 10);
-        // else if(hash == hash_thp_fault_alloc && strcmp(name, "thp_fault_alloc") == 0) thp_fault_alloc = strtoull(value, NULL, 10);
-        // else if(hash == hash_thp_fault_fallback && strcmp(name, "thp_fault_fallback") == 0) thp_fault_fallback = strtoull(value, NULL, 10);
-        // else if(hash == hash_thp_split && strcmp(name, "thp_split") == 0) thp_split = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_cleared && strcmp(name, "unevictable_pgs_cleared") == 0) unevictable_pgs_cleared = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_culled && strcmp(name, "unevictable_pgs_culled") == 0) unevictable_pgs_culled = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_mlocked && strcmp(name, "unevictable_pgs_mlocked") == 0) unevictable_pgs_mlocked = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_mlockfreed && strcmp(name, "unevictable_pgs_mlockfreed") == 0) unevictable_pgs_mlockfreed = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_munlocked && strcmp(name, "unevictable_pgs_munlocked") == 0) unevictable_pgs_munlocked = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_rescued && strcmp(name, "unevictable_pgs_rescued") == 0) unevictable_pgs_rescued = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_scanned && strcmp(name, "unevictable_pgs_scanned") == 0) unevictable_pgs_scanned = strtoull(value, NULL, 10);
-        // else if(hash == hash_unevictable_pgs_stranded && strcmp(name, "unevictable_pgs_stranded") == 0) unevictable_pgs_stranded = strtoull(value, NULL, 10);
+        if(unlikely(0)) ;
+        // else if(unlikely(hash == hash_allocstall && strcmp(name, "allocstall") == 0)) allocstall = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_blocks_moved && strcmp(name, "compact_blocks_moved") == 0)) compact_blocks_moved = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_fail && strcmp(name, "compact_fail") == 0)) compact_fail = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_pagemigrate_failed && strcmp(name, "compact_pagemigrate_failed") == 0)) compact_pagemigrate_failed = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_pages_moved && strcmp(name, "compact_pages_moved") == 0)) compact_pages_moved = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_stall && strcmp(name, "compact_stall") == 0)) compact_stall = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_compact_success && strcmp(name, "compact_success") == 0)) compact_success = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_htlb_buddy_alloc_fail && strcmp(name, "htlb_buddy_alloc_fail") == 0)) htlb_buddy_alloc_fail = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_htlb_buddy_alloc_success && strcmp(name, "htlb_buddy_alloc_success") == 0)) htlb_buddy_alloc_success = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_kswapd_high_wmark_hit_quickly && strcmp(name, "kswapd_high_wmark_hit_quickly") == 0)) kswapd_high_wmark_hit_quickly = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_kswapd_inodesteal && strcmp(name, "kswapd_inodesteal") == 0)) kswapd_inodesteal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_kswapd_low_wmark_hit_quickly && strcmp(name, "kswapd_low_wmark_hit_quickly") == 0)) kswapd_low_wmark_hit_quickly = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_kswapd_skip_congestion_wait && strcmp(name, "kswapd_skip_congestion_wait") == 0)) kswapd_skip_congestion_wait = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_active_anon && strcmp(name, "nr_active_anon") == 0)) nr_active_anon = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_active_file && strcmp(name, "nr_active_file") == 0)) nr_active_file = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_anon_pages && strcmp(name, "nr_anon_pages") == 0)) nr_anon_pages = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_anon_transparent_hugepages && strcmp(name, "nr_anon_transparent_hugepages") == 0)) nr_anon_transparent_hugepages = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_bounce && strcmp(name, "nr_bounce") == 0)) nr_bounce = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_dirtied && strcmp(name, "nr_dirtied") == 0)) nr_dirtied = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_dirty && strcmp(name, "nr_dirty") == 0)) nr_dirty = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_dirty_background_threshold && strcmp(name, "nr_dirty_background_threshold") == 0)) nr_dirty_background_threshold = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_dirty_threshold && strcmp(name, "nr_dirty_threshold") == 0)) nr_dirty_threshold = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_file_pages && strcmp(name, "nr_file_pages") == 0)) nr_file_pages = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_free_pages && strcmp(name, "nr_free_pages") == 0)) nr_free_pages = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_inactive_anon && strcmp(name, "nr_inactive_anon") == 0)) nr_inactive_anon = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_inactive_file && strcmp(name, "nr_inactive_file") == 0)) nr_inactive_file = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_isolated_anon && strcmp(name, "nr_isolated_anon") == 0)) nr_isolated_anon = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_isolated_file && strcmp(name, "nr_isolated_file") == 0)) nr_isolated_file = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_kernel_stack && strcmp(name, "nr_kernel_stack") == 0)) nr_kernel_stack = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_mapped && strcmp(name, "nr_mapped") == 0)) nr_mapped = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_mlock && strcmp(name, "nr_mlock") == 0)) nr_mlock = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_page_table_pages && strcmp(name, "nr_page_table_pages") == 0)) nr_page_table_pages = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_shmem && strcmp(name, "nr_shmem") == 0)) nr_shmem = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_slab_reclaimable && strcmp(name, "nr_slab_reclaimable") == 0)) nr_slab_reclaimable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_slab_unreclaimable && strcmp(name, "nr_slab_unreclaimable") == 0)) nr_slab_unreclaimable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_unevictable && strcmp(name, "nr_unevictable") == 0)) nr_unevictable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_unstable && strcmp(name, "nr_unstable") == 0)) nr_unstable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_vmscan_immediate_reclaim && strcmp(name, "nr_vmscan_immediate_reclaim") == 0)) nr_vmscan_immediate_reclaim = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_vmscan_write && strcmp(name, "nr_vmscan_write") == 0)) nr_vmscan_write = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_writeback && strcmp(name, "nr_writeback") == 0)) nr_writeback = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_writeback_temp && strcmp(name, "nr_writeback_temp") == 0)) nr_writeback_temp = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_nr_written && strcmp(name, "nr_written") == 0)) nr_written = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pageoutrun && strcmp(name, "pageoutrun") == 0)) pageoutrun = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgactivate && strcmp(name, "pgactivate") == 0)) pgactivate = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgalloc_dma && strcmp(name, "pgalloc_dma") == 0)) pgalloc_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgalloc_dma32 && strcmp(name, "pgalloc_dma32") == 0)) pgalloc_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgalloc_movable && strcmp(name, "pgalloc_movable") == 0)) pgalloc_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgalloc_normal && strcmp(name, "pgalloc_normal") == 0)) pgalloc_normal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgdeactivate && strcmp(name, "pgdeactivate") == 0)) pgdeactivate = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pgfault && strcmp(name, "pgfault") == 0)) pgfault = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgfree && strcmp(name, "pgfree") == 0)) pgfree = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pginodesteal && strcmp(name, "pginodesteal") == 0)) pginodesteal = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pgmajfault && strcmp(name, "pgmajfault") == 0)) pgmajfault = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pgpgin && strcmp(name, "pgpgin") == 0)) pgpgin = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pgpgout && strcmp(name, "pgpgout") == 0)) pgpgout = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgrefill_dma && strcmp(name, "pgrefill_dma") == 0)) pgrefill_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgrefill_dma32 && strcmp(name, "pgrefill_dma32") == 0)) pgrefill_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgrefill_movable && strcmp(name, "pgrefill_movable") == 0)) pgrefill_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgrefill_normal && strcmp(name, "pgrefill_normal") == 0)) pgrefill_normal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgrotated && strcmp(name, "pgrotated") == 0)) pgrotated = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_direct_dma && strcmp(name, "pgscan_direct_dma") == 0)) pgscan_direct_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_direct_dma32 && strcmp(name, "pgscan_direct_dma32") == 0)) pgscan_direct_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_direct_movable && strcmp(name, "pgscan_direct_movable") == 0)) pgscan_direct_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_direct_normal && strcmp(name, "pgscan_direct_normal") == 0)) pgscan_direct_normal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_kswapd_dma && strcmp(name, "pgscan_kswapd_dma") == 0)) pgscan_kswapd_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_kswapd_dma32 && strcmp(name, "pgscan_kswapd_dma32") == 0)) pgscan_kswapd_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_kswapd_movable && strcmp(name, "pgscan_kswapd_movable") == 0)) pgscan_kswapd_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgscan_kswapd_normal && strcmp(name, "pgscan_kswapd_normal") == 0)) pgscan_kswapd_normal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_direct_dma && strcmp(name, "pgsteal_direct_dma") == 0)) pgsteal_direct_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_direct_dma32 && strcmp(name, "pgsteal_direct_dma32") == 0)) pgsteal_direct_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_direct_movable && strcmp(name, "pgsteal_direct_movable") == 0)) pgsteal_direct_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_direct_normal && strcmp(name, "pgsteal_direct_normal") == 0)) pgsteal_direct_normal = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_kswapd_dma && strcmp(name, "pgsteal_kswapd_dma") == 0)) pgsteal_kswapd_dma = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_kswapd_dma32 && strcmp(name, "pgsteal_kswapd_dma32") == 0)) pgsteal_kswapd_dma32 = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_kswapd_movable && strcmp(name, "pgsteal_kswapd_movable") == 0)) pgsteal_kswapd_movable = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_pgsteal_kswapd_normal && strcmp(name, "pgsteal_kswapd_normal") == 0)) pgsteal_kswapd_normal = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pswpin && strcmp(name, "pswpin") == 0)) pswpin = strtoull(value, NULL, 10);
+        else if(unlikely(hash == hash_pswpout && strcmp(name, "pswpout") == 0)) pswpout = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_slabs_scanned && strcmp(name, "slabs_scanned") == 0)) slabs_scanned = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_thp_collapse_alloc && strcmp(name, "thp_collapse_alloc") == 0)) thp_collapse_alloc = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_thp_collapse_alloc_failed && strcmp(name, "thp_collapse_alloc_failed") == 0)) thp_collapse_alloc_failed = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_thp_fault_alloc && strcmp(name, "thp_fault_alloc") == 0)) thp_fault_alloc = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_thp_fault_fallback && strcmp(name, "thp_fault_fallback") == 0)) thp_fault_fallback = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_thp_split && strcmp(name, "thp_split") == 0)) thp_split = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_cleared && strcmp(name, "unevictable_pgs_cleared") == 0)) unevictable_pgs_cleared = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_culled && strcmp(name, "unevictable_pgs_culled") == 0)) unevictable_pgs_culled = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_mlocked && strcmp(name, "unevictable_pgs_mlocked") == 0)) unevictable_pgs_mlocked = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_mlockfreed && strcmp(name, "unevictable_pgs_mlockfreed") == 0)) unevictable_pgs_mlockfreed = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_munlocked && strcmp(name, "unevictable_pgs_munlocked") == 0)) unevictable_pgs_munlocked = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_rescued && strcmp(name, "unevictable_pgs_rescued") == 0)) unevictable_pgs_rescued = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_scanned && strcmp(name, "unevictable_pgs_scanned") == 0)) unevictable_pgs_scanned = strtoull(value, NULL, 10);
+        // else if(unlikely(hash == hash_unevictable_pgs_stranded && strcmp(name, "unevictable_pgs_stranded") == 0)) unevictable_pgs_stranded = strtoull(value, NULL, 10);
     }
 
     // --------------------------------------------------------------------
@@ -419,7 +417,7 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
         do_swapio = CONFIG_ONDEMAND_YES;
 
         static RRDSET *st_swapio = NULL;
-        if(!st_swapio) {
+        if(unlikely(!st_swapio)) {
             st_swapio = rrdset_create("system", "swapio", NULL, "swap", NULL, "Swap I/O", "kilobytes/s", 250, update_every, RRDSET_TYPE_AREA);
 
             rrddim_add(st_swapio, "in",  NULL, sysconf(_SC_PAGESIZE), 1024, RRDDIM_INCREMENTAL);
@@ -436,7 +434,7 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
 
     if(do_io) {
         static RRDSET *st_io = NULL;
-        if(!st_io) {
+        if(unlikely(!st_io)) {
             st_io = rrdset_create("system", "io", NULL, "disk", NULL, "Disk I/O", "kilobytes/s", 150, update_every, RRDSET_TYPE_AREA);
 
             rrddim_add(st_io, "in",  NULL,  1, 1, RRDDIM_INCREMENTAL);
@@ -453,7 +451,7 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
 
     if(do_pgfaults) {
         static RRDSET *st_pgfaults = NULL;
-        if(!st_pgfaults) {
+        if(unlikely(!st_pgfaults)) {
             st_pgfaults = rrdset_create("mem", "pgfaults", NULL, "system", NULL, "Memory Page Faults", "page faults/s", 500, update_every, RRDSET_TYPE_LINE);
             st_pgfaults->isdetail = 1;