#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct ThreadLocalAllocatorConfiguration
{
pub heap_size: NonZeroU64,
pub inclusive_maximum_bytes_wasted: u64,
pub strict_numa_memory_policy: bool,
pub block_size_hint: NonZeroUsize,
}
impl Default for ThreadLocalAllocatorConfiguration
{
#[inline(always)]
fn default() -> Self
{
Self
{
heap_size: new_non_zero_u64(1024 * 1024 * 1024),
inclusive_maximum_bytes_wasted: 0,
strict_numa_memory_policy: false,
block_size_hint: new_non_zero_usize(64),
}
}
}
impl ThreadLocalAllocatorConfiguration
{
#[inline(always)]
pub fn mapped_memory_settings(&self, defaults: &DefaultHugePageSizes) -> MappedMemorySettings
{
let mapped_memory_configuration = MappedMemoryConfiguration
{
address_hint: AddressHint::any(),
protection: Protection::ReadWrite,
sharing: Sharing::Private,
page_size_preference: self.page_size_preference(defaults),
prefault: true,
reserve_swap_space: false,
numa_memory_policy: self.numa_memory_policy(),
lock: Some(MemoryLockSettings::Normal),
advice: fast_secure_hash_set!
{
MemoryAdvice::DontFork
},
};
mapped_memory_configuration.into_settings(defaults)
}
#[inline(always)]
fn page_size_preference(&self, defaults: &DefaultHugePageSizes) -> PageSizePreference
{
use self::PageSizePreference::*;
match defaults.best_fit_huge_page_size_if_any(self.heap_size.get(), self.inclusive_maximum_bytes_wasted)
{
None => DefaultPageSize,
Some(huge_page_size) => PreferredHugePageSize(huge_page_size),
}
}
#[inline(always)]
fn numa_memory_policy(&self) -> Option<(SetMemoryPolicy, SetMemoryPolicyStrictness)>
{
use self::SetMemoryPolicyStrictness::*;
if self.strict_numa_memory_policy
{
Some((SetMemoryPolicy::BindCurrent(), SetPolicyAndMovePagesOrFail))
}
else
{
Some((SetMemoryPolicy::Local, JustSetPolicy))
}
}
}