config_tools: update the hugepage algorithm

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@intel.com>
This commit is contained in:
Kunhui-Li 2022-06-14 23:37:36 +08:00 committed by acrnsi-robot
parent 36cfc14e9c
commit 8c47c324f5
2 changed files with 3 additions and 7 deletions

View File

@ -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)

View File

@ -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), '')" />