Skip to content

Commit 2bb7175

Browse files
authored
Merge pull request #219 from mkroening/free-list
2024-05: add `mkroening/free-list`
2 parents 7849815 + 431cbb7 commit 2bb7175

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

content/this-month/2024-05/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ In this section, we describe updates to Rust OS projects that are not directly r
7676
-->
7777

7878

79+
### [`mkroening/free-list`](https://github.com/mkroening/free-list)
80+
<span class="maintainers">(Section written by [@mkroening](https://github.com/mkroening))</span>
81+
82+
The `free-list` crate provides the `FreeList` type for managing virtual or physical memory.
83+
Opposed to normal memory allocators, `FreeList` does not use pointers but page ranges.
84+
It operates by keeping a list of free page ranges (hence the name) and allows allocating at user-provided ranges.
85+
Instead of operating directly on the unallocated memory through a linked list, this free list uses statically allocated memory before dynamically allocating more memory to hold its elements.
86+
87+
```rust
88+
use free_list::{FreeList, PageLayout};
89+
90+
let mut free_list = FreeList::<16>::new();
91+
92+
unsafe {
93+
free_list.deallocate((0x1000..0x5000).try_into().unwrap()).unwrap();
94+
}
95+
assert_eq!(free_list.free_space(), 0x4000);
96+
97+
let layout = PageLayout::from_size(0x4000).unwrap();
98+
assert_eq!(free_list.allocate(layout).unwrap(), (0x1000..0x5000).try_into().unwrap());
99+
```
100+
101+
79102
## Join Us?
80103

81104
Are you interested in Rust-based operating system development? Our `rust-osdev` organization is always open to new members and new projects. Just let us know if you want to join! A good way for getting in touch is our [Zulip chat](https://rust-osdev.zulipchat.com).

0 commit comments

Comments
 (0)