* [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
@ 2026-12-04 8:54 ` 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
` (9 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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, Mubashir Adnan Qureshi
LINUX_MIB_TCPDUPLICATEDATAREHASH and LINUX_MIB_TCPTIMEOUTREHASH
are incremented only when a flow is actually rehashed and
__sk_rethink_txhash_reset_dst() returns true.
OTOH, even when it returns false, tcp_plb_check_rehash() resets
plb->consec_cong_rounds and increments LINUX_MIB_TCPPLBREHASH
and tp->plb_rehash.
Let's do nothing when __sk_rethink_txhash_reset_dst() returns
false in tcp_plb_check_rehash().
Fixes: 1a91bb7c3ebf ("tcp: add PLB functionality for TCP")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: Mubashir Adnan Qureshi <mubashirq@google.com>
---
net/ipv4/tcp_plb.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index bcc2f0add6af..0cc14cf41f8a 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -78,7 +78,9 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
if (plb->pause_until)
return;
- __sk_rethink_txhash_reset_dst(sk);
+ 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);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto().
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 ` 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
` (8 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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, Jason A. Donenfeld
Even when net.ipv4.tcp_plb_suspend_rto_sec is set to 0,
tcp_plb_update_state_upon_rto() calls get_random_u32_below().
Since the cited commit, when get_random_u32_below() is called with 0,
it falls back to get_random_u32(), which results in [0, UINT_MAX].
Then, plb->pause_until is set to a random value, which is normally
cleared in tcp_plb_check_rehash() while tcp_plb_suspend_rto_sec stays
0, but can pause PLB unintentionally if the sysctl is raised later.
Let's not set pause_until when tcp_plb_suspend_rto_sec is 0.
Fixes: 7f576b2593a9 ("random: add helpers for random numbers with given floor or range")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
---
net/ipv4/tcp_plb.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 0cc14cf41f8a..d101a424c444 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -100,8 +100,10 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
return;
pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
- pause += get_random_u32_below(pause);
- plb->pause_until = tcp_jiffies32 + pause;
+ if (pause) {
+ pause += get_random_u32_below(pause);
+ 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
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
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 ` Kuniyuki Iwashima
2026-12-04 10:34 ` David Laight
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
` (7 subsequent siblings)
10 siblings, 1 reply; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
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 */
+
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);
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
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
0 siblings, 0 replies; 14+ messages in thread
From: David Laight @ 2026-12-04 10:34 UTC (permalink / raw)
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
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);
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (2 preceding siblings ...)
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 8:54 ` 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
` (6 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
dctcp_cwnd_event() calls tcp_plb_update_state_upon_rto() upon
CA_EVENT_LOSS in tcp_enter_loss() to reset plb_consec_cong_rounds
and pause PLB after an RTO triggers a path rehash.
However, tcp_enter_loss() does not always correspond to an RTO
rehash:
1. tcp_enter_loss() is called from 3 paths but the first two
do not rehash the flow:
- tcp_fastopen_synack_timer()
- tcp_retransmit_timer() when !tp->snd_wnd
- tcp_retransmit_timer() when tcp_write_timeout() returns 0
2. Even on the last path, tcp_enter_loss() skips CA_EVENT_LOSS
if after(tp->high_seq, tp->snd_una) is true and the socket
is in TCP_CA_CWR (e.g. after receiving ECN CE in DCTCP),
TCP_CA_Recovery, or TCP_CA_Loss with icsk_retransmits > 0.
In the second case, even when tcp_write_timeout() rehashes the
flow, tcp_plb_update_state_upon_rto() is missed.
Then, a subsequent tcp_plb_check_rehash() in dctcp_update_alpha()
or dctcp_cwnd_event_tx_start() can immediately rehash the flow
again, potentially back to the previous bad path.
Let's move tcp_plb_update_state_upon_rto() just after
__sk_rethink_txhash_reset_dst() in tcp_write_timeout().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/ipv4/tcp_dctcp.c | 1 -
net/ipv4/tcp_plb.c | 1 -
net/ipv4/tcp_timer.c | 1 +
3 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index bc3724d1da90..bbfff24ed5f0 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -198,7 +198,6 @@ __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);
dctcp_react_to_loss(sk);
break;
default:
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 26ca53d6fb9d..c21fcb7945c0 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -113,4 +113,3 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
*/
tp->plb_consec_cong_rounds = 0;
}
-EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 814fadb30749..a3210cda2515 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -297,6 +297,7 @@ static int tcp_write_timeout(struct sock *sk)
}
if (__sk_rethink_txhash_reset_dst(sk)) {
+ tcp_plb_update_state_upon_rto(sk);
WRITE_ONCE(tp->timeout_rehash, tp->timeout_rehash + 1);
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHASH);
}
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (3 preceding siblings ...)
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 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
` (5 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
The current PLB requires ECN signals.
We will introduce Generic PLB, which does not use ECN.
Let's rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
include/net/tcp.h | 2 +-
net/ipv4/tcp_dctcp.c | 4 ++--
net/ipv4/tcp_plb.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index bcff640c16a1..7e53293ed3c8 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2736,7 +2736,7 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
#define TCP_PLB_SCALE 8
void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
-void tcp_plb_check_rehash(struct sock *sk);
+void tcp_plb_check_rehash_ecn(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_dctcp.c b/net/ipv4/tcp_dctcp.c
index bbfff24ed5f0..37653a8765c9 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -144,7 +144,7 @@ __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, (int)ce_ratio);
- tcp_plb_check_rehash(sk);
+ tcp_plb_check_rehash_ecn(sk);
}
/* alpha = (1 - g) * alpha + g * F */
@@ -208,7 +208,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)
{
- tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */
+ tcp_plb_check_rehash_ecn(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 c21fcb7945c0..0006d3b1bf55 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -44,7 +44,7 @@ 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)
+void tcp_plb_check_rehash_ecn(struct sock *sk)
{
bool forced_rehash = false, idle_rehash = false;
struct tcp_sock *tp = tcp_sk(sk);
@@ -86,7 +86,7 @@ void tcp_plb_check_rehash(struct sock *sk)
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);
+EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
/* Upon RTO, disallow load balancing for a while, to avoid having load
* balancing decisions switch traffic to a black-holed path that was
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (4 preceding siblings ...)
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 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default Kuniyuki Iwashima
` (4 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
We will introduces Generic PLB.
It will share some code with tcp_plb_check_rehash_ecn() to
perform rehash, update plb_pause_until, and increment stats.
Let's factorise the common part as tcp_plb_rehash().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/ipv4/tcp_plb.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 0006d3b1bf55..794bddc4dc2d 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -41,30 +41,12 @@ void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
}
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_ecn(struct sock *sk)
+static void tcp_plb_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;
- if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
- return;
-
- 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 &&
- tp->plb_consec_cong_rounds >=
- READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
-
- if (!forced_rehash && !idle_rehash)
- return;
-
/* Note that tcp_jiffies32 can wrap; we detect wraps by checking for
* cases where the max suspension end is before the actual suspension
* end. We clear pause_until to 0 to indicate there is no recent
@@ -86,6 +68,32 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
}
+
+/* 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_ecn(struct sock *sk)
+{
+ bool forced_rehash = false, idle_rehash = false;
+ struct tcp_sock *tp = tcp_sk(sk);
+ struct net *net = sock_net(sk);
+
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
+ return;
+
+ 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 &&
+ tp->plb_consec_cong_rounds >=
+ READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
+
+ if (!forced_rehash && !idle_rehash)
+ return;
+
+ tcp_plb_rehash(sk);
+}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
/* Upon RTO, disallow load balancing for a while, to avoid having load
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (5 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (3 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
tcp_plb_suspend_rto_sec specifies the base duration to suspend
PLB repathing after an RTO triggers a rehash, pausing PLB for a
random duration in [1x, 2x) of this value. Currently, it defaults
to 60, suspending PLB for 60 - 120 seconds.
ECN-PLB normally detects congestion via ECN before an RTO occurs,
so stopping PLB upon RTO rarely becomes an issue. However, even
under ECN-PLB, 60 - 120 seconds is unnecessarily long and lowers
fairness when occasional RTOs happen.
Moreover, Generic PLB introduced by the next patch runs alongside
occasional tail-drop and probe-induced RTOs, where suspending PLB
for 60 - 120 seconds effectively disables it.
On the other hand, setting tcp_plb_suspend_rto_sec to 0 allows
flows rescued off a blackholed link by an RTO to be immediately
rehashed back onto the dead path upon subsequent congestion or
probe losses.
A 5-second base duration (5 - 10 second pause) keeps both ECN-PLB
and Generic PLB responsive without causing immediate re-entry
thrashing onto blackholed links.
Let's lower the default value to 5.
Note that the link-repair-time guidance in ip-sysctl.rst is also
removed, as this setting balances blackhole cooldown against PLB
responsiveness rather than link repair time.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Documentation/networking/ip-sysctl.rst | 5 ++---
net/ipv4/tcp_ipv4.c | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index 671011c74e14..dffcec335a77 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1413,12 +1413,11 @@ tcp_plb_suspend_rto_sec - INTEGER
having PLB repath onto a connectivity "black hole", after an RTO a TCP
connection suspends PLB repathing for a random duration between 1x and
2x of this parameter. Randomness is added to avoid concurrent rehashing
- of multiple TCP connections. This should be set corresponding to the
- amount of time it takes to repair a failed link.
+ of multiple TCP connections.
Possible Values: 0 - 255
- Default: 60
+ Default: 5
tcp_plb_cong_thresh - INTEGER
Fraction of packets marked with congestion over a round (RTT) to
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index f2a5c8f3bf9d..14ba61845f49 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -3528,7 +3528,7 @@ static int __net_init tcp_sk_init(struct net *net)
net->ipv4.sysctl_tcp_plb_enabled = 0; /* Disabled by default */
net->ipv4.sysctl_tcp_plb_idle_rehash_rounds = 3;
net->ipv4.sysctl_tcp_plb_rehash_rounds = 12;
- net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 60;
+ net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
/* Default congestion threshold for PLB to mark a round is 50% */
net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (6 preceding siblings ...)
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 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
` (2 subsequent siblings)
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
Currently, PLB (Protective Load Balancing) relies on ECN signals
and is only hooked into DCTCP. However, ECN is often unavailable
in cloud VM and virtualised network environments, and widely deployed
congestion control algorithms such as CUBIC and BBR cannot benefit
from PLB.
This commit introduces Generic PLB, a congestion-control-agnostic
PLB mechanism triggered by a combination of packet loss and low
delivery rate.
Generic PLB adds one per-netns sysctl knob:
net.ipv4.tcp_plb_loss_rehash_prob (default: 128, range: 0 - 255)
Every 5th Fast Recovery, tcp_plb_check_rehash_loss() computes a
rehash probability in [0, 255] from rate_prob and floor, and
rehashes the flow via tcp_plb_rehash() if a random number in
[0, 254] is smaller than the probability:
prob = max(rate_prob, floor)
if (get_random_u32_below(255) < prob)
tcp_plb_rehash(sk);
1. Rehash probability based on delivery rate regression (rate_prob)
rate_prob is a repath probability calculation that reflects
how much the current delivery rate (cur_rate) has regressed
relative to tp->plb_max_rate, the highest delivery rate recorded
in tcp_rate_gen():
deficit = (plb_max_rate - cur_rate) / plb_max_rate
rate_prob = min(255, 4 * base_prob * deficit^2)
Squaring deficit suppresses noise churn under small jitter
while quickly evacuating severely degraded paths.
To filter burst noise and avoid 64-bit division on the ACK
fast path, tcp_rate_gen() updates tp->plb_max_rate when a
sample exceeds tp->plb_max_rate by more than 1/8, applying
1/8 upward EWMA after the first sample.
2. Rehash probability floor (floor):
rate_prob cannot trigger when a flow initially lands on a bad
path and has not yet observed a healthy rate. Thus, floor is
used to explore alternative paths.
For the first two rehashes (tp->plb_rehash < 2), floor is set
to base_prob >> 1 (25% at default 128). The cumulative
rehash probability across n evaluations is:
1 - (1 - p)^n
With tcp_plb_loss_rehash_prob = 128, a flow rehashes by the
20th Fast Recovery (n = 4) with ~68% probability:
1 - (1 - 0.25)^4 = 0.6836
Once the flow has rehashed twice (tp->plb_rehash >= 2), it
likely already knows a healthy tp->plb_max_rate, where a 25%
floor is too high and causes unnecessary churn. Thus, floor
is lowered to base_prob >> 3 (6.25%) thereafter.
3. Stale-hop peak rate decay (tp->plb_stale_hops):
After repathing, keeping tp->plb_max_rate at a stale high value
can inflate rehashes if all paths share lower bandwidth.
Conversely, decaying tp->plb_max_rate on every single hop erodes
good-path memory during short exploration on asymmetric ECMP.
Therefore, tp->plb_stale_hops counts consecutive rehashes
without recovery within ~15% of the peak (deficit < 38).
Once three consecutive rehashes stay >= ~15% below
tp->plb_max_rate, each subsequent stale rehash decays
tp->plb_max_rate by 1/8 (to 7/8) so the flow adapts to the
new paths.
Below are benchmark results with the script below [0] across a 4-way
IPv6 ECMP router topology (r0..r3, net.ipv6.fib_multipath_hash_policy
= 0) under three failure and weight-mismatch scenarios:
a. Single-link degradation with 3% random packet loss (base RTT 4 ms;
r0..r2: 4 Gbps healthy, r3: 800 Mbps with 3% loss; 20 flows paced
at 440 Mbps = 8.8 Gbps total demand; mean of 3 runs):
Scenario Total(M) Min(M) Jain Flows(r0..r3) Retrans
---------------------------- -------- ------ ------ --------------- -------
20x CUBIC (PLB OFF) 7699.77 16.10 0.8925 5.7/5.3/6.7/2.7 1088
20x CUBIC (Generic-PLB ON) 8578.08 313.25 0.9917 6.3/7.0/6.3/0.3 390
20x BBR (PLB OFF) 8116.67 228.09 0.9704 4.7/6.0/6.3/3.0 18552
20x BBR (Generic-PLB ON) 8643.48 424.69 0.9997 8.0/5.3/6.7/0.0 908
20x DCTCP (PLB OFF) 7160.94 27.71 0.8308 4.7/5.3/6.0/4.0 1951
20x DCTCP (Both PLB ON) 8700.88 415.98 0.9998 6.3/6.7/7.0/0.3 303
10x CUBIC + 10x BBR (OFF) 7333.90 8.02 0.8873 6.0/5.0/5.0/4.0 16615
10x CUBIC + 10x BBR (ON) 8563.66 364.49 0.9980 6.0/8.0/5.7/1.0 2816
10x CUBIC + 10x DCTCP (OFF) 7036.39 24.59 0.8314 5.7/6.3/4.3/3.7 2023
10x CUBIC + 10x DCTCP (ON) 8380.88 172.64 0.9745 5.7/6.7/7.0/0.7 656
Generic PLB evacuates flows from the lossy path r3, recovering
per-flow minimum goodput and reducing retransmissions by 64% - 95%.
b. Spine switch failure / ECMP hash-collapse (base RTT 4 ms; 8 switches
in 4 pairs of 2.8 Gbps; one switch in pair r3 fails so r3 has
1.4 Gbps capacity and half buffer with 0% random loss while still
receiving 1/4 of ECMP hashes; 56 flows paced at 160 Mbps = 8.96 Gbps
demand, 96% of surviving capacity; mean of 3 runs):
Scenario Total(M) Min(M) Jain Flows(r0..r3) Retrans
---------------------------- -------- ------ ------ ------------------- -------
56x CUBIC (PLB OFF) 7894.50 80.31 0.9584 14.0/14.3/12.3/12.3 5148
56x CUBIC (Generic-PLB ON) 8604.32 143.26 0.9994 16.7/15.7/15.7/7.7 4041
56x BBR (PLB OFF) 8576.75 146.80 0.9997 16.0/15.3/16.0/7.3 27681
56x BBR (Generic-PLB ON) 8641.33 149.46 0.9998 15.3/16.3/16.3/7.7 14884
56x DCTCP (PLB OFF) 7982.80 95.07 0.9642 14.7/14.7/15.0/11.7 6083
56x DCTCP (Both PLB ON) 8632.26 144.06 0.9995 15.7/16.0/16.0/8.3 3502
28x CUBIC + 28x BBR (OFF) 8149.27 94.77 0.9811 15.3/16.0/13.7/9.7 8480
28x CUBIC + 28x BBR (ON) 8585.09 140.94 0.9993 16.7/15.0/15.7/7.3 5143
28x CUBIC + 28x DCTCP (OFF) 7826.17 78.05 0.9643 11.7/18.0/14.0/12.3 6329
28x CUBIC + 28x DCTCP (ON) 8623.33 147.09 0.9996 15.7/16.0/15.3/8.7 3857
Generic PLB spreads flows in proportion to path capacity (converging
towards the ideal 16/16/16/8 flow distribution across [2.8G, 2.8G,
2.8G, 1.4G]), recovering minimum flow goodput and cutting
retransmissions by 22% - 46%.
c. Inverted WCMP weight mismatch (2 ms return delay, HTB + bfifo with
TSO/GSO/GRO enabled; 64 flows across r0..r3 with weights
[1, 1, 2, 2] vs capacities [3.2G, 3.2G, 1.6G, 1.6G] for M=4, and
[1, 1, 3, 3] vs [3.6G, 3.6G, 1.2G, 1.2G] for M=9, where
M = (w_b / c_b) / (w_a / c_a) is the worst-to-best ratio of WCMP
weight fraction w_i = weight_i / sum(weight) to capacity fraction
c_i = cap_i / sum(cap); CUBIC unpaced, BBR unpaced for M=4 and
paced at 120 Mbps for M=9; mean of 5 runs):
Scenario Total(M) Min(M) Jain Share(r0..r3 %) Retrans
---------------------------- -------- ------ ------ ------------------- -------
64x CUBIC M=4 (PLB OFF) 9049.36 57.59 0.6479 34.6/33.4/16.3/15.7 30246
64x CUBIC M=4 (Generic-PLB) 9053.84 66.40 0.8984 34.5/33.5/16.3/15.7 29921
64x BBR M=4 (PLB OFF) 9036.99 43.09 0.7037 34.8/33.5/16.2/15.5 1072387
64x BBR M=4 (Generic-PLB) 9046.21 56.38 0.8062 34.7/33.5/16.2/15.5 1106217
64x CUBIC M=9 (PLB OFF) 9054.20 36.43 0.4541 38.7/37.4/12.2/11.8 24724
64x CUBIC M=9 (Generic-PLB) 9053.08 40.46 0.7532 38.7/37.5/12.2/11.7 28021
64x BBR M=9 120M (PLB OFF) 4908.21 26.49 0.8216 25.9/29.5/22.8/21.8 104658
64x BBR M=9 120M (Generic-PLB) 5748.63 31.60 0.8796 33.2/29.5/19.2/18.1 8310
Under extreme M=4 and M=9 weight inversions, Generic PLB migrates
excess flows off the overloaded r2/r3 paths towards the underutilised
r0/r1 paths, improving per-flow Jain's index across both CUBIC and
BBR (0.45 -> 0.75 on unpaced CUBIC M=9) and raising aggregate BBR
goodput by +17.1% while cutting retransmissions by 92.1% on M=9.
Link: https://gist.github.com/q2ven/c04b56477dea4d1a58f5eadc4b07f9e0 #[0]
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Documentation/networking/ip-sysctl.rst | 19 ++++-
.../net_cachelines/netns_ipv4_sysctl.rst | 1 +
.../networking/net_cachelines/tcp_sock.rst | 3 +
include/linux/tcp.h | 5 ++
include/net/netns/ipv4.h | 3 +-
include/net/tcp.h | 1 +
net/core/net_namespace.c | 2 +
net/ipv4/sysctl_net_ipv4.c | 7 ++
net/ipv4/tcp.c | 4 ++
net/ipv4/tcp_input.c | 15 ++++
net/ipv4/tcp_ipv4.c | 1 +
net/ipv4/tcp_plb.c | 69 +++++++++++++++++--
12 files changed, 123 insertions(+), 7 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index dffcec335a77..3046f6725b21 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1360,8 +1360,8 @@ tcp_child_ehash_entries - INTEGER
tcp_plb_enabled - BOOLEAN
If enabled and the underlying congestion control (e.g. DCTCP) supports
- and enables PLB feature, TCP PLB (Protective Load Balancing) is
- enabled. PLB is described in the following paper:
+ ECN-based PLB feature, TCP PLB (Protective Load Balancing) is enabled.
+ PLB is described in the following paper:
https://doi.org/10.1145/3544216.3544226. Based on PLB parameters,
upon sensing sustained congestion, TCP triggers a change in
flow label field for outgoing IPv6 packets. A change in flow label
@@ -1437,6 +1437,21 @@ tcp_plb_cong_thresh - INTEGER
Default: 128
+tcp_plb_loss_rehash_prob - INTEGER
+ Base probability for Generic PLB repathing, mapped from [0, 1]
+ to [0, 255] (e.g., 128 means 50%). Setting this to 0 disables
+ Generic PLB.
+
+ Unlike tcp_plb_enabled which relies on ECN signals, Generic PLB
+ is congestion-control-agnostic and triggers repathing based on
+ packet loss and delivery rate regression relative to the flow's
+ recent peak delivery rate. Larger tcp_plb_loss_rehash_prob
+ values make repathing more aggressive.
+
+ Possible Values: 0 - 255
+
+ Default: 128
+
tcp_pingpong_thresh - INTEGER
The number of estimated data replies sent for estimated incoming data
requests that must happen before TCP considers that a connection is a
diff --git a/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst b/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
index 2833ce6cba1d..99cccfbb5444 100644
--- a/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
+++ b/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
@@ -136,6 +136,7 @@ u32 tcp_challenge_count
u8 sysctl_tcp_plb_enabled
u8 sysctl_tcp_plb_idle_rehash_rounds
u8 sysctl_tcp_plb_rehash_rounds
+u8 sysctl_tcp_plb_loss_rehash_prob read_mostly tcp_rate_gen
u8 sysctl_tcp_plb_suspend_rto_sec
int sysctl_tcp_plb_cong_thresh
int sysctl_udp_wmem_min
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 6eb058478665..43fcfd0356c0 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -159,11 +159,14 @@ u8 bpf_sock_ops_cb_flags
u8:1 bpf_chg_cc_inprogress
u16 timeout_rehash
u8 plb_consec_cong_rounds
+u8 plb_loss_recoveries
+u8 plb_stale_hops
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
struct rcvq_space read_write tcp_rcv_space_adjust
+u64 plb_max_rate read_write tcp_rate_gen
struct mtu_probe
u32 plb_rehash
u32 mtu_info
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 3f275ac8e512..cdbd25e2a26b 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -379,6 +379,9 @@ struct tcp_sock {
u32 seq;
u64 time;
} rcvq_space;
+ u64 plb_max_rate; /* PLB est. recent max rate
+ * ((MSS packets / us) << 20)
+ */
__cacheline_group_end(tcp_sock_write_rx);
/* End of Hot Path */
@@ -508,6 +511,8 @@ struct tcp_sock {
/* State for PLB (Protective Load Balancing) for a single TCP connection. */
u8 plb_consec_cong_rounds; /* consecutive congested rounds */
+ u8 plb_loss_recoveries; /* fast recoveries since last PLB check */
+ u8 plb_stale_hops; /* consecutive degraded rehashes */
u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */
u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 3efbc7f4b4f7..b225f30580f9 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -83,7 +83,8 @@ struct netns_ipv4 {
u8 sysctl_ip_early_demux;
u8 sysctl_tcp_early_demux;
u8 sysctl_tcp_l3mdev_accept;
- /* 3 bytes hole, try to pack */
+ u8 sysctl_tcp_plb_loss_rehash_prob;
+ /* 1 bytes hole, try to pack */
int sysctl_tcp_reordering;
int sysctl_tcp_rmem[3];
int sysctl_tcp_rcvbuf_low_rtt;
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 7e53293ed3c8..a956ed173e70 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2737,6 +2737,7 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
void tcp_plb_check_rehash_ecn(struct sock *sk);
+void tcp_plb_check_rehash_loss(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/core/net_namespace.c b/net/core/net_namespace.c
index 217021eeab13..e12de8cf7707 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1252,6 +1252,8 @@ static void __init netns_ipv4_struct_check(void)
sysctl_tcp_early_demux);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
sysctl_tcp_l3mdev_accept);
+ CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
+ sysctl_tcp_plb_loss_rehash_prob);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
sysctl_tcp_reordering);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index fb0f3124836d..f99852d3fda4 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -1598,6 +1598,13 @@ static const struct ctl_table ipv4_net_table[] = {
.proc_handler = proc_dou8vec_minmax,
.extra2 = &tcp_plb_max_rounds,
},
+ {
+ .procname = "tcp_plb_loss_rehash_prob",
+ .data = &init_net.ipv4.sysctl_tcp_plb_loss_rehash_prob,
+ .maxlen = sizeof(u8),
+ .mode = 0644,
+ .proc_handler = proc_dou8vec_minmax,
+ },
{
.procname = "tcp_plb_suspend_rto_sec",
.data = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 002eaca58c46..aa18d018f2eb 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3487,8 +3487,11 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->sacked_out = 0;
tp->tlp_high_seq = 0;
tp->last_oow_ack_time = 0;
+ tp->plb_max_rate = 0;
tp->plb_rehash = 0;
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
+ tp->plb_stale_hops = 0;
tp->plb_pause_until = 0;
/* There's a bubble in the pipe until at least the first ACK. */
tp->app_limited = ~0U;
@@ -5330,6 +5333,7 @@ static void __init tcp_struct_check(void)
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_collapse_credit);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space);
+ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, plb_max_rate);
}
void __init tcp_init(void)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 975e6501aef8..8902103ab932 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1831,6 +1831,18 @@ static void tcp_rate_gen(struct sock *sk, u32 delivered, u32 lost,
tp->rate_delivered = rs->delivered;
tp->rate_interval_us = rs->interval_us;
tp->rate_app_limited = rs->is_app_limited;
+
+ if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_plb_loss_rehash_prob) &&
+ (u64)rs->delivered << 20 >
+ (u64)(tp->plb_max_rate + (tp->plb_max_rate >> 3)) * rs->interval_us) {
+ u64 new_rate;
+
+ new_rate = div64_ul((u64)rs->delivered << 20, rs->interval_us);
+ if (!tp->plb_max_rate)
+ tp->plb_max_rate = new_rate;
+ else
+ tp->plb_max_rate += (new_rate - tp->plb_max_rate) >> 3;
+ }
}
}
@@ -3235,6 +3247,8 @@ void tcp_enter_recovery(struct sock *sk, bool ece_ack)
tcp_init_cwnd_reduction(sk);
}
tcp_set_ca_state(sk, TCP_CA_Recovery);
+
+ tcp_plb_check_rehash_loss(sk);
}
static void tcp_update_rto_time(struct tcp_sock *tp)
@@ -4201,6 +4215,7 @@ static void tcp_process_tlp_ack(struct sock *sk, u32 ack, int flag)
tcp_try_keep_open(sk);
NET_INC_STATS(sock_net(sk),
LINUX_MIB_TCPLOSSPROBERECOVERY);
+ tcp_plb_check_rehash_loss(sk);
} else if (!(flag & (FLAG_SND_UNA_ADVANCED |
FLAG_NOT_DUP | FLAG_DATA_SACKED))) {
/* Pure dupack: original and TLP probe arrived; no loss */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 14ba61845f49..05c916a3f34e 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -3531,6 +3531,7 @@ static int __net_init tcp_sk_init(struct net *net)
net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
/* Default congestion threshold for PLB to mark a round is 50% */
net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
+ net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
/* Reno is always built in */
if (!net_eq(net, &init_net) &&
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 794bddc4dc2d..324bcb27f540 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -41,7 +41,7 @@ void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
}
EXPORT_SYMBOL_GPL(tcp_plb_update_state);
-static void tcp_plb_rehash(struct sock *sk)
+static bool tcp_plb_rehash(struct sock *sk)
{
struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
@@ -59,14 +59,16 @@ static void tcp_plb_rehash(struct sock *sk)
tp->plb_pause_until = 0;
if (tp->plb_pause_until)
- return;
+ return false;
if (!__sk_rethink_txhash_reset_dst(sk))
- return;
+ return false;
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
+ return true;
}
/* Check whether recent congestion has been persistent enough to warrant
@@ -96,6 +98,63 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
+void tcp_plb_check_rehash_loss(struct sock *sk)
+{
+ u32 base_prob, rate_prob, floor, prob;
+ struct tcp_sock *tp = tcp_sk(sk);
+ struct net *net = sock_net(sk);
+ u64 cur_rate, max_rate;
+
+ base_prob = READ_ONCE(net->ipv4.sysctl_tcp_plb_loss_rehash_prob);
+ if (!base_prob)
+ return;
+
+ if (++tp->plb_loss_recoveries < 5)
+ return;
+
+ tp->plb_loss_recoveries = 0;
+
+ /* self-normalise MSS-per-sec rate, using the highest
+ * observed rate. More regression, more rehash.
+ */
+ rate_prob = 0;
+ cur_rate = (u64)tp->rate_delivered << 20;
+ max_rate = tp->plb_max_rate * tp->rate_interval_us;
+ if (max_rate > cur_rate) {
+ u64 deficit;
+
+ deficit = mul_u64_u64_div_u64(max_rate - cur_rate,
+ 1 << 8, max_rate);
+ rate_prob = (4 * base_prob * deficit * deficit) >> 16;
+ rate_prob = min_t(u32, rate_prob, 255);
+
+ /* Don't decay plb_max_rate if the regression is
+ * under 15% (38/256).
+ */
+ if (deficit < 38)
+ tp->plb_stale_hops = 0;
+ } else {
+ tp->plb_stale_hops = 0;
+ }
+
+ if (tp->plb_rehash < 2)
+ floor = base_prob >> 1;
+ else
+ floor = base_prob >> 3;
+
+ prob = max(rate_prob, floor);
+ if (get_random_u32_below(255) >= prob)
+ return;
+
+ if (!tcp_plb_rehash(sk))
+ return;
+
+ if (tp->plb_stale_hops < 3)
+ tp->plb_stale_hops++;
+ if (tp->plb_stale_hops == 3)
+ tp->plb_max_rate -= tp->plb_max_rate >> 3;
+}
+
/* Upon RTO, disallow load balancing for a while, to avoid having load
* balancing decisions switch traffic to a black-holed path that was
* previously avoided with a sk_rethink_txhash() call at RTO time.
@@ -106,7 +165,8 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
struct net *net = sock_net(sk);
u32 pause;
- if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled) &&
+ !READ_ONCE(net->ipv4.sysctl_tcp_plb_loss_rehash_prob))
return;
pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
@@ -120,4 +180,5 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
* congestion characteristics.
*/
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
}
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (7 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
@ 2026-12-04 8:54 ` 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
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
tcp_plb_loss_rate.pkt verifies that rehash happens when
cur_rate drops sharply.
tcp_plb_loss_rto_suspend.pkt verifies Generic PLB is also
suspended for net.ipv4.tcp_plb_suspend_rto_sec seconds.
tcp_plb_loss_tlp.pkt verifies spurious TLP does not rehash
but TLP loss rehashes the flow.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
.../net/packetdrill/tcp_plb_loss_rate.pkt | 83 +++++++++
.../packetdrill/tcp_plb_loss_rto_suspend.pkt | 166 ++++++++++++++++++
.../net/packetdrill/tcp_plb_loss_tlp.pkt | 102 +++++++++++
3 files changed, 351 insertions(+)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
new file mode 100644
index 000000000000..2e81fde34e60
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: rate-drop triggered PLB rehash in Fast Recovery.
+// - Phase 1: 4 Fast Recovery rounds (< 5) -> no rehash.
+// - Phase 2: Record non-app-limited plb_max_rate, then drop cur_rate
+// upon entering the 5th Fast Recovery -> rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_early_retrans=0
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT (srtt ~ 10ms, RTO ~ 210ms > 50ms rate-drop wait).
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Phase 1: 4 Fast Recovery rounds (plb_loss_recoveries = 1..4 < 5 -> no rehash).
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3401 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3401:3801(400) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320 <sack 3501:3801,nop,nop>
+ +0 > (flowlabel 0x1) . 3401:3501(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3801 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3801:4201(400) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320 <sack 3901:4201,nop,nop>
+ +0 > (flowlabel 0x1) . 3801:3901(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4201 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 4201:4601(400) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320 <sack 4301:4601,nop,nop>
+ +0 > (flowlabel 0x1) . 4201:4301(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4601 win 320
+ +0 %{ assert tcpi_ca_state == TCP_CA_Open, tcpi_ca_state }%
+
+// Phase 2 (5th recovery with delivery rate drop -> rehash): cwnd == 9.
+// Write 9 + 4 = 13 segments (1300B).
+// Batch 1 (900B) is sent with is_app_limited = 1.
+ +.01 write(4, ..., 1300) = 1300
+ +0 > (flowlabel 0x1) . 4601:5501(900) ack 1
+
+// ACK Batch 1 at +.01: clears app_limited and clocks out Batch 2 (400B)
+// with is_app_limited = 0.
+ +.01 < . 1:1(0) ack 5501 win 320
+ +0 > (flowlabel 0x1) P. 5501:5901(400) ack 1
+
+// Lose 5501:5601.
+// 1st SACK at +.05 updates rate sample to 1 segment / 50ms with is_app_limited = 0.
+// 2nd SACK makes sacked_out == 3 and enters Fast Recovery on the 5th recovery.
+ +.05 < . 1:1(0) ack 5501 win 320 <sack 5601:5701,nop,nop>
+ +0 < . 1:1(0) ack 5501 win 320 <sack 5601:5901,nop,nop>
+
+// Rate-drop on 5th recovery triggers rehash:
+// Fast retransmit has flowlabel 0x2 and tcpi_rehash == 1.
+ +0 > (flowlabel 0x2) . 5501:5601(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Clean finish.
+ +.01 < . 1:1(0) ack 5901 win 320
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
new file mode 100644
index 000000000000..c44f7c65c8e5
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: RTO reset of plb_loss_recoveries and RTO suspension.
+// - Pre-RTO: 1 Fast Recovery sets plb_loss_recoveries = 1.
+// - RTO: rehashes the socket, sets plb_pause_until to [1.0s, 2.0s),
+// and resets plb_loss_recoveries to 0.
+// - Phase 1: 5 Fast Recoveries within < 1.0s reach plb_loss_recoveries == 5
+// with rate_prob == 255, but rehash is suppressed by plb_pause_until.
+// - Phase 2: After > 2.0s, 4 Fast Recoveries (< 5) do not rehash, and the
+// 5th Fast Recovery clears plb_pause_until and triggers PLB rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_early_retrans=0
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255
+sysctl -q net.ipv4.tcp_plb_suspend_rto_sec=1`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT.
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Pre-RTO Fast Recovery: plb_loss_recoveries becomes 1.
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3401 win 320
+
+// RTO: rehashes flowlabel to 0x2 (tcpi_rehash == 1), sets pause_until to [1s, 2s),
+// and resets plb_loss_recoveries from 1 to 0.
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x1) P. 3401:3501(100) ack 1
++.19~+.27 > (flowlabel 0x2) P. 3401:3501(100) ack 1
+ +.01 < . 1:1(0) ack 3501 win 320
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Phase 1: 5 Fast Recoveries within < 1.0s since RTO.
+// Recovery 1 (plb_loss_recoveries == 1):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3501:3601(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3601:3701(100) ack 1
+ +.01 < . 1:1(0) ack 3501 win 320 <sack 3601:3701,nop,nop>
+ +0 > (flowlabel 0x2) P. 3501:3601(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3701 win 320
+
+// Recovery 2 (plb_loss_recoveries == 2):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3701:3801(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3801:3901(100) ack 1
+ +.01 < . 1:1(0) ack 3701 win 320 <sack 3801:3901,nop,nop>
+ +0 > (flowlabel 0x2) P. 3701:3801(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3901 win 320
+
+// Recovery 3 (plb_loss_recoveries == 3):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3901:4001(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4001:4101(100) ack 1
+ +.01 < . 1:1(0) ack 3901 win 320 <sack 4001:4101,nop,nop>
+ +0 > (flowlabel 0x2) P. 3901:4001(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4101 win 320
+
+// Recovery 4 (plb_loss_recoveries == 4):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4101:4201(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4201:4301(100) ack 1
+ +.01 < . 1:1(0) ack 4101 win 320 <sack 4201:4301,nop,nop>
+ +0 > (flowlabel 0x2) P. 4101:4201(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4301 win 320
+
+// Deliver non-app-limited data and wait 50ms to establish low rate sample
+// (rate_prob == 255) before Recovery 5 in Phase 1:
+ +0 write(4, ..., 300) = 300
+ +0 > (flowlabel 0x2) . 4301:4501(200) ack 1
+ +.01 < . 1:1(0) ack 4501 win 320
+ +0 > (flowlabel 0x2) P. 4501:4601(100) ack 1
+ +.05 < . 1:1(0) ack 4601 win 320
+
+// Recovery 5 (plb_loss_recoveries reaches 5 and resets to 0; suppressed by pause_until):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4601:4701(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4701:4801(100) ack 1
+ +.01 < . 1:1(0) ack 4601 win 320 <sack 4701:4801,nop,nop>
+ +0 > (flowlabel 0x2) P. 4601:4701(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4801 win 320
+
+// Phase 2: Wait 2.5s (> 2.0s max suspension window).
+// Recovery 1 in Phase 2 (plb_loss_recoveries == 1):
+ +2.5 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4801:4901(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4901:5001(100) ack 1
+ +.01 < . 1:1(0) ack 4801 win 320 <sack 4901:5001,nop,nop>
+ +0 > (flowlabel 0x2) P. 4801:4901(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5001 win 320
+
+// Recovery 2 in Phase 2 (plb_loss_recoveries == 2):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5001:5101(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5101:5201(100) ack 1
+ +.01 < . 1:1(0) ack 5001 win 320 <sack 5101:5201,nop,nop>
+ +0 > (flowlabel 0x2) P. 5001:5101(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5201 win 320
+
+// Recovery 3 in Phase 2 (plb_loss_recoveries == 3):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5201:5301(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5301:5401(100) ack 1
+ +.01 < . 1:1(0) ack 5201 win 320 <sack 5301:5401,nop,nop>
+ +0 > (flowlabel 0x2) P. 5201:5301(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5401 win 320
+
+// Recovery 4 in Phase 2 (plb_loss_recoveries == 4):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5401:5501(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5501:5601(100) ack 1
+ +.01 < . 1:1(0) ack 5401 win 320 <sack 5501:5601,nop,nop>
+ +0 > (flowlabel 0x2) P. 5401:5501(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5601 win 320
+
+// Deliver non-app-limited data and wait 50ms to establish low rate sample:
+ +0 write(4, ..., 300) = 300
+ +0 > (flowlabel 0x2) . 5601:5801(200) ack 1
+ +.01 < . 1:1(0) ack 5801 win 320
+ +0 > (flowlabel 0x2) P. 5801:5901(100) ack 1
+ +.05 < . 1:1(0) ack 5901 win 320
+
+// Recovery 5 in Phase 2 (plb_loss_recoveries reaches 5 -> clears pause_until and rehashes):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5901:6001(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 6001:6101(100) ack 1
+ +.01 < . 1:1(0) ack 5901 win 320 <sack 6001:6101,nop,nop>
+ +0 > (flowlabel 0x3) P. 5901:6001(100) ack 1
+ +0 %{ assert tcpi_rehash == 2, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 6101 win 320
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
new file mode 100644
index 000000000000..d6c8ee5d184e
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: TLP loss probe triggered PLB rehash.
+// - Setup: Establish high plb_max_rate and 4 Fast Recoveries
+// so plb_loss_recoveries == 4.
+// - Part A: Spurious TLP acked by DSACK does not call
+// tcp_plb_check_rehash_loss() -> no rehash.
+// - Part B: Real tail loss detected by TLP (after(ack, tp->tlp_high_seq))
+// increments plb_loss_recoveries to 5 and triggers PLB rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT.
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Trigger 4 Fast Recovery rounds so plb_loss_recoveries == 4 (< 5).
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3401:3801(400) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320 <sack 3501:3801,nop,nop>
+ +0 > (flowlabel 0x1) . 3401:3501(100) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3801:4201(400) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320 <sack 3901:4201,nop,nop>
+ +0 > (flowlabel 0x1) . 3801:3901(100) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 4201:4601(400) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320 <sack 4301:4601,nop,nop>
+ +0 > (flowlabel 0x1) . 4201:4301(100) ack 1
+ +.01 < . 1:1(0) ack 4601 win 320
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+
+// Part A: DSACK TLP (no actual loss) must NOT call tcp_plb_check_rehash_loss().
+// cwnd == 9. Write 9 + 2 = 11 segments (1100B) so Batch 2 (5501:5701, 200B)
+// is clocked out with is_app_limited = 0.
+ +0 write(4, ..., 1100) = 1100
+ +0 > (flowlabel 0x1) . 4601:5501(900) ack 1
+ +.01 < . 1:1(0) ack 5501 win 320
+ +0 > (flowlabel 0x1) P. 5501:5701(200) ack 1
+
+// With packets_out == 2 > 1 and srtt == 10ms, TLP probe fires
+// at 2 * srtt + 2ms = 22ms:
++.018~+.040 > (flowlabel 0x1) P. 5601:5701(100) ack 1
+
+// Wait +.05 (< 210ms RTO) and ACK 5601 (1 segment / ~72ms with is_app_limited = 0),
+// rearming RTO while keeping tlp_high_seq == 5701.
+ +.05 < . 1:1(0) ack 5601 win 320
+
+// Wait +.05 and receive DSACK. FLAG_DSACK_TLP skips tcp_plb_check_rehash_loss(),
+// so plb_loss_recoveries stays 4 and no rehash occurs.
+ +.05 < . 1:1(0) ack 5701 win 320 <sack 5601:5701,nop,nop>
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+
+// Part B: TLP Loss Recovery (after(ack, tp->tlp_high_seq)) calls
+// tcp_plb_check_rehash_loss(), incrementing plb_loss_recoveries to 5.
+// Write 2 segments (200B) so packets_out == 2 > 1:
+ +0 write(4, ..., 200) = 200
+ +0 > (flowlabel 0x1) P. 5701:5901(200) ack 1
+
+// With packets_out == 2 > 1 and srtt ~ 18ms, TLP probe fires at
+// 2 * srtt + 2ms ~ 38ms (tlp_high_seq = 5901):
++.028~+.055 > (flowlabel 0x1) P. 5801:5901(100) ack 1
+
+// Sender transmits new data while TLP is in flight (tlp_high_seq remains 5901):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x1) P. 5901:6001(100) ack 1
+
+// Peer cumulatively ACKs 6001 (ack 6001 > tlp_high_seq 5901).
+// tcp_process_tlp_ack() runs before tcp_rate_gen(), sees
+// after(ack, tp->tlp_high_seq) on the 5th recovery, and triggers rehash!
+ +.01 < . 1:1(0) ack 6001 win 320
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Outbound packet now has flowlabel 0x2.
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 6001:6101(100) ack 1
+ +.01 < . 1:1(0) ack 6101 win 320
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (8 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
10 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
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
ecmp_rehash.sh uses unpaced socat over veth, where packet drops
or SMP reordering can trigger >= 5 Fast Recoveries.
With Generic PLB enabled by default, tcp_plb_check_rehash_loss()
can rehash the client socket, and the resulting IPv6 flow label
change can also trigger tcp_rcv_spurious_retrans() on the server
side.
This makes test_ecmp_dst_rebuild_consistency() and
test_ecmp_syncookie_path_consistency() flaky.
Let's disable Generic PLB in setup().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
tools/testing/selftests/net/ecmp_rehash.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/net/ecmp_rehash.sh b/tools/testing/selftests/net/ecmp_rehash.sh
index f05a6c8edd2a..a2b732cf2418 100755
--- a/tools/testing/selftests/net/ecmp_rehash.sh
+++ b/tools/testing/selftests/net/ecmp_rehash.sh
@@ -186,6 +186,7 @@ setup()
ip netns exec "$ns" sysctl -qw net.ipv6.conf.default.accept_dad=0
ip netns exec "$ns" sysctl -qw net.ipv6.conf.all.forwarding=1
ip netns exec "$ns" sysctl -qw net.core.txrehash=1
+ ip netns exec "$ns" sysctl -qw net.ipv4.tcp_plb_loss_rehash_prob=0
done
local i sub
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (9 preceding siblings ...)
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 ` netdev-bot+sinfo
2026-12-04 9:29 ` Kuniyuki Iwashima
10 siblings, 1 reply; 14+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 9:03 UTC (permalink / raw)
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
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB.
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
0 siblings, 0 replies; 14+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 9:29 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Yuchung Cheng,
Kuniyuki Iwashima, netdev
On Fri, Dec 4, 2026 at 1:03 AM <netdev-bot+sinfo@kernel.org> wrote:
>
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - How the issue was discovered, e.g. hit in production, hit during
> development, syzbot report, manual code inspection, LLM or static
> analysis tool scan.
Found by Sashiko review during development,
>
> - Whether the issue was actually triggered,
and it was triggered.
> or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.
^ permalink raw reply [flat|nested] 14+ messages in thread