[PATCH] config_tools: update the hugepage algorithm


Kunhui Li
 

update the hugepages algorithm as the following steps.
1. calculate the total hugepages of service vm using the formula.
"total memory*0.98 - the memory consumed by pre-launched VMs - 5G
-300M*num(number of virtio gpu instance)".
2. calculate hugepage 1G based post-launched vm memory setting.
3. check if the memory configured in post launch VMs is not larger than
the total hugepages.

Compared with the previous version, this patch removes the 2M hugepage
and the correction value, also update the formula of total hugepage.

Tracked-On: #7301
Signed-off-by: Kunhui-Li <kunhuix.li@...>
---
misc/config_tools/static_allocators/memory_allocator.py | 8 ++------
misc/config_tools/xforms/misc_cfg.h.xsl | 2 +-
2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/misc/config_tools/static_allocators/memory_allocator.py b/misc/config_tools/static_allocators/memory_allocator.py
index fd8e0cf88..f47c8d1a0 100644
--- a/misc/config_tools/static_allocators/memory_allocator.py
+++ b/misc/config_tools/static_allocators/memory_allocator.py
@@ -157,9 +157,9 @@ def allocate_hugepages(board_etree, scenario_etree, allocation_etree):
hugepages_1gb = 0
hugepages_2mb = 0
ram_range_info = import_memory_info(board_etree)
- total_hugepages = sum(ram_range_info[i] for i in ram_range_info if i >= 0x100000000)/(1024*1024*1024) \
+ total_hugepages = int(sum(ram_range_info[i] for i in ram_range_info if i >= 0x100000000)*0.98/(1024*1024*1024) \
- sum(int(i) for i in scenario_etree.xpath("//vm[load_order = 'PRE_LAUNCHED_VM']/memory/hpa_region/size_hpa/text()"))/1024 \
- - 4 - 300/1024 * len(scenario_etree.xpath("//virtio_devices/gpu"))
+ - 5 - 300/1024 * len(scenario_etree.xpath("//virtio_devices/gpu")))

post_launch_vms = scenario_etree.xpath("//vm[load_order = 'POST_LAUNCHED_VM']")
if len(post_launch_vms) > 0:
@@ -171,14 +171,10 @@ def allocate_hugepages(board_etree, scenario_etree, allocation_etree):
hugepages_2mb = int(hugepages_2mb + math.ceil(mb * 1024 / 2))

post_vms_memory = sum(int(i) for i in scenario_etree.xpath("//vm[load_order = 'POST_LAUNCHED_VM']/memory/size/text()")) / 1024
- correction_mb, correction_gb = math.modf(total_hugepages - post_vms_memory)
if total_hugepages - post_vms_memory < 0:
logging.warning(f"The sum {post_vms_memory} of memory configured in post launch VMs should not be larger than " \
f"the calculated total hugepages {total_hugepages} of service VMs. Please update the configuration in post launch VMs")

- hugepages_1gb = hugepages_1gb + correction_gb
- hugepages_2mb = hugepages_2mb + math.ceil(correction_mb * 1024 / 2)
-
allocation_service_vm_node = common.get_node("/acrn-config/vm[load_order = 'SERVICE_VM']", allocation_etree)
if allocation_service_vm_node is not None:
common.append_node("./hugepages/gb", int(hugepages_1gb), allocation_service_vm_node)
diff --git a/misc/config_tools/xforms/misc_cfg.h.xsl b/misc/config_tools/xforms/misc_cfg.h.xsl
index f742a78ee..d5ffb3ea8 100644
--- a/misc/config_tools/xforms/misc_cfg.h.xsl
+++ b/misc/config_tools/xforms/misc_cfg.h.xsl
@@ -93,7 +93,7 @@
</xsl:variable>
<xsl:variable name="hugepage_kernelstring">
<xsl:if test="//board-data//processors//capability[@id='gbyte_pages']">
- <xsl:value-of select="concat('hugepagesz=1G hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/gb, ' hugepagesz=2M hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/mb)" />
+ <xsl:value-of select="concat('hugepagesz=1G hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/gb)" />
</xsl:if>
</xsl:variable>
<xsl:value-of select="acrn:define('SERVICE_VM_ROOTFS', concat($quot, $sos_rootfs, ' ', $quot), '')" />
--
2.25.1

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.