@cryptotaxi247 / netdata-1 / commits / 899053e65

allow configuring journal v2 unmount time; turn it off for parents (#19724)

Costa Tsaousis committed Feb 27, 2025 at 08:49 UTC 899053e655994d9ed8581f5e0284f4817eb4fa8d
4 files changed +17 -7
src/daemon/config/netdata-conf-db.c
+3
@@ -15,6 +15,8 @@ time_t rrdset_free_obsolete_time_s = 3600;
15 time_t rrdhost_cleanup_orphan_to_archive_time_s = 3600;
16 time_t rrdhost_free_ephemeral_time_s = 0;
17
18 +extern time_t dbengine_journal_v2_unmount_time;
19 +
20 size_t get_tier_grouping(size_t tier) {
21 if(unlikely(tier >= nd_profile.storage_tiers)) tier = nd_profile.storage_tiers - 1;
22
@@ -177,6 +179,7 @@ void netdata_conf_dbengine_init(const char *hostname) {
179 // ----------------------------------------------------------------------------------------------------------------
180
181 dbengine_use_direct_io = inicfg_get_boolean(&netdata_config, CONFIG_SECTION_DB, "dbengine use direct io", dbengine_use_direct_io);
182 + dbengine_journal_v2_unmount_time = inicfg_get_duration_seconds(&netdata_config, CONFIG_SECTION_DB, "dbengine journal v2 unmount time", nd_profile.dbengine_journal_v2_unmount_time);
183
184 unsigned read_num = (unsigned)inicfg_get_number(&netdata_config, CONFIG_SECTION_DB, "dbengine pages per extent", DEFAULT_PAGES_PER_EXTENT);
185 if (read_num > 0 && read_num <= DEFAULT_PAGES_PER_EXTENT)
src/daemon/config/netdata-conf-profile.c
+4
@@ -104,6 +104,7 @@ void nd_profile_setup(void) {
104 nd_profile.malloc_arenas = 1;
105 nd_profile.malloc_trim = 32 * 1024;
106 nd_profile.stream_sender_compression = ND_COMPRESSION_FASTEST;
107 + nd_profile.dbengine_journal_v2_unmount_time = 120;
108 // web server threads = 6
109 // aclk query threads = 6
110 // backfill threads = 0
@@ -120,6 +121,7 @@ void nd_profile_setup(void) {
121 nd_profile.malloc_arenas = 4;
122 nd_profile.malloc_trim = 128 * 1024;
123 nd_profile.stream_sender_compression = ND_COMPRESSION_FASTEST;
124 + nd_profile.dbengine_journal_v2_unmount_time = 0;
125 // web server threads = dynamic
126 // aclk query threads = dynamic
127 // backfill threads = dynamic
@@ -133,6 +135,7 @@ void nd_profile_setup(void) {
135 nd_profile.malloc_arenas = 1;
136 nd_profile.malloc_trim = 32 * 1024;
137 nd_profile.stream_sender_compression = ND_COMPRESSION_DEFAULT;
138 + nd_profile.dbengine_journal_v2_unmount_time = 120;
139 // web server threads = 6
140 // aclk query threads = 6
141 // backfill threads = 0
@@ -146,6 +149,7 @@ void nd_profile_setup(void) {
149 nd_profile.malloc_arenas = 1;
150 nd_profile.malloc_trim = 64 * 1024;
151 nd_profile.stream_sender_compression = ND_COMPRESSION_DEFAULT;
152 + nd_profile.dbengine_journal_v2_unmount_time = 120;
153 // web server threads = 6
154 // aclk query threads = 6
155 // backfill threads = 0
src/daemon/config/netdata-conf-profile.h
+1
@@ -52,6 +52,7 @@ struct nd_profile_t {
52 time_t update_every;
53 size_t malloc_arenas;
54 size_t malloc_trim;
55 + time_t dbengine_journal_v2_unmount_time;
56 ND_COMPRESSION_PROFILE stream_sender_compression;
57 };
58
src/database/engine/journalfile.c
+9 -7
@@ -1,6 +1,10 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 #include "rrdengine.h"
3
4 +
5 +// the default value is set in ND_PROFILE, not here
6 +time_t dbengine_journal_v2_unmount_time = 120;
7 +
8 /* Careful to always call this before creating a new journal file */
9 void journalfile_v1_extent_write(struct rrdengine_instance *ctx, struct rrdengine_datafile *datafile, WAL *wal)
10 {
@@ -210,6 +214,8 @@ static struct journal_v2_header *journalfile_v2_mounted_data_get(struct rrdengin
214
215 madvise_dontfork(journalfile->mmap.data, journalfile->mmap.size);
216 madvise_dontdump(journalfile->mmap.data, journalfile->mmap.size);
217 + // madvise_dontneed(journalfile->mmap.data, journalfile->mmap.size);
218 + madvise_random(journalfile->mmap.data, journalfile->mmap.size);
219
220 spinlock_lock(&journalfile->v2.spinlock);
221 journalfile->v2.flags |= JOURNALFILE_FLAG_IS_AVAILABLE | JOURNALFILE_FLAG_IS_MOUNTED;
@@ -220,11 +226,6 @@ static struct journal_v2_header *journalfile_v2_mounted_data_get(struct rrdengin
226 // we need the entire metrics directory into memory to process it
227 madvise_willneed(journalfile->mmap.data, journalfile->v2.size_of_directory);
228 }
223 - else {
224 - // let the kernel know that we don't want read-ahead on this file
225 - madvise_random(journalfile->mmap.data, journalfile->mmap.size);
226 - // madvise_dontneed(journalfile->mmap.data, journalfile->mmap.size);
227 - }
229 }
230 }
231
@@ -312,8 +313,9 @@ void journalfile_v2_data_unmount_cleanup(time_t now_s) {
313 if (!journalfile->v2.not_needed_since_s)
314 journalfile->v2.not_needed_since_s = now_s;
315
315 - else if (now_s - journalfile->v2.not_needed_since_s >= 120)
316 - // 2 minutes have passed since last use
316 + else if (
317 + dbengine_journal_v2_unmount_time && now_s - journalfile->v2.not_needed_since_s >= dbengine_journal_v2_unmount_time)
318 + // enough time has passed since we last needed this journal
319 unmount = true;
320 }
321 spinlock_unlock(&journalfile->v2.spinlock);