虚拟机资源控制Virtual Machine Resource Controls

适用于:Windows Server 2016、Microsoft Hyper-V Server 2016、Windows Server 2019、Microsoft Hyper-V Server 2019Applies To: Windows Server 2016, Microsoft Hyper-V Server 2016, Windows Server 2019, Microsoft Hyper-V Server 2019

本文介绍了虚拟机的 Hyper-v 资源和隔离控制。This article describes Hyper-V resource and isolation controls for virtual machines. Windows Server 2016 中引入了这些功能,这些功能称为虚拟机 CPU 组,或只是 "CPU 组"。These capabilities, which we'll refer to as Virtual Machine CPU Groups, or just "CPU groups", were introduced in Windows Server 2016. 利用 CPU 组,Hyper-v 管理员可以更好地管理和分配跨来宾虚拟机的主机 CPU 资源。CPU groups allow Hyper-V administrators to better manage and allocate the host's CPU resources across guest virtual machines. 使用 CPU 组,Hyper-v 管理员可以:Using CPU groups, Hyper-V administrators can:

  • 创建虚拟机组,其中每个组都有不同的虚拟化主机 CPU 资源分配,在整个组中共享。Create groups of virtual machines, with each group having different allocations of the virtualization host's total CPU resources, shared across the entire group. 这允许主机管理员为不同类型的 Vm 实现服务类。This allows the host administrator to implement classes of service for different types of VMs.

  • 将 CPU 资源限制设置为特定组。Set CPU resource limits to specific groups. 此 "组上限" 设置整个组可能使用的主机 CPU 资源的上限,为该组有效地强制实施所需的服务类别。This "group cap" sets the upper bound for host CPU resources that the entire group may consume, effectively enforcing the desired class of service for that group.

  • 约束一个 CPU 组,使其仅在一组特定主机系统的处理器上运行。Constrain a CPU group to run only on a specific set of the host system's processors. 这可用于隔离属于不同 CPU 组的虚拟机。This can be used to isolate VMs belonging to different CPU groups from each other.

管理 CPU 组Managing CPU Groups

CPU 组通过 Hyper-v 主机计算服务或 HCS 进行管理。CPU groups are managed through the Hyper-V Host Compute Service, or HCS. Microsoft 虚拟化团队的博客提供了有关 HCS 的详细说明,其中 genesis、HCS Api 的链接以及更多内容,请访问 Microsoft 虚拟化团队的博客,其中 介绍了主机计算服务 (HCS) A great description of the HCS, its genesis, links to the HCS APIs, and more is available on the Microsoft Virtualization team's blog in the posting Introducing the Host Compute Service (HCS).

备注

只有 HCS 可以用于创建和管理 CPU 组;Hyper-v 管理器 applet、WMI 和 PowerShell 管理接口不支持 CPU 组。Only the HCS may be used to create and manage CPU groups; the Hyper-V Manager applet, WMI and PowerShell management interfaces don't support CPU groups.

Microsoft 在 Microsoft 下载中心 提供了一个命令行实用程序 cpugroups.exe,该程序使用 HCS 界面来管理 CPU 组。Microsoft provides a command line utility, cpugroups.exe, on the Microsoft Download Center which uses the HCS interface to manage CPU groups. 此实用程序还可以显示主机的 CPU 拓扑。This utility can also display the CPU topology of a host.

CPU 组的工作方式How CPU Groups Work

Hyper-v 虚拟机监控程序使用计算的 CPU 组上限来强制对 CPU 组分配主机计算资源。Allocation of host compute resources across CPU groups is enforced by the Hyper-V hypervisor, using a computed CPU group cap. CPU 组上限是 CPU 组的总 CPU 容量的一部分。The CPU group cap is a fraction of the total CPU capacity for a CPU group. 组帽的值取决于组类或分配的优先级。The value of the group cap depends on the group class, or priority level assigned. 计算出的组帽可以视为 "一定数量的 LP CPU 时间"。The computed group cap can be thought of as "a number of LP's worth of CPU time". 此组预算是共享的,因此,如果只有一个 VM 处于活动状态,则它可以使用整个组的 CPU 分配。This group budget is shared, so if only a single VM were active, it could use the entire group's CPU allocation for itself.

