minor fixes (#19849)
* extended dbegnine stats should be enabled * creash reports are enabled when the agent is claimed (directly or indirectly) * make mmap() report out of memory * for open cache, use the current hot size, not the max ever used
Costa Tsaousis committed
Mar 13, 2025 at 14:25 UTC
b51fdecd43e9be6bfe78271c736a6ec4106bf315
9 files changed
+52
-53
src/daemon/config/README.md
+12
-12
@@ -35,18 +35,18 @@ After `netdata.conf` has been modified, Netdata needs to be [restarted](/docs/ne
35
36
### `global` section options
37
38
-| setting | default | info |
39
-|:----------------------------------:|:--------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
40
-| process scheduling policy | `keep` | See [Netdata process scheduling policy](/src/daemon/README.md#process-scheduling-policy-unix-only) |
41
-| OOM score | `0` | |
42
-| glibc malloc arena max for plugins | `1` | |
43
-| glibc malloc arena max for Netdata | `1` | |
44
-| hostname | auto-detected | The hostname of the computer running Netdata. |
45
-| host access prefix | empty | This is used in Docker environments where /proc, /sys, etc have to be accessed via another path. You may also have to set SYS_PTRACE capability on the docker for this work. Check [issue 43](https://github.com/netdata/netdata/issues/43). |
46
-| timezone | auto-detected | The timezone retrieved from the environment variable |
47
-| run as user | `netdata` | The user Netdata will run as. |
48
-| pthread stack size | auto-detected | |
49
-| crash reports | `all` or `off` | It is `off` when anonymous telemetry is disabled, otherwise `all`. When it is `all` Netdata reports agent restarts and crashes. It can also be `crashes` to report only crashes. Each kind of event is deduplicated and reported at most once per day. |
38
+| setting | default | info |
39
+|:----------------------------------:|:--------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
40
+| process scheduling policy | `keep` | See [Netdata process scheduling policy](/src/daemon/README.md#process-scheduling-policy-unix-only) |
41
+| OOM score | `0` | |
42
+| glibc malloc arena max for plugins | `1` | |
43
+| glibc malloc arena max for Netdata | `1` | |
44
+| hostname | auto-detected | The hostname of the computer running Netdata. |
45
+| host access prefix | empty | This is used in Docker environments where /proc, /sys, etc have to be accessed via another path. You may also have to set SYS_PTRACE capability on the docker for this work. Check [issue 43](https://github.com/netdata/netdata/issues/43). |
46
+| timezone | auto-detected | The timezone retrieved from the environment variable |
47
+| run as user | `netdata` | The user Netdata will run as. |
48
+| pthread stack size | auto-detected | |
49
+| crash reports | `all` or `off` | `all` when anonymous telemetry is enabled, or the agent is claimed or connected to Netdata Cloud (directly or via a Netdata Parent). When it is `all` Netdata reports restarts and crashes. It can also be `crashes` to report only crashes. When it is `off` nothing is reported. Each kind of event is deduplicated and reported at most once per day. [Read more at this blog post](https://www.netdata.cloud/blog/2025-03-06-monitoring-netdata-restarts/). |
50
51
### `db` section options
52
src/daemon/daemon-status-file.c
+5
-3
@@ -866,13 +866,15 @@ enum crash_report_t {
866
};
867
868
static enum crash_report_t check_crash_reports_config(void) {
869
- bool analytics = analytics_check_enabled();
869
+ bool default_enabled = analytics_check_enabled() ||
870
+ !UUIDiszero(session_status.node_id) || !UUIDiszero(last_session_status.node_id) ||
871
+ !UUIDiszero(session_status.claim_id) || !UUIDiszero(last_session_status.claim_id);
872
871
- const char *t = inicfg_get(&netdata_config, CONFIG_SECTION_GLOBAL, "crash reports", analytics ? "all" : "off");
873
+ const char *t = inicfg_get(&netdata_config, CONFIG_SECTION_GLOBAL, "crash reports", default_enabled ? "all" : "off");
874
875
enum crash_report_t rc;
876
if(!t || !*t)
875
- rc = analytics ? DSF_REPORT_ALL : DSF_REPORT_DISABLED;
877
+ rc = default_enabled ? DSF_REPORT_ALL : DSF_REPORT_DISABLED;
878
else if(strcmp(t, "all") == 0)
879
rc = DSF_REPORT_ALL;
880
else if(strcmp(t, "crashes") == 0)
src/daemon/pulse/pulse.h
-15
@@ -42,11 +42,6 @@ void *pulse_thread_memory_extended_main(void *ptr);
42
#define p1_store(variable, value) __atomic_store_n(variable, value, __ATOMIC_RELAXED)
43
#define p1_load(variable) __atomic_load_n(variable, value, __ATOMIC_RELAXED)
44
45
-#if !defined(PULSE_EXTENDED_STATISTICS) && (defined(NETDATA_INTERNAL_CHECKS) || defined(NETDATA_GOD_MODE))
46
-#define PULSE_EXTENDED_STATISTICS
47
-#endif
48
-
49
-#if defined(PULSE_EXTENDED_STATISTICS)
45
#define p2_add_fetch(variable, value) __atomic_add_fetch(variable, value, __ATOMIC_RELAXED)
46
#define p2_sub_fetch(variable, value) __atomic_sub_fetch(variable, value, __ATOMIC_RELAXED)
47
@@ -55,15 +50,5 @@ void *pulse_thread_memory_extended_main(void *ptr);
50
51
#define p2_store(variable, value) __atomic_store_n(variable, value, __ATOMIC_RELAXED)
52
#define p2_load(variable) __atomic_load_n(variable, value, __ATOMIC_RELAXED)
58
-#else
59
-#define p2_add_fetch(variable, value) debug_dummy()
60
-#define p2_sub_fetch(variable, value) debug_dummy()
61
-
62
-#define p2_fetch_add(variable, value) debug_dummy()
63
-#define p2_fetch_sub(variable, value) debug_dummy()
64
-
65
-#define p2_store(variable, value) debug_dummy()
66
-#define p2_load(variable) debug_dummy()
67
-#endif
53
54
#endif /* NETDATA_PULSE_H */
src/database/engine/cache.c
+18
-10
@@ -334,7 +334,8 @@ static inline void pgc_size_histogram_del(PGC *cache, struct pgc_size_histogram
334
// ----------------------------------------------------------------------------
335
// evictions control
336
337
-static ALWAYS_INLINE int64_t pgc_threshold(ssize_t threshold, int64_t wanted, int64_t current, int64_t clean) {
337
+ALWAYS_INLINE
338
+static int64_t pgc_threshold(ssize_t threshold, int64_t wanted, int64_t current, int64_t clean) {
339
if(current < clean)
340
current = clean;
341
@@ -348,6 +349,18 @@ static ALWAYS_INLINE int64_t pgc_threshold(ssize_t threshold, int64_t wanted, in
349
return ret;
350
}
351
352
+ALWAYS_INLINE
353
+static int64_t pgc_wanted_size(const int64_t hot, const int64_t hot_max, const int64_t dirty_max, const int64_t index) {
354
+ // our promise to users
355
+ const int64_t max_size1 = MAX(hot_max, hot) * 2;
356
+
357
+ // protection against slow flushing
358
+ const int64_t max_size2 = hot_max + MAX(dirty_max * 2, hot_max * 2 / 3) + index;
359
+
360
+ // the final wanted cache size
361
+ return MIN(max_size1, max_size2);
362
+}
363
+
364
static ssize_t cache_usage_per1000(PGC *cache, int64_t *size_to_evict) {
365
366
if(size_to_evict)
@@ -372,20 +385,15 @@ static ssize_t cache_usage_per1000(PGC *cache, int64_t *size_to_evict) {
385
const int64_t dirty_max = __atomic_load_n(&cache->dirty.stats->max_size, __ATOMIC_RELAXED);
386
const int64_t hot_max = __atomic_load_n(&cache->hot.stats->max_size, __ATOMIC_RELAXED);
387
375
- // our promise to users
376
- const int64_t max_size1 = MAX(hot_max, hot) * 2;
377
-
378
- // protection against slow flushing
379
- const int64_t max_size2 = hot_max + ((dirty_max * 2 < hot_max * 2 / 3) ? hot_max * 2 / 3 : dirty_max * 2) + index;
380
-
381
- // the final wanted cache size
382
- wanted_cache_size = MIN(max_size1, max_size2);
383
-
388
if(cache->config.dynamic_target_size_cb) {
389
+ wanted_cache_size = pgc_wanted_size(hot, hot, dirty, index);
390
+
391
const int64_t wanted_cache_size_cb = cache->config.dynamic_target_size_cb();
392
if(wanted_cache_size_cb > wanted_cache_size)
393
wanted_cache_size = wanted_cache_size_cb;
394
}
395
+ else
396
+ wanted_cache_size = pgc_wanted_size(hot, hot_max, dirty_max, index);
397
398
if (wanted_cache_size < hot + dirty + index + cache->config.clean_size)
399
wanted_cache_size = hot + dirty + index + cache->config.clean_size;
src/database/engine/journalfile.c
+1
-1
@@ -1329,7 +1329,7 @@ void journalfile_migrate_to_v2_callback(Word_t section, unsigned datafile_fileno
1329
int fd_v2;
1330
uint8_t *data_start = nd_mmap_advanced(path, total_file_size, MAP_SHARED, 0, false, true, &fd_v2);
1331
if(!data_start)
1332
- fatal("DBENGINE: failed to memory map file '%s' of size %zu.", path, total_file_size);
1332
+ out_of_memory(__FUNCTION__, total_file_size, path);
1333
1334
memset(data_start, 0, extent_offset);
1335
src/libnetdata/aral/aral.c
+1
-2
@@ -544,8 +544,7 @@ static ARAL_PAGE *aral_create_page___no_lock_needed(ARAL *ar, size_t size TRACE_
544
page->data =
545
nd_mmap_advanced(page->filename, size, MAP_SHARED, 0, false, ar->config.options & ARAL_DONT_DUMP, NULL);
546
if (unlikely(!page->data))
547
- fatal("ARAL: '%s' cannot allocate aral buffer of size %zu on filename '%s'",
548
- ar->config.name, size, page->filename);
547
+ out_of_memory(__FUNCTION__, size, page->filename);
548
549
total_size = size + sizeof(ARAL_PAGE);
550
stats = &ar->stats->mmap;
src/libnetdata/memory/nd-mallocz.c
+11
-9
@@ -8,7 +8,7 @@ void mallocz_register_out_of_memory_cb(out_of_memory_cb cb) {
8
}
9
10
ALWAYS_INLINE NORETURN
11
-static void out_of_memory(const char *call, size_t size) {
11
+void out_of_memory(const char *call, size_t size, const char *details) {
12
exit_initiated_add(EXIT_REASON_OUT_OF_MEMORY);
13
14
if(out_of_memory_callback)
@@ -33,10 +33,12 @@ static void out_of_memory(const char *call, size_t size) {
33
34
fatal("Out of memory on %s(%zu bytes)!\n"
35
"System memory available: %s, while our max RSS usage is: %s\n"
36
- "O/S mmap limit: %llu, while our mmap count is: %zu",
36
+ "O/S mmap limit: %llu, while our mmap count is: %zu\n"
37
+ "Additional details: %s",
38
call, size,
39
mem_available, rss_used,
39
- os_mmap_limit(), __atomic_load_n(&nd_mmap_count, __ATOMIC_RELAXED));
40
+ os_mmap_limit(), __atomic_load_n(&nd_mmap_count, __ATOMIC_RELAXED),
41
+ details ? details : "none");
42
}
43
44
// ----------------------------------------------------------------------------
@@ -429,7 +431,7 @@ char *strdupz(const char *s) {
431
432
char *t = strdup(s);
433
if (unlikely(!t))
432
- out_of_memory(__FUNCTION__ , strlen(s) + 1);
434
+ out_of_memory(__FUNCTION__ , strlen(s) + 1, NULL);
435
436
return t;
437
}
@@ -440,7 +442,7 @@ char *strndupz(const char *s, size_t len) {
442
443
char *t = strndup(s, len);
444
if (unlikely(!t))
443
- out_of_memory(__FUNCTION__ , len + 1);
445
+ out_of_memory(__FUNCTION__ , len + 1, NULL);
446
447
return t;
448
}
@@ -459,7 +461,7 @@ void *mallocz(size_t size) {
461
workers_memory_call(WORKERS_MEMORY_CALL_LIBC_MALLOC);
462
void *p = malloc(size);
463
if (unlikely(!p))
462
- out_of_memory(__FUNCTION__, size);
464
+ out_of_memory(__FUNCTION__, size, NULL);
465
466
return p;
467
}
@@ -469,7 +471,7 @@ void *callocz(size_t nmemb, size_t size) {
471
workers_memory_call(WORKERS_MEMORY_CALL_LIBC_CALLOC);
472
void *p = calloc(nmemb, size);
473
if (unlikely(!p))
472
- out_of_memory(__FUNCTION__, nmemb * size);
474
+ out_of_memory(__FUNCTION__, nmemb * size, NULL);
475
476
return p;
477
}
@@ -479,7 +481,7 @@ void *reallocz(void *ptr, size_t size) {
481
workers_memory_call(WORKERS_MEMORY_CALL_LIBC_REALLOC);
482
void *p = realloc(ptr, size);
483
if (unlikely(!p))
482
- out_of_memory(__FUNCTION__, size);
484
+ out_of_memory(__FUNCTION__, size, NULL);
485
486
return p;
487
}
@@ -489,7 +491,7 @@ int posix_memalignz(void **memptr, size_t alignment, size_t size) {
491
workers_memory_call(WORKERS_MEMORY_CALL_LIBC_POSIX_MEMALIGN);
492
int rc = posix_memalign(memptr, alignment, size);
493
if(unlikely(rc))
492
- out_of_memory(__FUNCTION__, size);
494
+ out_of_memory(__FUNCTION__, size, NULL);
495
496
return rc;
497
}
src/libnetdata/memory/nd-mallocz.h
+3
@@ -67,4 +67,7 @@ void posix_memalign_freez(void *ptr);
67
typedef void (*out_of_memory_cb)(void);
68
void mallocz_register_out_of_memory_cb(out_of_memory_cb cb);
69
70
+NORETURN
71
+void out_of_memory(const char *call, size_t size, const char *details);
72
+
73
#endif //NETDATA_ND_MALLOCZ_H
src/libnetdata/uuid/uuidmap.c
+1
-1
@@ -61,7 +61,7 @@ static void uuidmap_init_aral(void) {
61
62
static UUIDMAP_ID get_next_id_unsafe(struct uuidmap_partition *partition) {
63
// Check if we've reached the maximum ID value
64
- if (partition->next_id >= 0x1FFFFFFF)
64
+ if (unlikely(partition->next_id >= 0x1FFFFFFF))
65
fatal("UUIDMAP: Maximum ID limit reached for partition %u. UUIDs exhausted.",
66
(unsigned int)(partition - uuid_map.p));
67