From: Suraj Jitindar Singh <surajjs@amazon.com>
To: <stable@vger.kernel.org>
Cc: <gregkh@linuxfoundation.org>, <trawets@amazon.com>,
<security@kernel.org>, Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
"Suraj Jitindar Singh" <surajjs@amazon.com>
Subject: [PATCH stable 4.19.x 2/4] net/dst: use a smaller percpu_counter batch for dst entries accounting
Date: Fri, 12 Jan 2024 16:53:06 -0800 [thread overview]
Message-ID: <20240113005308.2422331-2-surajjs@amazon.com> (raw)
In-Reply-To: <20240113005308.2422331-1-surajjs@amazon.com>
From: Eric Dumazet <edumazet@google.com>
commit cf86a086a18095e33e0637cb78cda1fcf5280852 upstream.
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 <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Suraj Jitindar Singh <surajjs@amazon.com>
Cc: <stable@vger.kernel.org> # 4.19.x
---
include/net/dst_ops.h | 4 +++-
net/core/dst.c | 8 ++++----
net/ipv6/route.c | 3 +++
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/include/net/dst_ops.h b/include/net/dst_ops.h
index 443863c7b8da..88ff7bb2bb9b 100644
--- a/include/net/dst_ops.h
+++ b/include/net/dst_ops.h
@@ -53,9 +53,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 a263309df115..1a9f84f8cde1 100644
--- a/net/core/dst.c
+++ b/net/core/dst.c
@@ -97,11 +97,11 @@ 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 &&
+ !(flags & DST_NOCOUNT) &&
+ dst_entries_get_fast(ops) > ops->gc_thresh) {
if (ops->gc(ops)) {
- printk_ratelimited(KERN_NOTICE "Route cache is full: "
- "consider increasing sysctl "
- "net.ipv[4|6].route.max_size.\n");
+ pr_notice_ratelimited("Route cache is full: consider increasing sysctl net.ipv6.route.max_size.\n");
return NULL;
}
}
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 7b41d5d3575f..d8944ae0171a 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2778,6 +2778,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;
--
2.34.1
next prev parent reply other threads:[~2024-01-13 0:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2024011155-gruffly-chunk-e186@gregkh>
2024-01-13 0:42 ` [PATCH stable 5.4.x 1/3] net/dst: use a smaller percpu_counter batch for dst entries accounting Suraj Jitindar Singh
2024-01-13 0:42 ` [PATCH stable 5.4.x 2/3] ipv6: make ip6_rt_gc_expire an atomic_t Suraj Jitindar Singh
2024-01-13 0:42 ` [PATCH stable 5.4.x 3/3] ipv6: remove max_size check inline with ipv4 Suraj Jitindar Singh
2024-01-13 0:53 ` [PATCH stable 4.19.x 1/4] net: add a route cache full diagnostic message Suraj Jitindar Singh
2024-01-13 0:53 ` Suraj Jitindar Singh [this message]
2024-01-13 0:53 ` [PATCH stable 4.19.x 3/4] ipv6: make ip6_rt_gc_expire an atomic_t Suraj Jitindar Singh
2024-01-13 0:53 ` [PATCH stable 4.19.x 4/4] ipv6: remove max_size check inline with ipv4 Suraj Jitindar Singh
2024-01-13 9:19 ` [PATCH stable 4.19.x 1/4] net: add a route cache full diagnostic message Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240113005308.2422331-2-surajjs@amazon.com \
--to=surajjs@amazon.com \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=security@kernel.org \
--cc=stable@vger.kernel.org \
--cc=trawets@amazon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.