#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[repr(i32)]
pub enum PageCluster
{
Off = 0,
#[serde(rename = "2")] TwoPages = 1,
#[serde(rename = "4")] FourPages = 2,
#[serde(rename = "8")] EightPages = 3,
#[serde(rename = "16")] SixteenPages = 4,
#[serde(rename = "32")] ThirtyTwoPages = 5,
#[serde(rename = "64")] SixtyFourPages = 6,
#[serde(rename = "128")] OneHundredAndTwentyEightPages = 7,
#[serde(rename = "256")] TwoHunderedAndFiftySixPages = 8,
#[serde(rename = "512")] FiveHundredAndTwelvePages = 9,
}
impl Default for PageCluster
{
#[inline(always)]
fn default() -> Self
{
PageCluster::EightPages
}
}
impl PageCluster
{
#[inline(always)]
pub fn read(proc_path: &ProcPath) -> io::Result<Either<Self, i32>>
{
use self::PageCluster::*;
let file_path = Self::file_path(proc_path);
let common = match file_path.read_value()?
{
0 => Off,
1 => TwoPages,
2 => FourPages,
3 => EightPages,
4 => SixteenPages,
5 => ThirtyTwoPages,
6 => SixtyFourPages,
7 => OneHundredAndTwentyEightPages,
8 => TwoHunderedAndFiftySixPages,
9 => FiveHundredAndTwelvePages,
other @ _ => return Ok(Right(other)),
};
Ok(Left(common))
}
#[inline(always)]
pub fn write(self, proc_path: &ProcPath) -> io::Result<()>
{
assert_effective_user_id_is_root("write /proc/sys/vm/page-cluster");
let file_path = Self::file_path(proc_path);
if file_path.exists()
{
file_path.write_value(UnpaddedDecimalInteger(self as i32))
}
else
{
Ok(())
}
}
#[inline(always)]
fn file_path(proc_path: &ProcPath) -> PathBuf
{
proc_path.sys_vm_file_path("page-cluster")
}
}