From b1013a976d9bbcfb38275f927b9480229d87d123 Mon Sep 17 00:00:00 2001 From: mcasquer Date: Wed, 18 Dec 2024 10:56:01 +0100 Subject: [PATCH] hugepage_reset: Test compatible with different NUMA topologies As the test will set 8 hugepages, this works fine for systems with 2 NUMA nodes, having e.g. 8 nodes is going to lead the on_numa_node variant to fail since the binded node doesn't have enough hugepages. As the cfg already suggests to allocate 1G hugepages on boot time, let's make user decision how many hugepages allocate, adding an informative comment in the cfg as well. Finally, if system hugepage_size is 1GB, allocates at runtime enough hugepages in all valid nodes. Signed-off-by: mcasquer --- qemu/tests/cfg/hugepage_reset.cfg | 6 ++++-- qemu/tests/hugepage_reset.py | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/qemu/tests/cfg/hugepage_reset.cfg b/qemu/tests/cfg/hugepage_reset.cfg index a2c80c9ed6..db6da8c47a 100644 --- a/qemu/tests/cfg/hugepage_reset.cfg +++ b/qemu/tests/cfg/hugepage_reset.cfg @@ -4,8 +4,10 @@ pre_command = 'echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory' mem = 4096 origin_nr = 8 - # Please set hugepage in kernel command line before this test: - # default_hugepagesz=1G hugepagesz=1G hugepages=8 + # Please allocate enough hugepages at boot time for this test. + # IMPORTANT! Keep in mind the system memory and the number of NUMA nodes + # to decide how many hugepages are needed to be allocated. + # Example: default_hugepagesz=1G hugepagesz=1G hugepages=24 expected_hugepage_size = 1048576 Windows: x86_64: diff --git a/qemu/tests/hugepage_reset.py b/qemu/tests/hugepage_reset.py index 16ba88cf15..0f02333de6 100644 --- a/qemu/tests/hugepage_reset.py +++ b/qemu/tests/hugepage_reset.py @@ -21,6 +21,24 @@ def run(test, params, env): :param env: Dictionary with the test environment. """ + def allocate_largepages_per_node(): + """ + The functions is inteded to set 1G hugepages per NUMA + node when the system has four or more of these nodes. + For this function to work the hugepage size should be 1G. + This way a QEMU failure could be avoided if it's unable + to allocate memory. + """ + node_list = host_numa_node.online_nodes_withcpumem + if len(node_list) >= 4: + for node in node_list: + node_mem_free = int( + host_numa_node.read_from_node_meminfo(node, "MemFree") + ) + mem_kb = mem * 1024 + if node_mem_free > mem_kb: + hp_config.set_node_num_huge_pages(4, node, "1048576") + def set_hugepage(): """Set nr_hugepages""" try: @@ -107,9 +125,9 @@ def heavyload_install(): "No node on your host has sufficient free memory for " "this test." ) hp_config = test_setup.HugePageConfig(params) + if params.get("on_numa_node"): + allocate_largepages_per_node() hp_config.target_hugepages = origin_nr - test.log.info("Setup hugepage number to %s", origin_nr) - hp_config.setup() hugepage_size = utils_memory.get_huge_page_size() params["hugepage_path"] = hp_config.hugepage_path params["start_vm"] = "yes"