@cryptotaxi247 / netdata-1 / commits / 30b92dd9e

fix tc bug that classes were left in memory although unused

Costa Tsaousis (ktsaou) committed Jan 20, 2017 at 23:39 UTC 30b92dd9e0a428b1bfecb117ebf5c1e149edb069
1 file changed +14 -14
src/plugin_tc.c
+14 -14
@@ -44,7 +44,7 @@ struct tc_class {
44
45 char name_updated;
46 char updated; // updated bytes
47 - int seen; // seen in the tc list (even without bytes)
47 + int unupdated; // the number of times, this has been found un-updated
48
49 struct tc_class *next;
50 struct tc_class *prev;
@@ -144,7 +144,7 @@ static inline void tc_class_free(struct tc_device *n, struct tc_class *c) {
144 if(c->next) c->next->prev = c->prev;
145 if(c->prev) c->prev->next = c->next;
146
147 - debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', seen=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->seen);
147 + debug(D_TC_LOOP, "Removing from device '%s' class '%s', parentid '%s', leafid '%s', unused=%d", n->id, c->id, c->parentid?c->parentid:"", c->leafid?c->leafid:"", c->unupdated);
148
149 if(unlikely(tc_class_index_del(n, c) != c))
150 error("plugin_tc: INTERNAL ERROR: attempt remove class '%s' from device '%s': removed a different calls", c->id, n->id);
@@ -169,7 +169,7 @@ static inline void tc_device_classes_cleanup(struct tc_device *d) {
169
170 struct tc_class *c = d->classes;
171 while(c) {
172 - if(unlikely(cleanup_every > 0 && c->seen >= cleanup_every)) {
172 + if(unlikely(cleanup_every && c->unupdated >= cleanup_every)) {
173 struct tc_class *nc = c->next;
174 tc_class_free(d, c);
175 c = nc;
@@ -204,6 +204,11 @@ static inline void tc_device_commit(struct tc_device *d) {
204 for(c = d->classes ; c ; c = c->next) {
205 c->isleaf = 1;
206 c->hasparent = 0;
207 +
208 + if(unlikely(!c->updated))
209 + c->unupdated++;
210 + else
211 + c->unupdated = 0;
212 }
213
214 // mark the classes as leafs and parents
@@ -257,22 +262,22 @@ static inline void tc_device_commit(struct tc_device *d) {
262 if(unlikely(d->enabled == (char)-1)) {
263 char var_name[CONFIG_MAX_NAME + 1];
264 snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
260 - d->enabled = config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces);
265 + d->enabled = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_new_interfaces);
266
267 snprintfz(var_name, CONFIG_MAX_NAME, "traffic chart for %s", d->id);
263 - d->enabled_bytes = config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes);
268 + d->enabled_bytes = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_bytes);
269
270 snprintfz(var_name, CONFIG_MAX_NAME, "packets chart for %s", d->id);
266 - d->enabled_packets = config_get_boolean_ondemand("plugin:tc", var_name, enable_packets);
271 + d->enabled_packets = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_packets);
272
273 snprintfz(var_name, CONFIG_MAX_NAME, "dropped packets chart for %s", d->id);
269 - d->enabled_dropped = config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
274 + d->enabled_dropped = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_dropped);
275
276 snprintfz(var_name, CONFIG_MAX_NAME, "tokens chart for %s", d->id);
272 - d->enabled_tokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
277 + d->enabled_tokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_tokens);
278
279 snprintfz(var_name, CONFIG_MAX_NAME, "ctokens chart for %s", d->id);
275 - d->enabled_ctokens = config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
280 + d->enabled_ctokens = (char)config_get_boolean_ondemand("plugin:tc", var_name, enable_ctokens);
281 }
282
283 debug(D_TC_LOOP, "TC: evaluating TC device '%s'. enabled = %d/%d (bytes: %d/%d, packets: %d/%d, dropped: %d/%d, tokens: %d/%d, ctokens: %d/%d), classes = %d (bytes = %llu, packets = %llu, dropped = %llu, tokens = %llu, ctokens = %llu).",
@@ -322,8 +327,6 @@ static inline void tc_device_commit(struct tc_device *d) {
327 if(unlikely(!c->updated)) continue;
328
329 if(c->isleaf && c->hasparent) {
325 - c->seen++;
326 -
330 if(unlikely(!c->rd_bytes)) {
331 c->rd_bytes = rrddim_find(d->st_bytes, c->id);
332 if(unlikely(!c->rd_bytes)) {
@@ -665,9 +668,6 @@ static inline struct tc_class *tc_class_add(struct tc_device *n, char *id, char
668 if(unlikely(tc_class_index_add(n, c) != c))
669 error("plugin_tc: INTERNAL ERROR: attempt index class '%s' on device '%s': already exists", c->id, n->id);
670 }
668 -
669 - c->seen = 1;
670 -
671 return(c);
672 }
673