@cryptotaxi247 / netdata-1 / commits / d16dba967

Fix labels memory accounting (#20158)

Stelios Fragkakis committed Apr 24, 2025 at 19:24 UTC d16dba9673d9e2a522e268e1915782972c44daa6
1 file changed +11 -3
src/database/rrdlabels.c
+11 -3
@@ -178,7 +178,7 @@ void rrdlabels_flush(RRDLABELS *labels) {
178 JudyAllocThreadPulseReset();
179 JudyLFreeArray(&labels->JudyL, PJE0);
180 int64_t judy_mem = JudyAllocThreadPulseGetAndReset();
181 - RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, -(int64_t)sizeof(RRDLABELS));
181 + RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
182 spinlock_unlock(&labels->spinlock);
183 }
184
@@ -226,11 +226,15 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
226 RRDLABEL_SRC new_ls = (ls & ~(RRDLABEL_FLAG_NEW | RRDLABEL_FLAG_OLD));
227
228 JudyAllocThreadPulseReset();
229 + int64_t judy_mem;
230
231 Pvoid_t *PValue = JudyLIns(&labels->JudyL, (Word_t)new_label, PJE0);
232 if (!PValue || PValue == PJERR)
233 fatal("RRDLABELS: corrupted labels JudyL array");
234
235 + judy_mem = JudyAllocThreadPulseGetAndReset();
236 + RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
237 +
238 if(*PValue) {
239 new_ls |= RRDLABEL_FLAG_OLD;
240 *((RRDLABEL_SRC *)PValue) = new_ls;
@@ -244,14 +248,16 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
248 RRDLABEL *old_label_with_same_key = rrdlabels_find_label_with_key_unsafe(labels, new_label, false);
249 if (old_label_with_same_key) {
250 (void) JudyLDel(&labels->JudyL, (Word_t) old_label_with_same_key, PJE0);
251 + judy_mem = JudyAllocThreadPulseGetAndReset();
252 + RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
253 delete_label(old_label_with_same_key);
254 }
255 }
256
257 labels->version++;
258
253 - int64_t judy_mem = JudyAllocThreadPulseGetAndReset();
254 - RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
259 +// judy_mem = JudyAllocThreadPulseGetAndReset();
260 +// RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
261
262 spinlock_unlock(&labels->spinlock);
263 }
@@ -655,7 +661,9 @@ void rrdlabels_copy(RRDLABELS *dst, RRDLABELS *src)
661 dst->version++;
662 update_statistics = true;
663 if (old_label_with_key) {
664 + int64_t judy_mem = JudyAllocThreadPulseGetAndReset();
665 (void)JudyLDel(&dst->JudyL, (Word_t)old_label_with_key, PJE0);
666 + RRDLABELS_MEMORY_DELTA(&dictionary_stats_category_rrdlabels, judy_mem, 0);
667 delete_label((RRDLABEL *)old_label_with_key);
668 }
669 }