Ebpf issues (#13259)
thiagoftsm committed
Jun 30, 2022 at 06:38 UTC
3f9d90a155f6b7526d430852012835aeab5d1770
27 files changed
+32
-196
collectors/ebpf.plugin/ebpf.c
-43
@@ -219,51 +219,8 @@ static void ebpf_exit(int sig)
219
return;
220
}
221
222
- if (ebpf_modules[EBPF_MODULE_SOCKET_IDX].enabled) {
223
- ebpf_modules[EBPF_MODULE_SOCKET_IDX].enabled = 0;
224
- clean_socket_apps_structures();
225
- freez(socket_bandwidth_curr);
226
- }
227
-
228
- if (ebpf_modules[EBPF_MODULE_CACHESTAT_IDX].enabled) {
229
- ebpf_modules[EBPF_MODULE_CACHESTAT_IDX].enabled = 0;
230
- clean_cachestat_pid_structures();
231
- freez(cachestat_pid);
232
- }
233
-
234
- if (ebpf_modules[EBPF_MODULE_DCSTAT_IDX].enabled) {
235
- ebpf_modules[EBPF_MODULE_DCSTAT_IDX].enabled = 0;
236
- clean_dcstat_pid_structures();
237
- freez(dcstat_pid);
238
- }
239
-
240
- if (ebpf_modules[EBPF_MODULE_SWAP_IDX].enabled) {
241
- ebpf_modules[EBPF_MODULE_SWAP_IDX].enabled = 0;
242
- clean_swap_pid_structures();
243
- freez(swap_pid);
244
- }
245
-
246
- if (ebpf_modules[EBPF_MODULE_VFS_IDX].enabled) {
247
- ebpf_modules[EBPF_MODULE_VFS_IDX].enabled = 0;
248
- clean_vfs_pid_structures();
249
- freez(vfs_pid);
250
- }
251
-
252
- if (ebpf_modules[EBPF_MODULE_FD_IDX].enabled) {
253
- ebpf_modules[EBPF_MODULE_FD_IDX].enabled = 0;
254
- clean_fd_pid_structures();
255
- freez(fd_pid);
256
- }
257
-
258
- if (ebpf_modules[EBPF_MODULE_SHM_IDX].enabled) {
259
- ebpf_modules[EBPF_MODULE_SHM_IDX].enabled = 0;
260
- clean_shm_pid_structures();
261
- freez(shm_pid);
262
- }
263
-
222
ebpf_close_cgroup_shm();
223
266
- ebpf_clean_cgroup_pids();
224
/*
225
int ret = fork();
226
if (ret < 0) // error
collectors/ebpf.plugin/ebpf_apps.h
-2
@@ -433,8 +433,6 @@ extern size_t read_bandwidth_statistic_using_pid_on_target(ebpf_bandwidth_t **ep
433
434
extern void collect_data_for_all_processes(int tbl_pid_stats_fd);
435
436
-extern void clean_global_memory();
437
-
436
extern ebpf_process_stat_t **global_process_stats;
437
extern ebpf_process_publish_apps_t **current_apps_data;
438
extern netdata_publish_cachestat_t **cachestat_pid;
collectors/ebpf.plugin/ebpf_cachestat.c
+2
-15
@@ -293,20 +293,6 @@ static inline int ebpf_cachestat_load_and_attach(struct cachestat_bpf *obj, ebpf
293
*
294
*****************************************************************/
295
296
-/**
297
- * Clean PID structures
298
- *
299
- * Clean the allocated structures.
300
- */
301
-void clean_cachestat_pid_structures() {
302
- struct pid_stat *pids = root_of_pids;
303
- while (pids) {
304
- freez(cachestat_pid[pids->pid]);
305
-
306
- pids = pids->next;
307
- }
308
-}
309
-
296
/**
297
* Clean up the main thread.
298
*
@@ -338,7 +324,8 @@ static void ebpf_cachestat_cleanup(void *ptr)
324
bpf_link__destroy(probe_links[i]);
325
i++;
326
}
341
- bpf_object__close(objects);
327
+ if (objects)
328
+ bpf_object__close(objects);
329
}
330
#ifdef LIBBPF_MAJOR_VERSION
331
else if (bpf_obj)
collectors/ebpf.plugin/ebpf_cachestat.h
-1
@@ -82,7 +82,6 @@ typedef struct netdata_publish_cachestat {
82
} netdata_publish_cachestat_t;
83
84
extern void *ebpf_cachestat_thread(void *ptr);
85
-extern void clean_cachestat_pid_structures();
85
86
extern struct config cachestat_config;
87
extern netdata_ebpf_targets_t cachestat_targets[];
collectors/ebpf.plugin/ebpf_cgroup.c
-20
@@ -133,26 +133,6 @@ static inline void ebpf_clean_specific_cgroup_pids(struct pid_on_target2 *pt)
133
}
134
}
135
136
-/**
137
- * Cleanup link list
138
- */
139
-void ebpf_clean_cgroup_pids()
140
-{
141
- if (!ebpf_cgroup_pids)
142
- return;
143
-
144
- ebpf_cgroup_target_t *ect = ebpf_cgroup_pids;
145
- while (ect) {
146
- ebpf_cgroup_target_t *next_cgroup = ect->next;
147
-
148
- ebpf_clean_specific_cgroup_pids(ect->pids);
149
- freez(ect);
150
-
151
- ect = next_cgroup;
152
- }
153
- ebpf_cgroup_pids = NULL;
154
-}
155
-
136
/**
137
* Remove Cgroup Update Target Update List
138
*
collectors/ebpf.plugin/ebpf_cgroup.h
-1
@@ -63,7 +63,6 @@ typedef struct ebpf_cgroup_target {
63
extern void ebpf_map_cgroup_shared_memory();
64
extern void ebpf_parse_cgroup_shm_data();
65
extern void ebpf_close_cgroup_shm();
66
-extern void ebpf_clean_cgroup_pids();
66
extern void ebpf_create_charts_on_systemd(char *id, char *title, char *units, char *family, char *charttype, int order,
67
char *algorithm, char *context, char *module, int update_every);
68
collectors/ebpf.plugin/ebpf_dcstat.c
+2
-15
@@ -251,20 +251,6 @@ void dcstat_update_publish(netdata_publish_dcstat_t *out, uint64_t cache_access,
251
*
252
*****************************************************************/
253
254
-/**
255
- * Clean PID structures
256
- *
257
- * Clean the allocated structures.
258
- */
259
-void clean_dcstat_pid_structures() {
260
- struct pid_stat *pids = root_of_pids;
261
- while (pids) {
262
- freez(dcstat_pid[pids->pid]);
263
-
264
- pids = pids->next;
265
- }
266
-}
267
-
254
/**
255
* Clean names
256
*
@@ -312,7 +298,8 @@ static void ebpf_dcstat_cleanup(void *ptr)
298
bpf_link__destroy(probe_links[i]);
299
i++;
300
}
315
- bpf_object__close(objects);
301
+ if (objects)
302
+ bpf_object__close(objects);
303
}
304
#ifdef LIBBPF_MAJOR_VERSION
305
else if (bpf_obj)
collectors/ebpf.plugin/ebpf_dcstat.h
-1
@@ -77,7 +77,6 @@ typedef struct netdata_publish_dcstat {
77
78
extern void *ebpf_dcstat_thread(void *ptr);
79
extern void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr);
80
-extern void clean_dcstat_pid_structures();
80
extern struct config dcstat_config;
81
extern netdata_ebpf_targets_t dc_targets[];
82
collectors/ebpf.plugin/ebpf_disk.c
+2
-1
@@ -465,7 +465,8 @@ static void ebpf_disk_cleanup(void *ptr)
465
bpf_link__destroy(probe_links[i]);
466
i++;
467
}
468
- bpf_object__close(objects);
468
+ if (objects)
469
+ bpf_object__close(objects);
470
}
471
}
472
collectors/ebpf.plugin/ebpf_fd.c
+2
-15
@@ -47,20 +47,6 @@ netdata_fd_stat_t **fd_pid = NULL;
47
*
48
*****************************************************************/
49
50
-/**
51
- * Clean PID structures
52
- *
53
- * Clean the allocated structures.
54
- */
55
-void clean_fd_pid_structures() {
56
- struct pid_stat *pids = root_of_pids;
57
- while (pids) {
58
- freez(fd_pid[pids->pid]);
59
-
60
- pids = pids->next;
61
- }
62
-}
63
-
50
/**
51
* Clean up the main thread.
52
*
@@ -92,7 +78,8 @@ static void ebpf_fd_cleanup(void *ptr)
78
bpf_link__destroy(probe_links[i]);
79
i++;
80
}
95
- bpf_object__close(objects);
81
+ if (objects)
82
+ bpf_object__close(objects);
83
}
84
}
85
collectors/ebpf.plugin/ebpf_fd.h
-1
@@ -79,7 +79,6 @@ extern void *ebpf_fd_thread(void *ptr);
79
extern void ebpf_fd_create_apps_charts(struct ebpf_module *em, void *ptr);
80
extern struct config fd_config;
81
extern netdata_fd_stat_t **fd_pid;
82
-extern void clean_fd_pid_structures();
82
83
#endif /* NETDATA_EBPF_FD_H */
84
collectors/ebpf.plugin/ebpf_filesystem.c
+2
-1
@@ -381,7 +381,8 @@ void ebpf_filesystem_cleanup_ebpf_data()
381
bpf_link__destroy(probe_links[j]);
382
j++;
383
}
384
- bpf_object__close(efp->objects);
384
+ if (efp->objects)
385
+ bpf_object__close(efp->objects);
386
}
387
}
388
}
collectors/ebpf.plugin/ebpf_hardirq.c
+2
-1
@@ -179,7 +179,8 @@ static void hardirq_cleanup(void *ptr)
179
bpf_link__destroy(probe_links[i]);
180
i++;
181
}
182
- bpf_object__close(objects);
182
+ if (objects)
183
+ bpf_object__close(objects);
184
}
185
}
186
collectors/ebpf.plugin/ebpf_mdflush.c
+2
-1
@@ -74,7 +74,8 @@ static void mdflush_cleanup(void *ptr)
74
bpf_link__destroy(probe_links[i]);
75
i++;
76
}
77
- bpf_object__close(objects);
77
+ if (objects)
78
+ bpf_object__close(objects);
79
}
80
}
81
collectors/ebpf.plugin/ebpf_mount.c
+2
-1
@@ -247,7 +247,8 @@ static void ebpf_mount_cleanup(void *ptr)
247
bpf_link__destroy(probe_links[i]);
248
i++;
249
}
250
- bpf_object__close(objects);
250
+ if (objects)
251
+ bpf_object__close(objects);
252
}
253
#ifdef LIBBPF_MAJOR_VERSION
254
else if (bpf_obj)
collectors/ebpf.plugin/ebpf_oomkill.c
+2
-1
@@ -60,7 +60,8 @@ static void oomkill_cleanup(void *ptr)
60
bpf_link__destroy(probe_links[i]);
61
i++;
62
}
63
- bpf_object__close(objects);
63
+ if (objects)
64
+ bpf_object__close(objects);
65
}
66
}
67
collectors/ebpf.plugin/ebpf_process.c
+2
-19
@@ -1093,20 +1093,6 @@ static void process_collector(ebpf_module_t *em)
1093
*
1094
*****************************************************************/
1095
1096
-void clean_global_memory() {
1097
- int pid_fd = process_maps[NETDATA_PROCESS_PID_TABLE].map_fd;
1098
- struct pid_stat *pids = root_of_pids;
1099
- while (pids) {
1100
- uint32_t pid = pids->pid;
1101
- freez(global_process_stats[pid]);
1102
-
1103
- bpf_map_delete_elem(pid_fd, &pid);
1104
- freez(current_apps_data[pid]);
1105
-
1106
- pids = pids->next;
1107
- }
1108
-}
1109
-
1096
/**
1097
* Process disable tracepoints
1098
*
@@ -1151,10 +1137,6 @@ static void ebpf_process_cleanup(void *ptr)
1137
ebpf_cleanup_publish_syscall(process_publish_aggregated);
1138
freez(process_hash_values);
1139
1154
- clean_global_memory();
1155
- freez(global_process_stats);
1156
- freez(current_apps_data);
1157
-
1140
ebpf_process_disable_tracepoints();
1141
1142
if (probe_links) {
@@ -1164,7 +1146,8 @@ static void ebpf_process_cleanup(void *ptr)
1146
bpf_link__destroy(probe_links[i]);
1147
i++;
1148
}
1167
- bpf_object__close(objects);
1149
+ if (objects)
1150
+ bpf_object__close(objects);
1151
}
1152
1153
freez(cgroup_thread.thread);
collectors/ebpf.plugin/ebpf_shm.c
+2
-13
@@ -242,18 +242,6 @@ static inline int ebpf_shm_load_and_attach(struct shm_bpf *obj, ebpf_module_t *e
242
* FUNCTIONS TO CLOSE THE THREAD
243
*****************************************************************/
244
245
-/**
246
- * Clean shm structure
247
- */
248
-void clean_shm_pid_structures() {
249
- struct pid_stat *pids = root_of_pids;
250
- while (pids) {
251
- freez(shm_pid[pids->pid]);
252
-
253
- pids = pids->next;
254
- }
255
-}
256
-
245
/**
246
* Clean up the main thread.
247
*
@@ -286,7 +274,8 @@ static void ebpf_shm_cleanup(void *ptr)
274
bpf_link__destroy(probe_links[i]);
275
i++;
276
}
289
- bpf_object__close(objects);
277
+ if (objects)
278
+ bpf_object__close(objects);
279
}
280
#ifdef LIBBPF_MAJOR_VERSION
281
else if (bpf_obj)
collectors/ebpf.plugin/ebpf_shm.h
-1
@@ -56,7 +56,6 @@ extern netdata_publish_shm_t **shm_pid;
56
57
extern void *ebpf_shm_thread(void *ptr);
58
extern void ebpf_shm_create_apps_charts(struct ebpf_module *em, void *ptr);
59
-extern void clean_shm_pid_structures();
59
extern netdata_ebpf_targets_t shm_targets[];
60
61
extern struct config shm_config;
collectors/ebpf.plugin/ebpf_socket.c
+2
-10
@@ -2827,15 +2827,6 @@ static void clean_hostnames(ebpf_network_viewer_hostname_list_t *hostnames)
2827
}
2828
}
2829
2830
-void clean_socket_apps_structures() {
2831
- struct pid_stat *pids = root_of_pids;
2832
- while (pids) {
2833
- freez(socket_bandwidth_curr[pids->pid]);
2834
-
2835
- pids = pids->next;
2836
- }
2837
-}
2838
-
2830
/**
2831
* Cleanup publish syscall
2832
*
@@ -2939,7 +2930,8 @@ static void ebpf_socket_cleanup(void *ptr)
2930
bpf_link__destroy(probe_links[i]);
2931
i++;
2932
}
2942
- bpf_object__close(objects);
2933
+ if (objects)
2934
+ bpf_object__close(objects);
2935
}
2936
finalized_threads = 1;
2937
}
collectors/ebpf.plugin/ebpf_socket.h
-1
@@ -362,7 +362,6 @@ extern void update_listen_table(uint16_t value, uint16_t proto, netdata_passive_
362
extern void parse_network_viewer_section(struct config *cfg);
363
extern void fill_ip_list(ebpf_network_viewer_ip_list_t **out, ebpf_network_viewer_ip_list_t *in, char *table);
364
extern void parse_service_name_section(struct config *cfg);
365
-extern void clean_socket_apps_structures();
365
366
extern ebpf_socket_publish_apps_t **socket_bandwidth_curr;
367
extern struct config socket_config;
collectors/ebpf.plugin/ebpf_softirq.c
+2
-1
@@ -97,7 +97,8 @@ static void softirq_cleanup(void *ptr)
97
bpf_link__destroy(probe_links[i]);
98
i++;
99
}
100
- bpf_object__close(objects);
100
+ if (objects)
101
+ bpf_object__close(objects);
102
}
103
}
104
collectors/ebpf.plugin/ebpf_swap.c
+2
-13
@@ -195,18 +195,6 @@ static inline int ebpf_swap_load_and_attach(struct swap_bpf *obj, ebpf_module_t
195
*
196
*****************************************************************/
197
198
-/**
199
- * Clean swap structure
200
- */
201
-void clean_swap_pid_structures() {
202
- struct pid_stat *pids = root_of_pids;
203
- while (pids) {
204
- freez(swap_pid[pids->pid]);
205
-
206
- pids = pids->next;
207
- }
208
-}
209
-
198
/**
199
* Clean up the main thread.
200
*
@@ -238,7 +226,8 @@ static void ebpf_swap_cleanup(void *ptr)
226
bpf_link__destroy(probe_links[i]);
227
i++;
228
}
241
- bpf_object__close(objects);
229
+ if (objects)
230
+ bpf_object__close(objects);
231
}
232
#ifdef LIBBPF_MAJOR_VERSION
233
else if (bpf_obj)
collectors/ebpf.plugin/ebpf_swap.h
-1
@@ -46,7 +46,6 @@ extern netdata_publish_swap_t **swap_pid;
46
47
extern void *ebpf_swap_thread(void *ptr);
48
extern void ebpf_swap_create_apps_charts(struct ebpf_module *em, void *ptr);
49
-extern void clean_swap_pid_structures();
49
50
extern struct config swap_config;
51
extern netdata_ebpf_targets_t swap_targets[];
collectors/ebpf.plugin/ebpf_sync.c
+2
-1
@@ -459,7 +459,8 @@ void ebpf_sync_cleanup_objects()
459
bpf_link__destroy(w->probe_links[j]);
460
j++;
461
}
462
- bpf_object__close(w->objects);
462
+ if (w->objects)
463
+ bpf_object__close(w->objects);
464
}
465
#ifdef LIBBPF_MAJOR_VERSION
466
else if (w->sync_obj)
collectors/ebpf.plugin/ebpf_vfs.c
+2
-15
@@ -49,20 +49,6 @@ static int read_thread_closed = 1;
49
*
50
*****************************************************************/
51
52
-/**
53
- * Clean PID structures
54
- *
55
- * Clean the allocated structures.
56
- */
57
-void clean_vfs_pid_structures() {
58
- struct pid_stat *pids = root_of_pids;
59
- while (pids) {
60
- freez(vfs_pid[pids->pid]);
61
-
62
- pids = pids->next;
63
- }
64
-}
65
-
52
/**
53
* Clean up the main thread.
54
*
@@ -92,7 +78,8 @@ static void ebpf_vfs_cleanup(void *ptr)
78
bpf_link__destroy(probe_links[i]);
79
i++;
80
}
95
- bpf_object__close(objects);
81
+ if (objects)
82
+ bpf_object__close(objects);
83
}
84
}
85
collectors/ebpf.plugin/ebpf_vfs.h
-1
@@ -156,7 +156,6 @@ extern netdata_publish_vfs_t **vfs_pid;
156
157
extern void *ebpf_vfs_thread(void *ptr);
158
extern void ebpf_vfs_create_apps_charts(struct ebpf_module *em, void *ptr);
159
-extern void clean_vfs_pid_structures();
159
160
extern struct config vfs_config;
161