tcp: properly reset skb->truesize for tx recycling
Subsystems (3)
PATCH 1/1 tcp: properly reset skb->truesize for tx recycling
tcp sendmsg() and sendpage() normally advance skb->data_len and skb->truesize by the payload added to an skb.
But sendmsg(fd, ..., MSG_ZEROCOPY) has to account for whole pages, even if a single byte of payload is used in the page.
This means that we can not assume skb->truesize can be adjusted by skb->data_len. We must instead overwrite its value.
Otherwise skb->truesize is too big and can hit socket sndbuf limit, especially if the skb is recycled multiple times :/
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -868,7 +868,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,if (likely (!size)) { skb = sk->sk_tx_skb_cache;if (skb && !skb_cloned (skb)) { - skb->truesize -= skb->data_len; + skb->truesize =SKB_TRUESIZE (skb_end_offset (skb)); sk->sk_tx_skb_cache =NULL ;pskb_trim (skb,0 );INIT_LIST_HEAD (&skb->tcp_tsorted_anchor);
Signature · 1 line
2.21.0.593.g511ec345e18-goog
Quoted 10 lines · Eric Dumazet
tcp
sendmsg()andsendpage()normally advanceskb->data_lenandskb->truesizeby the payload added to an skb.But
sendmsg(fd, ..., MSG_ZEROCOPY)has to account for whole pages, even if a single byte of payload is used in the page.This means that we can not assume
skb->truesizecan be adjusted byskb->data_len. We must instead overwrite its value.
Quoted 7 lines
Otherwise
skb->truesizeis too big and can hit socket sndbuf limit, especially if the skb is recycled multiple times :/Fixes 472c2e07eef0 ("tcp: add one skb cache for tx")Signed-off-by Eric Dumazet <[email protected]>Cc Soheil Hassas Yeganeh <[email protected]>Cc Willem de Bruijn <[email protected]>
Nice catch! Thank you for the fix.
Quoted 20 lines
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/tcp.c +1
-2@@ -868,7 +868,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,if (likely (!size)) { skb = sk->sk_tx_skb_cache;if (skb && !skb_cloned (skb)) { - skb->truesize -= skb->data_len; + skb->truesize =SKB_TRUESIZE (skb_end_offset (skb)); sk->sk_tx_skb_cache =NULL ;pskb_trim (skb,0 );INIT_LIST_HEAD (&skb->tcp_tsorted_anchor); --2.21.0.593.g511ec345e18-goog
From: Eric Dumazet <[email protected]>
Date: Fri, 19 Apr 2019 16:02:03 -0700
Quoted 6 lines
tcp
sendmsg()andsendpage()normally advanceskb->data_lenandskb->truesizeby the payload added to an skb.But
sendmsg(fd, ..., MSG_ZEROCOPY)has to account for whole pages, even if a single byte of payload is used in the page.
Quoted 8 lines
This means that we can not assume
skb->truesizecan be adjusted byskb->data_len. We must instead overwrite its value.Otherwise
skb->truesizeis too big and can hit socket sndbuf limit, especially if the skb is recycled multiple times :/Fixes 472c2e07eef0 ("tcp: add one skb cache for tx")Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks Eric.