#[derive(Default, Debug, Clone, Eq, PartialEq)]
#[derive(Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct GlobalMemoryConfiguration
{
pub same_page_merging: GlobalLinuxKernelSamePageMergingConfiguration,
pub transparent_huge_pages: Option<GlobalTransparentHugePagesConfiguration>,
pub swap: GlobalSwapConfiguration,
pub out_of_memory: GlobalOutOfMemoryConfiguration,
pub numa_memory_balancing: Option<GlobalNumaBalancingConfiguration>,
pub numa_reclaim: GlobalNumaMemoryReclaimConfiguration,
pub statistics: GlobalMemoryStatisticsConfiguration,
pub compact_unevictable_allowed: Option<bool>,
pub signal_using_SIGBUS_all_processes_affected_by_a_memory_check_failure: Option<bool>,
pub per_hyper_thread_page_list_fraction: Option<Option<NonZeroU8>>,
}
impl GlobalMemoryConfiguration
{
#[inline(always)]
pub fn configure(&self, sys_path: &SysPath, proc_path: &ProcPath) -> Result<(), GlobalMemoryConfigurationError>
{
use self::GlobalMemoryConfigurationError::*;
self.same_page_merging.configure(sys_path)?;
if let Some(ref transparent_huge_pages) = self.transparent_huge_pages
{
transparent_huge_pages.configure(sys_path)?;
}
self.swap.configure(proc_path)?;
self.out_of_memory.configure(proc_path)?;
if let Some(ref numa_memory_balancing) = self.numa_memory_balancing
{
numa_memory_balancing.configure(proc_path)?;
}
self.numa_reclaim.configure(proc_path)?;
self.statistics.configure(proc_path)?;
set_proc_sys_vm_value(proc_path, "compact_unevictable_allowed", self.compact_unevictable_allowed, CouldNotChangeCompactUnevictableAllowed)?;
set_proc_sys_vm_value(proc_path, "memory_failure_early_kill", self.signal_using_SIGBUS_all_processes_affected_by_a_memory_check_failure, CouldNotChangeSignalOnMemoryCheckFailure)?;
self.configure_per_hyper_thread_page_list_fraction(proc_path)?;
Ok(())
}
#[inline(always)]
fn configure_per_hyper_thread_page_list_fraction(&self, proc_path: &ProcPath) -> Result<(), GlobalMemoryConfigurationError>
{
if let Some(per_hyper_thread_page_list_fraction) = self.per_hyper_thread_page_list_fraction
{
let value = match per_hyper_thread_page_list_fraction
{
None => 0,
Some(value) =>
{
let value = value.get();
if value < 8
{
8
}
else
{
8
}
}
};
set_proc_sys_vm_value(proc_path, "percpu_pagelist_fraction", Some(UnpaddedDecimalInteger(value)), GlobalMemoryConfigurationError::CouldNotChangePerHyperThreadPageListFraction)
}
else
{
Ok(())
}
}
}