Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiered allocators #73

Open
hawkw opened this issue Jan 30, 2017 · 1 comment
Open

Tiered allocators #73

hawkw opened this issue Jan 30, 2017 · 1 comment
Assignees
Labels
area/alloc Area: this issue concerns memory allocation. area/kernel Area: this issue relates to the core kernel. kind/feature Kind: this issue is a feature. kind/refactor Kind: this issue describes refactoring or code quality improvement.

Comments

@hawkw
Copy link
Member

hawkw commented Jan 30, 2017

As I rewrite the kernel memory allocator, I should think about incorporating some notion of tiering. We could start with a simple bump pointer allocator early in the init process, and use that for allocating heap objects that live as long as the kernel does (and will never need to be deallocated), and wait to set up the buddy-block allocator until after we've remapped the kernel into the higher address space (since the buddy allocator seems to break occasionally when our paging setup is incomplete).

There's precedent for this sort of tiered allocation scheme; the Linux kernel starts out with a bump pointer allocator at boot time.

We could use an enum to encode one-way allocator state transitions in the type system, so that once the system allocator has been upgraded to the buddy-block allocator, there's no way for it to "go back".

In addition to tiering the system allocator for Rust collections, we should be able to compose slab allocators on top of the main allocator, for constructing specific object types. We should use these slab allocators for kernel objects that we need to allocate a large number of.

@hawkw hawkw added kind/feature Kind: this issue is a feature. area/kernel Area: this issue relates to the core kernel. kind/refactor Kind: this issue describes refactoring or code quality improvement. labels Jan 30, 2017
@hawkw hawkw self-assigned this Jan 30, 2017
@hawkw
Copy link
Member Author

hawkw commented Jan 31, 2017

Alternative: placement expressions

Another option is to look into using the placement expressions feature (rust-lang/rust#27779) to control where objects are allocated. Rather than making the bump pointer allocator a system allocator that links with the allocator lang items, we could explicitly use it to allocate objects using placement expressions.

Pros & Cons

  • Makes where objects are allocated explicit at the call site (:thumbsup:)
    • rather than just using heap-allocated objects and assuming that the allocator crate will put them in the right place, using placement expressions makes allocations explicit in the code that does the allocating. this would help make our code easier to read and conveys more intent.
  • Getting to use a cool new language feature (:thumbsup:)
  • Having to deal with an unstable new API (:thumbsdown:)
    • This is the flip side of the previous point
  • Wouldn't have to mutate a global static as much (:thumbsup:)

Even if we do still use tiered allocators for the system allocator, we might still want to look into using placement expressions for the kernel slab allocators...

More information

@hawkw hawkw added the area/alloc Area: this issue concerns memory allocation. label Mar 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alloc Area: this issue concerns memory allocation. area/kernel Area: this issue relates to the core kernel. kind/feature Kind: this issue is a feature. kind/refactor Kind: this issue describes refactoring or code quality improvement.
Projects
None yet
Development

No branches or pull requests

1 participant