net/ipv4/tcp_plb.c
Source file repositories/reference/linux-study-clean/net/ipv4/tcp_plb.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/tcp_plb.c- Extension
.c- Size
- 3860 bytes
- Lines
- 111
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/tcp.h
Detected Declarations
function tcp_plb_update_statefunction tcp_plb_check_rehashfunction sk_rethink_txhashexport tcp_plb_update_stateexport tcp_plb_check_rehashexport tcp_plb_update_state_upon_rto
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Protective Load Balancing (PLB)
*
* PLB was designed to reduce link load imbalance across datacenter
* switches. PLB is a host-based optimization; it leverages congestion
* signals from the transport layer to randomly change the path of the
* connection experiencing sustained congestion. PLB prefers to repath
* after idle periods to minimize packet reordering. It repaths by
* changing the IPv6 Flow Label on the packets of a connection, which
* datacenter switches include as part of ECMP/WCMP hashing.
*
* PLB is described in detail in:
*
* Mubashir Adnan Qureshi, Yuchung Cheng, Qianwen Yin, Qiaobin Fu,
* Gautam Kumar, Masoud Moshref, Junhua Yan, Van Jacobson,
* David Wetherall,Abdul Kabbani:
* "PLB: Congestion Signals are Simple and Effective for
* Network Load Balancing"
* In ACM SIGCOMM 2022, Amsterdam Netherlands.
*
*/
#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)
{
struct net *net = sock_net(sk);
if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
return;
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 <
READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds))
plb->consec_cong_rounds++;
}
}
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)
{
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 >=
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 >=
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
* 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 (plb->pause_until)
return;
__sk_rethink_txhash_reset_dst(sk);
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);
}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
/* 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.
Annotation
- Immediate include surface: `net/tcp.h`.
- Detected declarations: `function tcp_plb_update_state`, `function tcp_plb_check_rehash`, `function sk_rethink_txhash`, `export tcp_plb_update_state`, `export tcp_plb_check_rehash`, `export tcp_plb_update_state_upon_rto`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.