SteinsOS is an OS targeting single-core
armv8-a written in Rust including these features:
This document will focus on the design of SteinsOS. If you want to learn
operating system principles, please refer to these resources:
Because in Rust, if we want to use alloc
crate, which has tons of excellent modules like vec
, string
, we must have a memory allocator.
SteinsOS has two kinds of buddy allocator. The first one is buddy allocator.
The buddy allocator in SteinsOS has eleven orders of memory blocks, range from 0 to 10, managed with linked list. Please refer to source code for further details. It's not complicated ;)
The other memory allocator in SteinsOS is slab allocator.
Some of you may be confused, and a question may come to your mind:
Why another memory allocator ?
Cause buddy allocator allocates memory in units of 4K bytes. That's a waste of memory if we just want 24 bytes. So, we need a "small memory allocator". That's what slab allocator does.
It asks a page from buddy allocator, divides it into a smaller size, manages it with linked list.
When being asked for memory, slab will check whether the size is too big or not. If so, it will propagate the request to buddy allocator:
Otherwise, it rounds up the requested size to the minimum size we have:
And return the result:
Buddy allocator is "big memory allocator", it manages memory in units of 4K bytes; Slab allocator is "small memory allocator", it manages memory with size range from 8 bytes to 1024 bytes.
to be continued…