CPU 组上限计算为 G = n x C,其中:The CPU group cap is calculated as G = n x C, where:

  • G 是要分配给组的主机 LP 数量G is the amount of host LP we'd like to assign to the group
  • n 是组中 (LPs) 的逻辑处理器总数n is the total number of logical processors (LPs) in the group
  • C 是最大 CPU 分配量,即组所需的服务类别,以系统总计算容量的百分比表示C is the maximum CPU allocation — that is, the class of service desired for the group, expressed as a percentage of the system's total compute capacity

例如,假设有4个逻辑处理器的 CPU 组 (LPs) ,上限为50%。For example, consider a CPU group configured with 4 logical processors (LPs), and a cap of 50%.

  • G = n * CG = n * C
  • G = 4 * 50%G = 4 * 50%
  • G = 2 LP 为整个组提供 CPU 时间G = 2 LP's worth of CPU time for the entire group

在此示例中,CPU 组 G 分配了2个 LP 的 CPU 时间。In this example, the CPU group G is allocated 2 LP's worth of CPU time.

请注意,无论绑定到组的虚拟机或虚拟处理器的数量是多少,无论状态 ((例如,关闭或) 启动分配给 CPU 组的虚拟机)的状态如何,组 cap 都适用。Note that the group cap applies regardless of the number of virtual machines or virtual processors bound to the group, and regardless of the state (e.g., shutdown or started) of the virtual machines assigned to the CPU group. 因此,绑定到同一个 CPU 组的每个 VM 都将收到该组的总 CPU 分配,这将更改与绑定到 CPU 组的 Vm 的数目。Therefore, each VM bound to the same CPU group will receive a fraction of the group's total CPU allocation, and this will change with the number of VMs bound to the CPU group. 因此,由于 Vm 是来自 CPU 组的绑定或未绑定 Vm,因此总体 CPU 组上限必须为重新调整,并设置为维护所需的每 VM 上限。Therefore, as VMs are bound or unbound VMs from a CPU group, the overall CPU group cap must be readjusted and set to maintain the resulting per-VM cap desired. VM 主机管理员或虚拟化管理软件层负责根据需要管理组帽以实现所需的每个 VM 的 CPU 资源分配。The VM host administrator or virtualization management software layer is responsible for managing group caps as necessary to achieve the desired per-VM CPU resource allocation.

服务的示例类Example Classes of Service

让我们看一些简单的示例。Let's look at some simple examples. 首先,假定 Hyper-v 主机管理员要为来宾 Vm 支持两个服务层:To start with, assume the Hyper-V host administrator would like to support two tiers of service for guest VMs:

  1. 低端 "C" 层。A low-end "C" tier. 我们将为此第10层的整个主机计算资源分配。We'll give this tier 10% of the entire host's compute resources.

  2. 中间范围 "B" 层。A mid-range "B" tier. 此级别分配了整个主机计算资源的50%。This tier is allocated 50% of the entire host's compute resources.

在本示例中,我们将断言未使用其他 CPU 资源控制,如单个 VM cap、权重和预留。At this point in our example we'll assert that no other CPU resource controls are in use, such as individual VM caps, weights, and reserves. 不过,单个 VM cap 非常重要,因为我们稍后会看到。However, individual VM caps are important, as we'll see a bit later.

为简单起见,我们假设每个 VM 都有1个副总裁,主机有 8 LPs。For simplicity's sake, let's assume each VM has 1 VP, and that our host has 8 LPs. 我们将从一个空主机开始。We'll start with an empty host.

若要创建 "B" 层,主机 adminstartor 会将组上限设置为50%:To create the "B" tier, the host adminstartor sets the group cap to 50%:

  • G = n * CG = n * C
  • G = 8 * 50%G = 8 * 50%
  • G = 适用于整个组的 4 LP LP CPU 时间G = 4 LP's worth of CPU time for the entire group

主机管理员添加了一个 "B" 层 VM。The host administrator adds a single "B" tier VM. 此时,"B" 层 VM 最多可使用50% 的主机 CPU,或在我们的示例系统中相当于 4 LPs。At this point, our "B" tier VM can use at most 50% worth of the host's CPU, or the equivalent of 4 LPs in our example system.

现在,管理员添加了第二个 "B 层" VM。Now, the admin adds a second "Tier B" VM. CPU 组的分配-在所有 Vm 之间平均划分。The CPU group's allocation—is divided evenly among all the VMs. 我们总共在 B 组中有2个 Vm,因此,每个 VM 现在获取全部50%、25% 或等于 2 LPs 计算时间的一半。We've got a total of 2 VMs in Group B, so each VM now gets half of Group B's total of 50%, 25% each, or the equivalent of 2 LPs worth of compute time.

