All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: netdev <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Soheil Hassas Yeganeh <soheil@google.com>,
	Neal Cardwell <ncardwell@google.com>,
	Arjun Roy <arjunroy@google.com>
Subject: [PATCH net-next 16/20] tcp: avoid indirect calls to sock_rfree
Date: Mon, 15 Nov 2021 11:02:45 -0800	[thread overview]
Message-ID: <20211115190249.3936899-17-eric.dumazet@gmail.com> (raw)
In-Reply-To: <20211115190249.3936899-1-eric.dumazet@gmail.com>

From: Eric Dumazet <edumazet@google.com>

TCP uses sk_eat_skb() when skbs can be removed from receive queue.
However, the call so skb_orphan() from __kfree_skb() incurs
an indirect call so sock_rfee(), which is more expensive than
a direct call, especially for CONFIG_RETPOLINE=y.

Add tcp_eat_recv_skb() function to make the call before
__kfree_skb().

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/tcp.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 9175e0d729f5e65b5fa39acadc5bf9de715854ad..4e7011672aa9a04370b7a03b972fe19cd48ea232 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1580,6 +1580,16 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)
 		tcp_send_ack(sk);
 }
 
+static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
+{
+	if (likely(skb->destructor == sock_rfree)) {
+		sock_rfree(skb);
+		skb->destructor = NULL;
+		skb->sk = NULL;
+	}
+	sk_eat_skb(sk, skb);
+}
+
 static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
 {
 	struct sk_buff *skb;
@@ -1599,7 +1609,7 @@ static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
 		 * splitted a fat GRO packet, while we released socket lock
 		 * in skb_splice_bits()
 		 */
-		sk_eat_skb(sk, skb);
+		tcp_eat_recv_skb(sk, skb);
 	}
 	return NULL;
 }
@@ -1665,11 +1675,11 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
 				continue;
 		}
 		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
-			sk_eat_skb(sk, skb);
+			tcp_eat_recv_skb(sk, skb);
 			++seq;
 			break;
 		}
-		sk_eat_skb(sk, skb);
+		tcp_eat_recv_skb(sk, skb);
 		if (!desc->count)
 			break;
 		WRITE_ONCE(tp->copied_seq, seq);
@@ -2481,14 +2491,14 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,
 		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			goto found_fin_ok;
 		if (!(flags & MSG_PEEK))
-			sk_eat_skb(sk, skb);
+			tcp_eat_recv_skb(sk, skb);
 		continue;
 
 found_fin_ok:
 		/* Process the FIN. */
 		WRITE_ONCE(*seq, *seq + 1);
 		if (!(flags & MSG_PEEK))
-			sk_eat_skb(sk, skb);
+			tcp_eat_recv_skb(sk, skb);
 		break;
 	} while (len > 0);
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


  parent reply	other threads:[~2021-11-16  0:28 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 19:02 [PATCH net-next 00/20] tcp: optimizations for linux-5.17 Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 01/20] tcp: minor optimization in tcp_add_backlog() Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 02/20] tcp: remove dead code in __tcp_v6_send_check() Eric Dumazet
2021-11-16  2:48   ` David Ahern
2021-11-16  2:57     ` Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 03/20] tcp: small optimization in tcp_v6_send_check() Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 04/20] net: use sk_is_tcp() in more places Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 05/20] net: remove sk_route_forced_caps Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 06/20] net: remove sk_route_nocaps Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 07/20] ipv6: shrink struct ipcm6_cookie Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 08/20] net: shrink struct sock by 8 bytes Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 09/20] net: forward_alloc_get depends on CONFIG_MPTCP Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 10/20] net: cache align tcp_memory_allocated, tcp_sockets_allocated Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 11/20] tcp: small optimization in tcp recvmsg() Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 12/20] tcp: add RETPOLINE mitigation to sk_backlog_rcv Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 13/20] tcp: annotate data-races on tp->segs_in and tp->data_segs_in Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 14/20] tcp: annotate races around tp->urg_data Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 15/20] tcp: tp->urg_data is unlikely to be set Eric Dumazet
2021-11-15 19:02 ` Eric Dumazet [this message]
2021-11-15 19:16   ` [PATCH net-next 16/20] tcp: avoid indirect calls to sock_rfree Arjun Roy
2021-11-15 19:02 ` [PATCH net-next 17/20] tcp: defer skb freeing after socket lock is released Eric Dumazet
2021-11-16 14:27   ` Jakub Kicinski
2021-11-16 15:05     ` Eric Dumazet
2021-11-16 15:20       ` Jakub Kicinski
2021-11-16 15:22       ` Eric Dumazet
2021-11-16 15:27         ` Jakub Kicinski
2021-11-16 16:46           ` Eric Dumazet
2021-11-16 18:18             ` Jakub Kicinski
2021-11-16 20:45             ` David Ahern
2021-11-16 21:35               ` Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 18/20] tcp: check local var (timeo) before socket fields in one test Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 19/20] tcp: do not call tcp_cleanup_rbuf() if we have a backlog Eric Dumazet
2021-11-15 19:02 ` [PATCH net-next 20/20] net: move early demux fields close to sk_refcnt Eric Dumazet
2021-11-15 20:37 ` [PATCH net-next 00/20] tcp: optimizations for linux-5.17 Soheil Hassas Yeganeh
2021-11-15 21:40   ` Paolo Abeni
2021-11-15 21:47     ` Eric Dumazet
2021-11-16  2:06       ` Eric Dumazet
2021-11-16  4:01         ` Arjun Roy
2021-11-16 13:32         ` David Miller
2021-11-16 15:06           ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211115190249.3936899-17-eric.dumazet@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=arjunroy@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=soheil@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.