Use vector allocation whenever is possible (eBPF) (#14591)
thiagoftsm committed
Feb 27, 2023 at 12:38 UTC
33d9fcb642322d6450b3b61ef47287c95111d9a6
15 files changed
+341
-36
collectors/ebpf.plugin/ebpf.c
+29
@@ -455,6 +455,35 @@ void *default_btf = NULL;
455
#endif
456
char *btf_path = NULL;
457
458
+/*****************************************************************
459
+ *
460
+ * FUNCTIONS USED TO ALLOCATE APPS/CGROUP MEMORIES (ARAL)
461
+ *
462
+ *****************************************************************/
463
+
464
+/**
465
+ * Allocate PID ARAL
466
+ *
467
+ * Allocate memory using ARAL functions to speed up processing.
468
+ *
469
+ * @param name the internal name used for allocated region.
470
+ * @param size size of each element inside allocated space
471
+ *
472
+ * @return It returns the address on success and NULL otherwise.
473
+ */
474
+ARAL *ebpf_allocate_pid_aral(char *name, size_t size)
475
+{
476
+ static size_t max_elements = NETDATA_EBPF_ALLOC_MAX_PID;
477
+ if (max_elements < NETDATA_EBPF_ALLOC_MIN_ELEMENTS) {
478
+ error("Number of elements given is too small, adjusting it for %d", NETDATA_EBPF_ALLOC_MIN_ELEMENTS);
479
+ max_elements = NETDATA_EBPF_ALLOC_MIN_ELEMENTS;
480
+ }
481
+
482
+ return aral_create(name, size,
483
+ 0, max_elements,
484
+ NULL, NULL, NULL, false, false);
485
+}
486
+
487
/*****************************************************************
488
*
489
* FUNCTIONS USED TO CLEAN MEMORY AND OPERATE SYSTEM FILES
collectors/ebpf.plugin/ebpf.h
+1
@@ -292,6 +292,7 @@ void ebpf_write_chart_obsolete(char *type, char *id, char *title, char *units, c
292
char *charttype, char *context, int order, int update_every);
293
void write_histogram_chart(char *family, char *name, const netdata_idx_t *hist, char **dimensions, uint32_t end);
294
void ebpf_update_disabled_plugin_stats(ebpf_module_t *em);
295
+ARAL *ebpf_allocate_pid_aral(char *name, size_t size);
296
extern ebpf_filesystem_partitions_t localfs[];
297
extern ebpf_sync_syscalls_t local_syscalls[];
298
extern int ebpf_exit_plugin;
collectors/ebpf.plugin/ebpf_apps.c
+9
-12
@@ -22,13 +22,10 @@ void ebpf_aral_init(void)
22
max_elements = NETDATA_EBPF_ALLOC_MIN_ELEMENTS;
23
}
24
25
- ebpf_aral_apps_pid_stat = aral_create("ebpf-pid_stat", sizeof(struct ebpf_pid_stat),
26
- 0, max_elements,
27
- NULL, NULL, NULL, false, false);
25
+ ebpf_aral_apps_pid_stat = ebpf_allocate_pid_aral("ebpf-pid_stat", sizeof(struct ebpf_pid_stat));
26
+
27
+ ebpf_aral_process_stat = ebpf_allocate_pid_aral("ebpf-proc_stat", sizeof(ebpf_process_stat_t));
28
29
- ebpf_aral_process_stat = aral_create("ebpf-proc_stat", sizeof(ebpf_process_stat_t),
30
- 0, max_elements,
31
- NULL, NULL, NULL, false, false);
29
#ifdef NETDATA_DEV_MODE
30
info("Plugin is using ARAL with values %d", NETDATA_EBPF_ALLOC_MAX_PID);
31
#endif
@@ -1021,19 +1018,19 @@ void cleanup_variables_from_other_threads(uint32_t pid)
1018
{
1019
// Clean socket structures
1020
if (socket_bandwidth_curr) {
1024
- freez(socket_bandwidth_curr[pid]);
1021
+ ebpf_socket_release(socket_bandwidth_curr[pid]);
1022
socket_bandwidth_curr[pid] = NULL;
1023
}
1024
1025
// Clean cachestat structure
1026
if (cachestat_pid) {
1030
- freez(cachestat_pid[pid]);
1027
+ ebpf_cachestat_release(cachestat_pid[pid]);
1028
cachestat_pid[pid] = NULL;
1029
}
1030
1031
// Clean directory cache structure
1032
if (dcstat_pid) {
1036
- freez(dcstat_pid[pid]);
1033
+ ebpf_dcstat_release(dcstat_pid[pid]);
1034
dcstat_pid[pid] = NULL;
1035
}
1036
@@ -1045,19 +1042,19 @@ void cleanup_variables_from_other_threads(uint32_t pid)
1042
1043
// Clean vfs structure
1044
if (vfs_pid) {
1048
- freez(vfs_pid[pid]);
1045
+ ebpf_vfs_release(vfs_pid[pid]);
1046
vfs_pid[pid] = NULL;
1047
}
1048
1049
// Clean fd structure
1050
if (fd_pid) {
1054
- freez(fd_pid[pid]);
1051
+ ebpf_fd_release(fd_pid[pid]);
1052
fd_pid[pid] = NULL;
1053
}
1054
1055
// Clean shm structure
1056
if (shm_pid) {
1060
- freez(shm_pid[pid]);
1057
+ ebpf_shm_release(shm_pid[pid]);
1058
shm_pid[pid] = NULL;
1059
}
1060
}
collectors/ebpf.plugin/ebpf_cachestat.c
+49
-4
@@ -3,6 +3,10 @@
3
#include "ebpf.h"
4
#include "ebpf_cachestat.h"
5
6
+// ----------------------------------------------------------------------------
7
+// ARAL vectors used to speed up processing
8
+ARAL *ebpf_aral_cachestat_pid;
9
+
10
netdata_publish_cachestat_t **cachestat_pid;
11
12
static char *cachestat_counter_dimension_name[NETDATA_CACHESTAT_END] = { "ratio", "dirty", "hit",
@@ -364,6 +368,46 @@ static void ebpf_cachestat_exit(void *ptr)
368
ebpf_cachestat_free(em);
369
}
370
371
+/*****************************************************************
372
+ *
373
+ * ARAL FUNCTIONS
374
+ *
375
+ *****************************************************************/
376
+
377
+/**
378
+ * eBPF Cachestat Aral init
379
+ *
380
+ * Initiallize array allocator that will be used when integration with apps is enabled.
381
+ */
382
+static inline void ebpf_cachestat_aral_init()
383
+{
384
+ ebpf_aral_cachestat_pid = ebpf_allocate_pid_aral("ebpf-cachestat", sizeof(netdata_publish_cachestat_t));
385
+}
386
+
387
+/**
388
+ * eBPF publish cachestat get
389
+ *
390
+ * Get a netdata_publish_cachestat_t entry to be used with a specific PID.
391
+ *
392
+ * @return it returns the address on success.
393
+ */
394
+netdata_publish_cachestat_t *ebpf_publish_cachestat_get(void)
395
+{
396
+ netdata_publish_cachestat_t *target = aral_mallocz(ebpf_aral_cachestat_pid);
397
+ memset(target, 0, sizeof(netdata_publish_cachestat_t));
398
+ return target;
399
+}
400
+
401
+/**
402
+ * eBPF cachestat release
403
+ *
404
+ * @param stat Release a target after usage.
405
+ */
406
+void ebpf_cachestat_release(netdata_publish_cachestat_t *stat)
407
+{
408
+ aral_freez(ebpf_aral_cachestat_pid, stat);
409
+}
410
+
411
/*****************************************************************
412
*
413
* COMMON FUNCTIONS
@@ -502,7 +546,7 @@ static void cachestat_fill_pid(uint32_t current_pid, netdata_cachestat_pid_t *pu
546
{
547
netdata_publish_cachestat_t *curr = cachestat_pid[current_pid];
548
if (!curr) {
505
- curr = callocz(1, sizeof(netdata_publish_cachestat_t));
549
+ curr = ebpf_publish_cachestat_get();
550
cachestat_pid[current_pid] = curr;
551
552
cachestat_save_pid_values(curr, publish);
@@ -1167,10 +1211,11 @@ static void ebpf_create_memory_charts(ebpf_module_t *em)
1211
*/
1212
static void ebpf_cachestat_allocate_global_vectors(int apps)
1213
{
1170
- if (apps)
1214
+ if (apps) {
1215
cachestat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_cachestat_t *));
1172
-
1173
- cachestat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_cachestat_pid_t));
1216
+ ebpf_cachestat_aral_init();
1217
+ cachestat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_cachestat_pid_t));
1218
+ }
1219
1220
cachestat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
1221
collectors/ebpf.plugin/ebpf_cachestat.h
+1
@@ -82,6 +82,7 @@ typedef struct netdata_publish_cachestat {
82
} netdata_publish_cachestat_t;
83
84
void *ebpf_cachestat_thread(void *ptr);
85
+void ebpf_cachestat_release(netdata_publish_cachestat_t *stat);
86
87
extern struct config cachestat_config;
88
extern netdata_ebpf_targets_t cachestat_targets[];
collectors/ebpf.plugin/ebpf_dcstat.c
+49
-3
@@ -3,6 +3,10 @@
3
#include "ebpf.h"
4
#include "ebpf_dcstat.h"
5
6
+// ----------------------------------------------------------------------------
7
+// ARAL vectors used to speed up processing
8
+ARAL *ebpf_aral_dcstat_pid;
9
+
10
static char *dcstat_counter_dimension_name[NETDATA_DCSTAT_IDX_END] = { "ratio", "reference", "slow", "miss" };
11
static netdata_syscall_stat_t dcstat_counter_aggregated_data[NETDATA_DCSTAT_IDX_END];
12
static netdata_publish_syscall_t dcstat_counter_publish_aggregated[NETDATA_DCSTAT_IDX_END];
@@ -327,6 +331,46 @@ static void ebpf_dcstat_exit(void *ptr)
331
ebpf_dcstat_free(em);
332
}
333
334
+/*****************************************************************
335
+ *
336
+ * ARAL FUNCTIONS
337
+ *
338
+ *****************************************************************/
339
+
340
+/**
341
+ * eBPF directory cache Aral init
342
+ *
343
+ * Initiallize array allocator that will be used when integration with apps is enabled.
344
+ */
345
+static inline void ebpf_dcstat_aral_init()
346
+{
347
+ ebpf_aral_dcstat_pid = ebpf_allocate_pid_aral("ebpf-dcstat", sizeof(netdata_publish_dcstat_t));
348
+}
349
+
350
+/**
351
+ * eBPF publish dcstat get
352
+ *
353
+ * Get a netdata_publish_dcstat_t entry to be used with a specific PID.
354
+ *
355
+ * @return it returns the address on success.
356
+ */
357
+netdata_publish_dcstat_t *ebpf_publish_dcstat_get(void)
358
+{
359
+ netdata_publish_dcstat_t *target = aral_mallocz(ebpf_aral_dcstat_pid);
360
+ memset(target, 0, sizeof(netdata_publish_dcstat_t));
361
+ return target;
362
+}
363
+
364
+/**
365
+ * eBPF dcstat release
366
+ *
367
+ * @param stat Release a target after usage.
368
+ */
369
+void ebpf_dcstat_release(netdata_publish_dcstat_t *stat)
370
+{
371
+ aral_freez(ebpf_aral_dcstat_pid, stat);
372
+}
373
+
374
/*****************************************************************
375
*
376
* APPS
@@ -432,7 +476,7 @@ static void dcstat_fill_pid(uint32_t current_pid, netdata_dcstat_pid_t *publish)
476
{
477
netdata_publish_dcstat_t *curr = dcstat_pid[current_pid];
478
if (!curr) {
435
- curr = callocz(1, sizeof(netdata_publish_dcstat_t));
479
+ curr = ebpf_publish_dcstat_get();
480
dcstat_pid[current_pid] = curr;
481
}
482
@@ -1064,10 +1108,12 @@ static void ebpf_create_filesystem_charts(int update_every)
1108
*/
1109
static void ebpf_dcstat_allocate_global_vectors(int apps)
1110
{
1067
- if (apps)
1111
+ if (apps) {
1112
+ ebpf_dcstat_aral_init();
1113
dcstat_pid = callocz((size_t)pid_max, sizeof(netdata_publish_dcstat_t *));
1114
+ dcstat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_dcstat_pid_t));
1115
+ }
1116
1070
- dcstat_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_dcstat_pid_t));
1117
dcstat_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
1118
1119
memset(dcstat_counter_aggregated_data, 0, NETDATA_DCSTAT_IDX_END * sizeof(netdata_syscall_stat_t));
collectors/ebpf.plugin/ebpf_dcstat.h
+1
@@ -75,6 +75,7 @@ typedef struct netdata_publish_dcstat {
75
76
void *ebpf_dcstat_thread(void *ptr);
77
void ebpf_dcstat_create_apps_charts(struct ebpf_module *em, void *ptr);
78
+void ebpf_dcstat_release(netdata_publish_dcstat_t *stat);
79
extern struct config dcstat_config;
80
extern netdata_ebpf_targets_t dc_targets[];
81
extern ebpf_local_maps_t dcstat_maps[];
collectors/ebpf.plugin/ebpf_fd.c
+49
-4
@@ -3,6 +3,10 @@
3
#include "ebpf.h"
4
#include "ebpf_fd.h"
5
6
+// ----------------------------------------------------------------------------
7
+// ARAL vectors used to speed up processing
8
+ARAL *ebpf_aral_fd_pid;
9
+
10
static char *fd_dimension_names[NETDATA_FD_SYSCALL_END] = { "open", "close" };
11
static char *fd_id_names[NETDATA_FD_SYSCALL_END] = { "do_sys_open", "__close_fd" };
12
@@ -394,6 +398,46 @@ static void ebpf_fd_exit(void *ptr)
398
ebpf_fd_free(em);
399
}
400
401
+/*****************************************************************
402
+ *
403
+ * ARAL FUNCTIONS
404
+ *
405
+ *****************************************************************/
406
+
407
+/**
408
+ * eBPF file descriptor Aral init
409
+ *
410
+ * Initiallize array allocator that will be used when integration with apps is enabled.
411
+ */
412
+static inline void ebpf_fd_aral_init()
413
+{
414
+ ebpf_aral_fd_pid = ebpf_allocate_pid_aral("ebpf-fd", sizeof(netdata_fd_stat_t));
415
+}
416
+
417
+/**
418
+ * eBPF publish file descriptor get
419
+ *
420
+ * Get a netdata_fd_stat_t entry to be used with a specific PID.
421
+ *
422
+ * @return it returns the address on success.
423
+ */
424
+netdata_fd_stat_t *ebpf_fd_stat_get(void)
425
+{
426
+ netdata_fd_stat_t *target = aral_mallocz(ebpf_aral_fd_pid);
427
+ memset(target, 0, sizeof(netdata_fd_stat_t));
428
+ return target;
429
+}
430
+
431
+/**
432
+ * eBPF file descriptor release
433
+ *
434
+ * @param stat Release a target after usage.
435
+ */
436
+void ebpf_fd_release(netdata_fd_stat_t *stat)
437
+{
438
+ aral_freez(ebpf_aral_fd_pid, stat);
439
+}
440
+
441
/*****************************************************************
442
*
443
* MAIN LOOP
@@ -479,7 +523,7 @@ static void fd_fill_pid(uint32_t current_pid, netdata_fd_stat_t *publish)
523
{
524
netdata_fd_stat_t *curr = fd_pid[current_pid];
525
if (!curr) {
482
- curr = callocz(1, sizeof(netdata_fd_stat_t));
526
+ curr = ebpf_fd_stat_get();
527
fd_pid[current_pid] = curr;
528
}
529
@@ -1070,10 +1114,11 @@ static void ebpf_create_fd_global_charts(ebpf_module_t *em)
1114
*/
1115
static void ebpf_fd_allocate_global_vectors(int apps)
1116
{
1073
- if (apps)
1117
+ if (apps) {
1118
+ ebpf_fd_aral_init();
1119
fd_pid = callocz((size_t)pid_max, sizeof(netdata_fd_stat_t *));
1075
-
1076
- fd_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_fd_stat_t));
1120
+ fd_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_fd_stat_t));
1121
+ }
1122
1123
fd_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
1124
}
collectors/ebpf.plugin/ebpf_fd.h
+1
@@ -80,6 +80,7 @@ enum fd_close_syscall {
80
81
void *ebpf_fd_thread(void *ptr);
82
void ebpf_fd_create_apps_charts(struct ebpf_module *em, void *ptr);
83
+void ebpf_fd_release(netdata_fd_stat_t *stat);
84
extern struct config fd_config;
85
extern netdata_fd_stat_t **fd_pid;
86
extern netdata_ebpf_targets_t fd_targets[];
collectors/ebpf.plugin/ebpf_shm.c
+49
-4
@@ -3,6 +3,10 @@
3
#include "ebpf.h"
4
#include "ebpf_shm.h"
5
6
+// ----------------------------------------------------------------------------
7
+// ARAL vectors used to speed up processing
8
+ARAL *ebpf_aral_shm_pid;
9
+
10
static char *shm_dimension_name[NETDATA_SHM_END] = { "get", "at", "dt", "ctl" };
11
static netdata_syscall_stat_t shm_aggregated_data[NETDATA_SHM_END];
12
static netdata_publish_syscall_t shm_publish_aggregated[NETDATA_SHM_END];
@@ -319,6 +323,46 @@ static void ebpf_shm_exit(void *ptr)
323
ebpf_shm_free(em);
324
}
325
326
+/*****************************************************************
327
+ *
328
+ * ARAL FUNCTIONS
329
+ *
330
+ *****************************************************************/
331
+
332
+/**
333
+ * eBPF shared memory Aral init
334
+ *
335
+ * Initiallize array allocator that will be used when integration with apps is enabled.
336
+ */
337
+static inline void ebpf_shm_aral_init()
338
+{
339
+ ebpf_aral_shm_pid = ebpf_allocate_pid_aral("ebpf-shm", sizeof(netdata_publish_shm_t));
340
+}
341
+
342
+/**
343
+ * eBPF shared memory get
344
+ *
345
+ * Get a netdata_publish_shm_t entry to be used with a specific PID.
346
+ *
347
+ * @return it returns the address on success.
348
+ */
349
+netdata_publish_shm_t *ebpf_shm_stat_get(void)
350
+{
351
+ netdata_publish_shm_t *target = aral_mallocz(ebpf_aral_shm_pid);
352
+ memset(target, 0, sizeof(netdata_publish_shm_t));
353
+ return target;
354
+}
355
+
356
+/**
357
+ * eBPF shared memory release
358
+ *
359
+ * @param stat Release a target after usage.
360
+ */
361
+void ebpf_shm_release(netdata_publish_shm_t *stat)
362
+{
363
+ aral_freez(ebpf_aral_shm_pid, stat);
364
+}
365
+
366
/*****************************************************************
367
* COLLECTOR THREAD
368
*****************************************************************/
@@ -355,7 +399,7 @@ static void shm_fill_pid(uint32_t current_pid, netdata_publish_shm_t *publish)
399
{
400
netdata_publish_shm_t *curr = shm_pid[current_pid];
401
if (!curr) {
358
- curr = callocz(1, sizeof(netdata_publish_shm_t));
402
+ curr = ebpf_shm_stat_get( );
403
shm_pid[current_pid] = curr;
404
}
405
@@ -945,10 +989,11 @@ void ebpf_shm_create_apps_charts(struct ebpf_module *em, void *ptr)
989
*/
990
static void ebpf_shm_allocate_global_vectors(int apps)
991
{
948
- if (apps)
992
+ if (apps) {
993
+ ebpf_shm_aral_init();
994
shm_pid = callocz((size_t)pid_max, sizeof(netdata_publish_shm_t *));
950
-
951
- shm_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_publish_shm_t));
995
+ shm_vector = callocz((size_t)ebpf_nprocs, sizeof(netdata_publish_shm_t));
996
+ }
997
998
shm_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_idx_t));
999
collectors/ebpf.plugin/ebpf_shm.h
+1
@@ -54,6 +54,7 @@ extern netdata_publish_shm_t **shm_pid;
54
55
void *ebpf_shm_thread(void *ptr);
56
void ebpf_shm_create_apps_charts(struct ebpf_module *em, void *ptr);
57
+void ebpf_shm_release(netdata_publish_shm_t *stat);
58
extern netdata_ebpf_targets_t shm_targets[];
59
60
extern struct config shm_config;
collectors/ebpf.plugin/ebpf_socket.c
+49
-4
@@ -5,6 +5,10 @@
5
#include "ebpf.h"
6
#include "ebpf_socket.h"
7
8
+// ----------------------------------------------------------------------------
9
+// ARAL vectors used to speed up processing
10
+ARAL *ebpf_aral_socket_pid;
11
+
12
/*****************************************************************
13
*
14
* GLOBAL VARIABLES
@@ -429,6 +433,46 @@ static inline int ebpf_socket_load_and_attach(struct socket_bpf *obj, ebpf_modul
433
}
434
#endif
435
436
+/*****************************************************************
437
+ *
438
+ * ARAL FUNCTIONS
439
+ *
440
+ *****************************************************************/
441
+
442
+/**
443
+ * eBPF socket Aral init
444
+ *
445
+ * Initiallize array allocator that will be used when integration with apps is enabled.
446
+ */
447
+static inline void ebpf_socket_aral_init()
448
+{
449
+ ebpf_aral_socket_pid = ebpf_allocate_pid_aral("ebpf-socket", sizeof(ebpf_socket_publish_apps_t));
450
+}
451
+
452
+/**
453
+ * eBPF socket get
454
+ *
455
+ * Get a ebpf_socket_publish_apps_t entry to be used with a specific PID.
456
+ *
457
+ * @return it returns the address on success.
458
+ */
459
+ebpf_socket_publish_apps_t *ebpf_socket_stat_get(void)
460
+{
461
+ ebpf_socket_publish_apps_t *target = aral_mallocz(ebpf_aral_socket_pid);
462
+ memset(target, 0, sizeof(ebpf_socket_publish_apps_t));
463
+ return target;
464
+}
465
+
466
+/**
467
+ * eBPF socket release
468
+ *
469
+ * @param stat Release a target after usage.
470
+ */
471
+void ebpf_socket_release(ebpf_socket_publish_apps_t *stat)
472
+{
473
+ aral_freez(ebpf_aral_socket_pid, stat);
474
+}
475
+
476
/*****************************************************************
477
*
478
* FUNCTIONS TO CLOSE THE THREAD
@@ -2227,7 +2271,7 @@ void ebpf_socket_fill_publish_apps(uint32_t current_pid, ebpf_bandwidth_t *eb)
2271
{
2272
ebpf_socket_publish_apps_t *curr = socket_bandwidth_curr[current_pid];
2273
if (!curr) {
2230
- curr = callocz(1, sizeof(ebpf_socket_publish_apps_t));
2274
+ curr = ebpf_socket_stat_get();
2275
socket_bandwidth_curr[current_pid] = curr;
2276
}
2277
@@ -2947,10 +2991,11 @@ static void ebpf_socket_allocate_global_vectors(int apps)
2991
memset(socket_publish_aggregated, 0 ,NETDATA_MAX_SOCKET_VECTOR * sizeof(netdata_publish_syscall_t));
2992
socket_hash_values = callocz(ebpf_nprocs, sizeof(netdata_idx_t));
2993
2950
- if (apps)
2994
+ if (apps) {
2995
+ ebpf_socket_aral_init();
2996
socket_bandwidth_curr = callocz((size_t)pid_max, sizeof(ebpf_socket_publish_apps_t *));
2952
-
2953
- bandwidth_vector = callocz((size_t)ebpf_nprocs, sizeof(ebpf_bandwidth_t));
2997
+ bandwidth_vector = callocz((size_t)ebpf_nprocs, sizeof(ebpf_bandwidth_t));
2998
+ }
2999
3000
socket_values = callocz((size_t)ebpf_nprocs, sizeof(netdata_socket_t));
3001
if (network_viewer_opt.enabled) {
collectors/ebpf.plugin/ebpf_socket.h
+1
@@ -363,6 +363,7 @@ void update_listen_table(uint16_t value, uint16_t proto, netdata_passive_connect
363
void parse_network_viewer_section(struct config *cfg);
364
void ebpf_fill_ip_list(ebpf_network_viewer_ip_list_t **out, ebpf_network_viewer_ip_list_t *in, char *table);
365
void parse_service_name_section(struct config *cfg);
366
+void ebpf_socket_release(ebpf_socket_publish_apps_t *stat);
367
368
extern ebpf_socket_publish_apps_t **socket_bandwidth_curr;
369
extern struct config socket_config;
collectors/ebpf.plugin/ebpf_vfs.c
+51
-5
@@ -5,6 +5,10 @@
5
#include "ebpf.h"
6
#include "ebpf_vfs.h"
7
8
+// ----------------------------------------------------------------------------
9
+// ARAL vectors used to speed up processing
10
+ARAL *ebpf_aral_vfs_pid;
11
+
12
static char *vfs_dimension_names[NETDATA_KEY_PUBLISH_VFS_END] = { "delete", "read", "write",
13
"fsync", "open", "create" };
14
static char *vfs_id_names[NETDATA_KEY_PUBLISH_VFS_END] = { "vfs_unlink", "vfs_read", "vfs_write",
@@ -382,6 +386,46 @@ static inline int ebpf_vfs_load_and_attach(struct vfs_bpf *obj, ebpf_module_t *e
386
}
387
#endif
388
389
+/*****************************************************************
390
+ *
391
+ * ARAL FUNCTIONS
392
+ *
393
+ *****************************************************************/
394
+
395
+/**
396
+ * eBPF VFS Aral init
397
+ *
398
+ * Initiallize array allocator that will be used when integration with apps is enabled.
399
+ */
400
+static inline void ebpf_vfs_aral_init()
401
+{
402
+ ebpf_aral_vfs_pid = ebpf_allocate_pid_aral("ebpf-vfs", sizeof(netdata_publish_vfs_t));
403
+}
404
+
405
+/**
406
+ * eBPF publish VFS get
407
+ *
408
+ * Get a netdata_publish_vfs_t entry to be used with a specific PID.
409
+ *
410
+ * @return it returns the address on success.
411
+ */
412
+netdata_publish_vfs_t *ebpf_vfs_get(void)
413
+{
414
+ netdata_publish_vfs_t *target = aral_mallocz(ebpf_aral_vfs_pid);
415
+ memset(target, 0, sizeof(netdata_publish_vfs_t));
416
+ return target;
417
+}
418
+
419
+/**
420
+ * eBPF VFS release
421
+ *
422
+ * @param stat Release a target after usage.
423
+ */
424
+void ebpf_vfs_release(netdata_publish_vfs_t *stat)
425
+{
426
+ aral_freez(ebpf_aral_vfs_pid, stat);
427
+}
428
+
429
/*****************************************************************
430
*
431
* FUNCTIONS TO CLOSE THE THREAD
@@ -775,7 +819,7 @@ static void vfs_fill_pid(uint32_t current_pid, netdata_publish_vfs_t *publish)
819
{
820
netdata_publish_vfs_t *curr = vfs_pid[current_pid];
821
if (!curr) {
778
- curr = callocz(1, sizeof(netdata_publish_vfs_t));
822
+ curr = ebpf_vfs_get();
823
vfs_pid[current_pid] = curr;
824
}
825
@@ -1825,14 +1869,16 @@ void ebpf_vfs_create_apps_charts(struct ebpf_module *em, void *ptr)
1869
*/
1870
static void ebpf_vfs_allocate_global_vectors(int apps)
1871
{
1872
+ if (apps) {
1873
+ ebpf_vfs_aral_init();
1874
+ vfs_pid = callocz((size_t)pid_max, sizeof(netdata_publish_vfs_t *));
1875
+ vfs_vector = callocz(ebpf_nprocs, sizeof(netdata_publish_vfs_t));
1876
+ }
1877
+
1878
memset(vfs_aggregated_data, 0, sizeof(vfs_aggregated_data));
1879
memset(vfs_publish_aggregated, 0, sizeof(vfs_publish_aggregated));
1880
1881
vfs_hash_values = callocz(ebpf_nprocs, sizeof(netdata_idx_t));
1832
- vfs_vector = callocz(ebpf_nprocs, sizeof(netdata_publish_vfs_t));
1833
-
1834
- if (apps)
1835
- vfs_pid = callocz((size_t)pid_max, sizeof(netdata_publish_vfs_t *));
1882
}
1883
1884
/*****************************************************************
collectors/ebpf.plugin/ebpf_vfs.h
+1
@@ -168,6 +168,7 @@ extern netdata_publish_vfs_t **vfs_pid;
168
169
void *ebpf_vfs_thread(void *ptr);
170
void ebpf_vfs_create_apps_charts(struct ebpf_module *em, void *ptr);
171
+void ebpf_vfs_release(netdata_publish_vfs_t *stat);
172
extern netdata_ebpf_targets_t vfs_targets[];
173
174
extern struct config vfs_config;