Skip to content

tcp: avoid struct socket cache line miss in tcp_check_space()

Eric Dumazet netdev stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest9 patches 1 replyIn review
  2. v19 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- Order set_bit(SOCK_NOSPACE) before tp->tcp_nospace = 1 in sk_set_nospace() and tp->tcp_nospace = 0 before
clear_bit(SOCK_NOSPACE) in sk_clear_nospace() so a concurrent
lockless tcp_poll() cannot leave SOCK_NOSPACE set with
tp->tcp_nospace cleared (Sashiko)
- Move tp->tcp_nospace to the 3-byte hole after tp->chrono_type so no
field in struct tcp_sock shifts after the AccECN bitfield additions (Sashiko)
- Clarify comment and Patch 2 changelog wording (Sashiko)
- Link to v1: https://lore.kernel.org/netdev/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9dlm: fix send buffer backpressure handlingfs/dlm/lowcomms.c+2 -40 replies
2/9net: add sk_set_nospace() and sk_clear_nospace()include/net/sock.h net/core/sock.c net/core/stream.c +7 more+52 -170 replies
3/9sunrpc: use sk_set_nospace() and sk_clear_nospace()net/sunrpc/svcsock.c net/sunrpc/xprtsock.c+4 -40 replies
4/9rds: use sk_set_nospace()net/rds/tcp_send.c+2 -30 replies
5/9dlm: use sk_set_nospace() and sk_clear_nospace()fs/dlm/lowcomms.c+2 -20 replies
6/9drbd: use sk_set_nospace()drivers/block/drbd/drbd_worker.c+1 -20 replies
7/9nvme-tcp: use sk_clear_nospace()drivers/nvme/host/tcp.c drivers/nvme/target/tcp.c+2 -20 replies
8/9libceph: use sk_clear_nospace()net/ceph/messenger.c+1 -10 replies
9/9tcp: add tp->tcp_nospaceDocumentation/networking/net_cachelines/tcp_sock.rst include/linux/tcp.h include/net/tcp.h +4 more+59 -60 replies

Reviews trailers per patch

8 of 9 patches have a Reviewed-by or Acked-by.

PatchAlexander AringKuniyuki Iwashima
1/9A-b R-b
2/9R-b
3/9R-b
4/9R-b
5/9R-b
6/9R-b
7/9R-b
8/9R-b
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 net-next 0/9] tcp: avoid struct socket cache line miss in tcp_check_space()

tcp_check_space() is called on every incoming ACK and every transmitted packet, and tests SOCK_NOSPACE in sk->sk_socket->flags. Because struct socket lives in its own cache line and the TCP fast paths do not touch it for anything else, that test pulls in an extra cache line that is cold when the working set of active sockets is large.

This series mirrors SOCK_NOSPACE into a new u8 field, tp->tcp_nospace, placed right after tp->chrono_type in the tcp_sock_write_tx cache line group (fitting in an existing 3-byte hole before chrono_start, so no other field moves and sizeof(struct tcp_sock) is unchanged). Both the transmit and ACK fast paths already touch that cache line, making the fast-path test in tcp_check_space() free of extra cache misses while keeping __tcp_check_space() authoritative on SOCK_NOSPACE.

To maintain the invariant (SOCK_NOSPACE set => tp->tcp_nospace set) from a single choke point:

- Patch 1 fixes a long-standing bug in dlm where SOCKWQ_ASYNC_NOSPACE was tested and cleared on con->sock->flags instead of SOCK_NOSPACE.
- Patch 2 introduces sk_set_nospace() and sk_clear_nospace() and converts the core networking callers.
- Patches 3-8 convert the remaining in-kernel callers (sunrpc, rds, dlm, drbd, nvme-tcp, libceph) so that no open-coded set_bit() or clear_bit() of SOCK_NOSPACE remains in the tree.
- Patch 9 adds tp->tcp_nospace, wires it into sk_set_nospace() and sk_clear_nospace(), and switches tcp_check_space() to test it.

v2:
- Order set_bit(SOCK_NOSPACE) before tp->tcp_nospace = 1 in sk_set_nospace() and tp->tcp_nospace = 0 before
clear_bit(SOCK_NOSPACE) in sk_clear_nospace() so a concurrent
lockless tcp_poll() cannot leave SOCK_NOSPACE set with
tp->tcp_nospace cleared (Sashiko)
- Move tp->tcp_nospace to the 3-byte hole after tp->chrono_type so no
field in struct tcp_sock shifts after the AccECN bitfield additions (Sashiko)
- Clarify comment and Patch 2 changelog wording (Sashiko)
- Link to v1: https://lore.kernel.org/netdev/[email protected]/

Eric Dumazet (9):
dlm: fix send buffer backpressure handling
net: add sk_set_nospace() and sk_clear_nospace()
sunrpc: use sk_set_nospace() and sk_clear_nospace()
rds: use sk_set_nospace()
dlm: use sk_set_nospace() and sk_clear_nospace()
drbd: use sk_set_nospace()
nvme-tcp: use sk_clear_nospace()
libceph: use sk_clear_nospace()
tcp: add tp->tcp_nospace

 .../networking/net_cachelines/tcp_sock.rst    |  1 +
 drivers/block/drbd/drbd_worker.c              |  3 +-
 drivers/nvme/host/tcp.c                       |  2 +-
 drivers/nvme/target/tcp.c                     |  2 +-
 fs/dlm/lowcomms.c                             | 10 ++--
 include/linux/tcp.h                           |  3 ++
 include/net/sock.h                            |  2 +
 include/net/tcp.h                             | 30 +++++++++++-
 net/ceph/messenger.c                          |  2 +-
 net/core/sock.c                               | 46 ++++++++++++++++++-
 net/core/stream.c                             |  6 +--
 net/ipv4/tcp.c                                |  5 +-
 net/ipv4/tcp_bpf.c                            |  2 +-
 net/ipv4/tcp_input.c                          |  8 +++-
 net/kcm/kcmsock.c                             |  4 +-
 net/mptcp/protocol.c                          |  4 +-
 net/mptcp/subflow.c                           |  5 ++
 net/rds/tcp_send.c                            |  5 +-
 net/smc/af_smc.c                              |  2 +-
 net/smc/smc_tx.c                              |  6 +--
 net/sunrpc/svcsock.c                          |  4 +-
 net/sunrpc/xprtsock.c                         |  4 +-
 net/tls/tls_sw.c                              |  2 +-
 23 files changed, 121 insertions(+), 37 deletions(-)
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog