Skip to content

Commit

Permalink
Merge pull request #3998 from liang-cong-red-hat/virttest_setup_enhan…
Browse files Browse the repository at this point in the history
…ce_hugepage_allocation

Add huge page allocation checking
  • Loading branch information
dzhengfy authored Sep 10, 2024
2 parents 22b34aa + 1d027e8 commit accb025
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions virttest/test_setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,33 @@ def get_kernel_hugepages(self, pagesize, type="total"):
obj = kernel_interface.SysFS(pgfile)
return obj.sys_fs_value

def set_kernel_hugepages(self, pagesize, pagenum):
def set_kernel_hugepages(self, pagesize, pagenum, ignore_error=True):
"""
Let kernel allocate some specific hugepages at runtime
write page number to
/sys/kernel/mm/hugepages/hugepages-${pagesize}kB/nr_hugepages
:param pagesize: string or int, page size in kB
:param pagenum: page number
:param pagenum: string or int, page number
:param ignore_error: boolean, True, not raise exception when failing
:return: boolean, False if huge page number is less than pagenum,
otherwise, True
"""
pgfile = "%s/hugepages-%skB/nr_hugepages" % (self.pool_path, pagesize)

obj = kernel_interface.SysFS(pgfile)
obj.sys_fs_value = pagenum
if obj.sys_fs_value < int(pagenum):
error_msg = (
"Only allocated %d pages %skiB huge pages, "
"but requried %s" % (obj.sys_fs_value, pagesize, pagenum)
)
if not ignore_error:
raise exceptions.TestSetupFail(error_msg)
else:
LOG.warning(error_msg)
return False
return True

def get_node_num_huge_pages(self, node, pagesize, type="total"):
"""
Expand Down

0 comments on commit accb025

Please sign in to comment.