tcp: fix possible freeze in tx path under memory pressure
authorEric Dumazet <edumazet@google.com>
Tue, 14 Jun 2022 17:17:34 +0000 (10:17 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 Jun 2022 09:03:42 +0000 (10:03 +0100)
commit849b425cd091e1804af964b771761cfbefbafb43
tree515ba0a18e7ceb06b5743cf38130fca4397dbd9d
parentc4ee118561a0f74442439b7b5b486db1ac1ddfeb
tcp: fix possible freeze in tx path under memory pressure

Blamed commit only dealt with applications issuing small writes.

Issue here is that we allow to force memory schedule for the sk_buff
allocation, but we have no guarantee that sendmsg() is able to
copy some payload in it.

In this patch, I make sure the socket can use up to tcp_wmem[0] bytes.

For example, if we consider tcp_wmem[0] = 4096 (default on x86),
and initial skb->truesize being 1280, tcp_sendmsg() is able to
copy up to 2816 bytes under memory pressure.

Before this patch a sendmsg() sending more than 2816 bytes
would either block forever (if persistent memory pressure),
or return -EAGAIN.

For bigger MTU networks, it is advised to increase tcp_wmem[0]
to avoid sending too small packets.

v2: deal with zero copy paths.

Fixes: 8e4d980ac215 ("tcp: fix behavior for epoll edge trigger")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: Wei Wang <weiwan@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/tcp.c