在单个 Vm 上设置 CPU 上限Setting CPU Caps on Individual VMs

除组帽外,每个 VM 还可以有一个单独的 "VM cap"。In addition to the group cap, each VM can also have an individual "VM cap". 自其简介以来,每个 VM 的 CPU 资源控制(包括 CPU 上限、权重和预留)都属于 Hyper-v。Per-VM CPU resource controls, including a CPU cap, weight, and reserve, have been a part of Hyper-V since its introduction. 与组帽结合使用时,VM cap 会指定每个 VP 可以获得的最大 CPU 数量,即使该组具有可用的 CPU 资源。When combined with a group cap, a VM cap specifies the maximum amount of CPU that each VP can get, even if the group has CPU resources available.

例如,主机管理员可能希望在 "C" Vm 上放置10% 的 VM cap。For example, the host administrator might want to place a 10% VM cap on "C" VMs. 这样,即使大多数 "C" VPs 处于空闲状态,每个副总裁也永远不会超过10%。That way, even if most "C" VPs are idle, each VP could never get more than 10%. 如果没有 VM cap,"C" Vm 就会找机会在其层所允许的级别之外实现性能。Without a VM cap, "C" VMs could opportunistically achieve performance beyond levels allowed by their tier.

将 VM 组隔离到特定主机处理器Isolating VM Groups to Specific Host Processors

Hyper-v 主机管理员可能还希望能够将计算资源专用于 VM。Hyper-V host administrators may also want the ability to dedicate compute resources to a VM. 例如,假设管理员想要提供一个高级的 "A" VM,其类帽为100%。For example, imagine the administrator wanted to offer a premium "A" VM that has a class cap of 100%. 这些高级 Vm 还需要尽可能低的计划延迟和抖动;也就是说,它们不能由任何其他 VM 取消计划。These premium VMs also require the lowest scheduling latency and jitter possible; that is, they may not be de-scheduled by any other VM. 若要实现这种分离,还可以使用特定的 LP 关联映射来配置一个 CPU 组。To achieve this separation, a CPU group can also be configured with a specific LP affinity mapping.

例如,若要在我们的示例中适应主机上的 "A" VM,管理员将创建新的 CPU 组,并将组的处理器关联设置为主机的 LPs 的子集。For example, to fit an "A" VM on the host in our example, the administrator would create a new CPU group, and set the group's processor affinity to a subset of the host's LPs. 组 B 和 C 会被关联到剩余的 LPs 中。Groups B and C would be affinitized to the remaining LPs. 管理员可以在组 A 中创建单个 VM,然后对组 A 中的所有 LPs 具有独占访问权限,而可能较低的层组 B 和 C 会共享剩余的 LPs。The administrator could create a single VM in Group A, which would then have exclusive access to all LPs in Group A, while the presumably lower tier groups B and C would share the remaining LPs.

将根 VPs 与来宾 VPs 分离Segregating Root VPs from Guest VPs

默认情况下,Hyper-v 将在每个基础物理 LP 上创建根副总裁。By default, Hyper-V will create a root VP on each underlying physical LP. 这些根 VPs 与系统 LPs 严格映射1:1,不迁移,也就是说,每个根副总将始终在同一物理 LP 上执行。These root VPs are strictly mapped 1:1 with the system LPs, and do not migrate — that is, each root VP will always execute on the same physical LP. 可以在任何可用的 LP 上运行来宾 VPs,并将执行与根 VPs 共享。Guest VPs may be run on any available LP, and will share execution with root VPs.

但是,可能需要从来宾 VPs 完全分离根副总裁活动。However, it may be desirable to completely separate root VP activity from guest VPs. 在上面的示例中,我们实现了高级的 "A" 层 VM。Consider our example above where we implement a premium "A" tier VM. 若要确保 "A" VM 的 VPs 具有最低的延迟和 "抖动" 或计划变化,我们想要在一组专用的 LPs 上运行它们,并确保根本不会在这些 LPs 上运行。To ensure our "A" VM's VPs have the lowest possible latency and "jitter", or scheduling variation, we'd like to run them on a dedicated set of LPs and ensure the root does not run on these LPs.

这可以使用 "minroot" 配置的组合来完成,这会将主机 OS 分区限制为在总系统逻辑处理器的子集上运行,以及一个或多个关联 CPU 组。This can be accomplished using a combination of the "minroot" configuration, which limits the host OS partition to running on a subset of the total system logical processors, along with one or more affinitized CPU groups.

可将虚拟化主机配置为将主机分区限制为特定的 LPs,并将一个或多个 CPU 组关联到剩余的 LPs。The virtualization host can be configured to restrict the host partition to specific LPs, with one or more CPU groups affinitized to the remaining LPs. 通过这种方式,可以在专用 CPU 资源上运行根和来宾分区,并完全隔离,无 CPU 共享。In this manner, the root and guest partitions can run on dedicated CPU resources, and completely isolated, with no CPU sharing.

有关 "minroot" 配置的详细信息,请参阅 Hyper-v 主机 CPU 资源管理For more information about the "minroot" configuration, see Hyper-V Host CPU Resource Management.

使用 CpuGroups 工具Using the CpuGroups Tool

让我们看看如何使用 CpuGroups 工具的一些示例。Let's look at some examples of how to use the CpuGroups tool.

备注

CpuGroups 工具的命令行参数只使用空格作为分隔符。Command line parameters for the CpuGroups tool are passed using only spaces as delimiters. "/" 或 "-" 字符不应继续所需的命令行开关。No '/' or '-' characters should proceed the desired command line switch.

发现 CPU 拓扑Discovering the CPU Topology

通过 GetCpuTopology 执行 CpuGroups 将返回有关当前系统的信息,如下所示,其中包括 LP 索引、LP 所属的 NUMA 节点、包和核心 Id 以及根 VP 索引。Executing CpuGroups with the GetCpuTopology returns information about the current system, as shown below, including the LP Index, the NUMA node to which the LP belongs, the Package and Core IDs, and the ROOT VP index.

以下示例显示了一个具有2个 CPU 插槽和 NUMA 节点的系统,总计为 32 LPs,已启用多线程,并且配置为从每个 NUMA 节点启用具有8个根 VPs,4的 Minroot。The following example shows a system with 2 CPU sockets and NUMA nodes, a total of 32 LPs, and multi threading enabled, and configured to enable Minroot with 8 root VPs, 4 from each NUMA node. 具有根 VPs 的 LPs 具有 RootVpIndex >= 0;RootVpIndex 为-1 的 LPs 不可用于根分区,但仍由虚拟机监控程序进行管理,并将按其他配置设置允许的方式运行来宾 VPs。The LPs that have root VPs have a RootVpIndex >= 0; LPs with a RootVpIndex of -1 are not available to the root partition, but are still managed by the hypervisor and will run guest VPs as allowed by other configuration settings.

C:\vm\tools>CpuGroups.exe GetCpuTopology

LpIndex NodeNumber PackageId CoreId RootVpIndex
------- ---------- --------- ------ -----------
      0          0         0      0           0
      1          0         0      0           1
      2          0         0      1           2
      3          0         0      1           3
      4          0         0      2          -1
      5          0         0      2          -1
      6          0         0      3          -1
      7          0         0      3          -1
      8          0         0      4          -1
      9          0         0      4          -1
     10          0         0      5          -1
     11          0         0      5          -1
     12          0         0      6          -1
     13          0         0      6          -1
     14          0         0      7          -1
     15          0         0      7          -1
     16          1         1     16           4
     17          1         1     16           5
     18          1         1     17           6
     19          1         1     17           7
     20          1         1     18          -1
     21          1         1     18          -1
     22          1         1     19          -1
     23          1         1     19          -1
     24          1         1     20          -1
     25          1         1     20          -1
     26          1         1     21          -1
     27          1         1     21          -1
     28          1         1     22          -1
     29          1         1     22          -1
     30          1         1     23          -1
     31          1         1     23          -1

示例2–打印主机上的所有 CPU 组Example 2 – Print all CPU groups on the host

此处列出了当前主机上的所有 CPU 组、其 GroupId、组的 CPU 上限,以及分配给该组的 LPs 的索引。Here, we'll list all CPU groups on the current host, their GroupId, the group's CPU cap, and the indicies of LPs assigned to that group.

请注意,有效的 CPU 上限值介于 [0,65536] 范围内,这些值表示以百分比表示的组上限 (例如 32768 = 50% ) 。Note that valid CPU cap values are in the range [0, 65536], and these values express the group cap in percent (e.g., 32768 = 50%).

C:\vm\tools>CpuGroups.exe GetGroups

CpuGroupId                          CpuCap  LpIndexes
------------------------------------ ------ --------
36AB08CB-3A76-4B38-992E-000000000002 32768  4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536  24,25,26,27,28,29,30,31

