@cryptotaxi247 / netdata-1 / commits / 67529430d

adaptive resortable list implementation; used it in cgroups and vmstat

Costa Tsaousis (ktsaou) committed Jan 20, 2017 at 02:28 UTC 67529430d68ad4068febc3b37473b05d99db4eda
6 files changed +386 -619
CMakeLists.txt
+1 -1
@@ -101,7 +101,7 @@ set(NETDATA_SOURCE_FILES
101 src/registry_person.c
102 src/registry_person.h
103 src/registry_machine.c
104 - 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)
104 + 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)
105
106 set(APPS_PLUGIN_SOURCE_FILES
107 src/appconfig.c
src/Makefile.am
+1
@@ -30,6 +30,7 @@ endif
30
31 netdata_SOURCES = \
32 appconfig.c appconfig.h \
33 + adaptive_resortable_list.c adaptive_resortable_list.h \
34 avl.c avl.h \
35 backends.c backends.h \
36 clocks.c clocks.h \
src/adaptive_resortable_list.c new
+172
@@ -0,0 +1,172 @@
1 +#include "adaptive_resortable_list.h"
2 +
3 +// the default processor() of the ARL
4 +// can be overwritten at arl_create()
5 +static inline void arl_callback_str2ull(const char *name, uint32_t hash, const char *value, void *dst) {
6 + (void)name;
7 + (void)hash;
8 +
9 + register unsigned long long *d = dst;
10 + *d = str2ull(value);
11 + // fprintf(stderr, "name '%s' with hash %u and value '%s' is %llu\n", name, hash, value, *d);
12 +}
13 +
14 +// create a new ARL
15 +ARL_BASE *arl_create(void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks) {
16 + ARL_BASE *base = callocz(1, sizeof(ARL_BASE));
17 +
18 + if(!processor)
19 + base->processor = arl_callback_str2ull;
20 + else
21 + base->processor = processor;
22 +
23 + base->rechecks = rechecks;
24 +
25 + return base;
26 +}
27 +
28 +void arl_free(ARL_BASE *arl_base) {
29 + if(unlikely(!arl_base))
30 + return;
31 +
32 + while(arl_base->head) {
33 + ARL_ENTRY *e = arl_base->head;
34 + arl_base->head = e->next;
35 +
36 + freez(e->name);
37 +#ifdef NETDATA_INTERNAL_CHECKS
38 + memset(e, 0, sizeof(ARL_ENTRY));
39 +#endif
40 + freez(e);
41 + }
42 +
43 +#ifdef NETDATA_INTERNAL_CHECKS
44 + memset(arl_base, 0, sizeof(ARL_BASE));
45 +#endif
46 +
47 + freez(arl_base);
48 +}
49 +
50 +void arl_begin(ARL_BASE *base) {
51 + ARL_ENTRY *e;
52 +
53 + /*
54 + info("iteration %zu, expected %zu, wanted %zu, allocated %zu, relinkings %zu, found %zu, added %zu"
55 + , base->iteration
56 + , base->expected
57 + , base->wanted
58 + , base->allocated
59 + , base->relinkings
60 + , base->found
61 + , base->added
62 + );
63 + for(e = base->head; e ; e = e->next) fprintf(stderr, "%s ", e->name);
64 + fprintf(stderr, "\n");
65 + */
66 +
67 + if(unlikely(base->added || base->iteration % base->rechecks) == 1) {
68 + base->added = 0;
69 + base->wanted = 0;
70 + for(e = base->head; e ; e = e->next)
71 + if(e->flags & ARL_ENTRY_FLAG_FOUND && e->flags & ARL_ENTRY_FLAG_EXPECTED)
72 + base->wanted++;
73 + }
74 +
75 + base->iteration++;
76 + base->next_keyword = base->head;
77 + base->found = 0;
78 +}
79 +
80 +// register an expected keyword to the ARL
81 +// together with its destination ( i.e. the output of the processor() )
82 +ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst) {
83 + ARL_ENTRY *e = callocz(1, sizeof(ARL_ENTRY));
84 + e->name = strdupz(keyword);
85 + e->hash = simple_hash(e->name);
86 + e->dst = dst;
87 + e->flags = ARL_ENTRY_FLAG_EXPECTED;
88 + e->prev = NULL;
89 + e->next = base->head;
90 +
91 + if(base->head) base->head->prev = e;
92 + else base->next_keyword = e;
93 +
94 + base->head = e;
95 + base->expected++;
96 + base->allocated++;
97 +
98 + base->wanted = base->expected;
99 +
100 + return e;
101 +}
102 +
103 +int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value) {
104 + ARL_ENTRY *e;
105 +
106 + // find if it already exists in the data
107 + for(e = base->head; e ; e = e->next)
108 + if(e->hash == hash && !strcmp(e->name, s))
109 + break;
110 +
111 +#ifdef NETDATA_INTERNAL_CHECKS
112 + if(unlikely(e == base->next_keyword))
113 + fatal("Internal Error: e == base->last");
114 +#endif
115 +
116 + if(e) {
117 + // found it in the keywords
118 + base->relinkings++;
119 +
120 + // run the processor for it
121 + if(unlikely(e->dst)) {
122 + base->processor(e->name, hash, value, e->dst);
123 + base->found++;
124 + }
125 +
126 + // unlink it - we will relink it below
127 + if(e->next) e->next->prev = e->prev;
128 + if(e->prev) e->prev->next = e->next;
129 +
130 + // make sure the head is properly linked
131 + if(base->head == e)
132 + base->head = e->next;
133 + }
134 + else {
135 + // not found
136 +
137 + // create it
138 + e = callocz(1, sizeof(ARL_ENTRY));
139 + e->name = strdupz(s);
140 + e->hash = hash;
141 + e->flags = ARL_ENTRY_FLAG_DYNAMIC;
142 +
143 + base->allocated++;
144 + base->added++;
145 + }
146 +
147 + e->flags |= ARL_ENTRY_FLAG_FOUND;
148 +
149 + // link it here
150 + e->next = base->next_keyword;
151 + if(base->next_keyword) {
152 + e->prev = base->next_keyword->prev;
153 + base->next_keyword->prev = e;
154 +
155 + if(base->head == base->next_keyword)
156 + base->head = e;
157 + }
158 + else
159 + e->prev = NULL;
160 +
161 + if(e->prev)
162 + e->prev->next = e;
163 +
164 + base->next_keyword = e->next;
165 + if(unlikely(!base->next_keyword))
166 + base->next_keyword = base->head;
167 +
168 + if(unlikely(base->found == base->wanted))
169 + return 1;
170 +
171 + return 0;
172 +}
src/adaptive_resortable_list.h new
+141
@@ -0,0 +1,141 @@
1 +#ifndef NETDATA_ADAPTIVE_RESORTABLE_LIST_H
2 +#define NETDATA_ADAPTIVE_RESORTABLE_LIST_H
3 +
4 +/*
5 + * ADAPTIVE RE-SORTABLE LIST
6 + * This structure allows netdata to read a file of NAME VALUE lines
7 + * in the fastest possible way.
8 + *
9 + * It maintains a linked list of all NAME (keywords), sorted in the
10 + * same order as found in the source data file.
11 + * The linked list is kept sorted at all times - the source file
12 + * may change at any time, the list will adapt.
13 + *
14 + * The caller:
15 + *
16 + * 1. calls arl_create() to create a list
17 + *
18 + * 2. calls arl_expect() to register the expected keyword
19 + *
20 + * Then:
21 + *
22 + * 3. calls arl_begin() to initiate a data collection iteration.
23 + * This is to be called just ONCE every time the source is re-scanned.
24 + *
25 + * 4. calls arl_check() for each line read from the file.
26 + *
27 + * Finally:
28 + *
29 + * 5. calls arl_free() to destroy this and free all memory.
30 + *
31 + * The program will call the processor() function, given to
32 + * arl_create(), for each expected keyword found.
33 + * The default processor() expects dst to be an unsigned long long *.
34 + *
35 + * LIMITATIONS
36 + * DO NOT USE THIS IF THE A NAME/KEYWORD MAY APPEAR MORE THAN
37 + * ONCE IN THE SOURCE DATA SET.
38 + */
39 +
40 +#include "common.h"
41 +
42 +#define ARL_ENTRY_FLAG_FOUND 0x01 // the entry has been found in the source data
43 +#define ARL_ENTRY_FLAG_EXPECTED 0x02 // the entry is expected by the program
44 +#define ARL_ENTRY_FLAG_DYNAMIC 0x04 // the entry was dynamically allocated, from source data
45 +
46 +typedef struct arl_entry {
47 + char *name; // the keywords
48 + uint32_t hash; // the hash of the keyword
49 +
50 + void *dst; // the dst to pass to the processor
51 +
52 + uint8_t flags; // ARL_ENTRY_FLAG_*
53 +
54 + // double linked list for fast re-linkings
55 + struct arl_entry *prev, *next;
56 +} ARL_ENTRY;
57 +
58 +typedef struct arl_base {
59 + size_t iteration; // incremented on each iteration (arl_begin())
60 + size_t found; // the number of expected keywords found in this iteration
61 + size_t expected; // the number of expected keywords
62 + size_t wanted; // the number of wanted keywords
63 + // i.e. the number of keywords found and expected
64 +
65 + size_t relinkings; // the number of relinkings we have made so far
66 + size_t allocated; // the number of keywords allocated
67 +
68 + size_t rechecks; // the number of iterations between re-checks of the
69 + // wanted number of keywords
70 + // this is only needed in cases where the source
71 + // is having less lines over time.
72 +
73 + size_t added; // it is non-zero if new keywords have been added
74 + // this is only needed to detect new lines have
75 + // been added to the file, over time.
76 +
77 + // the processor to do the job
78 + void (*processor)(const char *name, uint32_t hash, const char *value, void *dst);
79 +
80 + // the linked list of the keywords
81 + ARL_ENTRY *head;
82 +
83 + // since we keep the list of keywords sorted (as found in the source data)
84 + // this is next keyword that we expect to find in the source data.
85 + ARL_ENTRY *next_keyword;
86 +} ARL_BASE;
87 +
88 +// create a new ARL
89 +extern ARL_BASE *arl_create(void (*processor)(const char *, uint32_t, const char *, void *), size_t rechecks);
90 +
91 +// free an ARL
92 +extern void arl_free(ARL_BASE *arl_base);
93 +
94 +// register an expected keyword to the ARL
95 +// together with its destination ( i.e. the output of the processor() )
96 +extern ARL_ENTRY *arl_expect(ARL_BASE *base, const char *keyword, void *dst);
97 +
98 +// an internal call to complete the check() call
99 +extern int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, const char *value);
100 +
101 +// begin an ARL iteration
102 +extern void arl_begin(ARL_BASE *base);
103 +
104 +// check a keyword against the ARL
105 +// this is to be called for each keyword read from source data
106 +// s = the keyword, as collected
107 +// src = the src data to be passed to the processor
108 +// it is defined in the header file in order to be inlined
109 +static inline int arl_check(ARL_BASE *base, const char *keyword, const char *value) {
110 + ARL_ENTRY *e = base->next_keyword;
111 + uint32_t hash = simple_hash(keyword);
112 +
113 + // it should be the first entry (pointed by base->next_keyword)
114 + if(likely(hash == e->hash && !strcmp(keyword, e->name))) {
115 + // it is
116 +
117 + e->flags |= ARL_ENTRY_FLAG_FOUND;
118 +
119 + // execute the processor
120 + if(unlikely(e->dst)) {
121 + base->processor(e->name, e->hash, value, e->dst);
122 + base->found++;
123 + }
124 +
125 + // be prepared for the next iteration
126 + base->next_keyword = e->next;
127 + if(unlikely(!base->next_keyword))
128 + base->next_keyword = base->head;
129 +
130 + // stop if we collected all the values for this iteration
131 + if(unlikely(base->found == base->wanted))
132 + return 1;
133 +
134 + return 0;
135 + }
136 +
137 + // we read from source, a not-expected keyword
138 + return arl_find_or_create_and_relink(base, keyword, hash, value);
139 +}
140 +
141 +#endif //NETDATA_ADAPTIVE_RESORTABLE_LIST_H
src/proc_vmstat.c
+41 -514
@@ -1,4 +1,5 @@
1 #include "common.h"
2 +#include "adaptive_resortable_list.h"
3
4 int do_proc_vmstat(int update_every, usec_t dt) {
5 (void)dt;
@@ -7,263 +8,45 @@ int do_proc_vmstat(int update_every, usec_t dt) {
8 static int do_swapio = -1, do_io = -1, do_pgfaults = -1, do_numa = -1;
9 static int has_numa = -1;
10
10 - // static uint32_t hash_allocstall_dma = 0;
11 - // static uint32_t hash_allocstall_dma32 = 0;
12 - // static uint32_t hash_allocstall_movable = 0;
13 - // static uint32_t hash_allocstall_normal = 0;
14 - // static uint32_t hash_balloon_deflate = 0;
15 - // static uint32_t hash_balloon_inflate = 0;
16 - // static uint32_t hash_balloon_migrate = 0;
17 - // static uint32_t hash_compact_daemon_wake = 0;
18 - // static uint32_t hash_compact_fail = 0;
19 - // static uint32_t hash_compact_free_scanned = 0;
20 - // static uint32_t hash_compact_isolated = 0;
21 - // static uint32_t hash_compact_migrate_scanned = 0;
22 - // static uint32_t hash_compact_stall = 0;
23 - // static uint32_t hash_compact_success = 0;
24 - // static uint32_t hash_drop_pagecache = 0;
25 - // static uint32_t hash_drop_slab = 0;
26 - // static uint32_t hash_htlb_buddy_alloc_fail = 0;
27 - // static uint32_t hash_htlb_buddy_alloc_success = 0;
28 - // static uint32_t hash_kswapd_high_wmark_hit_quickly = 0;
29 - // static uint32_t hash_kswapd_inodesteal = 0;
30 - // static uint32_t hash_kswapd_low_wmark_hit_quickly = 0;
31 - // static uint32_t hash_nr_active_anon = 0;
32 - // static uint32_t hash_nr_active_file = 0;
33 - // static uint32_t hash_nr_anon_pages = 0;
34 - // static uint32_t hash_nr_anon_transparent_hugepages = 0;
35 - // static uint32_t hash_nr_bounce = 0;
36 - // static uint32_t hash_nr_dirtied = 0;
37 - // static uint32_t hash_nr_dirty = 0;
38 - // static uint32_t hash_nr_dirty_background_threshold = 0;
39 - // static uint32_t hash_nr_dirty_threshold = 0;
40 - // static uint32_t hash_nr_file_pages = 0;
41 - // static uint32_t hash_nr_free_cma = 0;
42 - // static uint32_t hash_nr_free_pages = 0;
43 - // static uint32_t hash_nr_inactive_anon = 0;
44 - // static uint32_t hash_nr_inactive_file = 0;
45 - // static uint32_t hash_nr_isolated_anon = 0;
46 - // static uint32_t hash_nr_isolated_file = 0;
47 - // static uint32_t hash_nr_kernel_stack = 0;
48 - // static uint32_t hash_nr_mapped = 0;
49 - // static uint32_t hash_nr_mlock = 0;
50 - // static uint32_t hash_nr_pages_scanned = 0;
51 - // static uint32_t hash_nr_page_table_pages = 0;
52 - // static uint32_t hash_nr_shmem = 0;
53 - // static uint32_t hash_nr_shmem_hugepages = 0;
54 - // static uint32_t hash_nr_shmem_pmdmapped = 0;
55 - // static uint32_t hash_nr_slab_reclaimable = 0;
56 - // static uint32_t hash_nr_slab_unreclaimable = 0;
57 - // static uint32_t hash_nr_unevictable = 0;
58 - // static uint32_t hash_nr_unstable = 0;
59 - // static uint32_t hash_nr_vmscan_immediate_reclaim = 0;
60 - // static uint32_t hash_nr_vmscan_write = 0;
61 - // static uint32_t hash_nr_writeback = 0;
62 - // static uint32_t hash_nr_writeback_temp = 0;
63 - // static uint32_t hash_nr_written = 0;
64 - // static uint32_t hash_nr_zone_active_anon = 0;
65 - // static uint32_t hash_nr_zone_active_file = 0;
66 - // static uint32_t hash_nr_zone_inactive_anon = 0;
67 - // static uint32_t hash_nr_zone_inactive_file = 0;
68 - // static uint32_t hash_nr_zone_unevictable = 0;
69 - // static uint32_t hash_nr_zone_write_pending = 0;
70 - // static uint32_t hash_nr_zspages = 0;
71 - static uint32_t hash_numa_foreign = 0;
72 - static uint32_t hash_numa_hint_faults = 0;
73 - static uint32_t hash_numa_hint_faults_local = 0;
74 - //static uint32_t hash_numa_hit = 0;
75 - static uint32_t hash_numa_huge_pte_updates = 0;
76 - static uint32_t hash_numa_interleave = 0;
77 - static uint32_t hash_numa_local = 0;
78 - //static uint32_t hash_numa_miss = 0;
79 - static uint32_t hash_numa_other = 0;
80 - static uint32_t hash_numa_pages_migrated = 0;
81 - static uint32_t hash_numa_pte_updates = 0;
82 - // static uint32_t hash_pageoutrun = 0;
83 - // static uint32_t hash_pgactivate = 0;
84 - // static uint32_t hash_pgalloc_dma = 0;
85 - // static uint32_t hash_pgalloc_dma32 = 0;
86 - // static uint32_t hash_pgalloc_movable = 0;
87 - // static uint32_t hash_pgalloc_normal = 0;
88 - // static uint32_t hash_pgdeactivate = 0;
89 - static uint32_t hash_pgfault = 0;
90 - // static uint32_t hash_pgfree = 0;
91 - // static uint32_t hash_pginodesteal = 0;
92 - // static uint32_t hash_pglazyfreed = 0;
93 - static uint32_t hash_pgmajfault = 0;
94 - // static uint32_t hash_pgmigrate_fail = 0;
95 - // static uint32_t hash_pgmigrate_success = 0;
96 - static uint32_t hash_pgpgin = 0;
97 - static uint32_t hash_pgpgout = 0;
98 - // static uint32_t hash_pgrefill = 0;
99 - // static uint32_t hash_pgrotated = 0;
100 - // static uint32_t hash_pgscan_direct = 0;
101 - // static uint32_t hash_pgscan_direct_throttle = 0;
102 - // static uint32_t hash_pgscan_kswapd = 0;
103 - // static uint32_t hash_pgskip_dma = 0;
104 - // static uint32_t hash_pgskip_dma32 = 0;
105 - // static uint32_t hash_pgskip_movable = 0;
106 - // static uint32_t hash_pgskip_normal = 0;
107 - // static uint32_t hash_pgsteal_direct = 0;
108 - // static uint32_t hash_pgsteal_kswapd = 0;
109 - static uint32_t hash_pswpin = 0;
110 - static uint32_t hash_pswpout = 0;
111 - // static uint32_t hash_slabs_scanned = 0;
112 - // static uint32_t hash_thp_collapse_alloc = 0;
113 - // static uint32_t hash_thp_collapse_alloc_failed = 0;
114 - // static uint32_t hash_thp_deferred_split_page = 0;
115 - // static uint32_t hash_thp_fault_alloc = 0;
116 - // static uint32_t hash_thp_fault_fallback = 0;
117 - // static uint32_t hash_thp_file_alloc = 0;
118 - // static uint32_t hash_thp_file_mapped = 0;
119 - // static uint32_t hash_thp_split_page = 0;
120 - // static uint32_t hash_thp_split_page_failed = 0;
121 - // static uint32_t hash_thp_split_pmd = 0;
122 - // static uint32_t hash_thp_zero_page_alloc = 0;
123 - // static uint32_t hash_thp_zero_page_alloc_failed = 0;
124 - // static uint32_t hash_unevictable_pgs_cleared = 0;
125 - // static uint32_t hash_unevictable_pgs_culled = 0;
126 - // static uint32_t hash_unevictable_pgs_mlocked = 0;
127 - // static uint32_t hash_unevictable_pgs_munlocked = 0;
128 - // static uint32_t hash_unevictable_pgs_rescued = 0;
129 - // static uint32_t hash_unevictable_pgs_scanned = 0;
130 - // static uint32_t hash_unevictable_pgs_stranded = 0;
131 - // static uint32_t hash_workingset_activate = 0;
132 - // static uint32_t hash_workingset_nodereclaim = 0;
133 - // static uint32_t hash_workingset_refault = 0;
134 - // static uint32_t hash_zone_reclaim_failed = 0;
135 -
136 - if(unlikely(do_swapio == -1)) {
11 + static ARL_BASE *arl_base = NULL;
12 + static unsigned long long numa_foreign = 0ULL;
13 + static unsigned long long numa_hint_faults = 0ULL;
14 + static unsigned long long numa_hint_faults_local = 0ULL;
15 + static unsigned long long numa_huge_pte_updates = 0ULL;
16 + static unsigned long long numa_interleave = 0ULL;
17 + static unsigned long long numa_local = 0ULL;
18 + static unsigned long long numa_other = 0ULL;
19 + static unsigned long long numa_pages_migrated = 0ULL;
20 + static unsigned long long numa_pte_updates = 0ULL;
21 + static unsigned long long pgfault = 0ULL;
22 + static unsigned long long pgmajfault = 0ULL;
23 + static unsigned long long pgpgin = 0ULL;
24 + static unsigned long long pgpgout = 0ULL;
25 + static unsigned long long pswpin = 0ULL;
26 + static unsigned long long pswpout = 0ULL;
27 +
28 + if(unlikely(!arl_base)) {
29 do_swapio = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "swap i/o", CONFIG_ONDEMAND_ONDEMAND);
30 do_io = config_get_boolean("plugin:proc:/proc/vmstat", "disk i/o", 1);
31 do_pgfaults = config_get_boolean("plugin:proc:/proc/vmstat", "memory page faults", 1);
32 do_numa = config_get_boolean_ondemand("plugin:proc:/proc/vmstat", "system-wide numa metric summary", CONFIG_ONDEMAND_ONDEMAND);
33
142 - // hash_allocstall_dma32 = simple_hash("allocstall_dma32");
143 - // hash_allocstall_dma = simple_hash("allocstall_dma");
144 - // hash_allocstall_movable = simple_hash("allocstall_movable");
145 - // hash_allocstall_normal = simple_hash("allocstall_normal");
146 - // hash_balloon_deflate = simple_hash("balloon_deflate");
147 - // hash_balloon_inflate = simple_hash("balloon_inflate");
148 - // hash_balloon_migrate = simple_hash("balloon_migrate");
149 - // hash_compact_daemon_wake = simple_hash("compact_daemon_wake");
150 - // hash_compact_fail = simple_hash("compact_fail");
151 - // hash_compact_free_scanned = simple_hash("compact_free_scanned");
152 - // hash_compact_isolated = simple_hash("compact_isolated");
153 - // hash_compact_migrate_scanned = simple_hash("compact_migrate_scanned");
154 - // hash_compact_stall = simple_hash("compact_stall");
155 - // hash_compact_success = simple_hash("compact_success");
156 - // hash_drop_pagecache = simple_hash("drop_pagecache");
157 - // hash_drop_slab = simple_hash("drop_slab");
158 - // hash_htlb_buddy_alloc_fail = simple_hash("htlb_buddy_alloc_fail");
159 - // hash_htlb_buddy_alloc_success = simple_hash("htlb_buddy_alloc_success");
160 - // hash_kswapd_high_wmark_hit_quickly = simple_hash("kswapd_high_wmark_hit_quickly");
161 - // hash_kswapd_inodesteal = simple_hash("kswapd_inodesteal");
162 - // hash_kswapd_low_wmark_hit_quickly = simple_hash("kswapd_low_wmark_hit_quickly");
163 - // hash_nr_active_anon = simple_hash("nr_active_anon");
164 - // hash_nr_active_file = simple_hash("nr_active_file");
165 - // hash_nr_anon_pages = simple_hash("nr_anon_pages");
166 - // hash_nr_anon_transparent_hugepages = simple_hash("nr_anon_transparent_hugepages");
167 - // hash_nr_bounce = simple_hash("nr_bounce");
168 - // hash_nr_dirtied = simple_hash("nr_dirtied");
169 - // hash_nr_dirty_background_threshold = simple_hash("nr_dirty_background_threshold");
170 - // hash_nr_dirty = simple_hash("nr_dirty");
171 - // hash_nr_dirty_threshold = simple_hash("nr_dirty_threshold");
172 - // hash_nr_file_pages = simple_hash("nr_file_pages");
173 - // hash_nr_free_cma = simple_hash("nr_free_cma");
174 - // hash_nr_free_pages = simple_hash("nr_free_pages");
175 - // hash_nr_inactive_anon = simple_hash("nr_inactive_anon");
176 - // hash_nr_inactive_file = simple_hash("nr_inactive_file");
177 - // hash_nr_isolated_anon = simple_hash("nr_isolated_anon");
178 - // hash_nr_isolated_file = simple_hash("nr_isolated_file");
179 - // hash_nr_kernel_stack = simple_hash("nr_kernel_stack");
180 - // hash_nr_mapped = simple_hash("nr_mapped");
181 - // hash_nr_mlock = simple_hash("nr_mlock");
182 - // hash_nr_pages_scanned = simple_hash("nr_pages_scanned");
183 - // hash_nr_page_table_pages = simple_hash("nr_page_table_pages");
184 - // hash_nr_shmem_hugepages = simple_hash("nr_shmem_hugepages");
185 - // hash_nr_shmem_pmdmapped = simple_hash("nr_shmem_pmdmapped");
186 - // hash_nr_shmem = simple_hash("nr_shmem");
187 - // hash_nr_slab_reclaimable = simple_hash("nr_slab_reclaimable");
188 - // hash_nr_slab_unreclaimable = simple_hash("nr_slab_unreclaimable");
189 - // hash_nr_unevictable = simple_hash("nr_unevictable");
190 - // hash_nr_unstable = simple_hash("nr_unstable");
191 - // hash_nr_vmscan_immediate_reclaim = simple_hash("nr_vmscan_immediate_reclaim");
192 - // hash_nr_vmscan_write = simple_hash("nr_vmscan_write");
193 - // hash_nr_writeback = simple_hash("nr_writeback");
194 - // hash_nr_writeback_temp = simple_hash("nr_writeback_temp");
195 - // hash_nr_written = simple_hash("nr_written");
196 - // hash_nr_zone_active_anon = simple_hash("nr_zone_active_anon");
197 - // hash_nr_zone_active_file = simple_hash("nr_zone_active_file");
198 - // hash_nr_zone_inactive_anon = simple_hash("nr_zone_inactive_anon");
199 - // hash_nr_zone_inactive_file = simple_hash("nr_zone_inactive_file");
200 - // hash_nr_zone_unevictable = simple_hash("nr_zone_unevictable");
201 - // hash_nr_zone_write_pending = simple_hash("nr_zone_write_pending");
202 - // hash_nr_zspages = simple_hash("nr_zspages");
203 - hash_numa_foreign = simple_hash("numa_foreign");
204 - hash_numa_hint_faults_local = simple_hash("numa_hint_faults_local");
205 - hash_numa_hint_faults = simple_hash("numa_hint_faults");
206 - //hash_numa_hit = simple_hash("numa_hit");
207 - hash_numa_huge_pte_updates = simple_hash("numa_huge_pte_updates");
208 - hash_numa_interleave = simple_hash("numa_interleave");
209 - hash_numa_local = simple_hash("numa_local");
210 - //hash_numa_miss = simple_hash("numa_miss");
211 - hash_numa_other = simple_hash("numa_other");
212 - hash_numa_pages_migrated = simple_hash("numa_pages_migrated");
213 - hash_numa_pte_updates = simple_hash("numa_pte_updates");
214 - // hash_pageoutrun = simple_hash("pageoutrun");
215 - // hash_pgactivate = simple_hash("pgactivate");
216 - // hash_pgalloc_dma32 = simple_hash("pgalloc_dma32");
217 - // hash_pgalloc_dma = simple_hash("pgalloc_dma");
218 - // hash_pgalloc_movable = simple_hash("pgalloc_movable");
219 - // hash_pgalloc_normal = simple_hash("pgalloc_normal");
220 - // hash_pgdeactivate = simple_hash("pgdeactivate");
221 - hash_pgfault = simple_hash("pgfault");
222 - // hash_pgfree = simple_hash("pgfree");
223 - // hash_pginodesteal = simple_hash("pginodesteal");
224 - // hash_pglazyfreed = simple_hash("pglazyfreed");
225 - hash_pgmajfault = simple_hash("pgmajfault");
226 - // hash_pgmigrate_fail = simple_hash("pgmigrate_fail");
227 - // hash_pgmigrate_success = simple_hash("pgmigrate_success");
228 - hash_pgpgin = simple_hash("pgpgin");
229 - hash_pgpgout = simple_hash("pgpgout");
230 - // hash_pgrefill = simple_hash("pgrefill");
231 - // hash_pgrotated = simple_hash("pgrotated");
232 - // hash_pgscan_direct = simple_hash("pgscan_direct");
233 - // hash_pgscan_direct_throttle = simple_hash("pgscan_direct_throttle");
234 - // hash_pgscan_kswapd = simple_hash("pgscan_kswapd");
235 - // hash_pgskip_dma32 = simple_hash("pgskip_dma32");
236 - // hash_pgskip_dma = simple_hash("pgskip_dma");
237 - // hash_pgskip_movable = simple_hash("pgskip_movable");
238 - // hash_pgskip_normal = simple_hash("pgskip_normal");
239 - // hash_pgsteal_direct = simple_hash("pgsteal_direct");
240 - // hash_pgsteal_kswapd = simple_hash("pgsteal_kswapd");
241 - hash_pswpin = simple_hash("pswpin");
242 - hash_pswpout = simple_hash("pswpout");
243 - // hash_slabs_scanned = simple_hash("slabs_scanned");
244 - // hash_thp_collapse_alloc_failed = simple_hash("thp_collapse_alloc_failed");
245 - // hash_thp_collapse_alloc = simple_hash("thp_collapse_alloc");
246 - // hash_thp_deferred_split_page = simple_hash("thp_deferred_split_page");
247 - // hash_thp_fault_alloc = simple_hash("thp_fault_alloc");
248 - // hash_thp_fault_fallback = simple_hash("thp_fault_fallback");
249 - // hash_thp_file_alloc = simple_hash("thp_file_alloc");
250 - // hash_thp_file_mapped = simple_hash("thp_file_mapped");
251 - // hash_thp_split_page_failed = simple_hash("thp_split_page_failed");
252 - // hash_thp_split_page = simple_hash("thp_split_page");
253 - // hash_thp_split_pmd = simple_hash("thp_split_pmd");
254 - // hash_thp_zero_page_alloc_failed = simple_hash("thp_zero_page_alloc_failed");
255 - // hash_thp_zero_page_alloc = simple_hash("thp_zero_page_alloc");
256 - // hash_unevictable_pgs_cleared = simple_hash("unevictable_pgs_cleared");
257 - // hash_unevictable_pgs_culled = simple_hash("unevictable_pgs_culled");
258 - // hash_unevictable_pgs_mlocked = simple_hash("unevictable_pgs_mlocked");
259 - // hash_unevictable_pgs_munlocked = simple_hash("unevictable_pgs_munlocked");
260 - // hash_unevictable_pgs_rescued = simple_hash("unevictable_pgs_rescued");
261 - // hash_unevictable_pgs_scanned = simple_hash("unevictable_pgs_scanned");
262 - // hash_unevictable_pgs_stranded = simple_hash("unevictable_pgs_stranded");
263 - // hash_workingset_activate = simple_hash("workingset_activate");
264 - // hash_workingset_nodereclaim = simple_hash("workingset_nodereclaim");
265 - // hash_workingset_refault = simple_hash("workingset_refault");
266 - // hash_zone_reclaim_failed = simple_hash("zone_reclaim_failed");
34 + arl_base = arl_create(NULL, 60);
35 + arl_expect(arl_base, "numa_foreign", &numa_foreign);
36 + arl_expect(arl_base, "numa_hint_faults_local", &numa_hint_faults_local);
37 + arl_expect(arl_base, "numa_hint_faults", &numa_hint_faults);
38 + arl_expect(arl_base, "numa_huge_pte_updates", &numa_huge_pte_updates);
39 + arl_expect(arl_base, "numa_interleave", &numa_interleave);
40 + arl_expect(arl_base, "numa_local", &numa_local);
41 + arl_expect(arl_base, "numa_other", &numa_other);
42 + arl_expect(arl_base, "numa_pages_migrated", &numa_pages_migrated);
43 + arl_expect(arl_base, "numa_pte_updates", &numa_pte_updates);
44 + arl_expect(arl_base, "pgfault", &pgfault);
45 + arl_expect(arl_base, "pgmajfault", &pgmajfault);
46 + arl_expect(arl_base, "pgpgin", &pgpgin);
47 + arl_expect(arl_base, "pgpgout", &pgpgout);
48 + arl_expect(arl_base, "pswpin", &pswpin);
49 + arl_expect(arl_base, "pswpout", &pswpout);
50 }
51
52 if(unlikely(!ff)) {
@@ -278,134 +61,7 @@ int do_proc_vmstat(int update_every, usec_t dt) {
61
62 uint32_t lines = procfile_lines(ff), l;
63
281 - // unsigned long long allocstall_dma = 0ULL;
282 - // unsigned long long allocstall_dma32 = 0ULL;
283 - // unsigned long long allocstall_movable = 0ULL;
284 - // unsigned long long allocstall_normal = 0ULL;
285 - // unsigned long long balloon_deflate = 0ULL;
286 - // unsigned long long balloon_inflate = 0ULL;
287 - // unsigned long long balloon_migrate = 0ULL;
288 - // unsigned long long compact_daemon_wake = 0ULL;
289 - // unsigned long long compact_fail = 0ULL;
290 - // unsigned long long compact_free_scanned = 0ULL;
291 - // unsigned long long compact_isolated = 0ULL;
292 - // unsigned long long compact_migrate_scanned = 0ULL;
293 - // unsigned long long compact_stall = 0ULL;
294 - // unsigned long long compact_success = 0ULL;
295 - // unsigned long long drop_pagecache = 0ULL;
296 - // unsigned long long drop_slab = 0ULL;
297 - // unsigned long long htlb_buddy_alloc_fail = 0ULL;
298 - // unsigned long long htlb_buddy_alloc_success = 0ULL;
299 - // unsigned long long kswapd_high_wmark_hit_quickly = 0ULL;
300 - // unsigned long long kswapd_inodesteal = 0ULL;
301 - // unsigned long long kswapd_low_wmark_hit_quickly = 0ULL;
302 - // unsigned long long nr_active_anon = 0ULL;
303 - // unsigned long long nr_active_file = 0ULL;
304 - // unsigned long long nr_anon_pages = 0ULL;
305 - // unsigned long long nr_anon_transparent_hugepages = 0ULL;
306 - // unsigned long long nr_bounce = 0ULL;
307 - // unsigned long long nr_dirtied = 0ULL;
308 - // unsigned long long nr_dirty = 0ULL;
309 - // unsigned long long nr_dirty_background_threshold = 0ULL;
310 - // unsigned long long nr_dirty_threshold = 0ULL;
311 - // unsigned long long nr_file_pages = 0ULL;
312 - // unsigned long long nr_free_cma = 0ULL;
313 - // unsigned long long nr_free_pages = 0ULL;
314 - // unsigned long long nr_inactive_anon = 0ULL;
315 - // unsigned long long nr_inactive_file = 0ULL;
316 - // unsigned long long nr_isolated_anon = 0ULL;
317 - // unsigned long long nr_isolated_file = 0ULL;
318 - // unsigned long long nr_kernel_stack = 0ULL;
319 - // unsigned long long nr_mapped = 0ULL;
320 - // unsigned long long nr_mlock = 0ULL;
321 - // unsigned long long nr_pages_scanned = 0ULL;
322 - // unsigned long long nr_page_table_pages = 0ULL;
323 - // unsigned long long nr_shmem = 0ULL;
324 - // unsigned long long nr_shmem_hugepages = 0ULL;
325 - // unsigned long long nr_shmem_pmdmapped = 0ULL;
326 - // unsigned long long nr_slab_reclaimable = 0ULL;
327 - // unsigned long long nr_slab_unreclaimable = 0ULL;
328 - // unsigned long long nr_unevictable = 0ULL;
329 - // unsigned long long nr_unstable = 0ULL;
330 - // unsigned long long nr_vmscan_immediate_reclaim = 0ULL;
331 - // unsigned long long nr_vmscan_write = 0ULL;
332 - // unsigned long long nr_writeback = 0ULL;
333 - // unsigned long long nr_writeback_temp = 0ULL;
334 - // unsigned long long nr_written = 0ULL;
335 - // unsigned long long nr_zone_active_anon = 0ULL;
336 - // unsigned long long nr_zone_active_file = 0ULL;
337 - // unsigned long long nr_zone_inactive_anon = 0ULL;
338 - // unsigned long long nr_zone_inactive_file = 0ULL;
339 - // unsigned long long nr_zone_unevictable = 0ULL;
340 - // unsigned long long nr_zone_write_pending = 0ULL;
341 - // unsigned long long nr_zspages = 0ULL;
342 - unsigned long long numa_foreign = 0ULL;
343 - unsigned long long numa_hint_faults = 0ULL;
344 - unsigned long long numa_hint_faults_local = 0ULL;
345 - //unsigned long long numa_hit = 0ULL;
346 - unsigned long long numa_huge_pte_updates = 0ULL;
347 - unsigned long long numa_interleave = 0ULL;
348 - unsigned long long numa_local = 0ULL;
349 - //unsigned long long numa_miss = 0ULL;
350 - unsigned long long numa_other = 0ULL;
351 - unsigned long long numa_pages_migrated = 0ULL;
352 - unsigned long long numa_pte_updates = 0ULL;
353 - // unsigned long long pageoutrun = 0ULL;
354 - // unsigned long long pgactivate = 0ULL;
355 - // unsigned long long pgalloc_dma = 0ULL;
356 - // unsigned long long pgalloc_dma32 = 0ULL;
357 - // unsigned long long pgalloc_movable = 0ULL;
358 - // unsigned long long pgalloc_normal = 0ULL;
359 - // unsigned long long pgdeactivate = 0ULL;
360 - unsigned long long pgfault = 0ULL;
361 - // unsigned long long pgfree = 0ULL;
362 - // unsigned long long pginodesteal = 0ULL;
363 - // unsigned long long pglazyfreed = 0ULL;
364 - unsigned long long pgmajfault = 0ULL;
365 - // unsigned long long pgmigrate_fail = 0ULL;
366 - // unsigned long long pgmigrate_success = 0ULL;
367 - unsigned long long pgpgin = 0ULL;
368 - unsigned long long pgpgout = 0ULL;
369 - // unsigned long long pgrefill = 0ULL;
370 - // unsigned long long pgrotated = 0ULL;
371 - // unsigned long long pgscan_direct = 0ULL;
372 - // unsigned long long pgscan_direct_throttle = 0ULL;
373 - // unsigned long long pgscan_kswapd = 0ULL;
374 - // unsigned long long pgskip_dma = 0ULL;
375 - // unsigned long long pgskip_dma32 = 0ULL;
376 - // unsigned long long pgskip_movable = 0ULL;
377 - // unsigned long long pgskip_normal = 0ULL;
378 - // unsigned long long pgsteal_direct = 0ULL;
379 - // unsigned long long pgsteal_kswapd = 0ULL;
380 - unsigned long long pswpin = 0ULL;
381 - unsigned long long pswpout = 0ULL;
382 - // unsigned long long slabs_scanned = 0ULL;
383 - // unsigned long long thp_collapse_alloc = 0ULL;
384 - // unsigned long long thp_collapse_alloc_failed = 0ULL;
385 - // unsigned long long thp_deferred_split_page = 0ULL;
386 - // unsigned long long thp_fault_alloc = 0ULL;
387 - // unsigned long long thp_fault_fallback = 0ULL;
388 - // unsigned long long thp_file_alloc = 0ULL;
389 - // unsigned long long thp_file_mapped = 0ULL;
390 - // unsigned long long thp_split_page = 0ULL;
391 - // unsigned long long thp_split_page_failed = 0ULL;
392 - // unsigned long long thp_split_pmd = 0ULL;
393 - // unsigned long long thp_zero_page_alloc = 0ULL;
394 - // unsigned long long thp_zero_page_alloc_failed = 0ULL;
395 - // unsigned long long unevictable_pgs_cleared = 0ULL;
396 - // unsigned long long unevictable_pgs_culled = 0ULL;
397 - // unsigned long long unevictable_pgs_mlocked = 0ULL;
398 - // unsigned long long unevictable_pgs_munlocked = 0ULL;
399 - // unsigned long long unevictable_pgs_rescued = 0ULL;
400 - // unsigned long long unevictable_pgs_scanned = 0ULL;
401 - // unsigned long long unevictable_pgs_stranded = 0ULL;
402 - // unsigned long long workingset_activate = 0ULL;
403 - // unsigned long long workingset_nodereclaim = 0ULL;
404 - // unsigned long long workingset_refault = 0ULL;
405 - // unsigned long long zone_reclaim_failed = 0ULL;
406 -
407 - unsigned long long *ptr = NULL;
408 -
64 + arl_begin(arl_base);
65 for(l = 0; l < lines ;l++) {
66 uint32_t words = procfile_linewords(ff, l);
67 if(unlikely(words < 2)) {
@@ -414,142 +70,11 @@ int do_proc_vmstat(int update_every, usec_t dt) {
70 }
71
72 char *name = procfile_lineword(ff, l, 0);
417 - char * value = procfile_lineword(ff, l, 1);
73 + char *value = procfile_lineword(ff, l, 1);
74 if(unlikely(!name || !*name || !value || !*value)) continue;
75
420 - uint32_t hash = simple_hash(name);
421 -
422 - if(unlikely(0)) ;
423 - // else if(unlikely(hash == hash_allocstall_dma32 && strcmp(name, "allocstall_dma32") == 0)) ptr = &allocstall_dma32;
424 - // else if(unlikely(hash == hash_allocstall_dma && strcmp(name, "allocstall_dma") == 0)) ptr = &allocstall_dma;
425 - // else if(unlikely(hash == hash_allocstall_movable && strcmp(name, "allocstall_movable") == 0)) ptr = &allocstall_movable;
426 - // else if(unlikely(hash == hash_allocstall_normal && strcmp(name, "allocstall_normal") == 0)) ptr = &allocstall_normal;
427 - // else if(unlikely(hash == hash_balloon_deflate && strcmp(name, "balloon_deflate") == 0)) ptr = &balloon_deflate;
428 - // else if(unlikely(hash == hash_balloon_inflate && strcmp(name, "balloon_inflate") == 0)) ptr = &balloon_inflate;
429 - // else if(unlikely(hash == hash_balloon_migrate && strcmp(name, "balloon_migrate") == 0)) ptr = &balloon_migrate;
430 - // else if(unlikely(hash == hash_compact_daemon_wake && strcmp(name, "compact_daemon_wake") == 0)) ptr = &compact_daemon_wake;
431 - // else if(unlikely(hash == hash_compact_fail && strcmp(name, "compact_fail") == 0)) ptr = &compact_fail;
432 - // else if(unlikely(hash == hash_compact_free_scanned && strcmp(name, "compact_free_scanned") == 0)) ptr = &compact_free_scanned;
433 - // else if(unlikely(hash == hash_compact_isolated && strcmp(name, "compact_isolated") == 0)) ptr = &compact_isolated;
434 - // else if(unlikely(hash == hash_compact_migrate_scanned && strcmp(name, "compact_migrate_scanned") == 0)) ptr = &compact_migrate_scanned;
435 - // else if(unlikely(hash == hash_compact_stall && strcmp(name, "compact_stall") == 0)) ptr = &compact_stall;
436 - // else if(unlikely(hash == hash_compact_success && strcmp(name, "compact_success") == 0)) ptr = &compact_success;
437 - // else if(unlikely(hash == hash_drop_pagecache && strcmp(name, "drop_pagecache") == 0)) ptr = &drop_pagecache;
438 - // else if(unlikely(hash == hash_drop_slab && strcmp(name, "drop_slab") == 0)) ptr = &drop_slab;
439 - // else if(unlikely(hash == hash_htlb_buddy_alloc_fail && strcmp(name, "htlb_buddy_alloc_fail") == 0)) ptr = &htlb_buddy_alloc_fail;
440 - // else if(unlikely(hash == hash_htlb_buddy_alloc_success && strcmp(name, "htlb_buddy_alloc_success") == 0)) ptr = &htlb_buddy_alloc_success;
441 - // else if(unlikely(hash == hash_kswapd_high_wmark_hit_quickly && strcmp(name, "kswapd_high_wmark_hit_quickly") == 0)) ptr = &kswapd_high_wmark_hit_quickly;
442 - // else if(unlikely(hash == hash_kswapd_inodesteal && strcmp(name, "kswapd_inodesteal") == 0)) ptr = &kswapd_inodesteal;
443 - // else if(unlikely(hash == hash_kswapd_low_wmark_hit_quickly && strcmp(name, "kswapd_low_wmark_hit_quickly") == 0)) ptr = &kswapd_low_wmark_hit_quickly;
444 - // else if(unlikely(hash == hash_nr_active_anon && strcmp(name, "nr_active_anon") == 0)) ptr = &nr_active_anon;
445 - // else if(unlikely(hash == hash_nr_active_file && strcmp(name, "nr_active_file") == 0)) ptr = &nr_active_file;
446 - // else if(unlikely(hash == hash_nr_anon_pages && strcmp(name, "nr_anon_pages") == 0)) ptr = &nr_anon_pages;
447 - // else if(unlikely(hash == hash_nr_anon_transparent_hugepages && strcmp(name, "nr_anon_transparent_hugepages") == 0)) ptr = &nr_anon_transparent_hugepages;
448 - // else if(unlikely(hash == hash_nr_bounce && strcmp(name, "nr_bounce") == 0)) ptr = &nr_bounce;
449 - // else if(unlikely(hash == hash_nr_dirtied && strcmp(name, "nr_dirtied") == 0)) ptr = &nr_dirtied;
450 - // else if(unlikely(hash == hash_nr_dirty_background_threshold && strcmp(name, "nr_dirty_background_threshold") == 0)) ptr = &nr_dirty_background_threshold;
451 - // else if(unlikely(hash == hash_nr_dirty && strcmp(name, "nr_dirty") == 0)) ptr = &nr_dirty;
452 - // else if(unlikely(hash == hash_nr_dirty_threshold && strcmp(name, "nr_dirty_threshold") == 0)) ptr = &nr_dirty_threshold;
453 - // else if(unlikely(hash == hash_nr_file_pages && strcmp(name, "nr_file_pages") == 0)) ptr = &nr_file_pages;
454 - // else if(unlikely(hash == hash_nr_free_cma && strcmp(name, "nr_free_cma") == 0)) ptr = &nr_free_cma;
455 - // else if(unlikely(hash == hash_nr_free_pages && strcmp(name, "nr_free_pages") == 0)) ptr = &nr_free_pages;
456 - // else if(unlikely(hash == hash_nr_inactive_anon && strcmp(name, "nr_inactive_anon") == 0)) ptr = &nr_inactive_anon;
457 - // else if(unlikely(hash == hash_nr_inactive_file && strcmp(name, "nr_inactive_file") == 0)) ptr = &nr_inactive_file;
458 - // else if(unlikely(hash == hash_nr_isolated_anon && strcmp(name, "nr_isolated_anon") == 0)) ptr = &nr_isolated_anon;
459 - // else if(unlikely(hash == hash_nr_isolated_file && strcmp(name, "nr_isolated_file") == 0)) ptr = &nr_isolated_file;
460 - // else if(unlikely(hash == hash_nr_kernel_stack && strcmp(name, "nr_kernel_stack") == 0)) ptr = &nr_kernel_stack;
461 - // else if(unlikely(hash == hash_nr_mapped && strcmp(name, "nr_mapped") == 0)) ptr = &nr_mapped;
462 - // else if(unlikely(hash == hash_nr_mlock && strcmp(name, "nr_mlock") == 0)) ptr = &nr_mlock;
463 - // else if(unlikely(hash == hash_nr_pages_scanned && strcmp(name, "nr_pages_scanned") == 0)) ptr = &nr_pages_scanned;
464 - // else if(unlikely(hash == hash_nr_page_table_pages && strcmp(name, "nr_page_table_pages") == 0)) ptr = &nr_page_table_pages;
465 - // else if(unlikely(hash == hash_nr_shmem_hugepages && strcmp(name, "nr_shmem_hugepages") == 0)) ptr = &nr_shmem_hugepages;
466 - // else if(unlikely(hash == hash_nr_shmem_pmdmapped && strcmp(name, "nr_shmem_pmdmapped") == 0)) ptr = &nr_shmem_pmdmapped;
467 - // else if(unlikely(hash == hash_nr_shmem && strcmp(name, "nr_shmem") == 0)) ptr = &nr_shmem;
468 - // else if(unlikely(hash == hash_nr_slab_reclaimable && strcmp(name, "nr_slab_reclaimable") == 0)) ptr = &nr_slab_reclaimable;
469 - // else if(unlikely(hash == hash_nr_slab_unreclaimable && strcmp(name, "nr_slab_unreclaimable") == 0)) ptr = &nr_slab_unreclaimable;
470 - // else if(unlikely(hash == hash_nr_unevictable && strcmp(name, "nr_unevictable") == 0)) ptr = &nr_unevictable;
471 - // else if(unlikely(hash == hash_nr_unstable && strcmp(name, "nr_unstable") == 0)) ptr = &nr_unstable;
472 - // else if(unlikely(hash == hash_nr_vmscan_immediate_reclaim && strcmp(name, "nr_vmscan_immediate_reclaim") == 0)) ptr = &nr_vmscan_immediate_reclaim;
473 - // else if(unlikely(hash == hash_nr_vmscan_write && strcmp(name, "nr_vmscan_write") == 0)) ptr = &nr_vmscan_write;
474 - // else if(unlikely(hash == hash_nr_writeback && strcmp(name, "nr_writeback") == 0)) ptr = &nr_writeback;
475 - // else if(unlikely(hash == hash_nr_writeback_temp && strcmp(name, "nr_writeback_temp") == 0)) ptr = &nr_writeback_temp;
476 - // else if(unlikely(hash == hash_nr_written && strcmp(name, "nr_written") == 0)) ptr = &nr_written;
477 - // else if(unlikely(hash == hash_nr_zone_active_anon && strcmp(name, "nr_zone_active_anon") == 0)) ptr = &nr_zone_active_anon;
478 - // else if(unlikely(hash == hash_nr_zone_active_file && strcmp(name, "nr_zone_active_file") == 0)) ptr = &nr_zone_active_file;
479 - // else if(unlikely(hash == hash_nr_zone_inactive_anon && strcmp(name, "nr_zone_inactive_anon") == 0)) ptr = &nr_zone_inactive_anon;
480 - // else if(unlikely(hash == hash_nr_zone_inactive_file && strcmp(name, "nr_zone_inactive_file") == 0)) ptr = &nr_zone_inactive_file;
481 - // else if(unlikely(hash == hash_nr_zone_unevictable && strcmp(name, "nr_zone_unevictable") == 0)) ptr = &nr_zone_unevictable;
482 - // else if(unlikely(hash == hash_nr_zone_write_pending && strcmp(name, "nr_zone_write_pending") == 0)) ptr = &nr_zone_write_pending;
483 - // else if(unlikely(hash == hash_nr_zspages && strcmp(name, "nr_zspages") == 0)) ptr = &nr_zspages;
484 - else if(unlikely(hash == hash_numa_foreign && strcmp(name, "numa_foreign") == 0)) ptr = &numa_foreign;
485 - else if(unlikely(hash == hash_numa_hint_faults_local && strcmp(name, "numa_hint_faults_local") == 0)) ptr = &numa_hint_faults_local;
486 - else if(unlikely(hash == hash_numa_hint_faults && strcmp(name, "numa_hint_faults") == 0)) ptr = &numa_hint_faults;
487 - //else if(unlikely(hash == hash_numa_hit && strcmp(name, "numa_hit") == 0)) ptr = &numa_hit;
488 - else if(unlikely(hash == hash_numa_huge_pte_updates && strcmp(name, "numa_huge_pte_updates") == 0)) ptr = &numa_huge_pte_updates;
489 - else if(unlikely(hash == hash_numa_interleave && strcmp(name, "numa_interleave") == 0)) ptr = &numa_interleave;
490 - else if(unlikely(hash == hash_numa_local && strcmp(name, "numa_local") == 0)) ptr = &numa_local;
491 - //else if(unlikely(hash == hash_numa_miss && strcmp(name, "numa_miss") == 0)) ptr = &numa_miss;
492 - else if(unlikely(hash == hash_numa_other && strcmp(name, "numa_other") == 0)) ptr = &numa_other;
493 - else if(unlikely(hash == hash_numa_pages_migrated && strcmp(name, "numa_pages_migrated") == 0)) ptr = &numa_pages_migrated;
494 - else if(unlikely(hash == hash_numa_pte_updates && strcmp(name, "numa_pte_updates") == 0)) ptr = &numa_pte_updates;
495 - // else if(unlikely(hash == hash_pageoutrun && strcmp(name, "pageoutrun") == 0)) ptr = &pageoutrun;
496 - // else if(unlikely(hash == hash_pgactivate && strcmp(name, "pgactivate") == 0)) ptr = &pgactivate;
497 - // else if(unlikely(hash == hash_pgalloc_dma32 && strcmp(name, "pgalloc_dma32") == 0)) ptr = &pgalloc_dma32;
498 - // else if(unlikely(hash == hash_pgalloc_dma && strcmp(name, "pgalloc_dma") == 0)) ptr = &pgalloc_dma;
499 - // else if(unlikely(hash == hash_pgalloc_movable && strcmp(name, "pgalloc_movable") == 0)) ptr = &pgalloc_movable;
500 - // else if(unlikely(hash == hash_pgalloc_normal && strcmp(name, "pgalloc_normal") == 0)) ptr = &pgalloc_normal;
501 - // else if(unlikely(hash == hash_pgdeactivate && strcmp(name, "pgdeactivate") == 0)) ptr = &pgdeactivate;
502 - else if(unlikely(hash == hash_pgfault && strcmp(name, "pgfault") == 0)) ptr = &pgfault;
503 - // else if(unlikely(hash == hash_pgfree && strcmp(name, "pgfree") == 0)) ptr = &pgfree;
504 - // else if(unlikely(hash == hash_pginodesteal && strcmp(name, "pginodesteal") == 0)) ptr = &pginodesteal;
505 - // else if(unlikely(hash == hash_pglazyfreed && strcmp(name, "pglazyfreed") == 0)) ptr = &pglazyfreed;
506 - else if(unlikely(hash == hash_pgmajfault && strcmp(name, "pgmajfault") == 0)) ptr = &pgmajfault;
507 - // else if(unlikely(hash == hash_pgmigrate_fail && strcmp(name, "pgmigrate_fail") == 0)) ptr = &pgmigrate_fail;
508 - // else if(unlikely(hash == hash_pgmigrate_success && strcmp(name, "pgmigrate_success") == 0)) ptr = &pgmigrate_success;
509 - else if(unlikely(hash == hash_pgpgin && strcmp(name, "pgpgin") == 0)) ptr = &pgpgin;
510 - else if(unlikely(hash == hash_pgpgout && strcmp(name, "pgpgout") == 0)) ptr = &pgpgout;
511 - // else if(unlikely(hash == hash_pgrefill && strcmp(name, "pgrefill") == 0)) ptr = &pgrefill;
512 - // else if(unlikely(hash == hash_pgrotated && strcmp(name, "pgrotated") == 0)) ptr = &pgrotated;
513 - // else if(unlikely(hash == hash_pgscan_direct && strcmp(name, "pgscan_direct") == 0)) ptr = &pgscan_direct;
514 - // else if(unlikely(hash == hash_pgscan_direct_throttle && strcmp(name, "pgscan_direct_throttle") == 0)) ptr = &pgscan_direct_throttle;
515 - // else if(unlikely(hash == hash_pgscan_kswapd && strcmp(name, "pgscan_kswapd") == 0)) ptr = &pgscan_kswapd;
516 - // else if(unlikely(hash == hash_pgskip_dma32 && strcmp(name, "pgskip_dma32") == 0)) ptr = &pgskip_dma32;
517 - // else if(unlikely(hash == hash_pgskip_dma && strcmp(name, "pgskip_dma") == 0)) ptr = &pgskip_dma;
518 - // else if(unlikely(hash == hash_pgskip_movable && strcmp(name, "pgskip_movable") == 0)) ptr = &pgskip_movable;
519 - // else if(unlikely(hash == hash_pgskip_normal && strcmp(name, "pgskip_normal") == 0)) ptr = &pgskip_normal;
520 - // else if(unlikely(hash == hash_pgsteal_direct && strcmp(name, "pgsteal_direct") == 0)) ptr = &pgsteal_direct;
521 - // else if(unlikely(hash == hash_pgsteal_kswapd && strcmp(name, "pgsteal_kswapd") == 0)) ptr = &pgsteal_kswapd;
522 - else if(unlikely(hash == hash_pswpin && strcmp(name, "pswpin") == 0)) ptr = &pswpin;
523 - else if(unlikely(hash == hash_pswpout && strcmp(name, "pswpout") == 0)) ptr = &pswpout;
524 - // else if(unlikely(hash == hash_slabs_scanned && strcmp(name, "slabs_scanned") == 0)) ptr = &slabs_scanned;
525 - // else if(unlikely(hash == hash_thp_collapse_alloc_failed && strcmp(name, "thp_collapse_alloc_failed") == 0)) ptr = &thp_collapse_alloc_failed;
526 - // else if(unlikely(hash == hash_thp_collapse_alloc && strcmp(name, "thp_collapse_alloc") == 0)) ptr = &thp_collapse_alloc;
527 - // else if(unlikely(hash == hash_thp_deferred_split_page && strcmp(name, "thp_deferred_split_page") == 0)) ptr = &thp_deferred_split_page;
528 - // else if(unlikely(hash == hash_thp_fault_alloc && strcmp(name, "thp_fault_alloc") == 0)) ptr = &thp_fault_alloc;
529 - // else if(unlikely(hash == hash_thp_fault_fallback && strcmp(name, "thp_fault_fallback") == 0)) ptr = &thp_fault_fallback;
530 - // else if(unlikely(hash == hash_thp_file_alloc && strcmp(name, "thp_file_alloc") == 0)) ptr = &thp_file_alloc;
531 - // else if(unlikely(hash == hash_thp_file_mapped && strcmp(name, "thp_file_mapped") == 0)) ptr = &thp_file_mapped;
532 - // else if(unlikely(hash == hash_thp_split_page_failed && strcmp(name, "thp_split_page_failed") == 0)) ptr = &thp_split_page_failed;
533 - // else if(unlikely(hash == hash_thp_split_page && strcmp(name, "thp_split_page") == 0)) ptr = &thp_split_page;
534 - // else if(unlikely(hash == hash_thp_split_pmd && strcmp(name, "thp_split_pmd") == 0)) ptr = &thp_split_pmd;
535 - // else if(unlikely(hash == hash_thp_zero_page_alloc_failed && strcmp(name, "thp_zero_page_alloc_failed") == 0)) ptr = &thp_zero_page_alloc_failed;
536 - // else if(unlikely(hash == hash_thp_zero_page_alloc && strcmp(name, "thp_zero_page_alloc") == 0)) ptr = &thp_zero_page_alloc;
537 - // else if(unlikely(hash == hash_unevictable_pgs_cleared && strcmp(name, "unevictable_pgs_cleared") == 0)) ptr = &unevictable_pgs_cleared;
538 - // else if(unlikely(hash == hash_unevictable_pgs_culled && strcmp(name, "unevictable_pgs_culled") == 0)) ptr = &unevictable_pgs_culled;
539 - // else if(unlikely(hash == hash_unevictable_pgs_mlocked && strcmp(name, "unevictable_pgs_mlocked") == 0)) ptr = &unevictable_pgs_mlocked;
540 - // else if(unlikely(hash == hash_unevictable_pgs_munlocked && strcmp(name, "unevictable_pgs_munlocked") == 0)) ptr = &unevictable_pgs_munlocked;
541 - // else if(unlikely(hash == hash_unevictable_pgs_rescued && strcmp(name, "unevictable_pgs_rescued") == 0)) ptr = &unevictable_pgs_rescued;
542 - // else if(unlikely(hash == hash_unevictable_pgs_scanned && strcmp(name, "unevictable_pgs_scanned") == 0)) ptr = &unevictable_pgs_scanned;
543 - // else if(unlikely(hash == hash_unevictable_pgs_stranded && strcmp(name, "unevictable_pgs_stranded") == 0)) ptr = &unevictable_pgs_stranded;
544 - // else if(unlikely(hash == hash_workingset_activate && strcmp(name, "workingset_activate") == 0)) ptr = &workingset_activate;
545 - // else if(unlikely(hash == hash_workingset_nodereclaim && strcmp(name, "workingset_nodereclaim") == 0)) ptr = &workingset_nodereclaim;
546 - // else if(unlikely(hash == hash_workingset_refault && strcmp(name, "workingset_refault") == 0)) ptr = &workingset_refault;
547 - // else if(unlikely(hash == hash_zone_reclaim_failed && strcmp(name, "zone_reclaim_failed") == 0)) ptr = &zone_reclaim_failed;
548 -
549 - if(unlikely(ptr)) {
550 - *ptr = str2ull(value);
551 - ptr = NULL;
552 - }
76 + if(unlikely(arl_check(arl_base, name, value)))
77 + break;
78 }
79
80 // --------------------------------------------------------------------
@@ -619,6 +144,8 @@ int do_proc_vmstat(int update_every, usec_t dt) {
144 }
145
146 if(do_numa == CONFIG_ONDEMAND_YES || (do_numa == CONFIG_ONDEMAND_ONDEMAND && has_numa)) {
147 + do_numa = CONFIG_ONDEMAND_YES;
148 +
149 static RRDSET *st_numa = NULL;
150 if(unlikely(!st_numa)) {
151 st_numa = rrdset_create("mem", "numa", NULL, "numa", NULL, "NUMA events", "events/s", 800, update_every, RRDSET_TYPE_LINE);
src/sys_fs_cgroup.c
+30 -104
@@ -1,4 +1,5 @@
1 #include "common.h"
2 +#include "adaptive_resortable_list.h"
3
4 // ----------------------------------------------------------------------------
5 // cgroup globals
@@ -295,6 +296,10 @@ struct blkio {
296
297 // https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
298 struct memory {
299 + ARL_BASE *arl_base;
300 + ARL_ENTRY *arl_dirty;
301 + ARL_ENTRY *arl_swap;
302 +
303 int updated_detailed;
304 int updated_usage_in_bytes;
305 int updated_msw_usage_in_bytes;
@@ -663,115 +668,35 @@ static inline void cgroup_read_memory(struct memory *mem) {
668 goto memory_next;
669 }
670
666 - for(i = 0; i < lines ; i++) {
667 - char *s = procfile_lineword(ff, i, 0);
668 - uint32_t hash = simple_hash(s);
669 -
670 - if(unlikely(hash == cache_hash && !strcmp(s, "cache")))
671 - mem->cache = str2ull(procfile_lineword(ff, i, 1));
672 -
673 - else if(unlikely(hash == rss_hash && !strcmp(s, "rss")))
674 - mem->rss = str2ull(procfile_lineword(ff, i, 1));
675 -
676 - else if(unlikely(hash == rss_huge_hash && !strcmp(s, "rss_huge")))
677 - mem->rss_huge = str2ull(procfile_lineword(ff, i, 1));
678 -
679 - else if(unlikely(hash == mapped_file_hash && !strcmp(s, "mapped_file")))
680 - mem->mapped_file = str2ull(procfile_lineword(ff, i, 1));
681 -
682 - else if(unlikely(hash == writeback_hash && !strcmp(s, "writeback")))
683 - mem->writeback = str2ull(procfile_lineword(ff, i, 1));
684 -
685 - else if(unlikely(hash == dirty_hash && !strcmp(s, "dirty"))) {
686 - mem->dirty = str2ull(procfile_lineword(ff, i, 1));
687 - mem->detailed_has_dirty = 1;
688 - }
689 -
690 - else if(unlikely(hash == swap_hash && !strcmp(s, "swap"))) {
691 - mem->swap = str2ull(procfile_lineword(ff, i, 1));
692 - mem->detailed_has_swap = 1;
693 - }
694 -
695 - else if(unlikely(hash == pgpgin_hash && !strcmp(s, "pgpgin")))
696 - mem->pgpgin = str2ull(procfile_lineword(ff, i, 1));
697 -
698 - else if(unlikely(hash == pgpgout_hash && !strcmp(s, "pgpgout")))
699 - mem->pgpgout = str2ull(procfile_lineword(ff, i, 1));
700 -
701 - else if(unlikely(hash == pgfault_hash && !strcmp(s, "pgfault")))
702 - mem->pgfault = str2ull(procfile_lineword(ff, i, 1));
703 -
704 - else if(unlikely(hash == pgmajfault_hash && !strcmp(s, "pgmajfault")))
705 - mem->pgmajfault = str2ull(procfile_lineword(ff, i, 1));
706 -
707 -/*
708 - else if(unlikely(hash == inactive_anon_hash && !strcmp(s, "inactive_anon")))
709 - mem->inactive_anon = str2ull(procfile_lineword(ff, i, 1));
710 -
711 - else if(unlikely(hash == active_anon_hash && !strcmp(s, "active_anon")))
712 - mem->active_anon = str2ull(procfile_lineword(ff, i, 1));
671 + if(unlikely(!mem->arl_base)) {
672 + mem->arl_base = arl_create(NULL, 60);
673
714 - else if(unlikely(hash == inactive_file_hash && !strcmp(s, "inactive_file")))
715 - mem->inactive_file = str2ull(procfile_lineword(ff, i, 1));
716 -
717 - else if(unlikely(hash == active_file_hash && !strcmp(s, "active_file")))
718 - mem->active_file = str2ull(procfile_lineword(ff, i, 1));
719 -
720 - else if(unlikely(hash == unevictable_hash && !strcmp(s, "unevictable")))
721 - mem->unevictable = str2ull(procfile_lineword(ff, i, 1));
722 -
723 - else if(unlikely(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit")))
724 - mem->hierarchical_memory_limit = str2ull(procfile_lineword(ff, i, 1));
725 -
726 - else if(unlikely(hash == total_cache_hash && !strcmp(s, "total_cache")))
727 - mem->total_cache = str2ull(procfile_lineword(ff, i, 1));
728 -
729 - else if(unlikely(hash == total_rss_hash && !strcmp(s, "total_rss")))
730 - mem->total_rss = str2ull(procfile_lineword(ff, i, 1));
731 -
732 - else if(unlikely(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge")))
733 - mem->total_rss_huge = str2ull(procfile_lineword(ff, i, 1));
734 -
735 - else if(unlikely(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file")))
736 - mem->total_mapped_file = str2ull(procfile_lineword(ff, i, 1));
737 -
738 - else if(unlikely(hash == total_writeback_hash && !strcmp(s, "total_writeback")))
739 - mem->total_writeback = str2ull(procfile_lineword(ff, i, 1));
740 -
741 - else if(unlikely(hash == total_dirty_hash && !strcmp(s, "total_dirty")))
742 - mem->total_dirty = str2ull(procfile_lineword(ff, i, 1));
743 -
744 - else if(unlikely(hash == total_swap_hash && !strcmp(s, "total_swap")))
745 - mem->total_swap = str2ull(procfile_lineword(ff, i, 1));
746 -
747 - else if(unlikely(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin")))
748 - mem->total_pgpgin = str2ull(procfile_lineword(ff, i, 1), NULL, 10);
749 -
750 - else if(unlikely(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout")))
751 - mem->total_pgpgout = str2ull(procfile_lineword(ff, i, 1));
752 -
753 - else if(unlikely(hash == total_pgfault_hash && !strcmp(s, "total_pgfault")))
754 - mem->total_pgfault = str2ull(procfile_lineword(ff, i, 1));
755 -
756 - else if(unlikely(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault")))
757 - mem->total_pgmajfault = str2ull(procfile_lineword(ff, i, 1));
758 -
759 - else if(unlikely(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon")))
760 - mem->total_inactive_anon = str2ull(procfile_lineword(ff, i, 1));
674 + arl_expect(mem->arl_base, "cache", &mem->cache);
675 + arl_expect(mem->arl_base, "rss", &mem->rss);
676 + arl_expect(mem->arl_base, "rss_huge", &mem->rss_huge);
677 + arl_expect(mem->arl_base, "mapped_file", &mem->mapped_file);
678 + arl_expect(mem->arl_base, "writeback", &mem->writeback);
679 + mem->arl_dirty = arl_expect(mem->arl_base, "dirty", &mem->dirty);
680 + mem->arl_swap = arl_expect(mem->arl_base, "swap", &mem->swap);
681 + arl_expect(mem->arl_base, "pgpgin", &mem->pgpgin);
682 + arl_expect(mem->arl_base, "pgpgout", &mem->pgpgout);
683 + arl_expect(mem->arl_base, "pgfault", &mem->pgfault);
684 + arl_expect(mem->arl_base, "pgmajfault", &mem->pgmajfault);
685 + }
686
762 - else if(unlikely(hash == total_active_anon_hash && !strcmp(s, "total_active_anon")))
763 - mem->total_active_anon = str2ull(procfile_lineword(ff, i, 1));
687 + arl_begin(mem->arl_base);
688
765 - else if(unlikely(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file")))
766 - mem->total_inactive_file = str2ull(procfile_lineword(ff, i, 1));
689 + for(i = 0; i < lines ; i++) {
690 + if(arl_check(mem->arl_base,
691 + procfile_lineword(ff, i, 0),
692 + procfile_lineword(ff, i, 1))) break;
693 + }
694
768 - else if(unlikely(hash == total_active_file_hash && !strcmp(s, "total_active_file")))
769 - mem->total_active_file = str2ull(procfile_lineword(ff, i, 1));
695 + if(unlikely(mem->arl_dirty->flags & ARL_ENTRY_FLAG_FOUND))
696 + mem->detailed_has_dirty = 1;
697
771 - else if(unlikely(hash == total_unevictable_hash && !strcmp(s, "total_unevictable")))
772 - mem->total_unevictable = str2ull(procfile_lineword(ff, i, 1));
773 -*/
774 - }
698 + if(unlikely(mem->arl_swap->flags & ARL_ENTRY_FLAG_FOUND))
699 + mem->detailed_has_swap = 1;
700
701 // 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);
702
@@ -1032,6 +957,7 @@ static inline void cgroup_free(struct cgroup *cg) {
957 freez(cg->cpuacct_stat.filename);
958 freez(cg->cpuacct_usage.filename);
959
960 + arl_free(cg->memory.arl_base);
961 freez(cg->memory.filename_detailed);
962 freez(cg->memory.filename_failcnt);
963 freez(cg->memory.filename_usage_in_bytes);