tcp: fix mem under-charging with zerocopy sendmsg()
Subsystems (3)
PATCH 1/1 tcp: fix mem under-charging with zerocopy sendmsg()
From: Eric Dumazet <[email protected]>
We got reports of following warning in inet_sock_destruct()
WARN_ON(sk_forward_alloc_get(sk));
Whenever we add a non zero-copy fragment to a pure zerocopy skb, we have to anticipate that whole skb->truesize will be uncharged when skb is finally freed.
skb->data_len is the payload length. But the memory truesize estimated by __zerocopy_sg_from_iter() is page aligned.
--- net/ipv4/tcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +5 -2
@@ -1322,10 +1322,13 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)/* skb changing from pure zc to mixed, must charge zc */ if (unlikely (skb_zcopy_pure (skb))) { -if (!sk_wmem_schedule (sk, skb->data_len)) +u32 extra = skb->truesize - +SKB_TRUESIZE (skb_end_offset (skb)); + +if (!sk_wmem_schedule (sk, extra)) goto wait_for_space; -sk_mem_charge (sk, skb->data_len); +sk_mem_charge (sk, extra);skb_shinfo (skb)->flags &= ~SKBFL_PURE_ZEROCOPY ; }
Signature · 1 line
2.35.0.rc2.247.g8bbb082509-goog
Quoted 14 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
We got reports of following warning in
inet_sock_destruct()WARN_ON(sk_forward_alloc_get(sk));Whenever we add a non zero-copy fragment to a pure zerocopy skb, we have to anticipate that whole
skb->truesizewill be uncharged when skb is finally freed.
skb->data_lenis the payload length. But the memory truesize estimated by__zerocopy_sg_from_iter()is page aligned.
Quoted 6 lines
Fixes 9b65b17db723 ("net: avoid double accounting for pure zerocopy skbs")Signed-off-by Eric Dumazet <[email protected]>Cc Talal Ahmad <[email protected]>Cc Arjun Roy <[email protected]>Cc Soheil Hassas Yeganeh <[email protected]>Cc Willem de Bruijn <[email protected]>
Nice catch! and thank you for the fix!
Quoted 27 lines
--- net/ipv4/tcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)net/ipv4/tcp.c +5
-3@@ -1322,10 +1322,13 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)/* skb changing from pure zc to mixed, must charge zc */ if (unlikely (skb_zcopy_pure (skb))) { -if (!sk_wmem_schedule (sk, skb->data_len)) +u32 extra = skb->truesize - +SKB_TRUESIZE (skb_end_offset (skb)); + +if (!sk_wmem_schedule (sk, extra)) goto wait_for_space; -sk_mem_charge (sk, skb->data_len); +sk_mem_charge (sk, extra);skb_shinfo (skb)->flags &= ~SKBFL_PURE_ZEROCOPY ; } --2.35.0.rc2.247.g8bbb082509-goog
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 31 Jan 2022 22:52:54 -0800 you wrote:
From: Eric Dumazet <[email protected]>
We got reports of following warning in
inet_sock_destruct()WARN_ON(sk_forward_alloc_get(sk));Whenever we add a non zero-copy fragment to a pure zerocopy skb, we have to anticipate that whole
skb->truesizewill be uncharged when skb is finally freed.[...]
Here is the summary with links:
- [net] tcp: fix mem under-charging with zerocopy sendmsg()
https://git.kernel.org/netdev/net/c/479f5547239d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html