示例3–打印单个 CPU 组Example 3 – Print a single CPU group

在此示例中,我们将使用 GroupId 作为筛选器来查询单个 CPU 组。In this example, we'll query a single CPU Group using the GroupId as a filter.

C:\vm\tools>CpuGroups.exe GetGroups /GroupId:36AB08CB-3A76-4B38-992E-000000000003
CpuGroupId                          CpuCap   LpIndexes
------------------------------------ ------ ----------
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15

示例4–创建新的 CPU 组Example 4 – Create a new CPU group

在这里,我们将创建一个新的 CPU 组,并指定组 ID 以及要分配给该组的 LPs 集。Here, we'll create a new CPU group, specifying the Group ID and the set of LPs to assign to the group.

C:\vm\tools>CpuGroups.exe CreateGroup /GroupId:36AB08CB-3A76-4B38-992E-000000000001 /GroupAffinity:0,1,16,17

现在会显示新添加的组。Now display our newly added group.

C:\vm\tools>CpuGroups.exe GetGroups
CpuGroupId                          CpuCap LpIndexes
------------------------------------ ------ ---------
36AB08CB-3A76-4B38-992E-000000000001 65536 0,1,16,17
36AB08CB-3A76-4B38-992E-000000000002 32768 4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536 12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536 24,25,26,27,28,29,30,31

示例5–将 CPU 组上限设置为50%Example 5 – Set the CPU group cap to 50%

在这里,我们将 CPU 组上限设置为50%。Here, we'll set the CPU group cap to 50%.

C:\vm\tools>CpuGroups.exe SetGroupProperty /GroupId:36AB08CB-3A76-4B38-992E-000000000001 /CpuCap:32768

现在,让我们通过显示刚刚更新的组来确认设置。Now let's confirm our setting by displaying the group we just updated.

C:\vm\tools>CpuGroups.exe GetGroups /GroupId:36AB08CB-3A76-4B38-992E-000000000001

CpuGroupId                          CpuCap LpIndexes
------------------------------------ ------ ---------
36AB08CB-3A76-4B38-992E-000000000001 32768 0,1,16,17

示例6–为主机上的所有 Vm 打印 CPU 组 idExample 6 – Print CPU group ids for all VMs on the host

C:\vm\tools>CpuGroups.exe GetVmGroup

VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 36ab08cb-3a76-4b38-992e-000000000002

示例7–从 CPU 组中取消绑定 VMExample 7 – Unbind a VM from the CPU group

若要从 CPU 组中删除 VM,请将设置为 VM 的 CpuGroupId 为 NULL GUID。To remove a VM from a CPU group, set to VM's CpuGroupId to the NULL GUID. 这会将 VM 从 CPU 组中解除绑定。This unbinds the VM from the CPU group.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:00000000-0000-0000-0000-000000000000

C:\vm\tools>CpuGroups.exe GetVmGroup
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 00000000-0000-0000-0000-000000000000

示例 8-将 VM 绑定到现有 CPU 组Example 8 – Bind a VM to an existing CPU group

此处,我们将 VM 添加到现有 CPU 组。Here, we'll add a VM to an existing CPU group. 请注意,VM 不能绑定到任何现有 CPU 组,或设置 CPU 组 id 会失败。Note that the VM must not be bound to any existing CPU group, or setting CPU group id will fail.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:36AB08CB-3A76-4B38-992E-000000000001

现在,确认 VM G1 是否处于所需的 CPU 组中。Now, confirm the VM G1 is in the desired CPU group.

C:\vm\tools>CpuGroups.exe GetVmGroup
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G2 4ABCFC2F-6C22-498C-BB38-7151CE678758 36ab08cb-3a76-4b38-992e-000000000002
    P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC 36ab08cb-3a76-4b38-992e-000000000003
    P2 A593D93A-3A5F-48AB-8862-A4350E3459E8 36ab08cb-3a76-4b38-992e-000000000004
    G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200 36ab08cb-3a76-4b38-992e-000000000002
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 36AB08CB-3A76-4B38-992E-000000000001

示例9–打印按 CPU 组 id 分组的所有 VmExample 9 – Print all VMs grouped by CPU group id

