use crate::chunks::CHUNK_SIZE;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Commit {
#[default]
Lazy,
Populate,
Lock,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Config {
capacity: usize,
max_heaps: usize,
huge_pages: bool,
numa: bool,
commit: Commit,
}
impl Config {
pub const fn new() -> Self {
Self {
capacity: 64 << 30,
max_heaps: 4096,
huge_pages: cfg!(target_os = "linux"),
numa: true,
commit: Commit::Lazy,
}
}
#[must_use]
pub const fn capacity(mut self, bytes: usize) -> Self {
self.capacity = bytes / CHUNK_SIZE * CHUNK_SIZE;
self
}
#[must_use]
pub const fn max_heaps(mut self, heaps: usize) -> Self {
self.max_heaps = heaps;
self
}
#[must_use]
pub const fn huge_pages(mut self, enabled: bool) -> Self {
self.huge_pages = enabled;
self
}
#[must_use]
pub const fn numa(mut self, enabled: bool) -> Self {
self.numa = enabled;
self
}
#[must_use]
pub const fn commit(mut self, commit: Commit) -> Self {
self.commit = commit;
self
}
pub const fn capacity_bytes(&self) -> usize {
self.capacity
}
pub const fn heap_count(&self) -> usize {
self.max_heaps
}
pub(crate) const fn wants_huge_pages(&self) -> bool {
self.huge_pages
}
pub(crate) const fn wants_numa(&self) -> bool {
self.numa
}
pub(crate) const fn commit_mode(&self) -> Commit {
self.commit
}
}
impl Default for Config {
fn default() -> Self {
Self::new()
}
}