17.4.2.2. 在虚拟机中配置内存在线
在使用 virtio-mem 在虚拟机中将内存热插到 之前,您必须将客户端操作系统配置为自动将热插内存设置为在线状态。否则,客户机OS无法使用额外内存。
默认情况下,RHEL 中的内存使用 udev 规则配置。但是,在使用 virtio-mem 时,请直接在内核中配置内存。
先决条件
- 主机使用 Intel 64、AMD64、ARM 64 或 IBM Z CPU 架构。
- 主机使用 RHEL 10 作为操作系统。
运行在主机上的虚拟机使用以下操作系统版本之一:
在 Intel 64 和 AMD64 主机上:RHEL 8.10、RHEL 9.4 或更高版本、RHEL 10.0 或更高版本,或者支持 64 位版本的 Windows
重要从正在运行的虚拟机中拔出内存在 RHEL 8.10 虚拟机中默认被禁用。
有关支持的 Windows 版本列表,请参阅: 认证的客户机操作系统
- 在 ARM 64 主机上:RHEL 9.6 或更高版本或 RHEL 10.0 或更高版本
- 在 IBM Z 主机上:RHEL 9.7 或更高版本或 RHEL 10.1 或更高版本
您已为简化的内存选择了最佳配置:
-
online_movable -
online_kernel -
auto-movable
要了解这些配置之间的区别,请参阅: 比较内存配置
-
流程
要在虚拟机中设置内存在线,以使用
online_movable配置:将
memhp_default_state内核命令行参数设置为online_movable:# grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online_movable- 重启虚拟机。
要在虚拟机中设置内存在线,以使用
online_kernel配置:将
memhp_default_state内核命令行参数设置为online_kernel:# grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online_kernel- 重启虚拟机。
要在虚拟机中使用
auto-movable内存在线策略:将
memhp_default_state内核命令行参数设置为online:# grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online将
memory_hotplug.online_policy内核命令行参数设置为auto-movable:# grubby --update-kernel=ALL --remove-args="memory_hotplug.online_policy" --args=memory_hotplug.online_policy=auto-movable可选:要进一步调优
auto-movable在线策略,请更改memory_hotplug.auto_movable_ratio和memory_hotplug.auto_movable_numa_aware参数:# grubby --update-kernel=ALL --remove-args="memory_hotplug.auto_movable_ratio" --args=memory_hotplug.auto_movable_ratio=<percentage> # grubby --update-kernel=ALL --remove-args="memory_hotplug.memory_auto_movable_numa_aware" --args=memory_hotplug.auto_movable_numa_aware=<y/n>-
与可用于任何分配的内存相比,
memory_hotplug.auto_movable_ratio 参数设置仅可用于可移动分配的最大内存比率。比率以百分比表示,默认值为 301 (%),它是 3:1 的比率。 memory_hotplug.auto_movable_numa_aware参数控制memory_hotplug.auto_movable_ratio参数是否应用到跨所有可用 NUMA 节点的内存,或仅应用到单个 NUMA 节点上的内存。默认值为:y (yes)例如,如果最大比率设置为 301%,并且
memory_hotplug.auto_movable_numa_aware设置为 y (yes),即使在附加了virtio-mem设备的 NUMA 节点内也应用 3:1 比率。如果参数设置为 n (no),则最大 3:1 比率仅应用于整个 NUMA 节点。另外,如果没有超过比率,则新热插拔内存将只可用于可移动分配。否则,新热拔插内存将同时可用于可移动和不可移动分配。
-
与可用于任何分配的内存相比,
- 重启虚拟机。
验证
要查看
online_movable配置是否已正确设置,请检查memhp_default_state内核参数的当前值:# cat /sys/devices/system/memory/auto_online_blocks online_movable要查看
online_kernel配置是否已正确设置,请检查memhp_default_state内核参数的当前值:# cat /sys/devices/system/memory/auto_online_blocks online_kernel要查看
auto-movable配置是否已正确设置,请检查以下内核参数:memhp_default_state:# cat /sys/devices/system/memory/auto_online_blocks onlinememory_hotplug.online_policy:# cat /sys/module/memory_hotplug/parameters/online_policy auto-movablememory_hotplug.auto_movable_ratio:# cat /sys/module/memory_hotplug/parameters/auto_movable_ratio 301memory_hotplug.auto_movable_numa_aware:# cat /sys/module/memory_hotplug/parameters/auto_movable_numa_aware y