Crate vmem

source ·
Expand description

§What is this?

Vmem is a resource management system theorized by Jeff Bonwick and Jonathan Adams in Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources. It provides O(1) allocation and deallocation of any opaque numerical “resource,” such as a block of memory or a process ID.

This particular implementation provides a safe vmem allocator for use inside of my custom kernel, velvet. I am additionally submitting it as my AP Computer Science Principles Create Task. It aims to conform exactly to the spec laid out in the aformentioned paper, however, some changes may have been made for pure practicality.

§What’s missing?

Quantum caches were left out of this implementation because they would be more easily implemented inside of a more specific heap allocator. However, it is still recommended to cache allocations, especially on arenas which are used as sources.

Additionally, constrained allocations with AllocPolicy::NextFit are not supported, simply because this is not incredibly useful, despite taking a non-trivial amount of work to implement.

§Crate features

§References

This crate was written with reference to xvanc’s Rust implementation, as well as the NetBSD C implementation it references. No code was directly copied, and any found issues were corrected. Both of the above implementations were designed to be placed inside of the kernel that they were written for. In contrast, this implementation is designed to work in nearly any environment (it even works in userspace, as seen in the tests!)

§Reporting issues

If you find any issues with this crate, including bugs, memory leaks, panics (other than the one listed for xalloc below), or undefined behavior, please open an issue on the GitHub repository.

§Licensing

This crate is licensed under your choice of either of the MIT or Apache 2.0 licenses.

Modules§

  • Allocation-related traits
  • Error types used across the crate.
  • Special layouts for constrained allocations.
  • Locking traits and implementations.

Structs§

  • A vmem arena.
  • A boundary tag.
  • A layout for a constrained allocation. See functions for more details.

Enums§

  • An allocation policy.
  • An error returned from a function in this crate.

Traits§

  • A generic allocator for boundary tags
  • A trait for types that can be used as locks.
  • Something that can be used as a source for an arena. See Arena for more details.

Type Aliases§