Skip to main content

Config

Struct Config 

Source
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

Source

pub const fn new() -> Self

The defaults are 64 GiB of address space, 4096 heaps, lazy commit, and transparent huge pages on Linux.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn commit(self, commit: Commit) -> Self

Sets how eagerly the region is backed by physical memory.

Source

pub const fn capacity_bytes(&self) -> usize

The configured region size in bytes.

Source

pub const fn heap_count(&self) -> usize

The configured number of heaps.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Config

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Forget for Config

§

impl Freeze for Config

§

impl Move for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnsafeUnpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.