diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c505bf7..4cc8d5c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -14,7 +14,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 components: rustfmt - name: Check code format @@ -30,7 +30,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 components: clippy - name: Rust Cache @@ -49,7 +49,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 @@ -67,7 +67,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4e9d74e..d3850e2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,10 +3,10 @@ name: Deploy on: push: branches: - - '**' + - "**" tags-ignore: - - 'v*' - - 'v*-pre.*' + - "v*" + - "v*-pre.*" pull_request: permissions: @@ -15,7 +15,7 @@ permissions: id-token: write concurrency: - group: 'pages' + group: "pages" cancel-in-progress: false jobs: @@ -34,16 +34,16 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install Rust 1.93.0 + - name: Install Rust uses: dtolnay/rust-toolchain@master with: - toolchain: "1.93.0" + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 - name: Build benchmarks - run: cargo +1.93.0 bench --features bench --no-run + run: cargo bench --no-run build-doc: name: Build documentation @@ -56,7 +56,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f102541..e807c93 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,8 +3,8 @@ name: Release on: push: tags: - - 'v*.*.*' - - 'v*.*.*-pre.*' + - "v*.*.*" + - "v*.*.*-pre.*" permissions: contents: write @@ -119,7 +119,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 61e2b44..8b1b763 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2025-04-01 + toolchain: nightly-2026-02-25 - name: Rust Cache uses: Swatinem/rust-cache@v2 diff --git a/Cargo.toml b/Cargo.toml index afaf573..3a274c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,34 +15,30 @@ categories = ["memory-management", "no-std", "embedded"] default = [] log = ["dep:log"] tracking = [] -# Enable benchmarking (requires criterion and rand as regular dependencies) -bench = ["dep:criterion", "dep:rand"] + +# Deprecated +bench = [] [dependencies] -log = { version = "0.4", optional = true } cfg-if = "1.0" -criterion = { version = "0.4", features = ["html_reports"], optional = true } -rand = { version = "0.8", features = ["small_rng"], optional = true } +log = { version = "0.4", optional = true } + +[dev-dependencies] +criterion = { version = "0.4", features = ["html_reports"] } +rand = { version = "0.8", features = ["small_rng"] } [[bench]] name = "global_allocator" harness = false -required-features = ["bench"] [[bench]] name = "buddy_allocator" harness = false -required-features = ["bench"] [[bench]] name = "slab_allocator" harness = false -required-features = ["bench"] [[bench]] name = "stability" harness = false -required-features = ["bench"] - - - diff --git a/README.md b/README.md index a07d12b..e3ceb89 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ This project includes comprehensive benchmarks to evaluate performance and stabi ```bash # Run all benchmarks -cargo bench --features bench +cargo bench ``` For detailed usage instructions, refer to `benches/README.md`. diff --git a/README_CN.md b/README_CN.md index b17b474..bf9e49b 100644 --- a/README_CN.md +++ b/README_CN.md @@ -157,7 +157,7 @@ cargo test --package buddy-slab-allocator --features tracking ```bash # 运行所有 benchmark -cargo bench --features bench +cargo bench ``` 详细使用方法请参考 `benches/README_CN.md`。 diff --git a/benches/README_CN.md b/benches/README_CN.md index 1eb79ea..fe6b470 100644 --- a/benches/README_CN.md +++ b/benches/README_CN.md @@ -2,67 +2,42 @@ 本目录包含 buddy-slab-allocator 项目的性能测试和稳定性测试。 -## 前置条件 - -运行 benchmark 需要启用 `bench` feature,该 feature 会添加 `criterion` 和 `rand` 依赖。 - -**重要提示**:由于 benchmark 依赖的 `zerocopy` 库需要较新的 Rust 特性,请使用 **Rust 1.93.0 或更高版本**运行 benchmark: - -```bash -# 安装 Rust 1.93.0 -rustup install 1.93.0 - -# 使用指定版本运行 benchmark -cargo +1.93.0 bench --features bench -``` - -**注意**:主项目使用 `nightly-2025-04-01` 工具链进行开发和 CI,但 benchmark 需要使用 1.93.0+ 以避免依赖兼容性问题。 - ## 运行 Benchmark -**推荐使用 Rust 1.93.0+**: - ```bash -# 一次性使用(推荐) -cargo +1.93.0 bench --features bench -``` - -### 运行所有 benchmark - -```bash -cargo +1.93.0 bench --features bench +cargo bench ``` ### 运行特定 benchmark suite ```bash # 测试全局分配器 -cargo +1.93.0 bench --features bench --bench global_allocator +cargo bench --bench global_allocator # 测试 Buddy 页分配器 -cargo +1.93.0 bench --features bench --bench buddy_allocator +cargo bench --bench buddy_allocator # 测试 Slab 字节分配器 -cargo +1.93.0 bench --features bench --bench slab_allocator +cargo bench --bench slab_allocator # 测试稳定性 -cargo +1.93.0 bench --features bench --bench stability +cargo bench --bench stability ``` ### 高级选项 ```bash # 启用 memory tracking 功能运行 benchmark -cargo +1.93.0 bench --features "bench tracking" +cargo bench --features tracking # 保存基线用于后续对比 -cargo +1.93.0 bench --features bench -- --save-baseline main +cargo bench -- --save-baseline main # 与基线对比 -cargo +1.93.0 bench --features bench -- --baseline main +cargo bench -- --baseline main # 只运行特定 benchmark -cargo +1.93.0 bench --features bench global_alloc_small +cargo bench global_alloc_small ``` ## Benchmark Suite 说明 @@ -264,18 +239,10 @@ criterion_main!(benches); ### Q: Benchmark 编译失败怎么办? -A: 最常见的原因是 Rust 版本不兼容。请确保使用 **Rust 1.93.0 或更高版本**: - -```bash -# 安装 Rust 1.93.0 -rustup install 1.93.0 - -# 使用指定版本 -cargo +1.93.0 bench --features bench -``` +A: 最常见的原因是 Rust 版本不兼容。请确保使用 **Rust 1.93.0 或更高版本**. 如果仍然失败: -1. 清理并重新构建:`cargo clean && cargo +1.93.0 build --features bench` +1. 清理并重新构建:`cargo clean && cargo build` 2. 检查网络连接和依赖下载 3. 更新 rustup:`rustup update` @@ -291,10 +258,10 @@ A: 可以: A: 使用 Criterion 的基线功能: ```bash # 第一次运行,保存基线 -cargo +1.93.0 bench --features bench -- --save-baseline v1 +cargo bench -- --save-baseline v1 # 修改代码后,对比基线 -cargo +1.93.0 bench --features bench -- --baseline v1 +cargo bench -- --baseline v1 ``` ### Q: Benchmark 结果不稳定怎么办? diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 2b572aa..a00a68a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2025-04-01" +channel = "nightly-2026-02-25" components = ["rust-src", "rustfmt", "clippy"] diff --git a/src/buddy/buddy_set.rs b/src/buddy/buddy_set.rs index 60db9f6..61bfab1 100644 --- a/src/buddy/buddy_set.rs +++ b/src/buddy/buddy_set.rs @@ -161,7 +161,7 @@ impl BuddySet { let mut max_order_by_alignment = 0; for test_order in 0..=self.max_order() { let block_size = (1 << test_order) * PAGE_SIZE; - if current_addr % block_size == 0 { + if current_addr.is_multiple_of(block_size) { max_order_by_alignment = test_order; } else { break; @@ -266,7 +266,7 @@ impl BuddySet { // Verify alignment requirement assert!( - block.addr % alignment == 0, + block.addr.is_multiple_of(alignment), "Allocated address {:#x} is not aligned to {:#x} bytes ", block.addr, alignment @@ -470,7 +470,7 @@ impl BuddySet { } // Check alignment requirement - if base % alignment != 0 { + if !base.is_multiple_of(alignment) { error!( "zone {}: Address {:#x} is not aligned to {:#x}", self.zone_id, base, alignment diff --git a/src/slab/slab_node.rs b/src/slab/slab_node.rs index e73f9c8..fabcdfd 100644 --- a/src/slab/slab_node.rs +++ b/src/slab/slab_node.rs @@ -179,7 +179,7 @@ impl SlabNode { } let offset = obj_addr - base; - if offset % self.size_class.size() != 0 { + if !offset.is_multiple_of(self.size_class.size()) { error!("Invalid object address: {obj_addr:x}"); return None; }