[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210622225057.2108592-2-kuba@kernel.org>
Date: Tue, 22 Jun 2021 15:50:57 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org, willemb@...gle.com, eric.dumazet@...il.com,
dsahern@...il.com, yoshfuji@...ux-ipv6.org,
Jakub Kicinski <kuba@...nel.org>, Dave Jones <dsj@...com>
Subject: [PATCH net-next v2 2/2] net: ip: avoid OOM kills with large UDP sends over loopback
Dave observed number of machines hitting OOM on the UDP send
path. The workload seems to be sending large UDP packets over
loopback. Since loopback has MTU of 64k kernel will try to
allocate an skb with up to 64k of head space. This has a good
chance of failing under memory pressure. What's worse if
the message length is <32k the allocation may trigger an
OOM killer.
This is entirely avoidable, we can use an skb with frags.
af_unix solves a similar problem by limiting the head
length to SKB_MAX_ALLOC. This seems like a good and simple
approach. It means that UDP messages > 16kB will now
use fragments if underlying device supports SG, if extra
allocator pressure causes regressions in real workloads
we can switch to trying the large allocation first and
falling back.
Reported-by: Dave Jones <dsj@...com>
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
net/ipv4/ip_output.c | 2 +-
net/ipv6/ip6_output.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 90031f5446bd..1ab140c173d0 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -1077,7 +1077,7 @@ static int __ip_append_data(struct sock *sk,
if ((flags & MSG_MORE) && !has_sg)
alloclen = mtu;
- else if (!paged)
+ else if (!paged && (fraglen < SKB_MAX_ALLOC || !has_sg))
alloclen = fraglen;
else {
alloclen = min_t(int, fraglen, MAX_HEADER);
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index c667b7e2856f..46d805097a79 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1585,7 +1585,7 @@ static int __ip6_append_data(struct sock *sk,
if ((flags & MSG_MORE) && !has_sg)
alloclen = mtu;
- else if (!paged)
+ else if (!paged && (fraglen < SKB_MAX_ALLOC || !has_sg))
alloclen = fraglen;
else {
alloclen = min_t(int, fraglen, MAX_HEADER);
--
2.31.1
Powered by blists - more mailing lists