2 releases

Uses old Rust 2015

0.1.1 Sep 3, 2017
0.1.0 Sep 3, 2017

#42 in #slab

Apache-2.0

235KB
4K SLoC

slab-alloc

The slab allocator. This crate implements an allocator whose design is based on Jeff Bonwick's The Slab Allocator: An Object-Caching Kernel Memory Allocator.

The slab allocator is an object allocator - it allocates and caches objects of a fixed type, and provides performance improvements over a general-purpose allocator. The allocator types in this crate implement the ObjectAlloc and UntypedObjectAlloc traits defined in the object-alloc crate. The slab allocator implemented in this crate is currently single-threaded and cannot be accessed concurrently.


lib.rs:

An ObjectAlloc which allocates objects in contiguous slabs and caches constructed objects.

Design

The SlabAlloc is based largely on the slab allocator design originally inroduced in the SunOS 5.4 kernel and described in depth in The Slab Allocator: An Object-Caching Kernel Memory Allocator. This implementation stays somewhat true to the original design, although it includes a number of performance improvements and modifications for user-land.

The SlabAlloc provides a number of performance benefits:

  • As with any ObjectAlloc, object caching reduces the overhead of object initialization in many cases.
  • As with any ObjectAlloc, only needing to allocate objects of a particular size and alignment allows for optimizations not available to general-purpose allocators.
  • Internal and external fragmentation are kept to a minimum.
  • A "coloring" scheme described in Section 4 of the original paper improves cache utilization.

Dependencies

~0.8–1MB
~17K SLoC