#![allow(unused_variables)]
use crate::advanced::HugePageSize;
#[inline]
pub fn is_supported() -> bool {
#[cfg(target_os = "linux")]
{
if let Ok(mut file) = File::open("/proc/meminfo") {
let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() {
return contents.contains("HugePages_Total") && !contents.contains("HugePages_Total: 0");
}
}
false
}
#[cfg(windows)]
{
false
}
#[cfg(not(any(target_os = "linux", windows)))]
{
false
}
}
#[inline]
pub fn default_huge_page_size() -> Option<HugePageSize> {
#[cfg(target_os = "linux")]
{
if let Ok(mut file) = File::open("/proc/meminfo") {
let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() {
for line in contents.lines() {
if line.starts_with("Hugepagesize:") {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 2 {
if let Ok(size) = parts[1].parse::<usize>() {
if size >= 1048576 {
return Some(HugePageSize::OneGB);
} else if size >= 2048 {
return Some(HugePageSize::TwoMB);
}
}
}
}
}
}
}
Some(HugePageSize::TwoMB)
}
#[cfg(windows)]
{
Some(HugePageSize::TwoMB)
}
#[cfg(not(any(target_os = "linux", windows)))]
{
None
}
}
#[inline]
pub fn is_1gb_supported() -> bool {
#[cfg(target_os = "linux")]
{
if let Ok(mut file) = File::open("/sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages") {
let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() {
if let Ok(count) = contents.trim().parse::<usize>() {
return count > 0;
}
}
}
false
}
#[cfg(not(target_os = "linux"))]
{
false
}
}