]> arthur.barton.de Git - netdata.git/commitdiff
adaptive resortable list implementation; used it in cgroups and vmstat
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 20 Jan 2017 00:28:22 +0000 (02:28 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 20 Jan 2017 00:28:22 +0000 (02:28 +0200)
CMakeLists.txt
src/Makefile.am
src/adaptive_resortable_list.c [new file with mode: 0644]
src/adaptive_resortable_list.h [new file with mode: 0644]
src/proc_vmstat.c
src/sys_fs_cgroup.c

index 4daf76cb5f90515dab482e5a20afa3fb97a406c2..19acbd5adb36837c86b43258f710c99081658072 100755 (executable)
@@ -101,7 +101,7 @@ set(NETDATA_SOURCE_FILES
         src/registry_person.c
         src/registry_person.h
         src/registry_machine.c
-        src/registry_machine.h src/registry_internals.c src/registry_init.c src/registry_db.c src/registry_log.c src/proc_uptime.c src/sys_devices_system_edac_mc.c src/plugin_proc_diskspace.c src/plugin_proc_diskspace.h src/simple_pattern.c src/simple_pattern.h src/inlined.h)
+        src/registry_machine.h src/registry_internals.c src/registry_init.c src/registry_db.c src/registry_log.c src/proc_uptime.c src/sys_devices_system_edac_mc.c src/plugin_proc_diskspace.c src/plugin_proc_diskspace.h src/simple_pattern.c src/simple_pattern.h src/inlined.h src/adaptive_resortable_list.h src/adaptive_resortable_list.c)
 
 set(APPS_PLUGIN_SOURCE_FILES
         src/appconfig.c
index 314f600fe2ea1539539997fcea38448e6f2e6ddf..d8274d25523dfbe96ca614e239238c6df61ac55c 100644 (file)
@@ -30,6 +30,7 @@ endif
 
 netdata_SOURCES = \
        appconfig.c appconfig.h \
+       adaptive_resortable_list.c adaptive_resortable_list.h \
        avl.c avl.h \
        backends.c backends.h \
        clocks.c clocks.h \
diff --git a/src/adaptive_resortable_list.c b/src/adaptive_resortable_list.c
new file mode 100644 (file)
index 0000000..2010650
--- /dev/null
@@ -0,0 +1,172 @@
+#include "adaptive_resortable_list.h"
+
+// the default processor() of the ARL
+// can be overwritten at arl_create()
+static inline void arl_callback_str2ull(const char *name, uint32_t hash, const char *value, void *dst) {
+    (void)name;
+    (void)hash;
+
+    register unsigned long long *d = dst;
+    *d = str2ull(value);
+    // fprintf(stderr, "name '%s' with hash %u and value '%s' is %llu\n", name, hash, value, *d);
+}
+
+// create a new ARL
+ARL_BASE *arl_create(void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks) {
+    ARL_BASE *base = callocz(1, sizeof(ARL_BASE));
+
+    if(!processor)
+        base->processor = arl_callback_str2ull;
+    else
+        base->processor = processor;
+
+    base->rechecks = rechecks;
+
+    return base;
+}
+
+void arl_free(ARL_BASE *arl_base) {
+    if(unlikely(!arl_base))
+        return;
+
+    while(arl_base->head) {
+        ARL_ENTRY *e = arl_base->head;
+        arl_base->head = e->next;
+
+        freez(e->name);
+#ifdef NETDATA_INTERNAL_CHECKS
+        memset(e, 0, sizeof(ARL_ENTRY));
+#endif
+        freez(e);
+    }
+
+#ifdef NETDATA_INTERNAL_CHECKS
+    memset(arl_base, 0, sizeof(ARL_BASE));
+#endif
+
+    freez(arl_base);
+}
+
+void arl_begin(ARL_BASE *base) {
+    ARL_ENTRY *e;
+
+    /*
+    info("iteration %zu, expected %zu, wanted %zu, allocated %zu, relinkings %zu, found %zu, added %zu"
+         , base->iteration
+         , base->expected
+         , base->wanted
+         , base->allocated
+         , base->relinkings
+         , base->found
+         , base->added
+    );
+    for(e = base->head; e ; e = e->next) fprintf(stderr, "%s ", e->name);
+    fprintf(stderr, "\n");
+     */
+
+    if(unlikely(base->added || base->iteration % base->rechecks) == 1) {
+        base->added = 0;
+        base->wanted = 0;
+        for(e = base->head; e ; e = e->next)
+            if(e->flags & ARL_ENTRY_FLAG_FOUND && e->flags & ARL_ENTRY_FLAG_EXPECTED)
+                base->wanted++;
+    }
+
+    base->iteration++;
+    base->next_keyword = base->head;
+    base->found = 0;
+}
+
+// register an expected keyword to the ARL
+// together with its destination ( i.e. the output of the processor() )
+ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst) {
+    ARL_ENTRY *e = callocz(1, sizeof(ARL_ENTRY));
+    e->name = strdupz(keyword);
+    e->hash = simple_hash(e->name);
+    e->dst = dst;
+    e->flags = ARL_ENTRY_FLAG_EXPECTED;
+    e->prev = NULL;
+    e->next = base->head;
+
+    if(base->head) base->head->prev = e;
+    else base->next_keyword = e;
+
+    base->head = e;
+    base->expected++;
+    base->allocated++;
+
+    base->wanted = base->expected;
+
+    return e;
+}
+
+int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value) {
+    ARL_ENTRY *e;
+
+    // find if it already exists in the data
+    for(e = base->head; e ; e = e->next)
+        if(e->hash == hash && !strcmp(e->name, s))
+            break;
+
+#ifdef NETDATA_INTERNAL_CHECKS
+    if(unlikely(e == base->next_keyword))
+        fatal("Internal Error: e == base->last");
+#endif
+
+    if(e) {
+        // found it in the keywords
+        base->relinkings++;
+
+        // run the processor for it
+        if(unlikely(e->dst)) {
+            base->processor(e->name, hash, value, e->dst);
+            base->found++;
+        }
+
+        // unlink it - we will relink it below
+        if(e->next) e->next->prev = e->prev;
+        if(e->prev) e->prev->next = e->next;
+
+        // make sure the head is properly linked
+        if(base->head == e)
+            base->head = e->next;
+    }
+    else {
+        // not found
+
+        // create it
+        e = callocz(1, sizeof(ARL_ENTRY));
+        e->name = strdupz(s);
+        e->hash = hash;
+        e->flags = ARL_ENTRY_FLAG_DYNAMIC;
+
+        base->allocated++;
+        base->added++;
+    }
+
+    e->flags |= ARL_ENTRY_FLAG_FOUND;
+
+    // link it here
+    e->next = base->next_keyword;
+    if(base->next_keyword) {
+        e->prev = base->next_keyword->prev;
+        base->next_keyword->prev = e;
+
+        if(base->head == base->next_keyword)
+            base->head = e;
+    }
+    else
+        e->prev = NULL;
+
+    if(e->prev)
+        e->prev->next = e;
+
+    base->next_keyword = e->next;
+    if(unlikely(!base->next_keyword))
+        base->next_keyword = base->head;
+
+    if(unlikely(base->found == base->wanted))
+        return 1;
+
+    return 0;
+}
diff --git a/src/adaptive_resortable_list.h b/src/adaptive_resortable_list.h
new file mode 100644 (file)
index 0000000..ccd92b9
--- /dev/null
@@ -0,0 +1,141 @@
+#ifndef NETDATA_ADAPTIVE_RESORTABLE_LIST_H
+#define NETDATA_ADAPTIVE_RESORTABLE_LIST_H
+
+/*
+ * ADAPTIVE RE-SORTABLE LIST
+ * This structure allows netdata to read a file of NAME VALUE lines
+ * in the fastest possible way.
+ *
+ * It maintains a linked list of all NAME (keywords), sorted in the
+ * same order as found in the source data file.
+ * The linked list is kept sorted at all times - the source file
+ * may change at any time, the list will adapt.
+ *
+ * The caller:
+ *
+ * 1. calls arl_create() to create a list
+ *
+ * 2. calls arl_expect() to register the expected keyword
+ *
+ * Then:
+ *
+ * 3. calls arl_begin() to initiate a data collection iteration.
+ *    This is to be called just ONCE every time the source is re-scanned.
+ *
+ * 4. calls arl_check() for each line read from the file.
+ *
+ * Finally:
+ *
+ * 5. calls arl_free() to destroy this and free all memory.
+ *
+ * The program will call the processor() function, given to
+ * arl_create(), for each expected keyword found.
+ * The default processor() expects dst to be an unsigned long long *.
+ *
+ * LIMITATIONS
+ * DO NOT USE THIS IF THE A NAME/KEYWORD MAY APPEAR MORE THAN
+ * ONCE IN THE SOURCE DATA SET.
+ */
+
+#include "common.h"
+
+#define ARL_ENTRY_FLAG_FOUND    0x01    // the entry has been found in the source data
+#define ARL_ENTRY_FLAG_EXPECTED 0x02    // the entry is expected by the program
+#define ARL_ENTRY_FLAG_DYNAMIC  0x04    // the entry was dynamically allocated, from source data
+
+typedef struct arl_entry {
+    char *name;             // the keywords
+    uint32_t hash;          // the hash of the keyword
+
+    void *dst;              // the dst to pass to the processor
+
+    uint8_t flags;          // ARL_ENTRY_FLAG_*
+
+    // double linked list for fast re-linkings
+    struct arl_entry *prev, *next;
+} ARL_ENTRY;
+
+typedef struct arl_base {
+    size_t iteration;   // incremented on each iteration (arl_begin())
+    size_t found;       // the number of expected keywords found in this iteration
+    size_t expected;    // the number of expected keywords
+    size_t wanted;      // the number of wanted keywords
+                        // i.e. the number of keywords found and expected
+
+    size_t relinkings;  // the number of relinkings we have made so far
+    size_t allocated;   // the number of keywords allocated
+
+    size_t rechecks;    // the number of iterations between re-checks of the
+                        // wanted number of keywords
+                        // this is only needed in cases where the source
+                        // is having less lines over time.
+
+    size_t added;       // it is non-zero if new keywords have been added
+                        // this is only needed to detect new lines have
+                        // been added to the file, over time.
+
+    // the processor to do the job
+    void (*processor)(const char *name, uint32_t hash, const char *value, void *dst);
+
+    // the linked list of the keywords
+    ARL_ENTRY *head;
+
+    // since we keep the list of keywords sorted (as found in the source data)
+    // this is next keyword that we expect to find in the source data.
+    ARL_ENTRY *next_keyword;
+} ARL_BASE;
+
+// create a new ARL
+extern ARL_BASE *arl_create(void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks);
+
+// free an ARL
+extern void arl_free(ARL_BASE *arl_base);
+
+// register an expected keyword to the ARL
+// together with its destination ( i.e. the output of the processor() )
+extern ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst);
+
+// an internal call to complete the check() call
+extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value);
+
+// begin an ARL iteration
+extern void arl_begin(ARL_BASE *base);
+
+// check a keyword against the ARL
+// this is to be called for each keyword read from source data
+// s = the keyword, as collected
+// src = the src data to be passed to the processor
+// it is defined in the header file in order to be inlined
+static inline int arl_check(ARL_BASE *base, const char *keyword, const char *value) {
+    ARL_ENTRY *e = base->next_keyword;
+    uint32_t hash = simple_hash(keyword);
+
+    // it should be the first entry (pointed by base->next_keyword)
+    if(likely(hash == e->hash && !strcmp(keyword, e->name))) {
+        // it is
+
+        e->flags |= ARL_ENTRY_FLAG_FOUND;
+
+        // execute the processor
+        if(unlikely(e->dst)) {
+            base->processor(e->name, e->hash, value, e->dst);
+            base->found++;
+        }
+
+        // be prepared for the next iteration
+        base->next_keyword = e->next;
+        if(unlikely(!base->next_keyword))
+            base->next_keyword = base->head;
+
+        // stop if we collected all the values for this iteration
+        if(unlikely(base->found == base->wanted))
+            return 1;
+
+        return 0;
+    }
+
+    // we read from source, a not-expected keyword
+    return arl_find_or_create_and_relink(base, keyword, hash, value);
+}
+
+#endif //NETDATA_ADAPTIVE_RESORTABLE_LIST_H
index 7e646427d1801345bdcca2a54554f4153434a769..191e8be3a7932eda27ebca2d292120b0fde55a1c 100644 (file)
@@ -1,4 +1,5 @@
 #include "common.h"
