|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 1/8] xen/mm: protect per-node claims in get_free_buddy()
Before calling get_free_buddy(), alloc_heap_pages() checks
the outstanding claims of a domain. This check is unchanged.
However, allow an allocation only if the node has enough unclaimed
memory after crediting any eligible claim on that node:
- Before searching a node's zones, subtract its outstanding claims
from its free page count.
- Clamp the result at zero, as memory errors detected during Xen
or platform scrubbing can trigger machine-check recovery and
sysctl(XEN_SYSCTL_page_offline_op) may offline free pages as well:
Claims protect against competing allocations, but can't protect
against physical memory loss.
- For ref-counted allocations, credit the domain's claim on that node
to the available capacity. Allocations with MEMF_no_refcount receive
no credit, matching the existing host-wide check, since they do not
redeem claims. If the capacity is below the request, skip this node.
No functional change without per-node claims: the added check skips
nodes whose capacity is below the request. The existing per-zone loop
would reject such nodes anyway, so allocation outcomes are unchanged.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Assisted-by: Vibe:Mistral-Medium-3.5, Copilot:claude-opus-5-5 # review
Assisted-by: Copilot:gpt-6.2-astra, Copilot:gpt-6.2-sol # review
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
---
v8:
- Make d->claims a pointer to a separately allocated array,
or NULL when no per-node claims are installed. In v5-v7,
the array was embedded in struct domain. Allocate it only
when needed during domain build, leaving space in struct
domain for permanent state.
- Replace the assertion that free memory covers outstanding
claims with a subtraction clamped at zero. Free pages can
be offlined by XEN_SYSCTL_page_offline_op or machine-check
recovery, including for errors detected during scrubbing.
- Refactor the submission into smaller topic-focused patches.
- As suggested by Baptiste Le Duc, add request = 1UL << order
and use it in both locations that need to check the request.
- While at it, fix the incorrect comment above the zone check:
/* Check if target node can support the allocation. */
if ( !avail[node] || (avail[node][zone] < request) )
continue;
to:
/* Skip zones on the node that can't support the allocation. */
if ( !avail[node] || (avail[node][zone] < request) )
continue;
v5:
- Introduce the per-node claims array to track outstanding claims
on individual NUMA nodes.
- The previous, functionally equivalent per-node claims protection
method is deployed on all Citrix XenServer 9 installations.
---
xen/include/xen/sched.h | 2 ++
xen/common/page_alloc.c | 22 ++++++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 644cbf70d0..2ee5354bae 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -429,6 +429,8 @@ struct domain
unsigned int xenheap_pages; /* pages allocated from Xen heap */
/* Pages claimed but not possessed, protected by global heap_lock. */
unsigned int outstanding_pages;
+ /* Per-node claims array or NULL, protected by global heap_lock. */
+ unsigned int *claims;
unsigned int max_pages; /* maximum value for
domain_tot_pages() */
unsigned int extra_pages; /* pages not included in
domain_tot_pages() */
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 56df17ea6c..fba5a907e3 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -491,6 +491,9 @@ static DEFINE_SPINLOCK(heap_lock);
/* Total outstanding claims by all domains */
static unsigned long outstanding_claims;
+/* Outstanding claims of all domains on each NUMA node. */
+static unsigned long node_claimed_pages[MAX_NUMNODES];
+
static unsigned long avail_heap_pages(
unsigned int zone_lo, unsigned int zone_hi, unsigned int node)
{
@@ -863,6 +866,7 @@ static struct page_info *get_free_buddy(unsigned int
zone_lo,
unsigned int order, unsigned int
memflags,
const struct domain *d)
{
+ const unsigned long request = 1UL << order;
nodeid_t first, node = MEMF_get_node(memflags), req_node = node;
nodemask_t nodemask = node_online_map;
unsigned int j, zone, nodemask_retry = 0;
@@ -907,10 +911,23 @@ static struct page_info *get_free_buddy(unsigned int
zone_lo,
*/
for ( ; ; )
{
+ /* Offlining can reduce free pages below outstanding claims. */
+ unsigned long available =
+ node_avail_pages[node] > node_claimed_pages[node]
+ ? node_avail_pages[node] - node_claimed_pages[node]
+ : 0;
+
+ /* Ref-counted allocations may use the domain's per-node claim. */
+ if ( d && !(memflags & MEMF_no_refcount) && d->claims )
+ available += d->claims[node];
+
+ if ( available < request )
+ goto next_node;
+
zone = zone_hi;
do {
- /* Check if target node can support the allocation. */
- if ( !avail[node] || (avail[node][zone] < (1UL << order)) )
+ /* Skip zones on the node that can't support the allocation. */
+ if ( !avail[node] || (avail[node][zone] < request) )
continue;
/* Find smallest order which can satisfy the request. */
@@ -936,6 +953,7 @@ static struct page_info *get_free_buddy(unsigned int
zone_lo,
}
} while ( zone-- > zone_lo ); /* careful: unsigned zone may wrap */
+ next_node:
if ( (memflags & MEMF_exact_node) && req_node != NUMA_NO_NODE )
return NULL;
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |