Skip to content

Commit

Permalink
chore(hugepage): add 1GB Hugepage checking
Browse files Browse the repository at this point in the history
In some enviroment, Hugepage is enabled on size 1GB.

Signed-off-by: Liu Xiaodong <[email protected]>
  • Loading branch information
dong-liuliu committed May 13, 2022
1 parent 7ecb3b8 commit a162431
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions mayastor/src/bin/mayastor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,51 @@ fn start_tokio_runtime(args: &MayastorCliArgs) {
});
}

fn hugepage_check() {
let hugepage_path = Path::new("/sys/kernel/mm/hugepages/hugepages-2048kB");
fn hugepage_get_nr(hugepage_path: &Path) -> (u32, u32) {
let nr_pages: u32 = sysfs::parse_value(hugepage_path, "nr_hugepages")
.expect("failed to read the number of pages");
let free_pages: u32 = sysfs::parse_value(hugepage_path, "free_hugepages")
.expect("failed to read the number of free pages");
if nr_pages < PAGES_NEEDED {
error!(?PAGES_NEEDED, ?nr_pages, "insufficient pages available");

(nr_pages, free_pages)
}

fn hugepage_check() {
let (nr_pages, free_pages) =
hugepage_get_nr(Path::new("/sys/kernel/mm/hugepages/hugepages-2048kB"));
let (nr_1g_pages, free_1g_pages) = hugepage_get_nr(Path::new(
"/sys/kernel/mm/hugepages/hugepages-1048576kB",
));

if nr_pages + nr_1g_pages * 512 < PAGES_NEEDED {
error!(
?PAGES_NEEDED,
?nr_pages,
?nr_1g_pages,
"insufficient pages available"
);
if !cfg!(debug_assertions) {
std::process::exit(1)
}
}

if free_pages < PAGES_NEEDED {
if free_pages + free_1g_pages * 512 < PAGES_NEEDED {
error!(
?PAGES_NEEDED,
?nr_pages,
?free_pages,
?free_1g_pages,
"insufficient free pages available"
);
if !cfg!(debug_assertions) {
std::process::exit(1)
}
}

info!("free_pages: {} nr_pages: {}", free_pages, nr_pages);
info!("free_pages 2MB: {} nr_pages 2MB: {}", free_pages, nr_pages);
info!(
"free_pages 1GB: {} nr_pages 1GB: {}",
free_1g_pages, nr_1g_pages
);
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down

0 comments on commit a162431

Please sign in to comment.