From: David Laight <david.laight.linux@gmail.com>
To: Kuniyuki Iwashima <kuniyu@google.com>
Cc: Eric Dumazet <edumazet@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Yuchung Cheng <ycheng@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
Date: Fri, 4 Dec 2026 10:34:13 +0000 [thread overview]
Message-ID: <20261204103413.42cea795@pumpkin> (raw)
In-Reply-To: <20261204085551.1518105-4-kuniyu@google.com>
On Fri, 4 Dec 2026 17:54:33 +0900
Kuniyuki Iwashima <kuniyu@google.com> 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 <kuniyu@google.com>
> ---
> .../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 <net/tcp.h>
>
> /* 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);
next prev parent reply other threads:[~2026-12-04 10:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
2026-12-04 10:34 ` David Laight [this message]
2026-12-04 8:54 ` [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh Kuniyuki Iwashima
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
2026-12-04 9:29 ` Kuniyuki Iwashima
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=20261204103413.42cea795@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@google.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
--cc=ycheng@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