From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796374571; b=tg/2f2BTE/ii01Gqq2VWO+Pa+IA1UERn/MT4t5khF0w/RSZpWFBz6CRh8lOFbxggnC6Q fUjU4jiOS2xGQqR+t4vr9PZ/wSHFbC9gZHyj9JZwS3ma7XEh82zIiPl7RufY2G2cwxNT1 bYj23h59PDOTFny8jOgX93QcSC3DHm+aKm5O9/9cWlREx+idfNCga7PODHuNw97dV8h5E Lj0IHVkV1ucaK6w+vJs2DMhGcJYzaKrw0x2N/oyE8MnHPLRvBWBwms68OufHDGBr5huXy FiU+ZeN5FqVVZJJgLdPLjG7OAFp/81KqB/9VFq6R1zLAeQaDJ2APN2x0Y6ZU+3GCfKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796374571; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=lf5SQ8c4MVod8xhHpW1Yy9jV0lx3hCBzvHUQzvtSjCQ=; b=K86rui4ozL5f9XjLsIJP3vZ/qGy9Ap0juZzOe2BIIh/P+lwS09AcwdEctFmN21t4LOCV en93pt+jsA26eWy3a7HCsloo9w8+NC+3lzggPNYDPEUTNWkrrBJRFHCM9Fyc7pTnDyEBN 0Pa/7+oPAuxHVxwk9WbHPaBsVOE3VBXdcqoJnGvjaeLoajrlDytTkIaRAV/PTVPLtV57P M18cqVUv6vKwnu7DdKyrEs1hfaOzpnj2SorVI4GzKG6LDzC2t56L5ZXkYsntyplXN5GpR g9ns2TrYHDEoa52NIRIMpi9M3F/3FvLG8yuhsufAc63toLv1Ha0Kx9n6I3h6t0YnWGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DTj9xx2c; arc=none smtp.remote-ip=209.85.210.200 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4613606A685 for ; Fri, 4 Dec 2026 08:56:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4613606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=DTj9xx2c Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8b69d1f2a18so664783b3a.1 for ; Fri, 04 Dec 2026 00:56:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796374570; x=1796979370; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=lf5SQ8c4MVod8xhHpW1Yy9jV0lx3hCBzvHUQzvtSjCQ=; b=DTj9xx2c5myXhVjIecglbBEF6D1xED3uURMn5cBYc21Uc0tDDiQtta2sGz0fb22se8 erndSJIUNTJAxBqVpI2ZLy4ZmZWUTrEvU6CAyw1BkdQkzhOcKH01TiQ3NIGEBLZHi91U AW//wufcrmYIhyLYZEicYk42psYAqIjzVj4I2v+oJlN5oJN34OsZoLw4KYRS//akdw4z VQU0IPx/JIG2EclP2tOjLcChNcAeyYkBRLnLN6pE0UkO/afzVPXJC9tLDL5/mcdOERkV JlgETcd1v+PzHqhfVDQnNAnuSSeQherc8J/7GhXa7scWhShQJq2mKH1/FjiZ4Vt443Pl ZGiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374570; x=1796979370; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lf5SQ8c4MVod8xhHpW1Yy9jV0lx3hCBzvHUQzvtSjCQ=; b=NBMF+SePc8+vm3V4nQ2hi6P3rB/eRjolNzhv0GVPD7h28cfHjjKnMd4z2Nc/R/wNHQ lJQu101ipstRb6Zjktrytp3TJk6yjED1sr7TZUumQq4GGhghWkPyQuaUNwGadc+ivKLd VaEq5wIOw/cg57eMQhgOzJsPGfJrvXRM0Ujo3EACdxm4DHRdD9BdSAm9yO5cHuBJXgUy 2SE9G+zUUfaQbSNZHI4r41TRFbbqe3xx0JMxex6mW8RQnOZq8A2rvvFF57DQVF/753D+ yF4y7fdE7rB7Gs0/O5bdt6rM9GhfUKSM5j5+Hl9cFZM9U5Lg/RkIwzE4US0oCS2D1xUQ DUPQ== X-Forwarded-Encrypted: i=1; AL+hErFkivzDy/763m2vZSOWYvA0O4bCTn4TQoAp48ryCC/8+OODBrNOcG3FJLSNDCPOmDDG5NeW1MM=@vger.kernel.org X-Gm-Message-State: APuU4Z9cto7SIZFMJ0LHaeOsjk1JoHr2OA1Xu4CYITz6FOq31Q7Y4D2O UyoHgiGYjAOaqhYDcEwXmatu+FJ9BPpueEc94dGwZdEO7iP4kxuXVYj0vCI5CvL/Ato8bc+xbDj zhjBjkA== X-Received: from pfbls44.prod.google.com ([2002:a05:6a00:742c:b0:896:c545:14b]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:99d:b0:8c6:37f1:16d1 with SMTP id d2e1a72fcca58-8dcce174fe2mr2976283b3a.46.1796374569595; Fri, 04 Dec 2026 00:56:09 -0800 (PST) Date: Fri, 4 Dec 2026 17:54:33 +0900 In-Reply-To: <20261204085551.1518105-1-kuniyu@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204085551.1518105-1-kuniyu@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204085551.1518105-4-kuniyu@google.com> Subject: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock. From: Kuniyuki Iwashima To: Eric Dumazet , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , Yuchung Cheng , Kuniyuki Iwashima , Kuniyuki Iwashima , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Currently, PLB is only used by DCTCP, but we will generalise it for other CCs. struct tcp_plb_state is 5 bytes and moving it to tcp_sock creates a hole after the struct without __packed. Let's inline consec_cong_rounds and pause_until to tcp_sock. plb_consec_cong_rounds uses 8 bits because compilers had to generate inefficient RMW for consec_cong_rounds:5 to preserve unused:3. Note that dctcp_init() no longer clears plb_pause_until so that an active RTO pause is preserved across handshake SYN RTOs and CC changes. tcp_disconnect() clears both fields. Signed-off-by: Kuniyuki Iwashima --- .../networking/net_cachelines/tcp_sock.rst | 2 + include/linux/tcp.h | 4 ++ include/net/tcp.h | 20 ++-------- net/ipv4/tcp.c | 2 + net/ipv4/tcp_dctcp.c | 18 ++++----- net/ipv4/tcp_plb.c | 40 ++++++++++--------- 6 files changed, 39 insertions(+), 47 deletions(-) diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst index 78f74eb76990..6eb058478665 100644 --- a/Documentation/networking/net_cachelines/tcp_sock.rst +++ b/Documentation/networking/net_cachelines/tcp_sock.rst @@ -158,6 +158,8 @@ u32 bpf_tcp_ops_flags read_mostly read_m u8 bpf_sock_ops_cb_flags u8:1 bpf_chg_cc_inprogress u16 timeout_rehash +u8 plb_consec_cong_rounds +u32 plb_pause_until u32 rcv_ooopack u32 rcv_rtt_last_tsecr struct rcv_rtt_est read_write tcp_rcv_space_adjust,tcp_rcv_established diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 3d6eb6c8681d..3f275ac8e512 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -506,6 +506,10 @@ struct tcp_sock { u16 timeout_rehash; /* Timeout-triggered rehash attempts */ + /* State for PLB (Protective Load Balancing) for a single TCP connection. */ + u8 plb_consec_cong_rounds; /* consecutive congested rounds */ + u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */ + u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */ /* TCP-specific MTU probe information. */ diff --git a/include/net/tcp.h b/include/net/tcp.h index 68a60268d19d..bcff640c16a1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2735,23 +2735,9 @@ extern void tcp_rack_reo_timeout(struct sock *sk); */ #define TCP_PLB_SCALE 8 -/* State for PLB (Protective Load Balancing) for a single TCP connection. */ -struct tcp_plb_state { - u8 consec_cong_rounds:5, /* consecutive congested rounds */ - unused:3; - u32 pause_until; /* jiffies32 when PLB can resume rerouting */ -}; - -static inline void tcp_plb_init(const struct sock *sk, - struct tcp_plb_state *plb) -{ - plb->consec_cong_rounds = 0; - plb->pause_until = 0; -} -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb, - const int cong_ratio); -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb); -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb); +void tcp_plb_update_state(struct sock *sk, const int cong_ratio); +void tcp_plb_check_rehash(struct sock *sk); +void tcp_plb_update_state_upon_rto(struct sock *sk); static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 58767b3b1b9a..002eaca58c46 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3488,6 +3488,8 @@ int tcp_disconnect(struct sock *sk, int flags) tp->tlp_high_seq = 0; tp->last_oow_ack_time = 0; tp->plb_rehash = 0; + tp->plb_consec_cong_rounds = 0; + tp->plb_pause_until = 0; /* There's a bubble in the pipe until at least the first ACK. */ tp->app_limited = ~0U; tp->rate_app_limited = 1; diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c index 5b457f68a581..bc3724d1da90 100644 --- a/net/ipv4/tcp_dctcp.c +++ b/net/ipv4/tcp_dctcp.c @@ -54,7 +54,6 @@ struct dctcp { u32 next_seq; u32 ce_state; u32 loss_cwnd; - struct tcp_plb_state plb; }; static unsigned int dctcp_shift_g __read_mostly = 4; /* g = 1/2^4 */ @@ -88,7 +87,7 @@ static void dctcp_reset(const struct tcp_sock *tp, struct dctcp *ca) __bpf_kfunc static void dctcp_init(struct sock *sk) { - const struct tcp_sock *tp = tcp_sk(sk); + struct tcp_sock *tp = tcp_sk(sk); if (tcp_ecn_mode_any(tp) || (sk->sk_state == TCP_LISTEN || @@ -103,8 +102,7 @@ __bpf_kfunc static void dctcp_init(struct sock *sk) ca->ce_state = 0; dctcp_reset(tp, ca); - tcp_plb_init(sk, &ca->plb); - + tp->plb_consec_cong_rounds = 0; return; } @@ -126,8 +124,8 @@ __bpf_kfunc static u32 dctcp_ssthresh(struct sock *sk) __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags) { - const struct tcp_sock *tp = tcp_sk(sk); struct dctcp *ca = inet_csk_ca(sk); + struct tcp_sock *tp = tcp_sk(sk); /* Expired RTT */ if (!before(tp->snd_una, ca->next_seq)) { @@ -145,8 +143,8 @@ __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags) */ if (delivered_ce > 0) ce_ratio = (delivered_ce << TCP_PLB_SCALE) / delivered; - tcp_plb_update_state(sk, &ca->plb, (int)ce_ratio); - tcp_plb_check_rehash(sk, &ca->plb); + tcp_plb_update_state(sk, (int)ce_ratio); + tcp_plb_check_rehash(sk); } /* alpha = (1 - g) * alpha + g * F */ @@ -200,7 +198,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev) dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state); break; case CA_EVENT_LOSS: - tcp_plb_update_state_upon_rto(sk, &ca->plb); + tcp_plb_update_state_upon_rto(sk); dctcp_react_to_loss(sk); break; default: @@ -211,9 +209,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev) __bpf_kfunc static void dctcp_cwnd_event_tx_start(struct sock *sk) { - struct dctcp *ca = inet_csk_ca(sk); - - tcp_plb_check_rehash(sk, &ca->plb); /* Maybe rehash when inflight is 0 */ + tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */ } static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr, diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c index d101a424c444..26ca53d6fb9d 100644 --- a/net/ipv4/tcp_plb.c +++ b/net/ipv4/tcp_plb.c @@ -23,9 +23,9 @@ #include /* Called once per round-trip to update PLB state for a connection. */ -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb, - const int cong_ratio) +void tcp_plb_update_state(struct sock *sk, const int cong_ratio) { + struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled)) @@ -33,10 +33,10 @@ void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb, if (cong_ratio >= 0) { if (cong_ratio < READ_ONCE(net->ipv4.sysctl_tcp_plb_cong_thresh)) - plb->consec_cong_rounds = 0; - else if (plb->consec_cong_rounds < + tp->plb_consec_cong_rounds = 0; + else if (tp->plb_consec_cong_rounds < READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds)) - plb->consec_cong_rounds++; + tp->plb_consec_cong_rounds++; } } EXPORT_SYMBOL_GPL(tcp_plb_update_state); @@ -44,21 +44,22 @@ EXPORT_SYMBOL_GPL(tcp_plb_update_state); /* Check whether recent congestion has been persistent enough to warrant * a load balancing decision that switches the connection to another path. */ -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb) +void tcp_plb_check_rehash(struct sock *sk) { + bool forced_rehash = false, idle_rehash = false; + struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); u32 max_suspend; - bool forced_rehash = false, idle_rehash = false; if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled)) return; - forced_rehash = plb->consec_cong_rounds >= + forced_rehash = tp->plb_consec_cong_rounds >= READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds); /* If sender goes idle then we check whether to rehash. */ idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) && !tcp_sk(sk)->packets_out && - plb->consec_cong_rounds >= + tp->plb_consec_cong_rounds >= READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds); if (!forced_rehash && !idle_rehash) @@ -70,19 +71,19 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb) * RTO event that constrains PLB rehashing. */ max_suspend = 2 * READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ; - if (plb->pause_until && - (!before(tcp_jiffies32, plb->pause_until) || - before(tcp_jiffies32 + max_suspend, plb->pause_until))) - plb->pause_until = 0; + if (tp->plb_pause_until && + (!before(tcp_jiffies32, tp->plb_pause_until) || + before(tcp_jiffies32 + max_suspend, tp->plb_pause_until))) + tp->plb_pause_until = 0; - if (plb->pause_until) + if (tp->plb_pause_until) return; if (!__sk_rethink_txhash_reset_dst(sk)) return; - plb->consec_cong_rounds = 0; - WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1); + tp->plb_consec_cong_rounds = 0; + WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH); } EXPORT_SYMBOL_GPL(tcp_plb_check_rehash); @@ -91,8 +92,9 @@ EXPORT_SYMBOL_GPL(tcp_plb_check_rehash); * balancing decisions switch traffic to a black-holed path that was * previously avoided with a sk_rethink_txhash() call at RTO time. */ -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb) +void tcp_plb_update_state_upon_rto(struct sock *sk) { + struct tcp_sock *tp = tcp_sk(sk); struct net *net = sock_net(sk); u32 pause; @@ -102,13 +104,13 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb) pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ; if (pause) { pause += get_random_u32_below(pause); - plb->pause_until = tcp_jiffies32 + pause; + tp->plb_pause_until = tcp_jiffies32 + pause; } /* Reset PLB state upon RTO, since an RTO causes a sk_rethink_txhash() call * that may switch this connection to a path with completely different * congestion characteristics. */ - plb->consec_cong_rounds = 0; + tp->plb_consec_cong_rounds = 0; } EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto); -- 2.56.1.915.g69d5ec7298-goog