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 配置:

    1. memhp_default_state 内核命令行参数设置为 online_movable

      # grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online_movable
    2. 重启虚拟机。
  • 要在虚拟机中设置内存在线,以使用 online_kernel 配置:

    1. memhp_default_state 内核命令行参数设置为 online_kernel

      # grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online_kernel
    2. 重启虚拟机。
  • 要在虚拟机中使用 auto-movable 内存在线策略:

    1. memhp_default_state 内核命令行参数设置为 online

      # grubby --update-kernel=ALL --remove-args=memhp_default_state --args=memhp_default_state=online
    2. memory_hotplug.online_policy 内核命令行参数设置为 auto-movable

      # grubby --update-kernel=ALL --remove-args="memory_hotplug.online_policy" --args=memory_hotplug.online_policy=auto-movable
    3. 可选:要进一步调优 auto-movable 在线策略,请更改 memory_hotplug.auto_movable_ratiomemory_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 节点。

        另外,如果没有超过比率,则新热插拔内存将只可用于可移动分配。否则,新热拔插内存将同时可用于可移动和不可移动分配。

    4. 重启虚拟机。

验证

  • 要查看 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
      
      online
    • memory_hotplug.online_policy:

      # cat /sys/module/memory_hotplug/parameters/online_policy
      
      auto-movable
    • memory_hotplug.auto_movable_ratio:

      # cat /sys/module/memory_hotplug/parameters/auto_movable_ratio
      
      301
    • memory_hotplug.auto_movable_numa_aware:

      # cat /sys/module/memory_hotplug/parameters/auto_movable_numa_aware
      
      y
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部