From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796374574; b=DNjeavmgO82HvXB0PTHQiTzsYb97QdFhazDobjRrdTcdHKKk2UR+HZXYt2fB/9vWFbi4 NwmYF4npdQSv8e8/hOyKkC+n3tTkZV+mI1V1TZ0Ws+4dL4WYDZAGOqV1CbKEJZ7xGrLC6 uMRBXCxjs/5u1jijlkrNFKlFhm1QgEc4eAHOUvTCidBSfI7ba9EIZTF0SJqXWBvtkwbWF 1U4K7yg30gE01utANG0cquLcpinTKwLoMdfq7g4kf6CTgHVnYi3kOJleBG9Q4RHr49OCj uJKWAMeCI/z5DiaBysVGpKiXLDRD3IFlVHxXhL0VU+aTxJZ2bnvh/ChjQUkniUUYgUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796374574; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=WhnFXWd5g6lmr0D6KX86x+tIYwChTmSggmcjTATQ3LM=; b=uJrmAvQzcMiuD5PMA4hg9Y5yHOjqhoQo2/dCu/m5oCWZf5KpDhCn1fXwhQBZJJePxaBn kurndhqXmWfuGDoZ5vjy4W8HiEBG1xjtFWXng/FIkF+280ItKAwdbCDfPVR0iSOSz7D9f Ud8/8DGcmIjVnEmzy6vPBPsO/6qd3Mbt3NKEuePiY1bhP9Sc8geewQE1D6Z5OX0z88ZSq 7FIj2cGYXN2KNjgmEnq+mu57jd4S+j2aTS6hWJSCPVtFYY+kZ4mrXhgQ1ztRJrRkoaXNn mGtvobKg/IdyNuGLvem+98NgU4nhI8zL6r6zzWpm/UbDKqgvE+SLoSVhkUXMMuadaIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IvVmxU8A; arc=none smtp.remote-ip=209.85.215.199 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D962606A6AE for ; Fri, 4 Dec 2026 08:56:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1D962606A6AE Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IvVmxU8A Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cd5ca3840c5so572042a12.2 for ; Fri, 04 Dec 2026 00:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796374573; x=1796979373; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WhnFXWd5g6lmr0D6KX86x+tIYwChTmSggmcjTATQ3LM=; b=IvVmxU8AFBYxAvQGfwfxgKFB6zD8WqbJV0XLG5/DlacErdDcznKGhHah9bD8Oz4EGi 9ba043+nhgNNMVD612eqpfa2HKz9rpdnO2AIt0yknYeJDqSDD0GhKG0TUHBlASSGM63/ 2jKJ7BhtfsaZB1icuAP8yDNicsZ9pIOTm3p+LZWTe4ym35n1Avrp85xzcENOP9DzW5i9 jTenH68M6SBGscR7U5ji62N5Y/q5u+hRCNa7U2vwtiOk0OyH/Lwnei4qijTs1iY9t1HJ nBtpYwI/f7v13yx+xBGyrD8xLv1s/w4M4uu+/yviQt17eF/QXNg0FdMtV3VYQxHneOv6 LRmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374573; x=1796979373; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WhnFXWd5g6lmr0D6KX86x+tIYwChTmSggmcjTATQ3LM=; b=WRaYQNv2bBP8W5jlxF3G/xa4Wq0z+0ZePh6DboC2R6V/pPatTepHY+54aSOy/rfnwM U3a7ybZdUtMXHF0X6CDNs26iDiPrS4SJaKVtU9B0pbicIrXqR7H+jGih2kGQjq7Pg03P A+vJq78d81EKeWRoa83qdS7CZh7ctq+6VMG6dE6Mgp+3V3LKZyOfnXsmX95IGV9fNgQy BHiQ/Z1II9xXGkumUphDFh3+pwaNTxWr1K5LFLZMRoC5wCrFhXKM7f1wqsKqbCGOJyJ5 AJ2n0ciwknnQelacFIolAP8dSwcpfGuBJnV2P8DeLz4tbXEtQvOiQnI8lfqAerrUjeZD BEBw== X-Forwarded-Encrypted: i=1; AL+hErF2mkqH9PfDa8bCqfCyScTknp/qSMo7ytqnnY+osLd+iUIpdRSvzjZqiqkt5isGkSw258ikEyo=@vger.kernel.org X-Gm-Message-State: APuU4Z+4fdnXl9Ax/4EC5BOW8XfaYp/KDa9aBuxhI/czEK70QzJPJmtW y43HmakxyKSV/VEjjYQLLcEjNA3ztIlMNdbL0YZANS4JIx8zRXoXVN8geLfqGLT/c8/TRqYh2dv yEglIUg== X-Received: from pgfz31-n2.prod.google.com ([2002:a05:6a02:84df:20b0:cc7:e0b2:a5a2]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6e0c:b0:3fc:7478:2af8 with SMTP id adf61e73a8af0-41561f2f4f7mr1492762637.34.1796374573119; Fri, 04 Dec 2026 00:56:13 -0800 (PST) Date: Fri, 4 Dec 2026 17:54:38 +0900 In-Reply-To: <20261204085551.1518105-1-kuniyu@google.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261204085551.1518105-1-kuniyu@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261204085551.1518105-9-kuniyu@google.com> Subject: [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB. From: Kuniyuki Iwashima To: Eric Dumazet , Neal Cardwell , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn Cc: Simon Horman , Yuchung Cheng , Kuniyuki Iwashima , Kuniyuki Iwashima , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Currently, PLB (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 --- 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