mirror of
https://github.com/JakeHillion/scx.git
synced 2026-12-04 02:30:50 +00:00
Arenas and our c-side allocators allow us to store more complex data
structures. However some of these data structures need to be managed
from Rust side, like mutable configuration. Create an allocator usable
from Rust backed by the arena memory.
This allocator does not directly interoperate with the BPF side
allocator. Instead both we and the bpf side allocator treat
`bpf_arena_alloc_pages` as `mmap`, and allocate separately on top of
this. We'll get some external fragmentation here but it's fine. All
memory allocated in BPF must be free'd in BPF, and all memory allocated
in Rust must be free'd in Rust. We'll work out the semantics of this,
and whether we need a better system for this, with experience.
Implementation is roughly:
- Add syscall progs to the shared `sdt_alloc.c` which expose
`bpf_arena_{,de}alloc_pages` to userspace.
- Write an Allocator trait based on the unstable Rust allocator trait
(we should switch to that eventually).
- Use a crate for a buddy allocator on top of our BPF side allocators to
manage smaller units of memory.
- Implement Allocator for chaos's skel and store this allocator.
This allows us to allocate large amounts of memory in chaos dynamically,
and share pointers between kernel and userspace. It's not yet used to do
anything useful, though has been tested with trivial examples.
Next step is writing some data structures like an equivalent of `Box`
that support our allocator. Once the Allocator interface is out of Rust
nightly we can switch to that and use upstream datastructures, but I'm
not hoping that'll be soon.
Test plan:
- Allocated an arena pointer and copied a string into it. Stored this in
a global in chaos and bpf_printk'd it. It worked!