Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/neigh_table_tuner.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl,

new_tbl_stats.family = BPFTUNE_CORE_READ(tbl, family);
new_tbl_stats.entries = BPFTUNE_CORE_READ(tbl, entries.counter);
new_tbl_stats.thresh1 = BPFTUNE_CORE_READ(tbl, gc_thresh1);
new_tbl_stats.thresh2 = BPFTUNE_CORE_READ(tbl, gc_thresh2);
new_tbl_stats.max = BPFTUNE_CORE_READ(tbl, gc_thresh3);
if (dev) {
bpf_probe_read(&new_tbl_stats.dev, sizeof(new_tbl_stats.dev), dev);
Expand All @@ -55,12 +57,14 @@ int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl,
}
tbl_stats->entries = BPFTUNE_CORE_READ(tbl, entries.counter);
tbl_stats->gc_entries = BPFTUNE_CORE_READ(tbl, gc_entries.counter);
tbl_stats->thresh1 = BPFTUNE_CORE_READ(tbl, gc_thresh1);
tbl_stats->thresh2 = BPFTUNE_CORE_READ(tbl, gc_thresh2);
tbl_stats->max = BPFTUNE_CORE_READ(tbl, gc_thresh3);

/* exempt from gc entries are not subject to space constraints, but
* do take up table entries.
*/
if (NEARLY_FULL(tbl_stats->entries, tbl_stats->max)) {
if (NEARLY_FULL(tbl_stats->entries, tbl_stats->max) && (tbl_stats->max < MAX_THRESH3)) {
struct neigh_parms *parms = BPFTUNE_CORE_READ(n, parms);
struct net *net = BPFTUNE_CORE_READ(parms, net.net);

Expand Down
22 changes: 19 additions & 3 deletions src/neigh_table_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void fini(struct bpftuner *tuner)
bpftuner_bpf_fini(tuner);
}

static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
static int increase_thresh(struct bpftuner *tuner, struct tbl_stats *stats)
{
char *tbl_name = stats->family == AF_INET ? "arp_cache" : "ndisc_cache";
/* Open raw socket for the NETLINK_ROUTE protocol */
Expand All @@ -89,6 +89,8 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
.ndtm_family = stats->family,
};
struct nl_msg *m = NULL, *parms = NULL;
int new_gc_thresh1 = 0;
int new_gc_thresh2 = 0;
int new_gc_thresh3 = 0;
int ret;

Expand Down Expand Up @@ -120,7 +122,19 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
NLA_PUT_STRING(m, NDTA_NAME, tbl_name);

new_gc_thresh3 = BPFTUNE_GROW_BY_DELTA(stats->max);

if (new_gc_thresh3 >= MAX_THRESH3) {
new_gc_thresh3 = MAX_THRESH3;
new_gc_thresh2 = MAX_THRESH2;
new_gc_thresh1 = MAX_THRESH1;
}
else {
new_gc_thresh2 = BPFTUNE_GROW_BY_DELTA(stats->thresh2);
new_gc_thresh1 = BPFTUNE_GROW_BY_DELTA(stats->thresh1);
}
NLA_PUT_U32(m, NDTA_THRESH3, new_gc_thresh3);
NLA_PUT_U32(m, NDTA_THRESH2, new_gc_thresh2);
NLA_PUT_U32(m, NDTA_THRESH1, new_gc_thresh1);

parms = nlmsg_alloc();
if (!parms) {
Expand Down Expand Up @@ -152,8 +166,10 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
stats->dev, strerror(-ret));
} else {
bpftuner_tunable_update(tuner, tunable, NEIGH_TABLE_FULL, 0,
"updated gc_thresh3 for %s table, dev '%s' (ifindex %d) from %ld to %ld\n",
"updated thresholds for %s table, dev '%s' (ifindex %d) thresh1: %ld to %ld, thresh2: %ld to %ld, thresh3: %ld to %ld\n",
tbl_name, stats->dev, stats->ifindex,
stats->thresh1, new_gc_thresh1,
stats->thresh2, new_gc_thresh2,
stats->max, new_gc_thresh3);
}
return ret;
Expand All @@ -169,7 +185,7 @@ void event_handler(struct bpftuner *tuner,
case NEIGH_TABLE_FULL:
if (bpftune_cap_add())
return;
set_gc_thresh3(tuner, stats);
increase_thresh(tuner, stats);
bpftune_cap_drop();
break;
default:
Expand Down
6 changes: 6 additions & 0 deletions src/neigh_table_tuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#define IFNAMSIZ 16
#endif

#define MAX_THRESH1 4096
#define MAX_THRESH2 16384
#define MAX_THRESH3 32768

enum neigh_table_tunables {
NEIGH_TABLE_IPV4_GC_INTERVAL,
NEIGH_TABLE_IPV4_GC_STALE_TIME,
Expand All @@ -45,6 +49,8 @@ struct tbl_stats {
int family;
int entries;
int gc_entries;
int thresh1;
int thresh2;
int max;
int ifindex;
char dev[IFNAMSIZ];
Expand Down