Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "allocator"
version = "0.1.2"
name = "axallocator"
version = "0.2.0"
edition = "2021"
authors = ["Yuekai Jia <equation618@gmail.com>"]
authors = [
"Yuekai Jia <equation618@gmail.com>",
"Yu Chen <yuchen@tsinghua.edu.cn>",
]
description = "Various allocator algorithms in a unified interface"
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0"
homepage = "https://github.com/arceos-org/arceos"
repository = "https://github.com/arceos-org/allocator"
documentation = "https://arceos-org.github.io/allocator"
repository = "https://github.com/arceos-org/axallocator"
readme = "README.md"

[features]
default = ["page-alloc-256m"]
Expand All @@ -16,7 +19,7 @@ full = ["bitmap", "tlsf", "slab", "buddy", "allocator_api", "page-alloc-256m"]
bitmap = ["dep:bitmap-allocator"]

tlsf = ["dep:rlsf"]
slab = ["dep:slab_allocator"]
slab = ["dep:ax_slab_allocator"]
buddy = ["dep:buddy_system_allocator"]

allocator_api = []
Expand All @@ -33,11 +36,11 @@ axerrno = { version = "0.1", optional = true }
cfg-if = "1.0"
rlsf = { version = "0.2", optional = true }
buddy_system_allocator = { version = "0.10", default-features = false, optional = true }
slab_allocator = { git = "https://github.com/arceos-org/slab_allocator.git", tag = "v0.3.1", optional = true }
ax_slab_allocator = { version = "0.4", optional = true }
bitmap-allocator = { version = "0.2", optional = true }

[dev-dependencies]
allocator = { path = ".", features = ["full"] }
axallocator = { path = ".", features = ["full"] }
rand = { version = "0.8", features = ["small_rng"] }
criterion = { version = "0.5", features = ["html_reports"] }

Expand Down
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This crate is licensed under any of:

- GPL-3.0-or-later https://spdx.org/licenses/GPL-3.0-or-later.html
- Apache-2.0 https://spdx.org/licenses/Apache-2.0.html
- MulanPSL-2.0 https://spdx.org/licenses/MulanPSL-2.0.html

at your option.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# axallocator

[![Crates.io](https://img.shields.io/crates/v/axallocator.svg?style=flat-square)](https://crates.io/crates/axallocator)
[![Documentation](https://docs.rs/axallocator/badge.svg?style=flat-square)](https://docs.rs/axallocator)
[![License](https://img.shields.io/crates/l/axallocator.svg?style=flat-square)](https://crates.io/crates/axallocator)

Various allocator algorithms behind a unified interface for `no_std` environments.

## Allocator types

- **Byte-granularity**: [`BuddyByteAllocator`], [`SlabByteAllocator`], [`TlsfByteAllocator`]
- **Page-granularity**: [`BitmapPageAllocator`]
- **ID allocator**: [`IdAllocator`]

[`BuddyByteAllocator`]: https://docs.rs/axallocator/latest/axallocator/struct.BuddyByteAllocator.html
[`SlabByteAllocator`]: https://docs.rs/axallocator/latest/axallocator/struct.SlabByteAllocator.html
[`TlsfByteAllocator`]: https://docs.rs/axallocator/latest/axallocator/struct.TlsfByteAllocator.html
[`BitmapPageAllocator`]: https://docs.rs/axallocator/latest/axallocator/struct.BitmapPageAllocator.html
[`IdAllocator`]: https://docs.rs/axallocator/latest/axallocator/trait.IdAllocator.html

## Features

| Feature | Description |
| --------------- | ---------------------------------------------- |
| `bitmap` | Bitmap-based page allocator |
| `tlsf` | TLSF byte allocator |
| `slab` | Slab byte allocator (uses `ax_slab_allocator`) |
| `buddy` | Buddy byte allocator |
| `allocator_api` | Implement `Allocator` (nightly) |
| `page-alloc-*` | Page size / range (e.g. `page-alloc-256m`) |
| `axerrno` | `AxError` integration |

Default: `page-alloc-256m`. Use `full` for all allocators and `allocator_api`.

## Usage

```toml
[dependencies]
axallocator = { version = "0.2", features = ["slab", "buddy"] }
```

## License

GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0. See [LICENSE](LICENSE).
7 changes: 4 additions & 3 deletions src/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
//!
//! TODO: comments

use super::{AllocError, AllocResult, BaseAllocator, ByteAllocator};
use ax_slab_allocator::Heap;
use core::alloc::Layout;
use core::ptr::NonNull;
use slab_allocator::Heap;

use super::{AllocError, AllocResult, BaseAllocator, ByteAllocator};

/// A byte-granularity memory allocator based on the [slab allocator].
///
/// [slab allocator]: ../slab_allocator/index.html
/// [slab allocator]: https://docs.rs/ax_slab_allocator
pub struct SlabByteAllocator {
inner: Option<Heap>,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::alloc::{Allocator, Layout};
use std::collections::BTreeMap;
use std::io::Write;

use allocator::{AllocatorRc, BuddyByteAllocator, SlabByteAllocator, TlsfByteAllocator};
use axallocator::{AllocatorRc, BuddyByteAllocator, SlabByteAllocator, TlsfByteAllocator};
use rand::{prelude::SliceRandom, Rng};

const POOL_SIZE: usize = 1024 * 1024 * 128;
Expand Down