pub struct Config { /* private fields */ }Expand description
Region settings. Every method is const, so a configuration can sit in a static.
use bcmalloc::{Commit, Config};
// A fixed 256 MiB heap that is fully resident and pinned, so allocation never page faults.
const CONFIG: Config = Config::new().capacity(256 << 20).max_heaps(64).commit(Commit::Lock);
assert_eq!(CONFIG.capacity_bytes(), 256 << 20);Implementations§
Source§impl Config
impl Config
Sourcepub const fn new() -> Self
pub const fn new() -> Self
The defaults are 64 GiB of address space, 4096 heaps, lazy commit, and transparent huge pages on Linux.
Sourcepub const fn capacity(self, bytes: usize) -> Self
pub const fn capacity(self, bytes: usize) -> Self
Sets the size of the managed region in bytes, rounded down to a multiple of 64 KiB.
This is a hard limit and allocations fail once it is used up. It is only address space until memory is touched, so a generous value costs little.
Sourcepub const fn max_heaps(self, heaps: usize) -> Self
pub const fn max_heaps(self, heaps: usize) -> Self
Sets how many threads get a heap of their own.
Each running thread holds one heap. Through Bcmalloc, threads past
this many share a few spare heaps, one call at a time, which is slower, and a
Region used directly hands out no more heaps than this. Set it to the
most threads the program runs at once, with some room to spare.
Sourcepub const fn huge_pages(self, enabled: bool) -> Self
pub const fn huge_pages(self, enabled: bool) -> Self
Asks Linux to back part of the region with transparent huge pages, which is the default there. Other platforms ignore it.
Huge pages cut the cost of address translation for programs whose working set is larger than the TLB covers with small pages. Only heaps that have grown past a threshold, and blocks of 2 MiB or more, take memory from them, and it goes back to the system one whole 2 MiB page at a time.
Sourcepub const fn numa(self, enabled: bool) -> Self
pub const fn numa(self, enabled: bool) -> Self
Splits the region into one part per NUMA node on Linux machines with more than one, which is the default. Each part prefers the memory of its node, and a heap takes its slabs from the part of the node its thread started on, so that a thread’s memory is local to it. Other platforms and single-node machines ignore it.
Sourcepub const fn commit(self, commit: Commit) -> Self
pub const fn commit(self, commit: Commit) -> Self
Sets how eagerly the region is backed by physical memory.
Sourcepub const fn capacity_bytes(&self) -> usize
pub const fn capacity_bytes(&self) -> usize
The configured region size in bytes.
Sourcepub const fn heap_count(&self) -> usize
pub const fn heap_count(&self) -> usize
The configured number of heaps.