Skip to content

Commit 28365b2

Browse files
committed
2022-07 allocator comparison
1 parent 3f781c2 commit 28365b2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

content/this-month/2022-07/index.md

+31
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,37 @@ If you maintain a Rust project related to operating system development and are l
6060

6161
In this section, we describe updates to Rust OS projects that are not directly related to the `rust-osdev` organization. Feel free to [create a pull request](https://github.com/rust-osdev/homepage/pulls) with the updates of your OS project for the next post.
6262

63+
### Comparison between [`phip1611/simple-chunk-allocator`](https://github.com/phip1611/simple-chunk-allocator) and [`rust-osdev/linked-list-allocator`](https://github.com/rust-osdev/linked-list-allocator)
64+
65+
<span class="gray">(Section written by [@phip1611](https://github.com/phip1611))</span>
66+
67+
In March 2022, Philipp Schuster proposed his [`simple-chunk-allocator`](https://github.com/phip1611/simple-chunk-allocator)
68+
crate. It focuses on being a very simple-to-use general purpose allocator that "just works" for various workloads
69+
in `no_std` context. However, there are other allocators, such as [`rust-osdev/linked-list-allocator`](https://github.com/rust-osdev/linked-list-allocator).
70+
When you choose an allocator, you should not only consider the API and how to set it up, but actually the runtime
71+
characteristics. OS research has shown us that there is no perfect allocator. You can optimize an allocator for speed,
72+
memory utilization (i.e., prevent fragmentation), code simplicity, and worst case execution time. There exist different
73+
strategies to reach those goals: first-fit, next-fit, best-fit
74+
75+
Recently, Philipp benchmarked his `simple-chunk-allocator` against [`rust-osdev/linked-list-allocator`](https://github.com/rust-osdev/linked-list-allocator)
76+
to learn under which conditions which performs better. But at first, let's point out some differences. `simple-chunk-allocator` needs
77+
a static backing storage for heap and an additional static backing storage for its internal bookkeeping. `linked-list-allocator`
78+
can solve this better by organizing the heap with the heap backing memory itself. `simple-chunk-allocator` uses a slightly
79+
adjusted variant of best-fit that tries to reduce fragmentation. `linked-list-allocator` is a first-fit allocator that
80+
has a lower performance to more heap is used.
81+
82+
The relevant outcome is that `simple-chunk-allocator` always outperforms `linked-list-allocator` in median allocation time.
83+
For stress tests with a low heap consumption, thus, no long stress test with 90% and more heap usage, `simple-chunk-allocator`
84+
also outperforms `linked-list-allocator` in average allocation time. However, if the heap is full and frequent allocations
85+
happen, the average (but not the median) allocation time of `linked-list-allocator` is better. Also, `linked-list-allocator`
86+
can come close to 100% heap usage which is not the case for `simple-chunk-allocator`, because it suffers from internal
87+
fragmentation under certain circumstances. Last but not least, even small allocations always takes up a multiple of the
88+
used chunk size in `simple-chunk-allocator`.
89+
90+
In the end, there is no optimal allocator. You must choose which properties are more relevant for your scenario.
91+
For concrete measurements, please head to the README of [`simple-chunk-allocator`](https://github.com/phip1611/simple-chunk-allocator).
92+
93+
6394
### [`phil-opp/blog_os`](https://github.com/phil-opp/blog_os)
6495

6596
<span class="gray">(Section written by [@phil-opp](https://github.com/phil-opp))</span>

0 commit comments

Comments
 (0)