From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380458; b=Pz6Pe81Okhv9f3jLbIKDx+EuibmtFbRlMUPoROnxyJjWzmFb0h/ulRQ1vzRLmKNE5/n7 NncqHKnskXfPuP6T7YuJk1soG8OrjbBtotun3BNheUGdyhJXYeg5QdVB1tBO4JoEHJ88I qzPADVrJ8NW3xnvlW49S3Q5vAz1hawK3KEKvllmvVwahTuyDbmo9GATbfJ1XVguiqdgyd k+15SGxfn0Xu1ad+MWyo85R1rC47JjKmYpFWUuzGJ1FslfMBE5278kCXs3ZRCAOvLudW1 cfSyty3T32ET3SO1ACVFnKz7670OpsBIN/8a9kx9/GDzYsSXDbrMtlfkmXmRF6FQF8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380458; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=WMCtKZZCxgXjERJ3OIScxi2bJ0rfwvV6qrAcJTJP1xY=; b=Bvwy6a7rQJpzh+aRvLh4HRgZJ8ij+yMwIZIDaMce0uQbZ4alvw8h0GshICILts1SCrqS A1vP+DvqKXxR82AFAT5n4wsESVJr/y6EzTQi26a04qkTiDjfQBZ3nUMl3bBuHjZ0JQlPa t6NQ+uYa2jOBahsDrwcT4KUB64HJiGiFHZjVu1qLwLRp0kMJkFptp0LtBb8XZyQfkEvA2 jgvSVRX8tKHEAJgVOuOBM8R58kKcTugno+FkANmTgZPLSibyEqWPHbWPJNy0sA9iMRUeH w9ukKHGnchVGXSNKDUa6uDEx9tNsr9bEMpJdx3/wTvlRXm/KduBG+pdtKWl72dTxIyg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R5WMeGkL; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 94C77606A680 for ; Fri, 4 Dec 2026 10:34:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 94C77606A680 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=R5WMeGkL Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso6114935e9.3 for ; Fri, 04 Dec 2026 02:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796380455; x=1796985255; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=WMCtKZZCxgXjERJ3OIScxi2bJ0rfwvV6qrAcJTJP1xY=; b=R5WMeGkL2vOpmFJOTYj/uQX9hH4gJA6WcJ5y7n9c3zZpgjbXcI6Zp9J8pNrCYWzDAb pSO5wCTUJENS3705UVsn4/dz1ib6mQ1GRkHDLrx1n4Zko8iLLRdOwQMrSanmq9vapJ3f cfgqFW+67Y0PZl5WF0HjFgYiACtp+JT8D5bRXTUCUqqr/Cx/rro0Sdo3Q1UYxH0z+8r0 YScQy2vrj7KsbEJ1blSlXVVuLfjQtGCmgTc2SNxFRA5GMnm9rdaC/uDEIgK4WILmV/4Z tzldcGVRlarSnLoowWi/GbNIq7rrBkrWTMQxE75JZMojXSvQsmU8N8GkEnQspYfQ1GiG tkcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796380455; x=1796985255; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WMCtKZZCxgXjERJ3OIScxi2bJ0rfwvV6qrAcJTJP1xY=; b=EVAb+uKeR6kxw6nbpssrmEChlZ4h/sxr4H9F0Ic7sxK20cXnuLMZ9mpua0gAwo126p SLMZN2QM/pjIrpH1oGRA1xCFLBDwJWKuO1IuyUPH7qkleh2CU8P1iYyaXRkGJAElb/S1 3R40wN7ciDfGtPFyuejMkFgOMu8o/U74xNGDA/u0VY8sefs2sDcgcvQjqfnfLoZPPu2I vEH8XAXLclfVP25LevRz08teAQC1R1BtFGzzU6cPXXUB/8Ph4RnXznt/fzIVA3ulH6lf mZpPMPkKdkR3zCu87ZlPH5Uk4vLNJYkuMJqaZyQmlGEIHQUHYbB7ncHja6qVcICqrw/q d7nQ== X-Forwarded-Encrypted: i=1; AL+hErGLhq0OMneFudL/033zKkQzT/IZonx+cbZEAYxV/AAVXS7QESJKhns8BKdhULn5LcCJqEbn4rk=@vger.kernel.org X-Gm-Message-State: APuU4Z9KuL76FXf6TSR0XbtUQ+j20xvIpnHx1mlo5fY/ty1Gz3rMxw+v oN5tzoQLPScVxlQiUWX3Uo/oOlCUNDy/9y+ZW2ZFPjx6k0TSD/7u3bPw X-Gm-Gg: AZFdTZckx0pkDo7UgqsWCP4zrSS7BWf7QlaDP0+l9dqdc751USBtY8Z2vcAkj76IhG7 PQPkAE7loMgGAcF40oewN/eXSePaP+fVYjyY7qWkLMEdVNGRViK8/QNOEsZS/PVJ8ZDUhoUZvoE h9iHX9V87+Ljlxm5QsVcOknyDSU3wdSEtxrhovpZxkF2FLlsQfTk6MdEgN9SBBF8ReMgpODCyF1 4Oy28h5WxDAplgKd2ztfBvQNIpOZWmuzZJsJ3NJolpTB1/M5njyJmrdVCPTPDXxnP5NUfuT9N0A BmZsYqDDNAz2RGorm/J3BiIS6FIhTfIYGD3zs5T9cd8d8xnGicihquM/bmwXuI/4Iw1ReV+lPN7 bwB8M1MaFrZ6hYgYC3wbCeO2lZXsjS64iHVtbwdVl4ikT/CHVW6WZAWIE+jKYAc4yydmudC5/bx DhKYrrQUFHAyhbizx8hYmHMGPWW60j3AhRd9OyXr62lfFA2DyW9cbmpbRgiyi2ryolwo1bb/gIK +TETvp7MVCyTdJ2r6zRuq9Yacvcr9dAXLjRBm+8uCtbv+5sk1/eMOGyj8s4VxEoiWcJZkTF+4Pg 509a20HYoNUyGtlnGCCB+6jxZzvUAe+5aAHaOMeyU9cER3IMBxGMAKVVq+WzHcJbL/H8PCn1uAV ceffZ09/d4g== X-Received: by 2002:a05:600c:1384:b0:4a3:5d64:df91 with SMTP id 5b1f17b1804b1-4bbeb8b930emr30607175e9.18.1796380454931; Fri, 04 Dec 2026 02:34:14 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1738cfb63sm4803082f8f.37.2026.12.04.02.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 02:34:14 -0800 (PST) Date: Fri, 4 Dec 2026 10:34:13 +0000 From: David Laight To: Kuniyuki Iwashima Cc: Eric Dumazet , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Yuchung Cheng , Kuniyuki Iwashima , netdev@vger.kernel.org Subject: Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock. Message-ID: <20261204103413.42cea795@pumpkin> In-Reply-To: <20261204085551.1518105-4-kuniyu@google.com> References: <20261204085551.1518105-1-kuniyu@google.com> <20261204085551.1518105-4-kuniyu@google.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 4 Dec 2026 17:54:33 +0900 Kuniyuki Iwashima wrote: > 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 */ > + There are probably better places to put those fields to avoid the 3 byte pad. Possibly reorder the fields so that plb_consec_cong_rounds can share a byte with bpf_chg_cc_inprogress? David > 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);