[PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node

Alejandro Vallejo posted 11 patches 9 months, 1 week ago
[PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node
Posted by Alejandro Vallejo 9 months, 1 week ago
Set the domain's node affinity to the claimed node if the claim
specified an exact node. Do it immediately before making any changes in
case setting the affinity fails (even though it shouldn't).

This allows preferentially allocating from the closest NUMA node when
"exact" is not specified (e.g: p2m tables, etc).

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
Toolstacks can just do it themselves, but it's more error prone. If it
claimed pages from an exact node (and remember we can only hold a single
claim at a time) it makes no sense for the domain to be intentionally
allocating from NUMA nodes other than its home node.
---
 xen/common/page_alloc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index cfaa64d3b858..e69a5fcc8d31 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -586,10 +586,16 @@ int domain_set_outstanding_pages(struct domain *d, nodeid_t node,
 
     if ( node != NUMA_NO_NODE )
     {
-        avail_pages = pernode_avail_pages[node] - pernode_oc[node];
+        nodemask_t affinity = NODE_MASK_NONE;
 
+        avail_pages = pernode_avail_pages[node] - pernode_oc[node];
         if ( pages > avail_pages )
             goto out;
+
+        node_set(node, affinity);
+        ret = domain_set_node_affinity(d, &affinity);
+        if ( ret )
+            goto out;
     }
 
     /* yay, claim fits in available memory, stake the claim, success! */
-- 
2.48.1
Re: [PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node
Posted by Jan Beulich 6 months, 1 week ago
On 14.03.2025 18:24, Alejandro Vallejo wrote:
> Set the domain's node affinity to the claimed node if the claim
> specified an exact node. Do it immediately before making any changes in
> case setting the affinity fails (even though it shouldn't).
> 
> This allows preferentially allocating from the closest NUMA node when
> "exact" is not specified (e.g: p2m tables, etc).
> 
> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> ---
> Toolstacks can just do it themselves, but it's more error prone. If it
> claimed pages from an exact node (and remember we can only hold a single
> claim at a time) it makes no sense for the domain to be intentionally
> allocating from NUMA nodes other than its home node.

I question this as a global, built-in policy: An admin may intentionally
do things in different ways, for whatever reasons they may have. Even in
the toolstack I'd consider such behavior a valid default, but requiring
a way to override.

Jan
Re: [PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node
Posted by Roger Pau Monné 6 months, 2 weeks ago
On Fri, Mar 14, 2025 at 05:24:58PM +0000, Alejandro Vallejo wrote:
> Set the domain's node affinity to the claimed node if the claim
> specified an exact node. Do it immediately before making any changes in
> case setting the affinity fails (even though it shouldn't).
> 
> This allows preferentially allocating from the closest NUMA node when
> "exact" is not specified (e.g: p2m tables, etc).
> 
> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> ---
> Toolstacks can just do it themselves, but it's more error prone. If it
> claimed pages from an exact node (and remember we can only hold a single
> claim at a time) it makes no sense for the domain to be intentionally
> allocating from NUMA nodes other than its home node.
> ---
>  xen/common/page_alloc.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> index cfaa64d3b858..e69a5fcc8d31 100644
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -586,10 +586,16 @@ int domain_set_outstanding_pages(struct domain *d, nodeid_t node,
>  
>      if ( node != NUMA_NO_NODE )
>      {
> -        avail_pages = pernode_avail_pages[node] - pernode_oc[node];
> +        nodemask_t affinity = NODE_MASK_NONE;
>  
> +        avail_pages = pernode_avail_pages[node] - pernode_oc[node];
>          if ( pages > avail_pages )
>              goto out;
> +
> +        node_set(node, affinity);
> +        ret = domain_set_node_affinity(d, &affinity);

You can use nodemask_of_node(node) here?

> +        if ( ret )
> +            goto out;

This seems a bit too much, specially failing the claim if the affinity
cannot be fulfilled.

If would maybe print a message if the claim is made against a
non-affine node, but that would be it.

Thanks, Roger.