Skip to content

Commit 409fff0

Browse files
author
szy
committed
feat:readme, test, optimize, workflows
fix fmt fix ci bug update liscence and ci fix CI test
1 parent 1316718 commit 409fff0

21 files changed

+1201
-209
lines changed

.github/workflows/check.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Quality Checks
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
fmt:
8+
name: Format Check
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Install Rust toolchain
15+
uses: dtolnay/rust-toolchain@master
16+
with:
17+
toolchain: nightly-2025-04-01
18+
components: rustfmt
19+
20+
- name: Check code format
21+
run: cargo fmt --all -- --check
22+
23+
clippy:
24+
name: Clippy Lint
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Install Rust toolchain
31+
uses: dtolnay/rust-toolchain@master
32+
with:
33+
toolchain: nightly-2025-04-01
34+
components: clippy
35+
36+
- name: Rust Cache
37+
uses: Swatinem/rust-cache@v2
38+
39+
- name: Run clippy
40+
run: cargo clippy --all-features -- -D warnings
41+
42+
build:
43+
name: Build
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
49+
- name: Install Rust toolchain
50+
uses: dtolnay/rust-toolchain@master
51+
with:
52+
toolchain: nightly-2025-04-01
53+
54+
- name: Rust Cache
55+
uses: Swatinem/rust-cache@v2
56+
57+
- name: Build library
58+
run: cargo build --all-features
59+
60+
doc:
61+
name: Documentation
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Install Rust toolchain
68+
uses: dtolnay/rust-toolchain@master
69+
with:
70+
toolchain: nightly-2025-04-01
71+
72+
- name: Rust Cache
73+
uses: Swatinem/rust-cache@v2
74+
75+
- name: Build documentation
76+
run: cargo doc --no-deps --all-features

