|
| 1 | +--- |
| 2 | +title: xc_domain_node_setaffinity() |
| 3 | +description: Set a Xen domain's NUMA node affinity |
| 4 | +--- |
| 5 | + |
| 6 | +`xc_domain_node_setaffinity()` controls the NUMA node affinity of a domain. |
| 7 | + |
| 8 | +By default, Xen enables the `auto_node_affinity` feature flag, |
| 9 | +where setting the vCPU affinity also sets the NUMA node affinity for |
| 10 | +memory allocations to be aligned with the vCPU affinity of the domain. |
| 11 | + |
| 12 | +Setting the NUMA node affinity using this call can be used, |
| 13 | +for example, when there might not be enough memory on the |
| 14 | +preferred NUMA node, but there are other NUMA nodes that have |
| 15 | +enough free memory to be used for the system memory of the domain. |
| 16 | + |
| 17 | +In terms of future NUMA design, it might be even more favourable to |
| 18 | +have a strategy in `xenguest` where in such cases, the superpages |
| 19 | +of the preferred node are used first and a fallback to neighbouring |
| 20 | +NUMA nodes only happens to the extent necessary. |
| 21 | + |
| 22 | +Likely, the future allocation strategy should be passed to `xenguest` |
| 23 | +using Xenstore like the other platform parameters for the VM. |
| 24 | + |
| 25 | +## Walk-through of xc_domain_node_setaffinity() |
| 26 | + |
| 27 | +```mermaid |
| 28 | +classDiagram |
| 29 | +class `xc_domain_node_setaffinity()` { |
| 30 | + +xch: xc_interface #42; |
| 31 | + +domid: uint32_t |
| 32 | + +nodemap: xc_nodemap_t |
| 33 | + 0(on success) |
| 34 | + -EINVAL(if a node in the nodemask is not online) |
| 35 | +} |
| 36 | +click `xc_domain_node_setaffinity()` href " |
| 37 | +https://github.com/xen-project/xen/blob/master/tools/libs/ctrl/xc_domain.c#L122-L158" |
| 38 | +
|
| 39 | +`xc_domain_node_setaffinity()` --> `Xen hypercall: do_domctl()` |
| 40 | +`xc_domain_node_setaffinity()` <-- `Xen hypercall: do_domctl()` |
| 41 | +class `Xen hypercall: do_domctl()` { |
| 42 | + Calls domain_set_node_affinity#40;#41; and returns its return value |
| 43 | + Passes: domain (struct domain *, looked up using the domid) |
| 44 | + Passes: new_affinity (modemask, converted from xc_nodemap_t) |
| 45 | +} |
| 46 | +click `Xen hypercall: do_domctl()` href " |
| 47 | +https://github.com/xen-project/xen/blob/master/xen/common/domctl.c#L516-L525" |
| 48 | +
|
| 49 | +`Xen hypercall: do_domctl()` --> `domain_set_node_affinity()` |
| 50 | +`Xen hypercall: do_domctl()` <-- `domain_set_node_affinity()` |
| 51 | +class `domain_set_node_affinity()` { |
| 52 | + domain: struct domain |
| 53 | + new_affinity: nodemask |
| 54 | + 0(on success, the domain's node_affinity is updated) |
| 55 | + -EINVAL(if a node in the nodemask is not online) |
| 56 | +} |
| 57 | +click `domain_set_node_affinity()` href " |
| 58 | +https://github.com/xen-project/xen/blob/master/xen/common/domain.c#L943-L970" |
| 59 | +``` |
| 60 | + |
| 61 | +### domain_set_node_affinity() |
| 62 | + |
| 63 | +This function implements the functionality of `xc_domain_node_setaffinity` |
| 64 | +to set the NUMA affinity of a domain as described above. |
| 65 | +If the new_affinity does not intersect the `node_online_map`, |
| 66 | +it returns `-EINVAL`, otherwise on success `0`. |
| 67 | + |
| 68 | +When the `new_affinity` is a specific set of NUMA nodes, it updates the NUMA |
| 69 | +`node_affinity` of the domain to these nodes and disables `auto_node_affinity` |
| 70 | +for this domain. It also notifies the Xen scheduler of the change. |
| 71 | + |
| 72 | +This sets the preference the memory allocator to the new NUMA nodes, |
| 73 | +and in theory, it could also alter the behaviour of the scheduler. |
| 74 | +This of course depends on the scheduler and its configuration. |
| 75 | + |
| 76 | +## Notes on future design improvements |
| 77 | + |
| 78 | +This call cannot influence the past: The `xenopsd` |
| 79 | +[VM_create](../../xenopsd/walkthroughs/VM.start.md#2-create-a-xen-domain) |
| 80 | +micro-ops calls `Xenctrl.domain_create`. It currently creates |
| 81 | +the domain's data structures before `numa_placement` was done. |
| 82 | + |
| 83 | +Improving `Xenctrl.domain_create` to pass a NUMA node |
| 84 | +for allocating the Hypervisor's data structures (e.g. vCPU) |
| 85 | +of the domain would require changes |
| 86 | +to the Xen hypervisor and the `xenopsd` |
| 87 | +[xenopsd VM_create](../../xenopsd/walkthroughs/VM.start.md#2-create-a-xen-domain) |
| 88 | +micro-op. |
0 commit comments