Skip to content

Commit cf86a08

Browse files
edumazetkuba-moo
authored andcommitted
net/dst: use a smaller percpu_counter batch for dst entries accounting
percpu_counter_add() uses a default batch size which is quite big on platforms with 256 cpus. (2*256 -> 512) This means dst_entries_get_fast() can be off by +/- 2*(nr_cpus^2) (131072 on servers with 256 cpus) Reduce the batch size to something more reasonable, and add logic to ip6_dst_gc() to call dst_entries_get_slow() before calling the _very_ expensive fib6_run_gc() function. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 790709f commit cf86a08

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

include/net/dst_ops.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ static inline int dst_entries_get_slow(struct dst_ops *dst)
5353
return percpu_counter_sum_positive(&dst->pcpuc_entries);
5454
}
5555

56+
#define DST_PERCPU_COUNTER_BATCH 32
5657
static inline void dst_entries_add(struct dst_ops *dst, int val)
5758
{
58-
percpu_counter_add(&dst->pcpuc_entries, val);
59+
percpu_counter_add_batch(&dst->pcpuc_entries, val,
60+
DST_PERCPU_COUNTER_BATCH);
5961
}
6062

6163
static inline int dst_entries_init(struct dst_ops *dst)

net/core/dst.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ void *dst_alloc(struct dst_ops *ops, struct net_device *dev,
8181
{
8282
struct dst_entry *dst;
8383

84-
if (ops->gc && dst_entries_get_fast(ops) > ops->gc_thresh) {
84+
if (ops->gc &&
85+
!(flags & DST_NOCOUNT) &&
86+
dst_entries_get_fast(ops) > ops->gc_thresh) {
8587
if (ops->gc(ops)) {
86-
printk_ratelimited(KERN_NOTICE "Route cache is full: "
87-
"consider increasing sysctl "
88-
"net.ipv[4|6].route.max_size.\n");
88+
pr_notice_ratelimited("Route cache is full: consider increasing sysctl net.ipv6.route.max_size.\n");
8989
return NULL;
9090
}
9191
}

net/ipv6/route.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,6 +3195,9 @@ static int ip6_dst_gc(struct dst_ops *ops)
31953195
int entries;
31963196

31973197
entries = dst_entries_get_fast(ops);
3198+
if (entries > rt_max_size)
3199+
entries = dst_entries_get_slow(ops);
3200+
31983201
if (time_after(rt_last_gc + rt_min_interval, jiffies) &&
31993202
entries <= rt_max_size)
32003203
goto out;

0 commit comments

Comments
 (0)