C:\vm\tools>CpuGroups.exe GetGroupVms
CpuGroupId                           VmName                                 VmId
------------------------------------ ------ ------------------------------------
36AB08CB-3A76-4B38-992E-000000000001     G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC
36ab08cb-3a76-4b38-992e-000000000002     G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002     G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200
36ab08cb-3a76-4b38-992e-000000000003     P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC
36ab08cb-3a76-4b38-992e-000000000004     P2 A593D93A-3A5F-48AB-8862-A4350E3459E8

示例10–打印单个 CPU 组的所有 VmExample 10 – Print all VMs for a single CPU group

C:\vm\tools>CpuGroups.exe GetGroupVms /GroupId:36ab08cb-3a76-4b38-992e-000000000002

CpuGroupId                           VmName                                VmId
------------------------------------ ------ ------------------------------------
36ab08cb-3a76-4b38-992e-000000000002     G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002     G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200

示例 11-尝试删除非空的 CPU 组Example 11 – Attempting to delete a non-empty CPU Group

只有空 CPU 组(即没有绑定 Vm 的 CPU 组)可以被删除。Only empty CPU groups—that is, CPU groups with no bound VMs—can be deleted. 尝试删除非空的 CPU 组将失败。Attempting to delete a non-empty CPU group will fail.

C:\vm\tools>CpuGroups.exe DeleteGroup /GroupId:36ab08cb-3a76-4b38-992e-000000000001
(null)
Failed with error 0xc0350070

示例12–取消绑定 CPU 组中的唯一 VM 并删除组Example 12 – Unbind the only VM from a CPU group and delete the group

在此示例中,我们将使用几个命令来检查 CPU 组,删除属于该组的单个 VM,然后删除该组。In this example, we'll use several commands to examine a CPU group, remove the single VM belonging to that group, then delete the group.

首先,让我们来枚举组中的 Vm。First, let's enumerate the VMs in our group.

C:\vm\tools>CpuGroups.exe GetGroupVms /GroupId:36AB08CB-3A76-4B38-992E-000000000001
CpuGroupId                           VmName                                VmId
------------------------------------ ------ ------------------------------------
36AB08CB-3A76-4B38-992E-000000000001     G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC

我们发现只有单个 VM (名为 G1)属于此组。We see that only a single VM, named G1, belongs to this group. 让我们从组中删除 G1 VM,方法是将 VM 的组 ID 设置为 NULL。Let's remove the G1 VM from our group by setting the VM's group ID to NULL.

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:00000000-0000-0000-0000-000000000000

并验证我们的更改 .。。And verify our change...

C:\vm\tools>CpuGroups.exe GetVmGroup /VmName:g1
VmName                                 VmId                           CpuGroupId
------ ------------------------------------ ------------------------------------
    G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC 00000000-0000-0000-0000-000000000000

现在,组为空,可以安全地将其删除。Now that the group is empty, we can safely delete it.

C:\vm\tools>CpuGroups.exe DeleteGroup /GroupId:36ab08cb-3a76-4b38-992e-000000000001

并确认我们的组已消失。And confirm our group is gone.

C:\vm\tools>CpuGroups.exe GetGroups
CpuGroupId                          CpuCap                     LpIndexes
------------------------------------ ------ -----------------------------
36AB08CB-3A76-4B38-992E-000000000002 32768  4,5,6,7,8,9,10,11,20,21,22,23
36AB08CB-3A76-4B38-992E-000000000003 65536  12,13,14,15
36AB08CB-3A76-4B38-992E-000000000004 65536 24,25,26,27,28,29,30,31

示例13–将 VM 重新绑定到其原始 CPU 组Example 13 – Bind a VM back to its original CPU group

C:\vm\tools>CpuGroups.exe SetVmGroup /VmName:g1 /GroupId:36AB08CB-3A76-4B38-992E-000000000002

C:\vm\tools>CpuGroups.exe GetGroupVms
CpuGroupId VmName VmId
------------------------------------ -------------------------------- ------------------------------------
36ab08cb-3a76-4b38-992e-000000000002 G2 4ABCFC2F-6C22-498C-BB38-7151CE678758
36ab08cb-3a76-4b38-992e-000000000002 G3 B0F3FCD5-FECF-4A21-A4A2-DE4102787200
36AB08CB-3A76-4B38-992E-000000000002 G1 F699B50F-86F2-4E48-8BA5-EB06883C1FDC
36ab08cb-3a76-4b38-992e-000000000003 P1 973B9426-0711-4742-AD3B-D8C39D6A0DEC
36ab08cb-3a76-4b38-992e-000000000004 P2 A593D93A-3A5F-48AB-8862-A4350E3459E8