Skip to content

Commit

Permalink
tcp: fix zerocopy and notsent_lowat issues
Browse files Browse the repository at this point in the history
My recent patch had at least three problems :

1) TX zerocopy wants notification when skb is acknowledged,
   thus we need to call skb_zcopy_clear() if the skb is
   cached into sk->sk_tx_skb_cache

2) Some applications might expect precise EPOLLOUT
   notifications, so we need to update sk->sk_wmem_queued
   and call sk_mem_uncharge() from sk_wmem_free_skb()
   in all cases. The SOCK_QUEUE_SHRUNK flag must also be set.

3) Reuse of saved skb should have used skb_cloned() instead
  of simply checking if the fast clone has been freed.

Fixes: 472c2e0 ("tcp: add one skb cache for tx")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Mar 27, 2019
1 parent 4d5ec89 commit 4f66154
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
7 changes: 4 additions & 3 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1465,13 +1465,14 @@ static inline void sk_mem_uncharge(struct sock *sk, int size)

static inline void sk_wmem_free_skb(struct sock *sk, struct sk_buff *skb)
{
sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
sk->sk_wmem_queued -= skb->truesize;
sk_mem_uncharge(sk, skb->truesize);
if (!sk->sk_tx_skb_cache) {
skb_zcopy_clear(skb, true);
sk->sk_tx_skb_cache = skb;
return;
}
sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
sk->sk_wmem_queued -= skb->truesize;
sk_mem_uncharge(sk, skb->truesize);
__kfree_skb(skb);
}

Expand Down
13 changes: 3 additions & 10 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,9 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
{
struct sk_buff *skb;

skb = sk->sk_tx_skb_cache;
if (skb && !size) {
const struct sk_buff_fclones *fclones;

fclones = container_of(skb, struct sk_buff_fclones, skb1);
if (refcount_read(&fclones->fclone_ref) == 1) {
sk->sk_wmem_queued -= skb->truesize;
sk_mem_uncharge(sk, skb->truesize);
if (likely(!size)) {
skb = sk->sk_tx_skb_cache;
if (skb && !skb_cloned(skb)) {
skb->truesize -= skb->data_len;
sk->sk_tx_skb_cache = NULL;
pskb_trim(skb, 0);
Expand Down Expand Up @@ -2543,8 +2538,6 @@ void tcp_write_queue_purge(struct sock *sk)
tcp_rtx_queue_purge(sk);
skb = sk->sk_tx_skb_cache;
if (skb) {
sk->sk_wmem_queued -= skb->truesize;
sk_mem_uncharge(sk, skb->truesize);
__kfree_skb(skb);
sk->sk_tx_skb_cache = NULL;
}
Expand Down

0 comments on commit 4f66154

Please sign in to comment.