Skip to content

Commit 6606e90

Browse files
committed
neigh_table_tuner: tune all thresholds and limit growth
increase all thresholds simultaneously instead of only gc_thresh3. Also set a limit to how large the thresholds can grow Signed-off-by: Pradyumn Rahar <pradyumn.rahar@oracle.com>
1 parent 5966387 commit 6606e90

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/neigh_table_tuner.bpf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl,
4343

4444
new_tbl_stats.family = BPFTUNE_CORE_READ(tbl, family);
4545
new_tbl_stats.entries = BPFTUNE_CORE_READ(tbl, entries.counter);
46+
new_tbl_stats.thresh1 = BPFTUNE_CORE_READ(tbl, gc_thresh1);
47+
new_tbl_stats.thresh2 = BPFTUNE_CORE_READ(tbl, gc_thresh2);
4648
new_tbl_stats.max = BPFTUNE_CORE_READ(tbl, gc_thresh3);
4749
if (dev) {
4850
bpf_probe_read(&new_tbl_stats.dev, sizeof(new_tbl_stats.dev), dev);
@@ -55,12 +57,14 @@ int BPF_PROG(bpftune_neigh_create, struct neigh_table *tbl,
5557
}
5658
tbl_stats->entries = BPFTUNE_CORE_READ(tbl, entries.counter);
5759
tbl_stats->gc_entries = BPFTUNE_CORE_READ(tbl, gc_entries.counter);
60+
tbl_stats->thresh1 = BPFTUNE_CORE_READ(tbl, gc_thresh1);
61+
tbl_stats->thresh2 = BPFTUNE_CORE_READ(tbl, gc_thresh2);
5862
tbl_stats->max = BPFTUNE_CORE_READ(tbl, gc_thresh3);
5963

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

src/neigh_table_tuner.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void fini(struct bpftuner *tuner)
7777
bpftuner_bpf_fini(tuner);
7878
}
7979

80-
static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
80+
static int increase_thresh(struct bpftuner *tuner, struct tbl_stats *stats)
8181
{
8282
char *tbl_name = stats->family == AF_INET ? "arp_cache" : "ndisc_cache";
8383
/* Open raw socket for the NETLINK_ROUTE protocol */
@@ -89,6 +89,8 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
8989
.ndtm_family = stats->family,
9090
};
9191
struct nl_msg *m = NULL, *parms = NULL;
92+
int new_gc_thresh1 = 0;
93+
int new_gc_thresh2 = 0;
9294
int new_gc_thresh3 = 0;
9395
int ret;
9496

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

122124
new_gc_thresh3 = BPFTUNE_GROW_BY_DELTA(stats->max);
125+
126+
if (new_gc_thresh3 >= MAX_THRESH3) {
127+
new_gc_thresh3 = MAX_THRESH3;
128+
new_gc_thresh2 = MAX_THRESH2;
129+
new_gc_thresh1 = MAX_THRESH1;
130+
}
131+
else {
132+
new_gc_thresh2 = BPFTUNE_GROW_BY_DELTA(stats->thresh2);
133+
new_gc_thresh1 = BPFTUNE_GROW_BY_DELTA(stats->thresh1);
134+
}
123135
NLA_PUT_U32(m, NDTA_THRESH3, new_gc_thresh3);
136+
NLA_PUT_U32(m, NDTA_THRESH2, new_gc_thresh2);
137+
NLA_PUT_U32(m, NDTA_THRESH1, new_gc_thresh1);
124138

125139
parms = nlmsg_alloc();
126140
if (!parms) {
@@ -152,8 +166,10 @@ static int set_gc_thresh3(struct bpftuner *tuner, struct tbl_stats *stats)
152166
stats->dev, strerror(-ret));
153167
} else {
154168
bpftuner_tunable_update(tuner, tunable, NEIGH_TABLE_FULL, 0,
155-
"updated gc_thresh3 for %s table, dev '%s' (ifindex %d) from %ld to %ld\n",
169+
"updated thresholds for %s table, dev '%s' (ifindex %d) thresh1: %ld to %ld, thresh2: %ld to %ld, thresh3: %ld to %ld\n",
156170
tbl_name, stats->dev, stats->ifindex,
171+
stats->thresh1, new_gc_thresh1,
172+
stats->thresh2, new_gc_thresh2,
157173
stats->max, new_gc_thresh3);
158174
}
159175
return ret;
@@ -169,7 +185,7 @@ void event_handler(struct bpftuner *tuner,
169185
case NEIGH_TABLE_FULL:
170186
if (bpftune_cap_add())
171187
return;
172-
set_gc_thresh3(tuner, stats);
188+
increase_thresh(tuner, stats);
173189
bpftune_cap_drop();
174190
break;
175191
default:

src/neigh_table_tuner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#define IFNAMSIZ 16
2424
#endif
2525

26+
#define MAX_THRESH1 4096
27+
#define MAX_THRESH2 16384
28+
#define MAX_THRESH3 32768
29+
2630
enum neigh_table_tunables {
2731
NEIGH_TABLE_IPV4_GC_INTERVAL,
2832
NEIGH_TABLE_IPV4_GC_STALE_TIME,
@@ -45,6 +49,8 @@ struct tbl_stats {
4549
int family;
4650
int entries;
4751
int gc_entries;
52+
int thresh1;
53+
int thresh2;
4854
int max;
4955
int ifindex;
5056
char dev[IFNAMSIZ];

0 commit comments

Comments
 (0)