.github/workflows/deploy.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- 'v*'
9+
- 'v*-pre.*'
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: 'pages'
19+
cancel-in-progress: false
20+
21+
jobs:
22+
check:
23+
uses: ./.github/workflows/check.yml
24+
25+
test:
26+
uses: ./.github/workflows/test.yml
27+
needs: check
28+
29+
build-doc:
30+
name: Build documentation
31+
runs-on: ubuntu-latest
32+
needs: test
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v4
36+
37+
- name: Install Rust toolchain
38+
uses: dtolnay/rust-toolchain@master
39+
with:
40+
toolchain: nightly-2025-04-01
41+
42+
- name: Rust Cache
43+
uses: Swatinem/rust-cache@v2
44+
45+
- name: Build docs
46+
run: cargo doc --no-deps --all-features
47+
48+
- name: Create index redirect
49+
run: |
50+
printf '<meta http-equiv="refresh" content="0;url=buddy_slab_allocator/index.html">' > target/doc/index.html
51+
52+
- name: Upload artifact
53+
uses: actions/upload-pages-artifact@v3
54+
with:
55+
path: target/doc
56+
57+
deploy-doc:
58+
name: Deploy to GitHub Pages
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
runs-on: ubuntu-latest
63+
needs: build-doc
64+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
65+
steps:
66+
- name: Deploy to GitHub Pages
67+
id: deployment
68+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
- 'v*.*.*-pre.*'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
check:
14+
uses: ./.github/workflows/check.yml
15+
16+
test:
17+
uses: ./.github/workflows/test.yml
18+
needs: check
19+
20+
create-release:
21+
name: Create GitHub Release
22+
runs-on: ubuntu-latest
23+
needs: [check, test]
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Validate tag and branch (HEAD-based)
32+
shell: bash
33+
run: |
34+
set -e
35+
36+
TAG="${{ github.ref_name }}"
37+
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
38+
39+
git fetch origin main dev
40+
41+
MAIN_HEAD=$(git rev-parse origin/main)
42+
DEV_HEAD=$(git rev-parse origin/dev)
43+
44+
echo "Tag: $TAG"
45+
echo "Tag commit: $TAG_COMMIT"
46+
echo "main HEAD: $MAIN_HEAD"
47+
echo "dev HEAD: $DEV_HEAD"
48+
49+
if [[ "$TAG" == *-pre.* ]]; then
50+
if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
51+
echo "❌ prerelease tag must be created from dev HEAD"
52+
exit 1
53+
fi
54+
echo "✅ prerelease tag validated on dev"
55+
else
56+
if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
57+
echo "❌ stable release tag must be created from main HEAD"
58+
exit 1
59+
fi
60+
echo "✅ stable release tag validated on main"
61+
fi
62+
63+
- name: Create GitHub Release
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
draft: false
67+
prerelease: ${{ contains(github.ref_name, '-pre.') }}
68+
body: |
69+
## ${{ github.ref_name }}
70+
71+
- [Documentation](https://docs.rs/buddy-slab-allocator)
72+
- [crates.io](https://crates.io/crates/buddy-slab-allocator)
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
76+
publish-crates:
77+
name: Publish to crates.io
78+
runs-on: ubuntu-latest
79+
needs: test
80+
81+
steps:
82+
- name: Checkout code
83+
uses: actions/checkout@v4
84+
with:
85+
fetch-depth: 0
86+
87+
- name: Validate tag and branch (HEAD-based)
88+
shell: bash
89+
run: |
90+
set -e
91+
92+
TAG="${{ github.ref_name }}"
93+
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
94+
95+
git fetch origin main dev
96+
97+
MAIN_HEAD=$(git rev-parse origin/main)
98+
DEV_HEAD=$(git rev-parse origin/dev)
99+
100+
echo "Tag: $TAG"
101+
echo "Tag commit: $TAG_COMMIT"
102+
echo "main HEAD: $MAIN_HEAD"
103+
echo "dev HEAD: $DEV_HEAD"
104+
105+
if [[ "$TAG" == *-pre.* ]]; then
106+
if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
107+
echo "❌ prerelease tag must be created from dev HEAD"
108+
exit 1
109+
fi
110+
echo "✅ prerelease tag validated on dev"
111+
else
112+
if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
113+
echo "❌ stable release tag must be created from main HEAD"
114+
exit 1
115+
fi
116+
echo "✅ stable release tag validated on main"
117+
fi
118+
119+
- name: Install Rust toolchain
120+
uses: dtolnay/rust-toolchain@master
121+
with:
122+
toolchain: nightly-2025-04-01
123+
124+
- name: Rust Cache
125+
uses: Swatinem/rust-cache@v2
126+
127+
- name: Publish to crates.io
128+
run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
host-test:
8+
name: Run Logic Tests (Host)
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Install Rust toolchain
15+
uses: dtolnay/rust-toolchain@master
16+
with:
17+
toolchain: nightly-2025-04-01
18+
19+
- name: Rust Cache
20+
uses: Swatinem/rust-cache@v2
21+
22+
- name: Run all tests
23+
run: cargo test --all-features

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] - 2025-01-30
11+
12+
### Added
13+
- Buddy page allocator implementation for page-level allocation
14+
- Slab byte allocator implementation for small object allocation
15+
- Composite page allocator for unified multi-region page allocation
16+
- Global allocator that coordinates page and byte allocators
17+
- Automatic allocation size selection (≤2048 bytes uses slab, >2048 bytes uses page)
18+
- Zero `std` dependency (`#![no_std]`) for embedded/kernel environments
19+
- Optional `log` feature for logging allocation events
20+
- Optional `tracking` feature for memory usage statistics
21+
- `AddrTranslator` trait for virtual-to-physical address translation
22+
- `BaseAllocator`, `ByteAllocator`, `PageAllocator`, and `IdAllocator` traits
23+
- Comprehensive error handling with `AllocError` enum
24+
25+
### Features
26+
- O(1) time complexity for small object allocation
27+
- Buddy algorithm for efficient page allocation with automatic merging
28+
- Support for multiple memory regions
29+
- Flexible page size configuration (const generic)
30+
- Memory fragmentation reduction through slab allocation
31+
- Statistics tracking for debugging and profiling
32+
33+
### Documentation
34+
- Complete API documentation with examples
35+
- README with bilingual (English/Chinese) documentation
36+
- Inline documentation for all public APIs
37+
38+
### Testing
39+
- Integration tests for page allocator
40+
- Integration tests for slab allocator
41+
- Integration tests for global allocator
42+
- DMA32 pages test cases
43+
- Comprehensive edge case coverage
44+
45+
## [Unreleased]: https://github.com/arceos-hypervisor/buddy-slab-allocator/compare/v0.1.0...HEAD
46+
## [0.1.0]: https://github.com/arceos-hypervisor/buddy-slab-allocator/releases/tag/v0.1.0

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
name = "buddy-slab-allocator"
33
version = "0.1.0"
44
edition = "2021"
5-
authors = ["Song Zhiyong <songzhy30@qq.com>"]
5+
authors = ["Song Zhiyong <songzhyo@qq.com>"]
66
description = "Memory allocator with Buddy and Slab allocation"
7-
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0"
7+
documentation = "https://docs.rs/buddy-slab-allocator"
8+
repository = "https://github.com/arceos-hypervisor/buddy-slab-allocator"
9+
readme = "README.md"
10+
license = "Apache-2.0"
11+
keywords = ["buddy", "slab", "allocator"]
12+
categories = ["memory-management", "no-std", "embedded"]
813

914
[features]
1015
default = []

0 commit comments

Comments
 (0)