From 93a59571e37dfd11fe53a783db0d9e4c026e215c Mon Sep 17 00:00:00 2001 From: Greg Kurz Date: Fri, 10 Mar 2023 07:32:08 +0100 Subject: [PATCH] Fix HugeTlbController::limit_in_bytes() for v2 With Cgroups v2, the file to use is "max", not "limit_in_bytes". Fixes #112 Signed-off-by: Greg Kurz --- src/hugetlb.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hugetlb.rs b/src/hugetlb.rs index 1ccc9ee..a174c66 100644 --- a/src/hugetlb.rs +++ b/src/hugetlb.rs @@ -138,8 +138,11 @@ impl HugeTlbController { /// Get the limit (in bytes) of how much memory can be backed by hugepages of a certain size /// (`hugetlb_size`). pub fn limit_in_bytes(&self, hugetlb_size: &str) -> Result { - self.open_path(&format!("hugetlb.{}.limit_in_bytes", hugetlb_size), false) - .and_then(read_u64_from) + let mut file_name = format!("hugetlb.{}.limit_in_bytes", hugetlb_size); + if self.v2 { + file_name = format!("hugetlb.{}.max", hugetlb_size); + } + self.open_path(&file_name, false).and_then(read_u64_from) } /// Get the current usage of memory that is backed by hugepages of a certain size