+#include "adaptive_resortable_list.h"
 
 int do_proc_vmstat(int update_every, usec_t dt) {
     (void)dt;
@@ -7,263 +8,45 @@ int do_proc_vmstat(int update_every, usec_t dt) {
     static int do_swapio = -1, do_io = -1, do_pgfaults = -1, do_numa = -1;
     static int has_numa = -1;
 
-    // static uint32_t hash_allocstall_dma = 0;
-    // static uint32_t hash_allocstall_dma32 = 0;
-    // static uint32_t hash_allocstall_movable = 0;
-    // static uint32_t hash_allocstall_normal = 0;
-    // static uint32_t hash_balloon_deflate = 0;
-    // static uint32_t hash_balloon_inflate = 0;
-    // static uint32_t hash_balloon_migrate = 0;
-    // static uint32_t hash_compact_daemon_wake = 0;
-    // static uint32_t hash_compact_fail = 0;
-    // static uint32_t hash_compact_free_scanned = 0;
-    // static uint32_t hash_compact_isolated = 0;
-    // static uint32_t hash_compact_migrate_scanned = 0;
-    // static uint32_t hash_compact_stall = 0;
-    // static uint32_t hash_compact_success = 0;
-    // static uint32_t hash_drop_pagecache = 0;
-    // static uint32_t hash_drop_slab = 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_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_cma = 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_pages_scanned = 0;
-    // static uint32_t hash_nr_page_table_pages = 0;
-    // static uint32_t hash_nr_shmem = 0;
-    // static uint32_t hash_nr_shmem_hugepages = 0;
-    // static uint32_t hash_nr_shmem_pmdmapped = 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_nr_zone_active_anon = 0;
-    // static uint32_t hash_nr_zone_active_file = 0;
-    // static uint32_t hash_nr_zone_inactive_anon = 0;
-    // static uint32_t hash_nr_zone_inactive_file = 0;
-    // static uint32_t hash_nr_zone_unevictable = 0;
-    // static uint32_t hash_nr_zone_write_pending = 0;
-    // static uint32_t hash_nr_zspages = 0;
-    static uint32_t hash_numa_foreign = 0;
-    static uint32_t hash_numa_hint_faults = 0;
-    static uint32_t hash_numa_hint_faults_local = 0;
-    //static uint32_t hash_numa_hit = 0;
-    static uint32_t hash_numa_huge_pte_updates = 0;
-    static uint32_t hash_numa_interleave = 0;
-    static uint32_t hash_numa_local = 0;
-    //static uint32_t hash_numa_miss = 0;
-    static uint32_t hash_numa_other = 0;
-    static uint32_t hash_numa_pages_migrated = 0;
-    static uint32_t hash_numa_pte_updates = 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_pglazyfreed = 0;
-    static uint32_t hash_pgmajfault = 0;
-    // static uint32_t hash_pgmigrate_fail = 0;
-    // static uint32_t hash_pgmigrate_success = 0;
-    static uint32_t hash_pgpgin = 0;
-    static uint32_t hash_pgpgout = 0;
-    // static uint32_t hash_pgrefill = 0;
-    // static uint32_t hash_pgrotated = 0;
-    // static uint32_t hash_pgscan_direct = 0;
-    // static uint32_t hash_pgscan_direct_throttle = 0;
-    // static uint32_t hash_pgscan_kswapd = 0;
-    // static uint32_t hash_pgskip_dma = 0;
-    // static uint32_t hash_pgskip_dma32 = 0;
-    // static uint32_t hash_pgskip_movable = 0;
-    // static uint32_t hash_pgskip_normal = 0;
-    // static uint32_t hash_pgsteal_direct = 0;
-    // static uint32_t hash_pgsteal_kswapd = 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_deferred_split_page = 0;
-    // static uint32_t hash_thp_fault_alloc = 0;
-    // static uint32_t hash_thp_fault_fallback = 0;
-    // static uint32_t hash_thp_file_alloc = 0;
-    // static uint32_t hash_thp_file_mapped = 0;
-    // static uint32_t hash_thp_split_page = 0;
-    // static uint32_t hash_thp_split_page_failed = 0;
-    // static uint32_t hash_thp_split_pmd = 0;
-    // static uint32_t hash_thp_zero_page_alloc = 0;
-    // static uint32_t hash_thp_zero_page_alloc_failed = 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_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_workingset_activate = 0;
-    // static uint32_t hash_workingset_nodereclaim = 0;
-    // static uint32_t hash_workingset_refault = 0;
-    // static uint32_t hash_zone_reclaim_failed = 0;
-
-    if(unlikely(do_swapio == -1)) {
+    static ARL_BASE *arl_base = NULL;
+    static unsigned long long numa_foreign = 0ULL;
+    static unsigned long long numa_hint_faults = 0ULL;
+    static unsigned long long numa_hint_faults_local = 0ULL;
+    static unsigned long long numa_huge_pte_updates = 0ULL;
+    static unsigned long long numa_interleave = 0ULL;
+    static unsigned long long numa_local = 0ULL;
+    static unsigned long long numa_other = 0ULL;
+    static unsigned long long numa_pages_migrated = 0ULL;
+    static unsigned long long numa_pte_updates = 0ULL;
+    static unsigned long long pgfault = 0ULL;
+    static unsigned long long pgmajfault = 0ULL;
+    static unsigned long long pgpgin = 0ULL;
+    static unsigned long long pgpgout = 0ULL;
+    static unsigned long long pswpin = 0ULL;
+    static unsigned long long pswpout = 0ULL;
+
+    if(unlikely(!arl_base)) {
         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);
         do_numa = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "system-wide numa metric summary", CONFIG_ONDEMAND_ONDEMAND);
 
-        // hash_allocstall_dma32 = simple_hash("allocstall_dma32");
-        // hash_allocstall_dma = simple_hash("allocstall_dma");
-        // hash_allocstall_movable = simple_hash("allocstall_movable");
-        // hash_allocstall_normal = simple_hash("allocstall_normal");
-        // hash_balloon_deflate = simple_hash("balloon_deflate");
-        // hash_balloon_inflate = simple_hash("balloon_inflate");
-        // hash_balloon_migrate = simple_hash("balloon_migrate");
-        // hash_compact_daemon_wake = simple_hash("compact_daemon_wake");
-        // hash_compact_fail = simple_hash("compact_fail");
-        // hash_compact_free_scanned = simple_hash("compact_free_scanned");
-        // hash_compact_isolated = simple_hash("compact_isolated");
-        // hash_compact_migrate_scanned = simple_hash("compact_migrate_scanned");
-        // hash_compact_stall = simple_hash("compact_stall");
-        // hash_compact_success = simple_hash("compact_success");
-        // hash_drop_pagecache = simple_hash("drop_pagecache");
-        // hash_drop_slab = simple_hash("drop_slab");
-        // hash_htlb_buddy_alloc_fail = simple_hash("htlb_buddy_alloc_fail");
-        // hash_htlb_buddy_alloc_success = simple_hash("htlb_buddy_alloc_success");
-        // hash_kswapd_high_wmark_hit_quickly = simple_hash("kswapd_high_wmark_hit_quickly");
-        // hash_kswapd_inodesteal = simple_hash("kswapd_inodesteal");
-        // hash_kswapd_low_wmark_hit_quickly = simple_hash("kswapd_low_wmark_hit_quickly");
-        // hash_nr_active_anon = simple_hash("nr_active_anon");
-        // hash_nr_active_file = simple_hash("nr_active_file");
-        // hash_nr_anon_pages = simple_hash("nr_anon_pages");
-        // hash_nr_anon_transparent_hugepages = simple_hash("nr_anon_transparent_hugepages");
-        // hash_nr_bounce = simple_hash("nr_bounce");
-        // hash_nr_dirtied = simple_hash("nr_dirtied");
-        // hash_nr_dirty_background_threshold = simple_hash("nr_dirty_background_threshold");
-        // hash_nr_dirty = simple_hash("nr_dirty");
-        // hash_nr_dirty_threshold = simple_hash("nr_dirty_threshold");
-        // hash_nr_file_pages = simple_hash("nr_file_pages");
-        // hash_nr_free_cma = simple_hash("nr_free_cma");
-        // hash_nr_free_pages = simple_hash("nr_free_pages");
-        // hash_nr_inactive_anon = simple_hash("nr_inactive_anon");
-        // hash_nr_inactive_file = simple_hash("nr_inactive_file");
-        // hash_nr_isolated_anon = simple_hash("nr_isolated_anon");
-        // hash_nr_isolated_file = simple_hash("nr_isolated_file");
-        // hash_nr_kernel_stack = simple_hash("nr_kernel_stack");
-        // hash_nr_mapped = simple_hash("nr_mapped");
-        // hash_nr_mlock = simple_hash("nr_mlock");
-        // hash_nr_pages_scanned = simple_hash("nr_pages_scanned");
-        // hash_nr_page_table_pages = simple_hash("nr_page_table_pages");
-        // hash_nr_shmem_hugepages = simple_hash("nr_shmem_hugepages");
-        // hash_nr_shmem_pmdmapped = simple_hash("nr_shmem_pmdmapped");
-        // hash_nr_shmem = simple_hash("nr_shmem");
-        // hash_nr_slab_reclaimable = simple_hash("nr_slab_reclaimable");
-        // hash_nr_slab_unreclaimable = simple_hash("nr_slab_unreclaimable");
-        // hash_nr_unevictable = simple_hash("nr_unevictable");
-        // hash_nr_unstable = simple_hash("nr_unstable");
-        // hash_nr_vmscan_immediate_reclaim = simple_hash("nr_vmscan_immediate_reclaim");
-        // hash_nr_vmscan_write = simple_hash("nr_vmscan_write");
-        // hash_nr_writeback = simple_hash("nr_writeback");
-        // hash_nr_writeback_temp = simple_hash("nr_writeback_temp");
-        // hash_nr_written = simple_hash("nr_written");
-        // hash_nr_zone_active_anon = simple_hash("nr_zone_active_anon");
-        // hash_nr_zone_active_file = simple_hash("nr_zone_active_file");
-        // hash_nr_zone_inactive_anon = simple_hash("nr_zone_inactive_anon");
-        // hash_nr_zone_inactive_file = simple_hash("nr_zone_inactive_file");
-        // hash_nr_zone_unevictable = simple_hash("nr_zone_unevictable");
-        // hash_nr_zone_write_pending = simple_hash("nr_zone_write_pending");
-        // hash_nr_zspages = simple_hash("nr_zspages");
-        hash_numa_foreign = simple_hash("numa_foreign");
-        hash_numa_hint_faults_local = simple_hash("numa_hint_faults_local");
-        hash_numa_hint_faults = simple_hash("numa_hint_faults");
-        //hash_numa_hit = simple_hash("numa_hit");
-        hash_numa_huge_pte_updates = simple_hash("numa_huge_pte_updates");
-        hash_numa_interleave = simple_hash("numa_interleave");
-        hash_numa_local = simple_hash("numa_local");
-        //hash_numa_miss = simple_hash("numa_miss");
-        hash_numa_other = simple_hash("numa_other");
-        hash_numa_pages_migrated = simple_hash("numa_pages_migrated");
-        hash_numa_pte_updates = simple_hash("numa_pte_updates");
-        // hash_pageoutrun = simple_hash("pageoutrun");
-        // hash_pgactivate = simple_hash("pgactivate");
-        // hash_pgalloc_dma32 = simple_hash("pgalloc_dma32");
-        // hash_pgalloc_dma = simple_hash("pgalloc_dma");
-        // hash_pgalloc_movable = simple_hash("pgalloc_movable");
-        // hash_pgalloc_normal = simple_hash("pgalloc_normal");
-        // hash_pgdeactivate = simple_hash("pgdeactivate");
-        hash_pgfault = simple_hash("pgfault");
-        // hash_pgfree = simple_hash("pgfree");
-        // hash_pginodesteal = simple_hash("pginodesteal");
-        // hash_pglazyfreed = simple_hash("pglazyfreed");
-        hash_pgmajfault = simple_hash("pgmajfault");
-        // hash_pgmigrate_fail = simple_hash("pgmigrate_fail");
-        // hash_pgmigrate_success = simple_hash("pgmigrate_success");
-        hash_pgpgin = simple_hash("pgpgin");
-        hash_pgpgout = simple_hash("pgpgout");
-        // hash_pgrefill = simple_hash("pgrefill");
-        // hash_pgrotated = simple_hash("pgrotated");
-        // hash_pgscan_direct = simple_hash("pgscan_direct");
-        // hash_pgscan_direct_throttle = simple_hash("pgscan_direct_throttle");
-        // hash_pgscan_kswapd = simple_hash("pgscan_kswapd");
-        // hash_pgskip_dma32 = simple_hash("pgskip_dma32");
-        // hash_pgskip_dma = simple_hash("pgskip_dma");
-        // hash_pgskip_movable = simple_hash("pgskip_movable");
-        // hash_pgskip_normal = simple_hash("pgskip_normal");
-        // hash_pgsteal_direct = simple_hash("pgsteal_direct");
-        // hash_pgsteal_kswapd = simple_hash("pgsteal_kswapd");
-        hash_pswpin = simple_hash("pswpin");
-        hash_pswpout = simple_hash("pswpout");
-        // hash_slabs_scanned = simple_hash("slabs_scanned");
-        // hash_thp_collapse_alloc_failed = simple_hash("thp_collapse_alloc_failed");
-        // hash_thp_collapse_alloc = simple_hash("thp_collapse_alloc");
-        // hash_thp_deferred_split_page = simple_hash("thp_deferred_split_page");
-        // hash_thp_fault_alloc = simple_hash("thp_fault_alloc");
-        // hash_thp_fault_fallback = simple_hash("thp_fault_fallback");
-        // hash_thp_file_alloc = simple_hash("thp_file_alloc");
-        // hash_thp_file_mapped = simple_hash("thp_file_mapped");
-        // hash_thp_split_page_failed = simple_hash("thp_split_page_failed");
-        // hash_thp_split_page = simple_hash("thp_split_page");
-        // hash_thp_split_pmd = simple_hash("thp_split_pmd");
-        // hash_thp_zero_page_alloc_failed = simple_hash("thp_zero_page_alloc_failed");
-        // hash_thp_zero_page_alloc = simple_hash("thp_zero_page_alloc");
-        // hash_unevictable_pgs_cleared = simple_hash("unevictable_pgs_cleared");
-        // hash_unevictable_pgs_culled = simple_hash("unevictable_pgs_culled");
-        // hash_unevictable_pgs_mlocked = simple_hash("unevictable_pgs_mlocked");
-        // hash_unevictable_pgs_munlocked = simple_hash("unevictable_pgs_munlocked");
-        // hash_unevictable_pgs_rescued = simple_hash("unevictable_pgs_rescued");
-        // hash_unevictable_pgs_scanned = simple_hash("unevictable_pgs_scanned");
-        // hash_unevictable_pgs_stranded = simple_hash("unevictable_pgs_stranded");
-        // hash_workingset_activate = simple_hash("workingset_activate");
-        // hash_workingset_nodereclaim = simple_hash("workingset_nodereclaim");
-        // hash_workingset_refault = simple_hash("workingset_refault");
-        // hash_zone_reclaim_failed = simple_hash("zone_reclaim_failed");
+        arl_base = arl_create(NULL, 60);
+        arl_expect(arl_base, "numa_foreign", &numa_foreign);
+        arl_expect(arl_base, "numa_hint_faults_local", &numa_hint_faults_local);
+        arl_expect(arl_base, "numa_hint_faults", &numa_hint_faults);
+        arl_expect(arl_base, "numa_huge_pte_updates", &numa_huge_pte_updates);
+        arl_expect(arl_base, "numa_interleave", &numa_interleave);
+        arl_expect(arl_base, "numa_local", &numa_local);
+        arl_expect(arl_base, "numa_other", &numa_other);
+        arl_expect(arl_base, "numa_pages_migrated", &numa_pages_migrated);
+        arl_expect(arl_base, "numa_pte_updates", &numa_pte_updates);
+        arl_expect(arl_base, "pgfault", &pgfault);
+        arl_expect(arl_base, "pgmajfault", &pgmajfault);
+        arl_expect(arl_base, "pgpgin", &pgpgin);
+        arl_expect(arl_base, "pgpgout", &pgpgout);
+        arl_expect(arl_base, "pswpin", &pswpin);
+        arl_expect(arl_base, "pswpout", &pswpout);
     }
 
     if(unlikely(!ff)) {
@@ -278,134 +61,7 @@ int do_proc_vmstat(int update_every, usec_t dt) {
 
     uint32_t lines = procfile_lines(ff), l;
 
-    // unsigned long long allocstall_dma = 0ULL;
-    // unsigned long long allocstall_dma32 = 0ULL;
-    // unsigned long long allocstall_movable = 0ULL;
-    // unsigned long long allocstall_normal = 0ULL;
-    // unsigned long long balloon_deflate = 0ULL;
-    // unsigned long long balloon_inflate = 0ULL;
-    // unsigned long long balloon_migrate = 0ULL;
-    // unsigned long long compact_daemon_wake = 0ULL;
-    // unsigned long long compact_fail = 0ULL;
-    // unsigned long long compact_free_scanned = 0ULL;
-    // unsigned long long compact_isolated = 0ULL;
-    // unsigned long long compact_migrate_scanned = 0ULL;
-    // unsigned long long compact_stall = 0ULL;
-    // unsigned long long compact_success = 0ULL;
-    // unsigned long long drop_pagecache = 0ULL;
-    // unsigned long long drop_slab = 0ULL;
-    // unsigned long long htlb_buddy_alloc_fail = 0ULL;
-    // unsigned long long htlb_buddy_alloc_success = 0ULL;
-    // unsigned long long kswapd_high_wmark_hit_quickly = 0ULL;
-    // unsigned long long kswapd_inodesteal = 0ULL;
-    // unsigned long long kswapd_low_wmark_hit_quickly = 0ULL;
-    // unsigned long long nr_active_anon = 0ULL;
-    // unsigned long long nr_active_file = 0ULL;
-    // unsigned long long nr_anon_pages = 0ULL;
-    // unsigned long long nr_anon_transparent_hugepages = 0ULL;
-    // unsigned long long nr_bounce = 0ULL;
-    // unsigned long long nr_dirtied = 0ULL;
-    // unsigned long long nr_dirty = 0ULL;
-    // unsigned long long nr_dirty_background_threshold = 0ULL;
-    // unsigned long long nr_dirty_threshold = 0ULL;
-    // unsigned long long nr_file_pages = 0ULL;
-    // unsigned long long nr_free_cma = 0ULL;
-    // unsigned long long nr_free_pages = 0ULL;
-    // unsigned long long nr_inactive_anon = 0ULL;
-    // unsigned long long nr_inactive_file = 0ULL;
-    // unsigned long long nr_isolated_anon = 0ULL;
-    // unsigned long long nr_isolated_file = 0ULL;
-    // unsigned long long nr_kernel_stack = 0ULL;
-    // unsigned long long nr_mapped = 0ULL;
-    // unsigned long long nr_mlock = 0ULL;
-    // unsigned long long nr_pages_scanned = 0ULL;
-    // unsigned long long nr_page_table_pages = 0ULL;
-    // unsigned long long nr_shmem = 0ULL;
-    // unsigned long long nr_shmem_hugepages = 0ULL;
-    // unsigned long long nr_shmem_pmdmapped = 0ULL;
-    // unsigned long long nr_slab_reclaimable = 0ULL;
-    // unsigned long long nr_slab_unreclaimable = 0ULL;
-    // unsigned long long nr_unevictable = 0ULL;
-    // unsigned long long nr_unstable = 0ULL;
-    // unsigned long long nr_vmscan_immediate_reclaim = 0ULL;
-    // unsigned long long nr_vmscan_write = 0ULL;
-    // unsigned long long nr_writeback = 0ULL;
-    // unsigned long long nr_writeback_temp = 0ULL;
-    // unsigned long long nr_written = 0ULL;
-    // unsigned long long nr_zone_active_anon = 0ULL;
-    // unsigned long long nr_zone_active_file = 0ULL;
-    // unsigned long long nr_zone_inactive_anon = 0ULL;
-    // unsigned long long nr_zone_inactive_file = 0ULL;
-    // unsigned long long nr_zone_unevictable = 0ULL;
-    // unsigned long long nr_zone_write_pending = 0ULL;
-    // unsigned long long nr_zspages = 0ULL;
-    unsigned long long numa_foreign = 0ULL;
-    unsigned long long numa_hint_faults = 0ULL;
-    unsigned long long numa_hint_faults_local = 0ULL;
-    //unsigned long long numa_hit = 0ULL;
-    unsigned long long numa_huge_pte_updates = 0ULL;
-    unsigned long long numa_interleave = 0ULL;
-    unsigned long long numa_local = 0ULL;
-    //unsigned long long numa_miss = 0ULL;
-    unsigned long long numa_other = 0ULL;
-    unsigned long long numa_pages_migrated = 0ULL;
-    unsigned long long numa_pte_updates = 0ULL;
-    // unsigned long long pageoutrun = 0ULL;
-    // unsigned long long pgactivate = 0ULL;
-    // unsigned long long pgalloc_dma = 0ULL;
-    // unsigned long long pgalloc_dma32 = 0ULL;
-    // unsigned long long pgalloc_movable = 0ULL;
-    // unsigned long long pgalloc_normal = 0ULL;
-    // unsigned long long pgdeactivate = 0ULL;
-    unsigned long long pgfault = 0ULL;
-    // unsigned long long pgfree = 0ULL;
-    // unsigned long long pginodesteal = 0ULL;
-    // unsigned long long pglazyfreed = 0ULL;
-    unsigned long long pgmajfault = 0ULL;
-    // unsigned long long pgmigrate_fail = 0ULL;
-    // unsigned long long pgmigrate_success = 0ULL;
-    unsigned long long pgpgin = 0ULL;
-    unsigned long long pgpgout = 0ULL;
-    // unsigned long long pgrefill = 0ULL;
-    // unsigned long long pgrotated = 0ULL;
-    // unsigned long long pgscan_direct = 0ULL;
-    // unsigned long long pgscan_direct_throttle = 0ULL;
-    // unsigned long long pgscan_kswapd = 0ULL;
-    // unsigned long long pgskip_dma = 0ULL;
-    // unsigned long long pgskip_dma32 = 0ULL;
-    // unsigned long long pgskip_movable = 0ULL;
-    // unsigned long long pgskip_normal = 0ULL;
-    // unsigned long long pgsteal_direct = 0ULL;
-    // unsigned long long pgsteal_kswapd = 0ULL;
-    unsigned long long pswpin = 0ULL;
-    unsigned long long pswpout = 0ULL;
-    // unsigned long long slabs_scanned = 0ULL;
-    // unsigned long long thp_collapse_alloc = 0ULL;
-    // unsigned long long thp_collapse_alloc_failed = 0ULL;
-    // unsigned long long thp_deferred_split_page = 0ULL;
-    // unsigned long long thp_fault_alloc = 0ULL;
-    // unsigned long long thp_fault_fallback = 0ULL;
-    // unsigned long long thp_file_alloc = 0ULL;
-    // unsigned long long thp_file_mapped = 0ULL;
-    // unsigned long long thp_split_page = 0ULL;
-    // unsigned long long thp_split_page_failed = 0ULL;
-    // unsigned long long thp_split_pmd = 0ULL;
-    // unsigned long long thp_zero_page_alloc = 0ULL;
-    // unsigned long long thp_zero_page_alloc_failed = 0ULL;
-    // unsigned long long unevictable_pgs_cleared = 0ULL;
-    // unsigned long long unevictable_pgs_culled = 0ULL;
-    // unsigned long long unevictable_pgs_mlocked = 0ULL;
-    // unsigned long long unevictable_pgs_munlocked = 0ULL;
-    // unsigned long long unevictable_pgs_rescued = 0ULL;
-    // unsigned long long unevictable_pgs_scanned = 0ULL;
-    // unsigned long long unevictable_pgs_stranded = 0ULL;
-    // unsigned long long workingset_activate = 0ULL;
-    // unsigned long long workingset_nodereclaim = 0ULL;
-    // unsigned long long workingset_refault = 0ULL;
-    // unsigned long long zone_reclaim_failed = 0ULL;
-
-    unsigned long long *ptr = NULL;
-
+    arl_begin(arl_base);
     for(l = 0; l < lines ;l++) {
         uint32_t words = procfile_linewords(ff, l);
         if(unlikely(words < 2)) {
@@ -414,142 +70,11 @@ int do_proc_vmstat(int update_every, usec_t dt) {
         }
 
         char *name = procfile_lineword(ff, l, 0);
-        char * value = procfile_lineword(ff, l, 1);
+        char *value = procfile_lineword(ff, l, 1);
         if(unlikely(!name || !*name || !value || !*value)) continue;
 
-        uint32_t hash = simple_hash(name);
-
-        if(unlikely(0)) ;
-        // else if(unlikely(hash == hash_allocstall_dma32 && strcmp(name, "allocstall_dma32") == 0)) ptr = &allocstall_dma32;
-        // else if(unlikely(hash == hash_allocstall_dma && strcmp(name, "allocstall_dma") == 0)) ptr = &allocstall_dma;
-        // else if(unlikely(hash == hash_allocstall_movable && strcmp(name, "allocstall_movable") == 0)) ptr = &allocstall_movable;
-        // else if(unlikely(hash == hash_allocstall_normal && strcmp(name, "allocstall_normal") == 0)) ptr = &allocstall_normal;
-        // else if(unlikely(hash == hash_balloon_deflate && strcmp(name, "balloon_deflate") == 0)) ptr = &balloon_deflate;
-        // else if(unlikely(hash == hash_balloon_inflate && strcmp(name, "balloon_inflate") == 0)) ptr = &balloon_inflate;
-        // else if(unlikely(hash == hash_balloon_migrate && strcmp(name, "balloon_migrate") == 0)) ptr = &balloon_migrate;
-        // else if(unlikely(hash == hash_compact_daemon_wake && strcmp(name, "compact_daemon_wake") == 0)) ptr = &compact_daemon_wake;
-        // else if(unlikely(hash == hash_compact_fail && strcmp(name, "compact_fail") == 0)) ptr = &compact_fail;
-        // else if(unlikely(hash == hash_compact_free_scanned && strcmp(name, "compact_free_scanned") == 0)) ptr = &compact_free_scanned;
-        // else if(unlikely(hash == hash_compact_isolated && strcmp(name, "compact_isolated") == 0)) ptr = &compact_isolated;
-        // else if(unlikely(hash == hash_compact_migrate_scanned && strcmp(name, "compact_migrate_scanned") == 0)) ptr = &compact_migrate_scanned;
-        // else if(unlikely(hash == hash_compact_stall && strcmp(name, "compact_stall") == 0)) ptr = &compact_stall;
-        // else if(unlikely(hash == hash_compact_success && strcmp(name, "compact_success") == 0)) ptr = &compact_success;
-        // else if(unlikely(hash == hash_drop_pagecache && strcmp(name, "drop_pagecache") == 0)) ptr = &drop_pagecache;
-        // else if(unlikely(hash == hash_drop_slab && strcmp(name, "drop_slab") == 0)) ptr = &drop_slab;
-        // else if(unlikely(hash == hash_htlb_buddy_alloc_fail && strcmp(name, "htlb_buddy_alloc_fail") == 0)) ptr = &htlb_buddy_alloc_fail;
-        // else if(unlikely(hash == hash_htlb_buddy_alloc_success && strcmp(name, "htlb_buddy_alloc_success") == 0)) ptr = &htlb_buddy_alloc_success;
-        // else if(unlikely(hash == hash_kswapd_high_wmark_hit_quickly && strcmp(name, "kswapd_high_wmark_hit_quickly") == 0)) ptr = &kswapd_high_wmark_hit_quickly;
-        // else if(unlikely(hash == hash_kswapd_inodesteal && strcmp(name, "kswapd_inodesteal") == 0)) ptr = &kswapd_inodesteal;
-        // else if(unlikely(hash == hash_kswapd_low_wmark_hit_quickly && strcmp(name, "kswapd_low_wmark_hit_quickly") == 0)) ptr = &kswapd_low_wmark_hit_quickly;
-        // else if(unlikely(hash == hash_nr_active_anon && strcmp(name, "nr_active_anon") == 0)) ptr = &nr_active_anon;
-        // else if(unlikely(hash == hash_nr_active_file && strcmp(name, "nr_active_file") == 0)) ptr = &nr_active_file;
-        // else if(unlikely(hash == hash_nr_anon_pages && strcmp(name, "nr_anon_pages") == 0)) ptr = &nr_anon_pages;
-        // else if(unlikely(hash == hash_nr_anon_transparent_hugepages && strcmp(name, "nr_anon_transparent_hugepages") == 0)) ptr = &nr_anon_transparent_hugepages;
-        // else if(unlikely(hash == hash_nr_bounce && strcmp(name, "nr_bounce") == 0)) ptr = &nr_bounce;
-        // else if(unlikely(hash == hash_nr_dirtied && strcmp(name, "nr_dirtied") == 0)) ptr = &nr_dirtied;
-        // else if(unlikely(hash == hash_nr_dirty_background_threshold && strcmp(name, "nr_dirty_background_threshold") == 0)) ptr = &nr_dirty_background_threshold;
-        // else if(unlikely(hash == hash_nr_dirty && strcmp(name, "nr_dirty") == 0)) ptr = &nr_dirty;
-        // else if(unlikely(hash == hash_nr_dirty_threshold && strcmp(name, "nr_dirty_threshold") == 0)) ptr = &nr_dirty_threshold;
-        // else if(unlikely(hash == hash_nr_file_pages && strcmp(name, "nr_file_pages") == 0)) ptr = &nr_file_pages;
-        // else if(unlikely(hash == hash_nr_free_cma && strcmp(name, "nr_free_cma") == 0)) ptr = &nr_free_cma;
-        // else if(unlikely(hash == hash_nr_free_pages && strcmp(name, "nr_free_pages") == 0)) ptr = &nr_free_pages;
-        // else if(unlikely(hash == hash_nr_inactive_anon && strcmp(name, "nr_inactive_anon") == 0)) ptr = &nr_inactive_anon;
-        // else if(unlikely(hash == hash_nr_inactive_file && strcmp(name, "nr_inactive_file") == 0)) ptr = &nr_inactive_file;
-        // else if(unlikely(hash == hash_nr_isolated_anon && strcmp(name, "nr_isolated_anon") == 0)) ptr = &nr_isolated_anon;
-        // else if(unlikely(hash == hash_nr_isolated_file && strcmp(name, "nr_isolated_file") == 0)) ptr = &nr_isolated_file;
-        // else if(unlikely(hash == hash_nr_kernel_stack && strcmp(name, "nr_kernel_stack") == 0)) ptr = &nr_kernel_stack;
-        // else if(unlikely(hash == hash_nr_mapped && strcmp(name, "nr_mapped") == 0)) ptr = &nr_mapped;
-        // else if(unlikely(hash == hash_nr_mlock && strcmp(name, "nr_mlock") == 0)) ptr = &nr_mlock;
-        // else if(unlikely(hash == hash_nr_pages_scanned && strcmp(name, "nr_pages_scanned") == 0)) ptr = &nr_pages_scanned;
-        // else if(unlikely(hash == hash_nr_page_table_pages && strcmp(name, "nr_page_table_pages") == 0)) ptr = &nr_page_table_pages;
-        // else if(unlikely(hash == hash_nr_shmem_hugepages && strcmp(name, "nr_shmem_hugepages") == 0)) ptr = &nr_shmem_hugepages;
-        // else if(unlikely(hash == hash_nr_shmem_pmdmapped && strcmp(name, "nr_shmem_pmdmapped") == 0)) ptr = &nr_shmem_pmdmapped;
-        // else if(unlikely(hash == hash_nr_shmem && strcmp(name, "nr_shmem") == 0)) ptr = &nr_shmem;
-        // else if(unlikely(hash == hash_nr_slab_reclaimable && strcmp(name, "nr_slab_reclaimable") == 0)) ptr = &nr_slab_reclaimable;
-        // else if(unlikely(hash == hash_nr_slab_unreclaimable && strcmp(name, "nr_slab_unreclaimable") == 0)) ptr = &nr_slab_unreclaimable;
-        // else if(unlikely(hash == hash_nr_unevictable && strcmp(name, "nr_unevictable") == 0)) ptr = &nr_unevictable;
-        // else if(unlikely(hash == hash_nr_unstable && strcmp(name, "nr_unstable") == 0)) ptr = &nr_unstable;
-        // else if(unlikely(hash == hash_nr_vmscan_immediate_reclaim && strcmp(name, "nr_vmscan_immediate_reclaim") == 0)) ptr = &nr_vmscan_immediate_reclaim;
-        // else if(unlikely(hash == hash_nr_vmscan_write && strcmp(name, "nr_vmscan_write") == 0)) ptr = &nr_vmscan_write;
-        // else if(unlikely(hash == hash_nr_writeback && strcmp(name, "nr_writeback") == 0)) ptr = &nr_writeback;
-        // else if(unlikely(hash == hash_nr_writeback_temp && strcmp(name, "nr_writeback_temp") == 0)) ptr = &nr_writeback_temp;
-        // else if(unlikely(hash == hash_nr_written && strcmp(name, "nr_written") == 0)) ptr = &nr_written;
-        // else if(unlikely(hash == hash_nr_zone_active_anon && strcmp(name, "nr_zone_active_anon") == 0)) ptr = &nr_zone_active_anon;
-        // else if(unlikely(hash == hash_nr_zone_active_file && strcmp(name, "nr_zone_active_file") == 0)) ptr = &nr_zone_active_file;
-        // else if(unlikely(hash == hash_nr_zone_inactive_anon && strcmp(name, "nr_zone_inactive_anon") == 0)) ptr = &nr_zone_inactive_anon;
-        // else if(unlikely(hash == hash_nr_zone_inactive_file && strcmp(name, "nr_zone_inactive_file") == 0)) ptr = &nr_zone_inactive_file;
-        // else if(unlikely(hash == hash_nr_zone_unevictable && strcmp(name, "nr_zone_unevictable") == 0)) ptr = &nr_zone_unevictable;
-        // else if(unlikely(hash == hash_nr_zone_write_pending && strcmp(name, "nr_zone_write_pending") == 0)) ptr = &nr_zone_write_pending;
-        // else if(unlikely(hash == hash_nr_zspages && strcmp(name, "nr_zspages") == 0)) ptr = &nr_zspages;
-        else if(unlikely(hash == hash_numa_foreign && strcmp(name, "numa_foreign") == 0)) ptr = &numa_foreign;
-        else if(unlikely(hash == hash_numa_hint_faults_local && strcmp(name, "numa_hint_faults_local") == 0)) ptr = &numa_hint_faults_local;
-        else if(unlikely(hash == hash_numa_hint_faults && strcmp(name, "numa_hint_faults") == 0)) ptr = &numa_hint_faults;
-        //else if(unlikely(hash == hash_numa_hit && strcmp(name, "numa_hit") == 0)) ptr = &numa_hit;
-        else if(unlikely(hash == hash_numa_huge_pte_updates && strcmp(name, "numa_huge_pte_updates") == 0)) ptr = &numa_huge_pte_updates;
-        else if(unlikely(hash == hash_numa_interleave && strcmp(name, "numa_interleave") == 0)) ptr = &numa_interleave;
-        else if(unlikely(hash == hash_numa_local && strcmp(name, "numa_local") == 0)) ptr = &numa_local;
-        //else if(unlikely(hash == hash_numa_miss && strcmp(name, "numa_miss") == 0)) ptr = &numa_miss;
-        else if(unlikely(hash == hash_numa_other && strcmp(name, "numa_other") == 0)) ptr = &numa_other;
-        else if(unlikely(hash == hash_numa_pages_migrated && strcmp(name, "numa_pages_migrated") == 0)) ptr = &numa_pages_migrated;
-        else if(unlikely(hash == hash_numa_pte_updates && strcmp(name, "numa_pte_updates") == 0)) ptr = &numa_pte_updates;
-        // else if(unlikely(hash == hash_pageoutrun && strcmp(name, "pageoutrun") == 0)) ptr = &pageoutrun;
-        // else if(unlikely(hash == hash_pgactivate && strcmp(name, "pgactivate") == 0)) ptr = &pgactivate;
-        // else if(unlikely(hash == hash_pgalloc_dma32 && strcmp(name, "pgalloc_dma32") == 0)) ptr = &pgalloc_dma32;
-        // else if(unlikely(hash == hash_pgalloc_dma && strcmp(name, "pgalloc_dma") == 0)) ptr = &pgalloc_dma;
-        // else if(unlikely(hash == hash_pgalloc_movable && strcmp(name, "pgalloc_movable") == 0)) ptr = &pgalloc_movable;
-        // else if(unlikely(hash == hash_pgalloc_normal && strcmp(name, "pgalloc_normal") == 0)) ptr = &pgalloc_normal;
-        // else if(unlikely(hash == hash_pgdeactivate && strcmp(name, "pgdeactivate") == 0)) ptr = &pgdeactivate;
-        else if(unlikely(hash == hash_pgfault && strcmp(name, "pgfault") == 0)) ptr = &pgfault;
-        // else if(unlikely(hash == hash_pgfree && strcmp(name, "pgfree") == 0)) ptr = &pgfree;
-        // else if(unlikely(hash == hash_pginodesteal && strcmp(name, "pginodesteal") == 0)) ptr = &pginodesteal;
-        // else if(unlikely(hash == hash_pglazyfreed && strcmp(name, "pglazyfreed") == 0)) ptr = &pglazyfreed;
-        else if(unlikely(hash == hash_pgmajfault && strcmp(name, "pgmajfault") == 0)) ptr = &pgmajfault;
-        // else if(unlikely(hash == hash_pgmigrate_fail && strcmp(name, "pgmigrate_fail") == 0)) ptr = &pgmigrate_fail;
-        // else if(unlikely(hash == hash_pgmigrate_success && strcmp(name, "pgmigrate_success") == 0)) ptr = &pgmigrate_success;
-        else if(unlikely(hash == hash_pgpgin && strcmp(name, "pgpgin") == 0)) ptr = &pgpgin;
-        else if(unlikely(hash == hash_pgpgout && strcmp(name, "pgpgout") == 0)) ptr = &pgpgout;
-        // else if(unlikely(hash == hash_pgrefill && strcmp(name, "pgrefill") == 0)) ptr = &pgrefill;
-        // else if(unlikely(hash == hash_pgrotated && strcmp(name, "pgrotated") == 0)) ptr = &pgrotated;
-        // else if(unlikely(hash == hash_pgscan_direct && strcmp(name, "pgscan_direct") == 0)) ptr = &pgscan_direct;
-        // else if(unlikely(hash == hash_pgscan_direct_throttle && strcmp(name, "pgscan_direct_throttle") == 0)) ptr = &pgscan_direct_throttle;
-        // else if(unlikely(hash == hash_pgscan_kswapd && strcmp(name, "pgscan_kswapd") == 0)) ptr = &pgscan_kswapd;
-        // else if(unlikely(hash == hash_pgskip_dma32 && strcmp(name, "pgskip_dma32") == 0)) ptr = &pgskip_dma32;
-        // else if(unlikely(hash == hash_pgskip_dma && strcmp(name, "pgskip_dma") == 0)) ptr = &pgskip_dma;
-        // else if(unlikely(hash == hash_pgskip_movable && strcmp(name, "pgskip_movable") == 0)) ptr = &pgskip_movable;
-        // else if(unlikely(hash == hash_pgskip_normal && strcmp(name, "pgskip_normal") == 0)) ptr = &pgskip_normal;
-        // else if(unlikely(hash == hash_pgsteal_direct && strcmp(name, "pgsteal_direct") == 0)) ptr = &pgsteal_direct;
-        // else if(unlikely(hash == hash_pgsteal_kswapd && strcmp(name, "pgsteal_kswapd") == 0)) ptr = &pgsteal_kswapd;
-        else if(unlikely(hash == hash_pswpin && strcmp(name, "pswpin") == 0)) ptr = &pswpin;
-        else if(unlikely(hash == hash_pswpout && strcmp(name, "pswpout") == 0)) ptr = &pswpout;
-        // else if(unlikely(hash == hash_slabs_scanned && strcmp(name, "slabs_scanned") == 0)) ptr = &slabs_scanned;
-        // else if(unlikely(hash == hash_thp_collapse_alloc_failed && strcmp(name, "thp_collapse_alloc_failed") == 0)) ptr = &thp_collapse_alloc_failed;
-        // else if(unlikely(hash == hash_thp_collapse_alloc && strcmp(name, "thp_collapse_alloc") == 0)) ptr = &thp_collapse_alloc;
-        // else if(unlikely(hash == hash_thp_deferred_split_page && strcmp(name, "thp_deferred_split_page") == 0)) ptr = &thp_deferred_split_page;
-        // else if(unlikely(hash == hash_thp_fault_alloc && strcmp(name, "thp_fault_alloc") == 0)) ptr = &thp_fault_alloc;
-        // else if(unlikely(hash == hash_thp_fault_fallback && strcmp(name, "thp_fault_fallback") == 0)) ptr = &thp_fault_fallback;
-        // else if(unlikely(hash == hash_thp_file_alloc && strcmp(name, "thp_file_alloc") == 0)) ptr = &thp_file_alloc;
-        // else if(unlikely(hash == hash_thp_file_mapped && strcmp(name, "thp_file_mapped") == 0)) ptr = &thp_file_mapped;
-        // else if(unlikely(hash == hash_thp_split_page_failed && strcmp(name, "thp_split_page_failed") == 0)) ptr = &thp_split_page_failed;
-        // else if(unlikely(hash == hash_thp_split_page && strcmp(name, "thp_split_page") == 0)) ptr = &thp_split_page;
-        // else if(unlikely(hash == hash_thp_split_pmd && strcmp(name, "thp_split_pmd") == 0)) ptr = &thp_split_pmd;
-        // else if(unlikely(hash == hash_thp_zero_page_alloc_failed && strcmp(name, "thp_zero_page_alloc_failed") == 0)) ptr = &thp_zero_page_alloc_failed;
-        // else if(unlikely(hash == hash_thp_zero_page_alloc && strcmp(name, "thp_zero_page_alloc") == 0)) ptr = &thp_zero_page_alloc;
-        // else if(unlikely(hash == hash_unevictable_pgs_cleared && strcmp(name, "unevictable_pgs_cleared") == 0)) ptr = &unevictable_pgs_cleared;
-        // else if(unlikely(hash == hash_unevictable_pgs_culled && strcmp(name, "unevictable_pgs_culled") == 0)) ptr = &unevictable_pgs_culled;
-        // else if(unlikely(hash == hash_unevictable_pgs_mlocked && strcmp(name, "unevictable_pgs_mlocked") == 0)) ptr = &unevictable_pgs_mlocked;
-        // else if(unlikely(hash == hash_unevictable_pgs_munlocked && strcmp(name, "unevictable_pgs_munlocked") == 0)) ptr = &unevictable_pgs_munlocked;
-        // else if(unlikely(hash == hash_unevictable_pgs_rescued && strcmp(name, "unevictable_pgs_rescued") == 0)) ptr = &unevictable_pgs_rescued;
-        // else if(unlikely(hash == hash_unevictable_pgs_scanned && strcmp(name, "unevictable_pgs_scanned") == 0)) ptr = &unevictable_pgs_scanned;
-        // else if(unlikely(hash == hash_unevictable_pgs_stranded && strcmp(name, "unevictable_pgs_stranded") == 0)) ptr = &unevictable_pgs_stranded;
-        // else if(unlikely(hash == hash_workingset_activate && strcmp(name, "workingset_activate") == 0)) ptr = &workingset_activate;
-        // else if(unlikely(hash == hash_workingset_nodereclaim && strcmp(name, "workingset_nodereclaim") == 0)) ptr = &workingset_nodereclaim;
-        // else if(unlikely(hash == hash_workingset_refault && strcmp(name, "workingset_refault") == 0)) ptr = &workingset_refault;
-        // else if(unlikely(hash == hash_zone_reclaim_failed && strcmp(name, "zone_reclaim_failed") == 0)) ptr = &zone_reclaim_failed;
-
-        if(unlikely(ptr)) {
-            *ptr = str2ull(value);
-            ptr = NULL;
-        }
+        if(unlikely(arl_check(arl_base, name, value)))
+            break;
     }
 
     // --------------------------------------------------------------------
@@ -619,6 +144,8 @@ int do_proc_vmstat(int update_every, usec_t dt) {
     }
 
     if(do_numa == CONFIG_ONDEMAND_YES || (do_numa == CONFIG_ONDEMAND_ONDEMAND && has_numa)) {
+        do_numa = CONFIG_ONDEMAND_YES;
+
         static RRDSET *st_numa = NULL;
         if(unlikely(!st_numa)) {
             st_numa = rrdset_create("mem", "numa", NULL, "numa", NULL, "NUMA events", "events/s", 800, update_every, RRDSET_TYPE_LINE);
index b43b936aa29f1a68e83a1aebf28a685e3ddc7acd..2eea60548b4a7a7ee5b2196d84a2f55041efb423 100644 (file)
@@ -1,4 +1,5 @@
 #include "common.h"
+#include "adaptive_resortable_list.h"
 
 // ----------------------------------------------------------------------------
 // cgroup globals
@@ -295,6 +296,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;
@@ -663,115 +668,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 = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == rss_hash && !strcmp(s, "rss")))
-                mem->rss = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == rss_huge_hash && !strcmp(s, "rss_huge")))
-                mem->rss_huge = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == mapped_file_hash && !strcmp(s, "mapped_file")))
-                mem->mapped_file = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == writeback_hash && !strcmp(s, "writeback")))
-                mem->writeback = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == dirty_hash && !strcmp(s, "dirty"))) {
-                mem->dirty = str2ull(procfile_lineword(ff, i, 1));
-                mem->detailed_has_dirty = 1;
-            }
-
-            else if(unlikely(hash == swap_hash && !strcmp(s, "swap"))) {
-                mem->swap = str2ull(procfile_lineword(ff, i, 1));
-                mem->detailed_has_swap = 1;
-            }
-
-            else if(unlikely(hash == pgpgin_hash && !strcmp(s, "pgpgin")))
-                mem->pgpgin = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == pgpgout_hash && !strcmp(s, "pgpgout")))
-                mem->pgpgout = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == pgfault_hash && !strcmp(s, "pgfault")))
-                mem->pgfault = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == pgmajfault_hash && !strcmp(s, "pgmajfault")))
-                mem->pgmajfault = str2ull(procfile_lineword(ff, i, 1));
-
-/*
-            else if(unlikely(hash == inactive_anon_hash && !strcmp(s, "inactive_anon")))
-                mem->inactive_anon = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == active_anon_hash && !strcmp(s, "active_anon")))
-                mem->active_anon = str2ull(procfile_lineword(ff, i, 1));
+        if(unlikely(!mem->arl_base)) {
+            mem->arl_base = arl_create(NULL, 60);
 
-            else if(unlikely(hash == inactive_file_hash && !strcmp(s, "inactive_file")))
-                mem->inactive_file = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == active_file_hash && !strcmp(s, "active_file")))
-                mem->active_file = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == unevictable_hash && !strcmp(s, "unevictable")))
-                mem->unevictable = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit")))
-                mem->hierarchical_memory_limit = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_cache_hash && !strcmp(s, "total_cache")))
-                mem->total_cache = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_rss_hash && !strcmp(s, "total_rss")))
-                mem->total_rss = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge")))
-                mem->total_rss_huge = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file")))
-                mem->total_mapped_file = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_writeback_hash && !strcmp(s, "total_writeback")))
-                mem->total_writeback = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_dirty_hash && !strcmp(s, "total_dirty")))
-                mem->total_dirty = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_swap_hash && !strcmp(s, "total_swap")))
-                mem->total_swap = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin")))
-                mem->total_pgpgin = str2ull(procfile_lineword(ff, i, 1), NULL, 10);
-
-            else if(unlikely(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout")))
-                mem->total_pgpgout = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_pgfault_hash && !strcmp(s, "total_pgfault")))
-                mem->total_pgfault = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault")))
-                mem->total_pgmajfault = str2ull(procfile_lineword(ff, i, 1));
-
-            else if(unlikely(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon")))
-                mem->total_inactive_anon = str2ull(procfile_lineword(ff, i, 1));
+            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);
+        }
 
-            else if(unlikely(hash == total_active_anon_hash && !strcmp(s, "total_active_anon")))
-                mem->total_active_anon = str2ull(procfile_lineword(ff, i, 1));
+        arl_begin(mem->arl_base);
 
-            else if(unlikely(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file")))
-                mem->total_inactive_file = str2ull(procfile_lineword(ff, i, 1));
+        for(i = 0; i < lines ; i++) {
+            if(arl_check(mem->arl_base,
+                    procfile_lineword(ff, i, 0),
+                    procfile_lineword(ff, i, 1))) break;
+        }
 
-            else if(unlikely(hash == total_active_file_hash && !strcmp(s, "total_active_file")))
-                mem->total_active_file = str2ull(procfile_lineword(ff, i, 1));
+        if(unlikely(mem->arl_dirty->flags & ARL_ENTRY_FLAG_FOUND))
+            mem->detailed_has_dirty = 1;
 
-            else if(unlikely(hash == total_unevictable_hash && !strcmp(s, "total_unevictable")))
-                mem->total_unevictable = str2ull(procfile_lineword(ff, i, 1));
-*/
-        }
+        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);
 
@@ -1032,6 +957,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);