From 3aa0c3852b1d3479217546a3db4148da737bd8aa Mon Sep 17 00:00:00 2001 From: Pradyumn Rahar Date: Tue, 11 Nov 2025 08:34:28 +0530 Subject: [PATCH] neigh_table_tuner: tune all thresholds increase all thresholds simultaneously instead of only gc_thresh3 Signed-off-by: Pradyumn Rahar --- src/neigh_table_tuner.bpf.c | 4 ++++ src/neigh_table_tuner.c | 14 +++++++++++--- src/neigh_table_tuner.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/neigh_table_tuner.bpf.c b/src/neigh_table_tuner.bpf.c index eedc6d6..1bb172d 100644 --- a/src/neigh_table_tuner.bpf.c +++ b/src/neigh_table_tuner.bpf.c @@ -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); @@ -55,6 +57,8 @@ 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 diff --git a/src/neigh_table_tuner.c b/src/neigh_table_tuner.c index a04d1a2..a1062db 100644 --- a/src/neigh_table_tuner.c +++ b/src/neigh_table_tuner.c @@ -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 */ @@ -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; @@ -121,6 +123,10 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats) new_gc_thresh3 = BPFTUNE_GROW_BY_DELTA(stats->max); NLA_PUT_U32(m, NDTA_THRESH3, new_gc_thresh3); + new_gc_thresh2 = BPFTUNE_GROW_BY_DELTA(stats->thresh2); + new_gc_thresh1 = BPFTUNE_GROW_BY_DELTA(stats->thresh1); + NLA_PUT_U32(m, NDTA_THRESH2, new_gc_thresh2); + NLA_PUT_U32(m, NDTA_THRESH1, new_gc_thresh1); parms = nlmsg_alloc(); if (!parms) { @@ -152,8 +158,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; @@ -169,7 +177,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: diff --git a/src/neigh_table_tuner.h b/src/neigh_table_tuner.h index 01b69db..6c99090 100644 --- a/src/neigh_table_tuner.h +++ b/src/neigh_table_tuner.h @@ -45,6 +45,8 @@ struct tbl_stats { int family; int entries; int gc_entries; + int thresh1; + int thresh2; int max; int ifindex; char dev[IFNAMSIZ];