Add BBRv3 Max kernel build

This commit is contained in:
byjoey
2026-06-15 15:04:37 +08:00
parent 9c436cad53
commit 8e47418950
5 changed files with 459 additions and 53 deletions
+57 -25
View File
@@ -53,13 +53,15 @@ jobs:
missing=0
for arch in x86_64 arm64; do
tag="$arch-$version"
if gh release view "$tag" >/dev/null 2>&1; then
echo "$tag already exists."
else
echo "$tag is missing."
missing=1
fi
for suffix in "" "-max"; do
tag="$arch-$version$suffix"
if gh release view "$tag" >/dev/null 2>&1; then
echo "$tag already exists."
else
echo "$tag is missing."
missing=1
fi
done
done
if [ "$missing" -eq 0 ]; then
@@ -90,8 +92,28 @@ jobs:
include:
- arch: x86_64
runs_on: ubuntu-latest
profile: standard
profile_name: BBRv3
release_suffix: ""
localversion: -joeyblog-bbrv3
- arch: arm64
runs_on: ubuntu-24.04-arm
profile: standard
profile_name: BBRv3
release_suffix: ""
localversion: -joeyblog-bbrv3
- arch: x86_64
runs_on: ubuntu-latest
profile: max
profile_name: BBRv3 Max
release_suffix: -max
localversion: -joeyblog-bbrv3-max
- arch: arm64
runs_on: ubuntu-24.04-arm
profile: max
profile_name: BBRv3 Max
release_suffix: -max
localversion: -joeyblog-bbrv3-max
runs-on: ${{ matrix.runs_on }}
env:
ARCH: ${{ matrix.arch }}
@@ -100,13 +122,13 @@ jobs:
- name: 检查是否已发布
id: check_release
run: |
tag="${{ matrix.arch }}-${{ env.KERNEL_VERSION }}"
tag="${{ matrix.arch }}-${{ env.KERNEL_VERSION }}${{ matrix.release_suffix }}"
if gh release view "$tag" >/dev/null 2>&1; then
echo "BUILD_NEEDED=false" >> "$GITHUB_ENV"
echo "$tag already exists; skipping build."
else
echo "BUILD_NEEDED=true" >> "$GITHUB_ENV"
echo "$tag does not exist; building latest kernel with pinned BBRv3 patch."
echo "$tag does not exist; building latest kernel with ${{ matrix.profile_name }}."
fi
- name: 检出代码
@@ -143,6 +165,12 @@ jobs:
bash "$GITHUB_WORKSPACE/scripts/apply-bbrv3-port.sh"
grep -n "BBR_VERSION" net/ipv4/tcp_bbr.c
- name: 应用 BBRv3 Max 极限内核配置
if: env.BUILD_NEEDED == 'true' && matrix.profile == 'max'
working-directory: ./kernel/linux
run: |
bash "$GITHUB_WORKSPACE/scripts/apply-bbrv3-max-profile.sh"
- name: 编译声明
if: env.BUILD_NEEDED == 'true'
working-directory: ./kernel/linux
@@ -150,7 +178,11 @@ jobs:
grep -v "MODULE_DESCRIPTION" net/ipv4/tcp_bbr.c > net/ipv4/tcp_bbr.c.tmp
mv net/ipv4/tcp_bbr.c.tmp net/ipv4/tcp_bbr.c
echo 'MODULE_DESCRIPTION("TCP BBR v3 (Bottleneck Bandwidth and RTT) - Compiled & Optimized by Joey");' >> net/ipv4/tcp_bbr.c
if [ "${{ matrix.profile }}" = "max" ]; then
echo 'MODULE_DESCRIPTION("TCP BBR v3 Max - extreme throughput profile by Joey");' >> net/ipv4/tcp_bbr.c
else
echo 'MODULE_DESCRIPTION("TCP BBR v3 (Bottleneck Bandwidth and RTT) - Compiled & Optimized by Joey");' >> net/ipv4/tcp_bbr.c
fi
tail -n 5 net/ipv4/tcp_bbr.c
@@ -171,10 +203,10 @@ jobs:
bash "$GITHUB_WORKSPACE/scripts/prepare-kernel-config.sh" "${{ matrix.arch }}"
- name: 上传最终配置文件
if: env.BUILD_NEEDED == 'true'
if: env.BUILD_NEEDED == 'true' && matrix.profile == 'standard'
uses: actions/upload-artifact@v4
with:
name: config-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}
name: config-${{ matrix.arch }}-${{ matrix.profile }}-${{ env.KERNEL_VERSION }}
path: ./build-configs/${{ matrix.arch }}*.config
- name: 构建内核 Debian 包
@@ -182,9 +214,9 @@ jobs:
working-directory: ./kernel/linux
run: |
if [ "${{ matrix.arch }}" = "arm64" ]; then
make ARCH=arm64 bindeb-pkg -j$(nproc) LOCALVERSION=-joeyblog-bbrv3 KDEB_COMPRESS=gzip skipdbg=true
make ARCH=arm64 bindeb-pkg -j$(nproc) LOCALVERSION=${{ matrix.localversion }} KDEB_COMPRESS=gzip skipdbg=true
else
make bindeb-pkg -j$(nproc) LOCALVERSION=-joeyblog-bbrv3 KDEB_COMPRESS=gzip skipdbg=true
make bindeb-pkg -j$(nproc) LOCALVERSION=${{ matrix.localversion }} KDEB_COMPRESS=gzip skipdbg=true
fi
- name: 检查 deb 包
@@ -200,14 +232,14 @@ jobs:
- name: 发布前复查是否已发布
if: env.BUILD_NEEDED == 'true'
run: |
tag="${{ matrix.arch }}-${KERNEL_VERSION}"
tag="${{ matrix.arch }}-${KERNEL_VERSION}${{ matrix.release_suffix }}"
if gh release view "$tag" >/dev/null 2>&1; then
echo "PUBLISH_NEEDED=false" >> "$GITHUB_ENV"
echo "$tag was published while this job was running; skipping upload and release."
else
echo "PUBLISH_NEEDED=true" >> "$GITHUB_ENV"
mkdir -p ./publish-markers
touch "./publish-markers/${{ matrix.arch }}"
touch "./publish-markers/${{ matrix.arch }}-${{ matrix.profile }}"
echo "$tag still missing; publishing this build."
fi
@@ -215,25 +247,25 @@ jobs:
if: env.BUILD_NEEDED == 'true' && env.PUBLISH_NEEDED == 'true'
uses: actions/upload-artifact@v4
with:
name: publish-${{ matrix.arch }}-${{ env.KERNEL_VERSION }}
path: ./publish-markers/${{ matrix.arch }}
name: publish-${{ matrix.arch }}-${{ matrix.profile }}-${{ env.KERNEL_VERSION }}
path: ./publish-markers/${{ matrix.arch }}-${{ matrix.profile }}
- name: 上传 deb 包
if: env.BUILD_NEEDED == 'true' && env.PUBLISH_NEEDED == 'true'
uses: actions/upload-artifact@v4
with:
name: deb-${{ matrix.arch }}
name: deb-${{ matrix.arch }}-${{ matrix.profile }}
path: ./kernel/linux-*.deb
- name: 发布到 GitHub Release
if: env.BUILD_NEEDED == 'true' && env.PUBLISH_NEEDED == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ matrix.arch }}-${{ env.KERNEL_VERSION }}
tag_name: ${{ matrix.arch }}-${{ env.KERNEL_VERSION }}${{ matrix.release_suffix }}
files: |
./kernel/linux-*.deb
./build-configs/${{ matrix.arch }}-${{ env.KERNEL_VERSION }}.config
body: "带有 BBRv3 的最新内核,适用于 ${{ matrix.arch }} 架构。Compiled & Optimized by Joey."
body: "带有 ${{ matrix.profile_name }} 的最新内核,适用于 ${{ matrix.arch }} 架构。Compiled & Optimized by Joey."
update-config-baseline:
needs: [preflight, build]
@@ -247,7 +279,7 @@ jobs:
uses: actions/download-artifact@v4
continue-on-error: true
with:
pattern: config-*
pattern: config-*-standard-*
path: ./generated-configs
merge-multiple: true
@@ -255,7 +287,7 @@ jobs:
uses: actions/download-artifact@v4
continue-on-error: true
with:
pattern: publish-*
pattern: publish-*-standard-*
path: ./publish-markers
merge-multiple: true
@@ -272,10 +304,10 @@ jobs:
exit 0
fi
if [ -f ./publish-markers/x86_64 ] && [ -f ./generated-configs/x86_64.config ]; then
if [ -f ./publish-markers/x86_64-standard ] && [ -f ./generated-configs/x86_64.config ]; then
cp ./generated-configs/x86_64.config ./x86-64.config
fi
if [ -f ./publish-markers/arm64 ] && [ -f ./generated-configs/arm64.config ]; then
if [ -f ./publish-markers/arm64-standard ] && [ -f ./generated-configs/arm64.config ]; then
cp ./generated-configs/arm64.config ./arm64.config
fi
+9 -4
View File
@@ -8,7 +8,7 @@
bash <(curl -fsSL https://raw.githubusercontent.com/byJoey/Actions-bbr-v3/main/install.sh)
```
脚本会自动识别当前系统架构,从本仓库 GitHub Releases 下载匹配的 BBRv3 内核 `.deb` 包,并提供安装、指定版本安装、状态检查、加速模式切换和卸载功能。
脚本会自动识别当前系统架构,从本仓库 GitHub Releases 下载匹配的 BBRv3 内核 `.deb` 包,并提供安装、指定版本安装、状态检查、加速模式切换和卸载功能。安装内核时可选择标准 BBRv3 或 BBRv3 Max 极限内核。
## 支持环境
@@ -46,7 +46,7 @@ bash <(curl -fsSL https://raw.githubusercontent.com/byJoey/Actions-bbr-v3/main/i
常用流程:
1. 选择 `1` 安装或更新 BBRv3 内核。
1. 选择 `1` 安装或更新 BBRv3 内核,并按提示选择标准版或 Max 极限版
2. 按提示重启系统。
3. 重新运行脚本,选择 `3` 检查 BBRv3 状态。
4. 按需选择 `4``7` 设置队列算法。
@@ -90,7 +90,8 @@ bash <(curl -fsSL https://raw.githubusercontent.com/byJoey/Actions-bbr-v3/main/i
- 检查系统是否为 Debian/Ubuntu。
- 检查架构是否为 `x86_64``aarch64`
- 从 GitHub Releases 获取当前架构最新版本
- 让用户选择标准 BBRv3 或 BBRv3 Max 极限内核
- 从 GitHub Releases 获取当前架构和内核类型匹配的最新版本。
- 下载非 debug 的内核 `.deb` 包。
- 安装新内核并更新引导配置。
- 提示是否重启。
@@ -110,15 +111,19 @@ bash <(curl -fsSL https://raw.githubusercontent.com/byJoey/Actions-bbr-v3/main/i
2. 指定版本安装
```
脚本会列出当前架构可用的 release tag,并按编号安装指定版本。
脚本会先让用户选择标准 BBRv3 或 BBRv3 Max,再列出当前架构可用的 release tag,并按编号安装指定版本。
release tag 格式:
```text
x86_64-7.0.11
arm64-7.0.11
x86_64-7.0.11-max
arm64-7.0.11-max
```
其中不带 `-max` 的 tag 是标准 BBRv3 内核,带 `-max` 的 tag 是 BBRv3 Max 极限内核。Max 版会弱化/关闭 BBRv3 的降速、ECN、loss/inflight 收敛等控制路径,只适合自有链路极限测速挑战,不建议日常生产使用。
## 检查 BBRv3 状态
运行脚本后选择:
+108 -23
View File
@@ -941,7 +941,76 @@ ask_to_save() {
# 函数:获取已安装的 joeyblog 内核版本
get_installed_version() {
dpkg -l | grep "linux-image" | grep "joeyblog" | awk '{print $2}' | sed 's/linux-image-//' | head -n 1
local profile="${1:-any}"
local versions
versions=$(dpkg -l 2>/dev/null | awk '/^ii/ && $2 ~ /^linux-image-/ && $2 ~ /joeyblog/ {sub(/^linux-image-/, "", $2); print $2}')
case "$profile" in
standard)
echo "$versions" | grep -E -- '-joeyblog-bbrv3$' | sort -V | tail -n 1
;;
max)
echo "$versions" | grep -E -- '-joeyblog-bbrv3-max$' | sort -V | tail -n 1
;;
*)
echo "$versions" | sort -V | tail -n 1
;;
esac
}
get_arch_filter() {
if [[ "$ARCH" == "aarch64" ]]; then
echo "arm64"
elif [[ "$ARCH" == "x86_64" ]]; then
echo "x86_64"
fi
}
get_profile_label() {
case "${1:-standard}" in
max) echo "BBR v3 Max(极限内核)" ;;
*) echo "BBR v3 标准版" ;;
esac
}
get_expected_installed_version() {
local tag="$1"
local profile="${2:-standard}"
local version
version="${tag#x86_64-}"
version="${version#arm64-}"
version="${version%-max}"
if [[ "$profile" == "max" ]]; then
echo "${version}-joeyblog-bbrv3-max"
else
echo "${version}-joeyblog-bbrv3"
fi
}
select_kernel_profile() {
KERNEL_PROFILE="standard"
echo -e "\033[36m请选择要安装的内核类型:\033[0m"
echo -e "\033[33m 1. BBR v3 标准版(推荐日常使用)\033[0m"
echo -e "\033[33m 2. BBR v3 Max 极限版(只为暴力测速,不管稳定性)\033[0m"
echo -n -e "\033[36m请输入选项 (1-2,默认 1): \033[0m"
read -r PROFILE_CHOICE
case "${PROFILE_CHOICE:-1}" in
1)
KERNEL_PROFILE="standard"
;;
2)
KERNEL_PROFILE="max"
echo -e "\033[31m警告:BBR v3 Max 会弱化/关闭降速与惩罚逻辑,只适合极限测速挑战,不建议日常生产使用。\033[0m"
;;
*)
echo -e "\033[31m输入无效,取消安装。\033[0m"
return 1
;;
esac
}
# 函数:智能更新引导加载程序
@@ -1003,9 +1072,15 @@ install_packages() {
# 函数:检查并安装最新版本
install_latest_version() {
assert_supported_kernel_install_system || return 1
local profile="${1:-standard}"
local profile_label
local arch_filter
local expected_version
echo -e "\033[36m正在从 GitHub 获取最新版本信息...\033[0m"
assert_supported_kernel_install_system || return 1
profile_label=$(get_profile_label "$profile")
echo -e "\033[36m正在从 GitHub 获取 ${profile_label} 最新版本信息...\033[0m"
BASE_URL="https://api.github.com/repos/byJoey/Actions-bbr-v3/releases"
RELEASE_DATA=$(gh_api_get "$BASE_URL")
if [[ -z "$RELEASE_DATA" ]]; then
@@ -1014,27 +1089,30 @@ install_latest_version() {
fi
check_release_api_response "$RELEASE_DATA" || return 1
local ARCH_FILTER=""
[[ "$ARCH" == "aarch64" ]] && ARCH_FILTER="arm64"
[[ "$ARCH" == "x86_64" ]] && ARCH_FILTER="x86_64"
LATEST_TAG_NAME=$(echo "$RELEASE_DATA" | jq -r --arg filter "$ARCH_FILTER" 'map(select(.tag_name | test($filter; "i"))) | sort_by(.published_at) | .[-1].tag_name')
arch_filter=$(get_arch_filter)
LATEST_TAG_NAME=$(echo "$RELEASE_DATA" | jq -r --arg filter "$arch_filter" --arg profile "$profile" '
map(
select(.tag_name | test("^" + $filter + "-[0-9]"; "i"))
| select(if $profile == "max" then (.tag_name | endswith("-max")) else ((.tag_name | endswith("-max")) | not) end)
)
| sort_by(.published_at)
| .[-1].tag_name
')
if [[ -z "$LATEST_TAG_NAME" || "$LATEST_TAG_NAME" == "null" ]]; then
echo -e "\033[31m未找到适合当前架构 ($ARCH) 的最新版本。\033[0m"
echo -e "\033[31m未找到适合当前架构 ($ARCH) 的 ${profile_label} 最新版本。\033[0m"
return 1
fi
echo -e "\033[36m检测到最新版本:\033[0m\033[1;32m$LATEST_TAG_NAME\033[0m"
INSTALLED_VERSION=$(get_installed_version)
INSTALLED_VERSION=$(get_installed_version "$profile")
echo -e "\033[36m当前已安装版本:\033[0m\033[1;32m${INSTALLED_VERSION:-"未安装"}\033[0m"
CORE_LATEST_VERSION="${LATEST_TAG_NAME#x86_64-}"
CORE_LATEST_VERSION="${CORE_LATEST_VERSION#arm64-}"
expected_version=$(get_expected_installed_version "$LATEST_TAG_NAME" "$profile")
if [[ -n "$INSTALLED_VERSION" && "$INSTALLED_VERSION" == "$CORE_LATEST_VERSION"* ]]; then
if [[ -n "$INSTALLED_VERSION" && "$INSTALLED_VERSION" == "$expected_version" ]]; then
# 修复了此处的颜文字,将反引号 ` 替换为单引号 '
echo -e "\033[1;32m(o'▽'o) 您已安装最新版本,无需更新!\033[0m"
echo -e "\033[1;32m(o'▽'o) 您已安装最新 ${profile_label},无需更新!\033[0m"
return 0
fi
@@ -1056,7 +1134,12 @@ install_latest_version() {
# 函数:安装指定版本
install_specific_version() {
local profile="${1:-standard}"
local profile_label
local arch_filter
assert_supported_kernel_install_system || return 1
profile_label=$(get_profile_label "$profile")
BASE_URL="https://api.github.com/repos/byJoey/Actions-bbr-v3/releases"
RELEASE_DATA=$(gh_api_get "$BASE_URL")
@@ -1066,18 +1149,20 @@ install_specific_version() {
fi
check_release_api_response "$RELEASE_DATA" || return 1
local ARCH_FILTER=""
[[ "$ARCH" == "aarch64" ]] && ARCH_FILTER="arm64"
[[ "$ARCH" == "x86_64" ]] && ARCH_FILTER="x86_64"
MATCH_TAGS=$(echo "$RELEASE_DATA" | jq -r --arg filter "$ARCH_FILTER" '.[] | select(.tag_name | test($filter; "i")) | .tag_name')
arch_filter=$(get_arch_filter)
MATCH_TAGS=$(echo "$RELEASE_DATA" | jq -r --arg filter "$arch_filter" --arg profile "$profile" '
.[]
| select(.tag_name | test("^" + $filter + "-[0-9]"; "i"))
| select(if $profile == "max" then (.tag_name | endswith("-max")) else ((.tag_name | endswith("-max")) | not) end)
| .tag_name
')
if [[ -z "$MATCH_TAGS" ]]; then
echo -e "\033[31m未找到适合当前架构的版本。\033[0m"
echo -e "\033[31m未找到适合当前架构的 ${profile_label} 版本。\033[0m"
return 1
fi
echo -e "\033[36m以下为适用于当前架构的版本:\033[0m"
echo -e "\033[36m以下为适用于当前架构的 ${profile_label} 版本:\033[0m"
IFS=$'\n' read -rd '' -a TAG_ARRAY <<<"$MATCH_TAGS"
for i in "${!TAG_ARRAY[@]}"; do
@@ -1149,11 +1234,11 @@ read -r ACTION
case "$ACTION" in
1)
echo -e "\033[1;32m٩(。•́‿•̀。)۶ 您选择了安装或更新 BBR v3\033[0m"
install_latest_version
select_kernel_profile && install_latest_version "$KERNEL_PROFILE"
;;
2)
echo -e "\033[1;32m(。・∀・)ノ゙ 您选择了安装指定版本的 BBR\033[0m"
install_specific_version
select_kernel_profile && install_specific_version "$KERNEL_PROFILE"
;;
3)
echo -e "\033[1;32m(。・ω・。) 检查是否为 BBR v3...\033[0m"
+204
View File
@@ -0,0 +1,204 @@
#!/usr/bin/env bash
set -euo pipefail
target="${1:-net/ipv4/tcp_bbr.c}"
if [[ ! -f "$target" ]]; then
echo "BBRv3 source file not found: $target" >&2
exit 1
fi
if ! grep -q '^#define BBR_VERSION[[:space:]]*3' "$target"; then
echo "BBRv3 max profile requires BBR_VERSION=3 in $target." >&2
exit 1
fi
python3 - "$target" <<'PY'
import re
import sys
from pathlib import Path
path = Path(sys.argv[1])
text = path.read_text()
replacements = {
r"static const u32 bbr_probe_rtt_win_ms = .*?;": "static const u32 bbr_probe_rtt_win_ms = 60 * 60 * 1000;",
r"static const u32 bbr_probe_rtt_cwnd_gain = .*?;": "static const u32 bbr_probe_rtt_cwnd_gain = BBR_UNIT * 3;",
r"static const u32 bbr_probe_rtt_mode_ms = .*?;": "static const u32 bbr_probe_rtt_mode_ms = 0;",
r"static const u32 bbr_tso_rtt_shift = .*?;": "static const u32 bbr_tso_rtt_shift = 2;",
r"static const int bbr_pacing_margin_percent = .*?;": "static const int bbr_pacing_margin_percent = 0;",
r"static const int bbr_startup_pacing_gain = .*?;": "static const int bbr_startup_pacing_gain = BBR_UNIT * 15 / 4;",
r"static const int bbr_startup_cwnd_gain = .*?;": "static const int bbr_startup_cwnd_gain = BBR_UNIT * 15 / 4;",
r"static const int bbr_drain_gain = .*?;": "static const int bbr_drain_gain = BBR_UNIT;",
r"static const int bbr_cwnd_gain = .*?;": "static const int bbr_cwnd_gain = BBR_UNIT * 15 / 4;",
r"static const u32 bbr_cwnd_min_target = .*?;": "static const u32 bbr_cwnd_min_target = 64;",
r"static const u32 bbr_full_bw_thresh = .*?;": "static const u32 bbr_full_bw_thresh = BBR_UNIT * 101 / 100;",
r"static const u32 bbr_full_bw_cnt = .*?;": "static const u32 bbr_full_bw_cnt = 12;",
r"static const int bbr_extra_acked_gain = .*?;": "static const int bbr_extra_acked_gain = BBR_UNIT * 4;",
r"static const u32 bbr_extra_acked_max_us = .*?;": "static const u32 bbr_extra_acked_max_us = 1000 * 1000;",
r"static const bool bbr_precise_ece_ack = .*?;": "static const bool bbr_precise_ece_ack = false;",
r"static const u32 bbr_ecn_max_rtt_us = .*?;": "static const u32 bbr_ecn_max_rtt_us = 0;",
r"static const u32 bbr_beta = .*?;": "static const u32 bbr_beta = 0;",
r"static const u32 bbr_ecn_alpha_gain = .*?;": "static const u32 bbr_ecn_alpha_gain = 0;",
r"static const u32 bbr_ecn_alpha_init = .*?;": "static const u32 bbr_ecn_alpha_init = 0;",
r"static const u32 bbr_ecn_factor = .*?;": "static const u32 bbr_ecn_factor = 0;",
r"static const u32 bbr_ecn_thresh = .*?;": "static const u32 bbr_ecn_thresh = 0;",
r"static const u32 bbr_ecn_reprobe_gain = .*?;": "static const u32 bbr_ecn_reprobe_gain = 0;",
r"static const u32 bbr_loss_thresh = [^\n]*": "static const u32 bbr_loss_thresh = BBR_UNIT; /* max: effectively disabled */",
r"static const bool bbr_loss_probe_recovery = .*?;": "static const bool bbr_loss_probe_recovery = false;",
r"static const u32 bbr_full_loss_cnt = .*?;": "static const u32 bbr_full_loss_cnt = 0;",
r"static const u32 bbr_full_ecn_cnt = .*?;": "static const u32 bbr_full_ecn_cnt = 0;",
r"static const u32 bbr_inflight_headroom = .*?;": "static const u32 bbr_inflight_headroom = 0;",
r"static const u32 bbr_bw_probe_cwnd_gain = .*?;": "static const u32 bbr_bw_probe_cwnd_gain = 3;",
r"static const u32 bbr_bw_probe_max_rounds = .*?;": "static const u32 bbr_bw_probe_max_rounds = 1;",
r"static const u32 bbr_bw_probe_rand_rounds = .*?;": "static const u32 bbr_bw_probe_rand_rounds = 0;",
r"static const u32 bbr_bw_probe_base_us = .*?;": "static const u32 bbr_bw_probe_base_us = 1000;",
r"static const u32 bbr_bw_probe_rand_us = .*?;": "static const u32 bbr_bw_probe_rand_us = 0;",
}
missing = []
for pattern, replacement in replacements.items():
text, count = re.subn(pattern, replacement, text, count=1)
if count != 1:
missing.append(pattern)
def find_matching(source, open_pos, open_char, close_char):
depth = 0
i = open_pos
in_string = None
in_line_comment = False
in_block_comment = False
escaped = False
while i < len(source):
ch = source[i]
nxt = source[i + 1] if i + 1 < len(source) else ""
if in_line_comment:
if ch == "\n":
in_line_comment = False
i += 1
continue
if in_block_comment:
if ch == "*" and nxt == "/":
in_block_comment = False
i += 2
continue
i += 1
continue
if in_string:
if escaped:
escaped = False
elif ch == "\\":
escaped = True
elif ch == in_string:
in_string = None
i += 1
continue
if ch == "/" and nxt == "/":
in_line_comment = True
i += 2
continue
if ch == "/" and nxt == "*":
in_block_comment = True
i += 2
continue
if ch in ('"', "'"):
in_string = ch
i += 1
continue
if ch == open_char:
depth += 1
elif ch == close_char:
depth -= 1
if depth == 0:
return i
i += 1
return -1
def next_code_char(source, pos):
i = pos
while i < len(source):
if source[i].isspace():
i += 1
continue
if source.startswith("//", i):
j = source.find("\n", i + 2)
i = len(source) if j == -1 else j + 1
continue
if source.startswith("/*", i):
j = source.find("*/", i + 2)
i = len(source) if j == -1 else j + 2
continue
return i
return -1
def replace_function_body(source, name, body):
for match in re.finditer(rf"\b{re.escape(name)}\s*\(", source):
open_paren = source.find("(", match.start())
close_paren = find_matching(source, open_paren, "(", ")")
if close_paren == -1:
continue
code_pos = next_code_char(source, close_paren + 1)
if code_pos == -1:
continue
if source[code_pos] == ";":
continue
if source[code_pos] != "{":
continue
close_brace = find_matching(source, code_pos, "{", "}")
if close_brace == -1:
continue
return source[:code_pos + 1] + body + source[close_brace:]
missing.append(f"function {name}")
return source
pacing_pattern = re.compile(
r"static const int bbr_pacing_gain\[\] = \{\n"
r".*?\n"
r"\};",
re.S,
)
pacing_replacement = """static const int bbr_pacing_gain[] = {
\tBBR_UNIT * 15 / 4,\t/* UP: max-rate probe */
\tBBR_UNIT,\t\t/* DOWN: no intentional drain */
\tBBR_UNIT * 5 / 4,\t/* CRUISE: keep pressure on the pipe */
\tBBR_UNIT * 2,\t\t/* REFILL: refill aggressively */
};"""
text, pacing_count = pacing_pattern.subn(pacing_replacement, text, count=1)
if pacing_count != 1:
missing.append("static const int bbr_pacing_gain[]")
extreme_bodies = {
"bbr_bw": "\n\treturn bbr_max_bw(sk);\n",
"bbr_can_use_ecn": "\n\treturn false;\n",
"bbr_check_ecn_too_high_in_startup": "\n\treturn;\n",
"bbr_update_ecn_alpha": "\n\treturn -1;\n",
"bbr_plb": "\n\treturn;\n",
"bbr_handle_queue_too_high_in_startup": "\n\treturn;\n",
"bbr_is_inflight_too_high": "\n\treturn false;\n",
"bbr_handle_inflight_too_high": "\n\treturn;\n",
"bbr_bound_cwnd_for_inflight_model": "\n\treturn;\n",
"bbr_adapt_lower_bounds": "\n\treturn;\n",
"bbr_check_loss_too_high_in_startup": "\n\treturn;\n",
"bbr_check_drain": "\n\treturn;\n",
}
for function_name, body in extreme_bodies.items():
text = replace_function_body(text, function_name, body)
if missing:
print("Failed to apply BBRv3 max profile; missing patterns:", file=sys.stderr)
for item in missing:
print(f" {item}", file=sys.stderr)
sys.exit(1)
path.write_text(text)
PY
grep -nE 'bbr_(startup_pacing_gain|startup_cwnd_gain|cwnd_gain|pacing_gain|beta|loss_thresh|full_loss_cnt|full_ecn_cnt|inflight_headroom|bw_probe_cwnd_gain|probe_rtt_mode_ms|pacing_margin_percent)' "$target"
echo "Applied BBRv3 max profile to $target"
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
set -euo pipefail
kernel_version="${1:-}"
arch="${2:-$(uname -m)}"
repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
workdir="${BBRV3_MAX_WORKDIR:-$repo_root/kernel-max}"
if [[ -z "$kernel_version" ]]; then
raw_version=$(curl -fsSL https://www.kernel.org/finger_banner |
awk -F: '/latest stable version/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2; exit}')
if [[ "$raw_version" =~ ^[0-9]+\.[0-9]+$ ]]; then
kernel_version="${raw_version}.0"
else
kernel_version="$raw_version"
fi
fi
case "$arch" in
aarch64|arm64)
build_arch="arm64"
config_arch="arm64"
;;
x86_64)
build_arch="x86_64"
config_arch="x86_64"
;;
*)
echo "Unsupported arch: $arch" >&2
exit 1
;;
esac
if ! [[ "$kernel_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Unexpected kernel version: $kernel_version" >&2
exit 1
fi
branch=$(echo "$kernel_version" | grep -oE '^[0-9]+\.[0-9]+')
mkdir -p "$workdir"
if [[ ! -d "$workdir/linux/.git" ]]; then
git clone --depth=1 --branch "linux-$branch.y" \
https://github.com/gregkh/linux.git "$workdir/linux"
fi
cd "$workdir/linux"
git fetch --depth=1 origin "linux-$branch.y"
git reset --hard FETCH_HEAD
git clean -fdx
bash "$repo_root/scripts/apply-bbrv3-port.sh"
bash "$repo_root/scripts/apply-bbrv3-max-profile.sh"
grep -v "MODULE_DESCRIPTION" net/ipv4/tcp_bbr.c > net/ipv4/tcp_bbr.c.tmp
mv net/ipv4/tcp_bbr.c.tmp net/ipv4/tcp_bbr.c
echo 'MODULE_DESCRIPTION("TCP BBR v3 Max - extreme throughput profile by Joey");' >> net/ipv4/tcp_bbr.c
IFS='.' read -r v p s <<< "$kernel_version"
sed -i "s/^VERSION *=.*/VERSION = $v/" Makefile
sed -i "s/^PATCHLEVEL *=.*/PATCHLEVEL = $p/" Makefile
sed -i "s/^SUBLEVEL *=.*/SUBLEVEL = $s/" Makefile
export GITHUB_WORKSPACE="$repo_root"
export KERNEL_VERSION="$kernel_version"
bash "$repo_root/scripts/prepare-kernel-config.sh" "$config_arch"
if [[ "$build_arch" == "arm64" ]]; then
make ARCH=arm64 bindeb-pkg -j"$(nproc)" LOCALVERSION=-joeyblog-bbrv3-max KDEB_COMPRESS=gzip skipdbg=true
else
make bindeb-pkg -j"$(nproc)" LOCALVERSION=-joeyblog-bbrv3-max KDEB_COMPRESS=gzip skipdbg=true
fi
if find "$workdir" -maxdepth 1 \( -name '*-dbg*.deb' -o -name '*-dbgsym*.deb' \) | grep -q .; then
echo "ERROR: debug deb package was generated." >&2
find "$workdir" -maxdepth 1 \( -name '*-dbg*.deb' -o -name '*-dbgsym*.deb' \) -print >&2
exit 1
fi
find "$workdir" -maxdepth 1 -name 'linux-*.deb' -print | sort