Alpha162 opened a new pull request, #14921:
URL: https://github.com/apache/cloudstack/pull/14921
### Description
This PR adds phase 1 of #14868: a compute offering can make its KVM
instances NUMA-aware.
Three compute offering details control it:
| Detail | Values | Meaning |
|---|---|---|
| `numa.policy` | `none` (default), `preferred`, `strict` | Build guest NUMA
nodes and bind their memory, and how firmly |
| `numa.nodes` | `auto` (default) or a number | Guest NUMA nodes. `auto`
uses the fewest host nodes the instance fits in |
| `numa.pin` | `node` (default), `none` | Pin each guest node's vCPUs to the
CPUs of its host node |
What happens for a NUMA-aware instance:
- The KVM agent splits the vCPUs and memory evenly over guest NUMA cells and
picks a host node for each cell, taking the nodes with the most memory
available.
- `CpuModeDef` writes the cells and a topology of one socket per guest node.
`CpuTuneDef` writes a `vcpupin` per vCPU, to the host node's CPUs without the
kernel-isolated ones. A new `NumaTuneDef` writes `numatune` with a `memnode`
per cell.
- If the instance can't be split evenly, or the host's nodes can't take it,
the start fails and the agent log says why. There's no quiet fallback.
- The agent reports each host node's usable CPU count and memory as host
details (`host.numa.nodes`, `host.numa.node.<id>`). `FirstFitAllocator` skips
KVM hosts that haven't reported a layout or whose nodes are too small.
One change affects instances that aren't NUMA-aware. Today a dynamically
scalable instance gets two `<cpu>` elements: one from `CpuModeDef` and one from
`GuestResourceDef` holding the cell that memory hot-add needs. libvirt takes
the mode, model and topology from the first one, and `LibvirtVMDef` keeps its
components in a `HashMap`, so the result depends on iteration order. That cell
now goes into `CpuModeDef`'s element and the domain XML has a single `<cpu>`.
With a DPDK NUMA extra config nothing changes.
Narrower than the issue text, on purpose:
- Only the compute offering can set these. The same keys as VM details are
ignored, so there's no per-VM override yet.
- A NUMA-aware instance gets all of its vCPUs and memory at start. The
offering has to have `dynamicscalingenabled=false`, so the existing checks
refuse to scale such an instance while it runs. Hot-add within fixed cells can
come later.
- The placement check only compares the instance with the size of the host's
nodes. It doesn't account for what other instances already use on them. For
`strict`, the agent checks the memory available on each node at start.
- Not in this PR: rewriting the pinning on live migration, DRS awareness,
emulator thread pinning, hugepages, UI.
Off by default. Offerings without `numa.policy` behave as before, and
there's no schema change.
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] Build/CI
- [ ] Test (unit or integration test code)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [x] Major
- [ ] Minor
### How Has This Been Tested?
Unit tests: 75 new ones in `utils`, the KVM plugin and `server`. The full
suites of those three modules pass on this branch (8,059 tests).
**End to end on a build of this branch.** A small lab upgraded from 4.23.0.0
to packages built from this branch (24.0.0-SNAPSHOT, Ubuntu 24.04, two KVM
hosts with two NUMA nodes of four CPUs each):
| Case | Result |
|---|---|
| Hosts after the upgrade | Both report `host.numa.nodes=0,1` and
`host.numa.node.<id>=4;<memory>` |
| `createServiceOffering` with `numa.policy=strict` and dynamic scaling left
at its default | Refused: "A compute offering with numa.policy=strict cannot
have dynamic scaling enabled. Set dynamicscalingenabled to false." |
| `createServiceOffering` with `numa.policy=always`, `numa.nodes=0` or
`numa.pin=core` | Each refused, naming the setting and its valid values |
| `strict`, `auto`, 2 vCPUs | One cell, both vCPUs pinned to one node's
CPUs, RAM `bind` to that node |
| `strict`, `auto`, 8 vCPUs | Two cells of four vCPUs, `sockets='2'`, each
cell pinned and bound to its own node |
| `preferred`, `numa.pin=none` | One cell, memory policy `prefer`, no
`vcpupin` |
| `strict`, 5 vCPUs; `strict`, 1 node, 12 GiB; `strict`, 4 nodes | No host
offered ("No destination found"). The allocator logs that it added each host to
the avoid set and why |
| NUMA keys passed as VM details on a plain offering | Ignored. The instance
starts with no cells, pinning or `numatune` |
| Stop and start of a NUMA-aware instance | Laid out again on start |
| Offering of a stopped plain instance changed to a NUMA-aware one |
NUMA-aware from the next start |
| Live migration of the two-cell instance to the other (identical) host |
Works. Pinning and binding are the same on the destination |
| Live scaling a NUMA-aware instance | Refused by the existing check,
because the instance isn't dynamically scalable |
| Dynamically scalable plain instance | One `<cpu>` element holding the
mode, the topology and the hot-add cell. Live scaling it from 512 MB to 1 GiB
works and attaches the DIMM to node 0 |
**On hardware.** On a KVM host (AlmaLinux 9, libvirt 11.10, two NUMA nodes
with interleaved CPU numbering and CPUs 0-1 isolated), with the agent side of
this change ported to 4.22.0.1:
| Case | Result |
|---|---|
| `strict`, 2 nodes, 4 vCPUs, 2 GiB | Two cells, `sockets='2'`, vCPUs 0-1
pinned to node 0's CPUs and 2-3 to node 1's. `/proc/<pid>/numa_maps` shows the
guest RAM as `bind:0` and `bind:1`, with pages only on the bound node |
| `strict`, `auto`, 4 vCPUs | One cell on one host node |
| `strict`, `auto`, 16 vCPUs (15 usable CPUs per node) | Split into two
cells of 8 |
| `preferred`, `numa.pin=none` | One cell, memory policy `prefer`, no
`vcpupin` |
| `strict`, 2 nodes, 3 vCPUs | Refused: "3 vCPU(s) cannot be split evenly
over 2 NUMA node(s)." |
| `strict`, 1 node, 16 vCPUs | Refused: "The host does not have 1 NUMA
node(s) with 16 CPU(s) and 2097152 KiB of available memory each." |
| `numa.policy=sometimes` | Refused: "Invalid value 'sometimes' for
numa.policy. Use none, preferred or strict." |
| No NUMA settings | Unchanged: one `<cpu>` element, no pinning |
The isolated CPUs were left out of every `vcpupin`, and the kernel's
`Cpus_allowed_list` of each vCPU thread matched.
Running domain XML of the first case:
```xml
<vcpupin vcpu='0' cpuset='2,4,6,8,10,12,14,16,18,20,22,24,26,28,30'/>
<vcpupin vcpu='1' cpuset='2,4,6,8,10,12,14,16,18,20,22,24,26,28,30'/>
<vcpupin vcpu='2' cpuset='3,5,7,9,11,13,15,17,19,21,23,25,27,29,31'/>
<vcpupin vcpu='3' cpuset='3,5,7,9,11,13,15,17,19,21,23,25,27,29,31'/>
<numatune>
<memory mode='strict' nodeset='0-1'/>
<memnode cellid='0' mode='strict' nodeset='0'/>
<memnode cellid='1' mode='strict' nodeset='1'/>
</numatune>
<topology sockets='2' dies='1' clusters='1' cores='2' threads='1'/>
<numa>
<cell id='0' cpus='0-1' memory='1048576' unit='KiB'/>
<cell id='1' cpus='2-3' memory='1048576' unit='KiB'/>
</numa>
```
Not tested: HA restarts, host maintenance, DRS, and live migration between
hosts with different NUMA layouts. Migration copies the pinning as it is, so it
needs the destination to have the same CPU numbering until phase 2.
#### How did you try to break this feature and the system with this change?
- Uneven splits, more guest nodes than the host has, nodes with too few CPUs
or too little memory, invalid setting values, and a host with no NUMA
information: each is refused with a message, in unit tests and on the host
above.
- A host whose CPU numbering alternates between nodes and has isolated CPUs.
- NUMA keys set as VM details on an offering without them: ignored (unit
test).
- Instances without the settings, and system VMs: unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]