pping: Preallocate memory for aggregation maps

When maps are not preallocated, the creation of map entries may
sometimes unpredictably fail with ENOMEM, despite plenty of free
memory being available. Solving this memory allocation issue may take
some time, so in the mean time let's just preallocate the memory for
the aggregation maps as well.

Preallocating the maps means the memory usage will be the same
regardless of the amount of traffic actually observed (i.e. regardless
of the number of aggregation entries that need to be created). To
compensate for this higher out-of-the-box memory usage, decrease the
histogram resolution from 1000 1ms bins to 250 4ms bins.

The memory usage (for the aggregation maps) should be approximately:
(56 + NR_BINS * 4) * CPUS * MAP_AGGREGATION_SIZE * 4

With the current values, that translates to roughly 66 MiB per CPU
core (down from ~254 MiB/core with 1000 bins).

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2023-07-04 19:27:20 +02:00
parent aadc7535c1
commit 59310e8ead
2 changed files with 2 additions and 6 deletions

View File

@@ -27,8 +27,8 @@ typedef __u64 fixpoint64;
#define EVENT_TYPE_MAP_FULL 3
#define EVENT_TYPE_MAP_CLEAN 4
#define RTT_AGG_NR_BINS 1000UL
#define RTT_AGG_BIN_WIDTH (1 * NS_PER_MS) // 1 ms
#define RTT_AGG_NR_BINS 250UL
#define RTT_AGG_BIN_WIDTH (4 * NS_PER_MS)
/* Special IPv4/IPv6 prefixes used for backup entries
* To avoid them colliding with and actual traffic (causing the traffic to end

View File

@@ -159,7 +159,6 @@ struct {
__type(key, __u32);
__type(value, struct aggregated_rtt_stats);
__uint(max_entries, MAP_AGGREGATION_SIZE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_v4_agg1 SEC(".maps");
struct {
@@ -167,7 +166,6 @@ struct {
__type(key, __u32);
__type(value, struct aggregated_rtt_stats);
__uint(max_entries, MAP_AGGREGATION_SIZE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_v4_agg2 SEC(".maps");
struct {
@@ -175,7 +173,6 @@ struct {
__type(key, __u64);
__type(value, struct aggregated_rtt_stats);
__uint(max_entries, MAP_AGGREGATION_SIZE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_v6_agg1 SEC(".maps");
struct {
@@ -183,7 +180,6 @@ struct {
__type(key, __u64);
__type(value, struct aggregated_rtt_stats);
__uint(max_entries, MAP_AGGREGATION_SIZE);
__uint(map_flags, BPF_F_NO_PREALLOC);
} map_v6_agg2 SEC(".maps");
struct {