diff --git a/include/net/dst_ops.h b/include/net/dst_ops.h index 33392b9a701ff6029c2b87d326e2f040d24d0770..b8ee48ea07f15a1f3a09e6eeef4d9f12fdff134f 100644 --- a/include/net/dst_ops.h +++ b/include/net/dst_ops.h @@ -63,9 +63,11 @@ static inline int dst_entries_get_slow(struct dst_ops *dst) return percpu_counter_sum_positive(&dst->pcpuc_entries); } +#define DST_PERCPU_COUNTER_BATCH 32 static inline void dst_entries_add(struct dst_ops *dst, int val) { - percpu_counter_add(&dst->pcpuc_entries, val); + percpu_counter_add_batch(&dst->pcpuc_entries, val, + DST_PERCPU_COUNTER_BATCH); } static inline int dst_entries_init(struct dst_ops *dst) diff --git a/net/core/dst.c b/net/core/dst.c index 81ccf20e28265ec61c2a4025b8f8f1f65f38c866..1a9f84f8cde16de2e6ab4949f158101a29158641 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -97,9 +97,13 @@ void *dst_alloc(struct dst_ops *ops, struct net_device *dev, { struct dst_entry *dst; - if (ops->gc && dst_entries_get_fast(ops) > ops->gc_thresh) { - if (ops->gc(ops)) + if (ops->gc && + !(flags & DST_NOCOUNT) && + dst_entries_get_fast(ops) > ops->gc_thresh) { + if (ops->gc(ops)) { + pr_notice_ratelimited("Route cache is full: consider increasing sysctl net.ipv6.route.max_size.\n"); return NULL; + } } dst = kmem_cache_alloc(ops->kmem_cachep, GFP_ATOMIC); diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 7b2ed1fb747e8243ffcaa1aceff24617d2f07e51..344e1548fd944cfe2ba17c52f8dcce44797e7f0a 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2781,6 +2781,9 @@ static int ip6_dst_gc(struct dst_ops *ops) int entries; entries = dst_entries_get_fast(ops); + if (entries > rt_max_size) + entries = dst_entries_get_slow(ops); + if (time_after(rt_last_gc + rt_min_interval, jiffies) && entries <= rt_max_size) goto out;