From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <edumazet@google.com>
Cc: <davem@davemloft.net>, <eric.dumazet@gmail.com>,
<horms@kernel.org>, <kuba@kernel.org>, <kuniyu@amazon.com>,
<ncardwell@google.com>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>
Subject: Re: [PATCH net-next] tcp: avoid atomic operations on sk->sk_rmem_alloc
Date: Mon, 24 Mar 2025 15:32:15 -0700 [thread overview]
Message-ID: <20250324223243.76632-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20250320121604.3342831-1-edumazet@google.com>
From: Eric Dumazet <edumazet@google.com>
Date: Thu, 20 Mar 2025 12:16:04 +0000
> TCP uses generic skb_set_owner_r() and sock_rfree()
> for received packets, with socket lock being owned.
>
> Switch to private versions, avoiding two atomic operations
> per packet.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
> include/net/tcp.h | 15 +++++++++++++++
> net/ipv4/tcp.c | 18 ++++++++++++++++--
> net/ipv4/tcp_fastopen.c | 2 +-
> net/ipv4/tcp_input.c | 6 +++---
> 4 files changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index d08fbf90495de69b157d3c87c50e82d781a365df..dd6d63a6f42b99774e9461b69d3e7932cf629082 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -779,6 +779,7 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize)
>
> /* tcp.c */
> void tcp_get_info(struct sock *, struct tcp_info *);
> +void tcp_sock_rfree(struct sk_buff *skb);
>
> /* Read 'sendfile()'-style from a TCP socket */
> int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
> @@ -2898,4 +2899,18 @@ enum skb_drop_reason tcp_inbound_hash(struct sock *sk,
> const void *saddr, const void *daddr,
> int family, int dif, int sdif);
>
> +/* version of skb_set_owner_r() avoiding one atomic_add() */
> +static inline void tcp_skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
> +{
> + skb_orphan(skb);
> + skb->sk = sk;
> + skb->destructor = tcp_sock_rfree;
> +
> + sock_owned_by_me(sk);
> + atomic_set(&sk->sk_rmem_alloc,
> + atomic_read(&sk->sk_rmem_alloc) + skb->truesize);
It's nice to learn that atomic_set() and _read() are just __WRITE_ONCE()
and __READ_ONCE() and have no LOCK_PREFIX :)
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Thanks!
next prev parent reply other threads:[~2025-03-24 22:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 12:16 [PATCH net-next] tcp: avoid atomic operations on sk->sk_rmem_alloc Eric Dumazet
2025-03-20 14:43 ` Neal Cardwell
2025-03-24 22:32 ` Kuniyuki Iwashima [this message]
2025-03-25 15:00 ` patchwork-bot+netdevbpf
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=20250324223243.76632-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).