optimizations for servers with vast amounts of sockets (#18820)
* faster local-sockets when there are hundreds of thousands of sockets * dynamic reallocation of fds in apps.plugin * apps.plugin dynamically grows global fds * apps.plugin processes files only where there are less than 100k files/sockets open * ensure all hashtables use a hash and not a random id for a hash
Costa Tsaousis committed
Oct 19, 2024 at 15:20 UTC
a78e8e13ca5db44127edabcb312e92be18638b03
12 files changed
+136
-117
src/collectors/apps.plugin/apps_os_freebsd.c
+7
-4
@@ -98,13 +98,16 @@ bool apps_os_read_pid_fds_freebsd(struct pid_stat *p, void *ptr) {
98
if (unlikely(fdid >= p->fds_size)) {
99
// it is small, extend it
100
101
- debug_log("extending fd memory slots for %s from %d to %d", pid_stat_comm(p), p->fds_size, fdid + MAX_SPARE_FDS);
101
+ uint32_t new_size = fds_new_size(p->fds_size, fdid);
102
103
- p->fds = reallocz(p->fds, (fdid + MAX_SPARE_FDS) * sizeof(struct pid_fd));
103
+ debug_log("extending fd memory slots for %s from %u to %u",
104
+ pid_stat_comm(p), p->fds_size, new_size);
105
+
106
+ p->fds = reallocz(p->fds, new_size * sizeof(struct pid_fd));
107
108
// and initialize it
106
- init_pid_fds(p, p->fds_size, (fdid + MAX_SPARE_FDS) - p->fds_size);
107
- p->fds_size = fdid + MAX_SPARE_FDS;
109
+ init_pid_fds(p, p->fds_size, new_size - p->fds_size);
110
+ p->fds_size = new_size;
111
}
112
113
if (unlikely(p->fds[fdid].fd == 0)) {
src/collectors/apps.plugin/apps_os_linux.c
+7
-8
@@ -55,17 +55,16 @@ bool apps_os_read_pid_fds_linux(struct pid_stat *p, void *ptr __maybe_unused) {
55
if(unlikely((size_t)fdid >= p->fds_size)) {
56
// it is small, extend it
57
58
- debug_log("extending fd memory slots for %s from %d to %d"
59
- , pid_stat_comm(p)
60
- , p->fds_size
61
- , fdid + MAX_SPARE_FDS
62
- );
58
+ uint32_t new_size = fds_new_size(p->fds_size, fdid);
59
64
- p->fds = reallocz(p->fds, (fdid + MAX_SPARE_FDS) * sizeof(struct pid_fd));
60
+ debug_log("extending fd memory slots for %s from %u to %u",
61
+ pid_stat_comm(p), p->fds_size, new_size);
62
+
63
+ p->fds = reallocz(p->fds, new_size * sizeof(struct pid_fd));
64
65
// and initialize it
67
- init_pid_fds(p, p->fds_size, (fdid + MAX_SPARE_FDS) - p->fds_size);
68
- p->fds_size = (size_t)fdid + MAX_SPARE_FDS;
66
+ init_pid_fds(p, p->fds_size, new_size - p->fds_size);
67
+ p->fds_size = new_size;
68
}
69
70
if(unlikely(p->fds[fdid].fd < 0 && de->d_ino != p->fds[fdid].inode)) {
src/collectors/apps.plugin/apps_output.c
+54
-64
@@ -90,7 +90,7 @@ void send_resource_usage_to_netdata(usec_t dt) {
90
, inodes_changed_counter
91
, links_changed_counter
92
, all_pids_count()
93
- , all_files_len
93
+ , all_file_len_get()
94
, apps_groups_targets_count
95
, targets_assignment_counter
96
);
@@ -186,30 +186,16 @@ void send_collected_data_to_netdata(struct target *root, const char *type, usec_
186
send_END();
187
#endif
188
189
- if (w->values[PDF_PROCESSES] == 0) {
190
- send_BEGIN(type, string2str(w->clean_name), "uptime", dt);
191
- send_SET("uptime", 0);
192
- send_END();
189
+ send_BEGIN(type, string2str(w->clean_name), "uptime", dt);
190
+ send_SET("uptime", w->uptime_max);
191
+ send_END();
192
194
- if (enable_detailed_uptime_charts) {
195
- send_BEGIN(type, string2str(w->clean_name), "uptime_summary", dt);
196
- send_SET("min", 0);
197
- send_SET("avg", 0);
198
- send_SET("max", 0);
199
- send_END();
200
- }
201
- } else {
202
- send_BEGIN(type, string2str(w->clean_name), "uptime", dt);
203
- send_SET("uptime", w->uptime_max);
193
+ if (enable_detailed_uptime_charts) {
194
+ send_BEGIN(type, string2str(w->clean_name), "uptime_summary", dt);
195
+ send_SET("min", w->uptime_min);
196
+ send_SET("avg", w->values[PDF_PROCESSES] > 0 ? w->values[PDF_UPTIME] / w->values[PDF_PROCESSES] : 0);
197
+ send_SET("max", w->uptime_max);
198
send_END();
205
-
206
- if (enable_detailed_uptime_charts) {
207
- send_BEGIN(type, string2str(w->clean_name), "uptime_summary", dt);
208
- send_SET("min", w->uptime_min);
209
- send_SET("avg", w->values[PDF_PROCESSES] > 0 ? w->values[PDF_UPTIME] / w->values[PDF_PROCESSES] : 0);
210
- send_SET("max", w->uptime_max);
211
- send_END();
212
- }
199
}
200
201
#if (PROCESSES_HAVE_PHYSICAL_IO == 1)
@@ -257,25 +243,55 @@ void send_collected_data_to_netdata(struct target *root, const char *type, usec_
243
// ----------------------------------------------------------------------------
244
// generate the charts
245
246
+static void send_file_charts_to_netdata(struct target *w, const char *type, const char *lbl_name, const char *title, bool obsolete) {
247
+#if (PROCESSES_HAVE_FDS == 1)
248
+ fprintf(stdout, "CHART %s.%s_fds_open_limit '' '%s open file descriptors limit' '%%' fds %s.fds_open_limit line 20200 %d %s\n",
249
+ type, string2str(w->clean_name), title, type, update_every, obsolete ? "obsolete" : "");
250
+
251
+ if(!obsolete) {
252
+ fprintf(stdout, "CLABEL '%s' '%s' 1\n", lbl_name, string2str(w->name));
253
+ fprintf(stdout, "CLABEL_COMMIT\n");
254
+ fprintf(stdout, "DIMENSION limit '' absolute 1 100\n");
255
+ }
256
+#endif
257
+
258
+#if (PROCESSES_HAVE_FDS == 1) || (PROCESSES_HAVE_HANDLES == 1)
259
+ fprintf(stdout, "CHART %s.%s_fds_open '' '%s open files descriptors' 'fds' fds %s.fds_open stacked 20210 %d %s\n",
260
+ type, string2str(w->clean_name), title, type, update_every, obsolete ? "obsolete" : "");
261
+
262
+ if(!obsolete) {
263
+ fprintf(stdout, "CLABEL '%s' '%s' 1\n", lbl_name, string2str(w->name));
264
+ fprintf(stdout, "CLABEL_COMMIT\n");
265
+#if (PROCESSES_HAVE_FDS == 1)
266
+ fprintf(stdout, "DIMENSION files '' absolute 1 1\n");
267
+ fprintf(stdout, "DIMENSION sockets '' absolute 1 1\n");
268
+ fprintf(stdout, "DIMENSION pipes '' absolute 1 1\n");
269
+ fprintf(stdout, "DIMENSION inotifies '' absolute 1 1\n");
270
+ fprintf(stdout, "DIMENSION event '' absolute 1 1\n");
271
+ fprintf(stdout, "DIMENSION timer '' absolute 1 1\n");
272
+ fprintf(stdout, "DIMENSION signal '' absolute 1 1\n");
273
+ fprintf(stdout, "DIMENSION eventpolls '' absolute 1 1\n");
274
+ fprintf(stdout, "DIMENSION other '' absolute 1 1\n");
275
+#endif // PROCESSES_HAVE_FDS
276
+#if (PROCESSES_HAVE_HANDLES == 1)
277
+ fprintf(stdout, "DIMENSION handles '' absolute 1 1\n");
278
+#endif // PROCESSES_HAVE_HANDLES
279
+ }
280
+#endif // PROCESSES_HAVE_FDS || PROCESSES_HAVE_HANDLES
281
+}
282
+
283
void send_charts_updates_to_netdata(struct target *root, const char *type, const char *lbl_name, const char *title) {
284
struct target *w;
285
263
- if (debug_enabled) {
264
- for (w = root; w; w = w->next) {
265
- if (unlikely(!w->target && w->values[PDF_PROCESSES])) {
266
- struct pid_on_target *pid_on_target;
267
- fprintf(stderr, "apps.plugin: target '%s' has aggregated %"PRIu64" process(es):", string2str(w->name), w->values[PDF_PROCESSES]);
268
- for (pid_on_target = w->root_pid; pid_on_target; pid_on_target = pid_on_target->next) {
269
- fprintf(stderr, " %d", pid_on_target->pid);
270
- }
271
- fputc('\n', stderr);
272
- }
273
- }
274
- }
286
+ bool disable_file_charts_on_this_run = obsolete_file_charts;
287
+ obsolete_file_charts = false;
288
289
for (w = root; w; w = w->next) {
277
- if (likely(w->exposed || (!w->values[PDF_PROCESSES])))
290
+ if (likely(w->exposed || (!w->values[PDF_PROCESSES]))) {
291
+ if(w->exposed && disable_file_charts_on_this_run)
292
+ send_file_charts_to_netdata(w, type, lbl_name, title, true);
293
continue;
294
+ }
295
296
w->exposed = true;
297
@@ -374,34 +390,8 @@ void send_charts_updates_to_netdata(struct target *root, const char *type, const
390
fprintf(stdout, "CLABEL_COMMIT\n");
391
fprintf(stdout, "DIMENSION threads '' absolute 1 1\n");
392
377
- if (enable_file_charts) {
378
-#if (PROCESSES_HAVE_FDS == 1)
379
- fprintf(stdout, "CHART %s.%s_fds_open_limit '' '%s open file descriptors limit' '%%' fds %s.fds_open_limit line 20200 %d\n",
380
- type, string2str(w->clean_name), title, type, update_every);
381
- fprintf(stdout, "CLABEL '%s' '%s' 1\n", lbl_name, string2str(w->name));
382
- fprintf(stdout, "CLABEL_COMMIT\n");
383
- fprintf(stdout, "DIMENSION limit '' absolute 1 100\n");
384
-#endif
385
-
386
- fprintf(stdout, "CHART %s.%s_fds_open '' '%s open files descriptors' 'fds' fds %s.fds_open stacked 20210 %d\n",
387
- type, string2str(w->clean_name), title, type, update_every);
388
- fprintf(stdout, "CLABEL '%s' '%s' 1\n", lbl_name, string2str(w->name));
389
- fprintf(stdout, "CLABEL_COMMIT\n");
390
-#if (PROCESSES_HAVE_FDS == 1)
391
- fprintf(stdout, "DIMENSION files '' absolute 1 1\n");
392
- fprintf(stdout, "DIMENSION sockets '' absolute 1 1\n");
393
- fprintf(stdout, "DIMENSION pipes '' absolute 1 1\n");
394
- fprintf(stdout, "DIMENSION inotifies '' absolute 1 1\n");
395
- fprintf(stdout, "DIMENSION event '' absolute 1 1\n");
396
- fprintf(stdout, "DIMENSION timer '' absolute 1 1\n");
397
- fprintf(stdout, "DIMENSION signal '' absolute 1 1\n");
398
- fprintf(stdout, "DIMENSION eventpolls '' absolute 1 1\n");
399
- fprintf(stdout, "DIMENSION other '' absolute 1 1\n");
400
-#endif
401
-#if (PROCESSES_HAVE_HANDLES == 1)
402
- fprintf(stdout, "DIMENSION handles '' absolute 1 1\n");
403
-#endif
404
- }
393
+ if (enable_file_charts)
394
+ send_file_charts_to_netdata(w, type, lbl_name, title, false);
395
396
fprintf(stdout, "CHART %s.%s_uptime '' '%s uptime' 'seconds' uptime %s.uptime line 20250 %d\n",
397
type, string2str(w->clean_name), title, type, update_every);
src/collectors/apps.plugin/apps_pid.c
+3
-3
@@ -58,7 +58,7 @@ void apps_pids_init(void) {
58
}
59
60
static inline uint64_t pid_hash(pid_t pid) {
61
- return ((uint64_t)pid << 31) + (uint64_t)pid; // we remove 1 bit when shifting to make it different
61
+ return XXH3_64bits(&pid, sizeof(pid));
62
}
63
64
inline struct pid_stat *find_pid_entry(pid_t pid) {
@@ -81,8 +81,8 @@ struct pid_stat *get_or_allocate_pid_entry(pid_t pid) {
81
p = aral_callocz(pids.all_pids.aral);
82
83
#if (PROCESSES_HAVE_FDS == 1)
84
- p->fds = mallocz(sizeof(struct pid_fd) * MAX_SPARE_FDS);
85
- p->fds_size = MAX_SPARE_FDS;
84
+ p->fds = mallocz(sizeof(struct pid_fd) * 3); // stdin, stdout, stderr
85
+ p->fds_size = 3;
86
init_pid_fds(p, 0, p->fds_size);
87
#endif
88
src/collectors/apps.plugin/apps_pid_files.c
+22
-3
@@ -38,6 +38,14 @@ struct file_descriptor {
38
FD_FILETYPE type;
39
} *all_files = NULL;
40
41
+static uint32_t
42
+ all_files_len,
43
+ all_files_size;
44
+
45
+uint32_t all_file_len_get(void) {
46
+ return all_files_len;
47
+}
48
+
49
// ----------------------------------------------------------------------------
50
51
static inline void reallocate_target_fds(struct target *w) {
@@ -110,6 +118,15 @@ static inline void aggregate_fd_on_target(int fd, struct target *w) {
118
}
119
120
void aggregate_pid_fds_on_targets(struct pid_stat *p) {
121
+ if(enable_file_charts == CONFIG_BOOLEAN_AUTO && all_files_len > MAX_SYSTEM_FD_TO_ALLOW_FILES_PROCESSING) {
122
+ nd_log(NDLS_COLLECTORS, NDLP_NOTICE, "apps.plugin: the number of system file descriptors are too many (%u), "
123
+ "disabling file charts. If you want this enabled, set the 'with-files' "
124
+ "parameter to [plugin:apps] section of netdata.conf", all_files_size);
125
+
126
+ enable_file_charts = CONFIG_BOOLEAN_NO;
127
+ obsolete_file_charts = true;
128
+ return;
129
+ }
130
131
if(unlikely(!p->updated)) {
132
// the process is not running
@@ -247,8 +264,10 @@ void file_descriptor_not_used(int id) {
264
static inline void all_files_grow() {
265
void *old = all_files;
266
267
+ uint32_t new_size = (all_files_size > 0) ? all_files_size * 2 : 2048;
268
+
269
// there is no empty slot
251
- all_files = reallocz(all_files, (all_files_size + FILE_DESCRIPTORS_INCREASE_STEP) * sizeof(struct file_descriptor));
270
+ all_files = reallocz(all_files, new_size * sizeof(struct file_descriptor));
271
272
// if the address changed, we have to rebuild the index
273
// since all pointers are now invalid
@@ -264,7 +283,7 @@ static inline void all_files_grow() {
283
284
// initialize the newly added entries
285
267
- for(uint32_t i = all_files_size; i < (all_files_size + FILE_DESCRIPTORS_INCREASE_STEP); i++) {
286
+ for(uint32_t i = all_files_size; i < new_size; i++) {
287
all_files[i].count = 0;
288
all_files[i].name = NULL;
289
#ifdef NETDATA_INTERNAL_CHECKS
@@ -274,7 +293,7 @@ static inline void all_files_grow() {
293
}
294
295
if(unlikely(!all_files_size)) all_files_len = 1;
277
- all_files_size += FILE_DESCRIPTORS_INCREASE_STEP;
296
+ all_files_size = new_size;
297
}
298
299
static inline uint32_t file_descriptor_set_on_empty_slot(const char *name, uint32_t hash, FD_FILETYPE type) {
src/collectors/apps.plugin/apps_plugin.c
+8
-5
@@ -34,11 +34,14 @@ bool enable_groups_charts = true;
34
bool include_exited_childs = true;
35
bool proc_pid_cmdline_is_needed = true; // true when we need to read /proc/cmdline
36
37
-#if defined(OS_FREEBSD) || defined(OS_MACOS) || defined(OS_WINDOWS)
38
-bool enable_file_charts = false;
37
+#if defined(OS_FREEBSD) || defined(OS_MACOS)
38
+int enable_file_charts = CONFIG_BOOLEAN_NO;
39
#elif defined(OS_LINUX)
40
-bool enable_file_charts = true;
40
+int enable_file_charts = CONFIG_BOOLEAN_AUTO;
41
+#elif defined(OS_WINDOWS)
42
+int enable_file_charts = CONFIG_BOOLEAN_YES;
43
#endif
44
+bool obsolete_file_charts = false;
45
46
// ----------------------------------------------------------------------------
47
// internal counters
@@ -468,12 +471,12 @@ static void parse_args(int argc, char **argv)
471
472
#if (PROCESSES_HAVE_FDS == 1)
473
if(strcmp("with-files", argv[i]) == 0) {
471
- enable_file_charts = 1;
474
+ enable_file_charts = CONFIG_BOOLEAN_YES;
475
continue;
476
}
477
478
if(strcmp("no-files", argv[i]) == 0 || strcmp("without-files", argv[i]) == 0) {
476
- enable_file_charts = 0;
479
+ enable_file_charts = CONFIG_BOOLEAN_NO;
480
continue;
481
}
482
#endif
src/collectors/apps.plugin/apps_plugin.h
+11
-10
@@ -151,6 +151,8 @@ extern int max_fds_cache_seconds;
151
152
// --------------------------------------------------------------------------------------------------------------------
153
154
+#define MAX_SYSTEM_FD_TO_ALLOW_FILES_PROCESSING 100000
155
+
156
extern pid_t INIT_PID;
157
158
extern bool debug_enabled;
@@ -161,7 +163,8 @@ extern bool enable_groups_charts;
163
extern bool include_exited_childs;
164
extern bool enable_function_cmdline;
165
extern bool proc_pid_cmdline_is_needed;
164
-extern bool enable_file_charts;
166
+extern int enable_file_charts;
167
+extern bool obsolete_file_charts;
168
169
extern size_t
170
global_iterations_counter,
@@ -178,10 +181,6 @@ extern bool enable_guest_charts;
181
extern bool show_guest_time;
182
#endif
183
181
-extern uint32_t
182
- all_files_len,
183
- all_files_size;
184
-
184
#if (ALL_PIDS_ARE_READ_INSTANTLY == 0)
185
extern kernel_uint_t
186
global_utime,
@@ -212,11 +211,12 @@ extern netdata_mutex_t apps_and_stdout_mutex;
211
#define MAX_CMDLINE 65536
212
213
// ----------------------------------------------------------------------------
215
-// to avoid reallocating too frequently, we can increase the number of spare
216
-// file descriptors used by processes.
217
-// IMPORTANT:
218
-// having a lot of spares, increases the CPU utilization of the plugin.
219
-#define MAX_SPARE_FDS 1
214
+// to avoid reallocating too frequently when we add file descriptors,
215
+// we double the allocation at every increase request.
216
+
217
+static inline uint32_t fds_new_size(uint32_t old_size, uint32_t new_fd) {
218
+ return MAX(old_size * 2, new_fd + 1); // 1 space always
219
+}
220
221
// ----------------------------------------------------------------------------
222
// some variables for keeping track of processes count by states
@@ -462,6 +462,7 @@ struct pid_fd {
462
463
#define pid_stat_comm(p) (string2str(p->comm))
464
#define pid_stat_cmdline(p) (string2str(p->cmdline))
465
+uint32_t all_file_len_get(void);
466
467
struct pid_stat {
468
int32_t pid;
src/libnetdata/maps/local-sockets.h
+9
-6
@@ -631,7 +631,8 @@ static inline bool local_sockets_find_all_sockets_in_proc(LS_STATE *ls, const ch
631
continue;
632
633
// fprintf(stderr, "%d: PID %d is using socket inode %"PRIu64"\n", gettid_uncached(), pid, inode);
634
- SIMPLE_HASHTABLE_SLOT_PID_SOCKET *sl = simple_hashtable_get_slot_PID_SOCKET(&ls->pid_sockets_hashtable, inode, &inode, true);
634
+ XXH64_hash_t inode_hash = XXH3_64bits(&inode, sizeof(inode));
635
+ SIMPLE_HASHTABLE_SLOT_PID_SOCKET *sl = simple_hashtable_get_slot_PID_SOCKET(&ls->pid_sockets_hashtable, inode_hash, &inode, true);
636
struct pid_socket *ps = SIMPLE_HASHTABLE_SLOT_DATA(sl);
637
if(!ps || (ps->pid == 1 && pid != 1)) {
638
if(uid == UID_UNSET && ls->config.uid) {
@@ -672,7 +673,8 @@ static inline bool local_sockets_find_all_sockets_in_proc(LS_STATE *ls, const ch
673
if(!net_ns_inode && ls->config.namespaces) {
674
snprintfz(filename, sizeof(filename), "%s/%s/ns/net", proc_filename, proc_entry->d_name);
675
if(local_sockets_read_proc_inode_link(ls, filename, &net_ns_inode, "net")) {
675
- SIMPLE_HASHTABLE_SLOT_NET_NS *sl_ns = simple_hashtable_get_slot_NET_NS(&ls->ns_hashtable, net_ns_inode, (uint64_t *)net_ns_inode, true);
676
+ XXH64_hash_t net_ns_inode_hash = XXH3_64bits(&net_ns_inode, sizeof(net_ns_inode));
677
+ SIMPLE_HASHTABLE_SLOT_NET_NS *sl_ns = simple_hashtable_get_slot_NET_NS(&ls->ns_hashtable, net_ns_inode_hash, (uint64_t *)net_ns_inode, true);
678
simple_hashtable_set_slot_NET_NS(&ls->ns_hashtable, sl_ns, net_ns_inode, (uint64_t *)net_ns_inode);
679
}
680
}
@@ -690,7 +692,7 @@ static inline bool local_sockets_find_all_sockets_in_proc(LS_STATE *ls, const ch
692
freez(ps->cmdline);
693
694
ps->cmdline = cmdline_trimmed ? strdupz(cmdline_trimmed) : NULL;
693
- simple_hashtable_set_slot_PID_SOCKET(&ls->pid_sockets_hashtable, sl, inode, ps);
695
+ simple_hashtable_set_slot_PID_SOCKET(&ls->pid_sockets_hashtable, sl, inode_hash, ps);
696
// fprintf(stderr, "%d: PID %d indexed for using socket inode %"PRIu64"\n", gettid_uncached(), pid, inode);
697
}
698
}
@@ -721,7 +723,8 @@ static inline void local_sockets_index_listening_port(LS_STATE *ls, LOCAL_SOCKET
723
static inline bool local_sockets_add_socket(LS_STATE *ls, LOCAL_SOCKET *tmp) {
724
if(!tmp->inode) return false;
725
724
- SIMPLE_HASHTABLE_SLOT_LOCAL_SOCKET *sl = simple_hashtable_get_slot_LOCAL_SOCKET(&ls->sockets_hashtable, tmp->inode, &tmp->inode, true);
726
+ XXH64_hash_t inode_hash = XXH3_64bits(&tmp->inode, sizeof(tmp->inode));
727
+ SIMPLE_HASHTABLE_SLOT_LOCAL_SOCKET *sl = simple_hashtable_get_slot_LOCAL_SOCKET(&ls->sockets_hashtable, inode_hash, &tmp->inode, true);
728
LOCAL_SOCKET *n = SIMPLE_HASHTABLE_SLOT_DATA(sl);
729
if(n) {
730
local_sockets_log(ls, "inode %" PRIu64" already exists in hashtable - ignoring duplicate", tmp->inode);
@@ -745,7 +748,7 @@ static inline bool local_sockets_add_socket(LS_STATE *ls, LOCAL_SOCKET *tmp) {
748
749
// --- look up a pid for it -----------------------------------------------------------------------------------
750
748
- SIMPLE_HASHTABLE_SLOT_PID_SOCKET *sl_pid = simple_hashtable_get_slot_PID_SOCKET(&ls->pid_sockets_hashtable, n->inode, &n->inode, false);
751
+ SIMPLE_HASHTABLE_SLOT_PID_SOCKET *sl_pid = simple_hashtable_get_slot_PID_SOCKET(&ls->pid_sockets_hashtable, inode_hash, &n->inode, false);
752
struct pid_socket *ps = SIMPLE_HASHTABLE_SLOT_DATA(sl_pid);
753
if(ps) {
754
n->net_ns_inode = ps->net_ns_inode;
@@ -766,7 +769,7 @@ static inline bool local_sockets_add_socket(LS_STATE *ls, LOCAL_SOCKET *tmp) {
769
770
// --- index it -----------------------------------------------------------------------------------------------
771
769
- simple_hashtable_set_slot_LOCAL_SOCKET(&ls->sockets_hashtable, sl, n->inode, n);
772
+ simple_hashtable_set_slot_LOCAL_SOCKET(&ls->sockets_hashtable, sl, inode_hash, n);
773
774
if(!local_sockets_is_zero_address(&n->local)) {
775
// put all the local IPs into the local_ips hashtable
src/libnetdata/maps/system-groups.h
+2
-1
@@ -21,7 +21,8 @@ typedef struct groupnames_cache {
21
static inline STRING *system_groupnames_cache_lookup_gid(GROUPNAMES_CACHE *gc, gid_t gid) {
22
spinlock_lock(&gc->spinlock);
23
24
- SIMPLE_HASHTABLE_SLOT_GROUPNAMES_CACHE *sl = simple_hashtable_get_slot_GROUPNAMES_CACHE(&gc->ht, gid, &gid, true);
24
+ XXH64_hash_t hash = XXH3_64bits(&gid, sizeof(gid));
25
+ SIMPLE_HASHTABLE_SLOT_GROUPNAMES_CACHE *sl = simple_hashtable_get_slot_GROUPNAMES_CACHE(&gc->ht, hash, &gid, true);
26
STRING *g = SIMPLE_HASHTABLE_SLOT_DATA(sl);
27
if(!g) {
28
char tmp[1024 + 1];
src/libnetdata/maps/system-services.h
+10
-6
@@ -19,10 +19,6 @@ typedef struct servicenames_cache {
19
SIMPLE_HASHTABLE_SERVICENAMES_CACHE ht;
20
} SERVICENAMES_CACHE;
21
22
-static inline uint64_t system_servicenames_key(uint16_t port, uint16_t ipproto) {
23
- return ((uint64_t)ipproto << 16) | (uint64_t)port;
24
-}
25
-
22
static inline const char *system_servicenames_ipproto2str(uint16_t ipproto) {
23
return (ipproto == IPPROTO_TCP) ? "tcp" : "udp";
24
}
@@ -38,10 +34,18 @@ static inline const char *static_portnames(uint16_t port, uint16_t ipproto) {
34
}
35
36
static inline STRING *system_servicenames_cache_lookup(SERVICENAMES_CACHE *sc, uint16_t port, uint16_t ipproto) {
41
- uint64_t key = system_servicenames_key(port, ipproto);
37
+ struct {
38
+ uint16_t ipproto;
39
+ uint16_t port;
40
+ } key = {
41
+ .ipproto = ipproto,
42
+ .port = port,
43
+ };
44
+ XXH64_hash_t hash = XXH3_64bits(&key, sizeof(key));
45
+
46
spinlock_lock(&sc->spinlock);
47
44
- SIMPLE_HASHTABLE_SLOT_SERVICENAMES_CACHE *sl = simple_hashtable_get_slot_SERVICENAMES_CACHE(&sc->ht, key, &key, true);
48
+ SIMPLE_HASHTABLE_SLOT_SERVICENAMES_CACHE *sl = simple_hashtable_get_slot_SERVICENAMES_CACHE(&sc->ht, hash, &key, true);
49
STRING *s = SIMPLE_HASHTABLE_SLOT_DATA(sl);
50
if (!s) {
51
const char *st = static_portnames(port, ipproto);
src/libnetdata/maps/system-users.h
+2
-1
@@ -21,7 +21,8 @@ typedef struct usernames_cache {
21
static inline STRING *system_usernames_cache_lookup_uid(USERNAMES_CACHE *uc, uid_t uid) {
22
spinlock_lock(&uc->spinlock);
23
24
- SIMPLE_HASHTABLE_SLOT_USERNAMES_CACHE *sl = simple_hashtable_get_slot_USERNAMES_CACHE(&uc->ht, uid, &uid, true);
24
+ XXH64_hash_t hash = XXH3_64bits(&uid, sizeof(uid));
25
+ SIMPLE_HASHTABLE_SLOT_USERNAMES_CACHE *sl = simple_hashtable_get_slot_USERNAMES_CACHE(&uc->ht, hash, &uid, true);
26
STRING *u = SIMPLE_HASHTABLE_SLOT_DATA(sl);
27
if(!u) {
28
char tmp[1024 + 1];
src/libnetdata/query_progress/progress.c
+1
-6
@@ -76,12 +76,7 @@ static struct progress {
76
};
77
78
SIMPLE_HASHTABLE_HASH query_hash(nd_uuid_t *transaction) {
79
- struct uuid_hi_lo_t {
80
- uint64_t hi;
81
- uint64_t lo;
82
- } *parts = (struct uuid_hi_lo_t *)transaction;
83
-
84
- return parts->lo;
79
+ return XXH3_64bits(transaction, sizeof(*transaction));
80
}
81
82
static void query_progress_init_unsafe(void) {