netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	netdev@vger.kernel.org,  eric.dumazet@gmail.com,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 0/4] net: introduce net_aligned_data
Date: Fri, 27 Jun 2025 20:05:47 +0000	[thread overview]
Message-ID: <20250627200551.348096-1-edumazet@google.com> (raw)

____cacheline_aligned_in_smp on small fields like
tcp_memory_allocated and udp_memory_allocated is not good enough.

It makes sure to put these fields at the start of a cache line,
but does not prevent the linker from using the cache line for other
fields, with potential performance impact.

nm -v vmlinux|egrep -5 "tcp_memory_allocated|udp_memory_allocated"

...
ffffffff849dd480 B tcp_memory_allocated
ffffffff849dd488 B google_shared_statistics
ffffffff849dd4a0 b tcp_orphan_cache
ffffffff849dd4a4 b tcp_enable_tx_delay.__tcp_tx_delay_enabled
...
ffffffff849dddc0 B udp_memory_allocated
ffffffff849dddc8 B udp_encap_needed_key
ffffffff849dddd8 B udpv6_encap_needed_key
ffffffff849dddf0 b inetsw_lock

One solution is to move these sensitive fields to a structure,
so that the compiler is forced to add empty holes between each member.

nm -v vmlinux|egrep -2 "tcp_memory_allocated|udp_memory_allocated|net_aligned_data"

ffffffff885af970 b mem_id_init
ffffffff885af980 b __key.0
ffffffff885af9c0 B net_aligned_data
ffffffff885afa80 B page_pool_mem_providers
ffffffff885afa90 b __key.2


Eric Dumazet (4):
  net: add struct net_aligned_data
  net: move net_cookie into net_aligned_data
  tcp: move tcp_memory_allocated into net_aligned_data
  udp: move udp_memory_allocated into net_aligned_data

 include/net/aligned_data.h | 21 +++++++++++++++++++++
 include/net/tcp.h          |  1 -
 include/net/udp.h          |  1 -
 net/core/hotdata.c         |  5 +++++
 net/core/net_namespace.c   |  8 ++------
 net/ipv4/tcp.c             |  2 --
 net/ipv4/tcp_ipv4.c        |  3 ++-
 net/ipv4/udp.c             |  4 +---
 net/ipv4/udp_impl.h        |  1 +
 net/ipv4/udplite.c         |  2 +-
 net/ipv6/tcp_ipv6.c        |  3 ++-
 net/ipv6/udp.c             |  2 +-
 net/ipv6/udp_impl.h        |  1 +
 net/ipv6/udplite.c         |  2 +-
 net/mptcp/protocol.c       |  3 ++-
 15 files changed, 40 insertions(+), 19 deletions(-)
 create mode 100644 include/net/aligned_data.h

-- 
2.50.0.727.gbf7dc18ff4-goog


             reply	other threads:[~2025-06-27 20:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 20:05 Eric Dumazet [this message]
2025-06-27 20:05 ` [PATCH net-next 1/4] net: add struct net_aligned_data Eric Dumazet
2025-06-28 14:48   ` Willem de Bruijn
2025-06-27 20:05 ` [PATCH net-next 2/4] net: move net_cookie into net_aligned_data Eric Dumazet
2025-06-28 14:49   ` Willem de Bruijn
2025-06-28 20:19   ` kernel test robot
2025-06-27 20:05 ` [PATCH net-next 3/4] tcp: move tcp_memory_allocated " Eric Dumazet
2025-06-28 14:49   ` Willem de Bruijn
2025-06-28 22:14   ` kernel test robot
2025-06-27 20:05 ` [PATCH net-next 4/4] udp: move udp_memory_allocated " Eric Dumazet
2025-06-28 14:49   ` Willem de Bruijn

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=20250627200551.348096-1-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@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 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).