Skip to contentSkip to conversation

xen/mm: Introduce NUMA-aware claim sets for domains

PATCH Superseded Bernhard Kaindl 2 participants 15 messages Apr 14 – May 5

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover xen/mm: Introduce NUMA-aware claim sets for domains

Hi all,

This series extends Xen's memory claim handling to support claim sets spanning multiple NUMA nodes.

Earlier review raised the concern that claims would need to evolve from a single claim into a multi-node model. Roger Pau Monné described the core requirement well:

Quoted 3 lines

Ideally, we would need to introduce a new hypercall that allows making claims from multiple nodes in a single locked region, as to ensure success or failure in an atomic way.

-- Roger Pau Monné

This submission implements that model, and its design and code have been validated through the following methods:

1. A suite of host-side integration tests (to be posted shortly), which can be executed on the build host (e.g., on a developer machine) like the PDX tests by Roger Pau Monné (make -C tools/tests/pdx run), as well as the domid and rangeset tests.

2. A comprehensive functional system test suite (with nineteen test cases), included in this v6 submission. These tests are run using automated deployment across various machine types and generations in our labs.

3. A set of high-level functional integration tests and performance tests, executed as part of end-to-end product deployment validation.

4. Validation in a customer's standardised application performance lab to confirm their performance expectations. (This testing was done on predecessor code sharing the same design, with the main difference being that only single-node claims were supported in the previous code base.)

The series has been reworked substantially in response to v4 review. Because of that, it is likely best reviewed as a fresh series rather than incrementally.

Patch summary:

1. xen/mm: Refactor deducting claims to prepare for functional changes
2. xen/mm: Claims check: Allow free pages to cover a shortfall of claims
3. xen/mm: Optimise getting free page counts per NUMA node
4. xen/mm: Split d->outstanding_pages to global_claims & node_claims
5. xen/mm: Introduce Claim Sets for multiple NUMA nodes
6. tools/ocaml/libs/xc: Add OCaml bindings for NUMA-aware claims
7. tools/tests/mem-claim: Add a test suite for the memory claim API

The v2 design document submitted ahead of this series may also help with review. It explains the background, design rationale, and implementation details.

Rendered version:
https://bernhard-xen.readthedocs.io/en/claim-sets-v2-design/designs/claims

Many thanks to everyone who contributed to the earlier work and review, especially Alejandro Vallejo, Jan Beulich, Andrew Cooper, Roger Pau Monné, Marcus Granado, and Edwin Török.

Changes since v5:
-----------------

- No functional changes for the sum of all commits.
(Adding a new function argument was moved to the commit that needs it.)

- Added a comprehensive test suite for the new hypercall using the libxenctrl wrapper xc_domain_claim_memory(), based on the test in tools/tests/mem-claim/test-mem-claim.c for the existing hypercall API by Andrew Cooper.

- Improved the function names to follow standard naming recommendations. The added functions are renamed as follows:

* claims_retire_allocation() -> redeem_claims_for_allocation()
- Use "redeem" because it is part of an exchange of claims for memory.

* claims_retire_global() -> deduct_global_claims()
* claims_retire_nodes() -> deduct_node_claims()
- These perform the act of reducing the amount of global/node claims.

* claims_retire_node() -> cancel_all_node_claims()
- Cancel all node claims when needed when the claims are terminated.

* The comments and the design document v2 have been updated accordingly.

Thanks,

Bernhard

Bernhard Kaindl (7):
xen/mm: Refactor claim deduction for later functional changes xen/mm: Allow free pages to cover a claims shortfall xen/mm: Optimise getting free page counts per NUMA node xen/mm: Split outstanding claims into global and node totals xen/mm: Introduce NUMA-aware memory claim sets tools/ocaml/libs/xc: Add an OCaml binding for NUMA-aware claims tools/tests/mem-claim: Add a test suite for the memory claim API

 tools/include/xenctrl.h                   |   4 +
 tools/libs/ctrl/xc_domain.c               |  38 +
 tools/ocaml/libs/xc/xenctrl.ml            |  11 +
 tools/ocaml/libs/xc/xenctrl.mli           |  11 +
 tools/ocaml/libs/xc/xenctrl_stubs.c       |  47 +
 tools/tests/mem-claim/.gitignore          |   1 +
 tools/tests/mem-claim/Makefile            |  17 +-
 tools/tests/mem-claim/accounting-1.h      | 401 +++++++++
 tools/tests/mem-claim/input-phase1.h      | 171 ++++
 tools/tests/mem-claim/input-phase2.h      |  91 ++
 tools/tests/mem-claim/libtestclaims.c     | 995 ++++++++++++++++++++++
 tools/tests/mem-claim/libtestclaims.h     | 202 +++++
 tools/tests/mem-claim/test-claim-memory.c | 129 +++
 xen/common/domctl.c                       |  56 +-
 xen/common/page_alloc.c                   | 374 +++++++-
 xen/include/public/domctl.h               |  32 +
 xen/include/public/memory.h               |   9 +
 xen/include/xen/mm.h                      |   3 +
 xen/include/xen/sched.h                   |  13 +-
 xen/xsm/flask/hooks.c                     |   1 +
 xen/xsm/flask/policy/access_vectors       |   1 +
 21 files changed, 2573 insertions(+), 34 deletions(-)
 create mode 100644 tools/tests/mem-claim/accounting-1.h
 create mode 100644 tools/tests/mem-claim/input-phase1.h
 create mode 100644 tools/tests/mem-claim/input-phase2.h
 create mode 100644 tools/tests/mem-claim/libtestclaims.c
 create mode 100644 tools/tests/mem-claim/libtestclaims.h
 create mode 100644 tools/tests/mem-claim/test-claim-memory.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v6 1/7 xen/mm: Refactor claim deduction for later functional changes

Refactor claim deduction to make the claims accounting model easier to follow ahead of later functional changes.

Three new callers will need to deduct claims, and two of them will also need the number of pages deducted to be returned.

No functional change.

---
History:

Functionally unchanged since v4, only minor cleanups have been applied and:
- Updated the function name deduct_global_claims() to follow standard naming.
- Moved the other function into another commit as it had no users here.

---
 xen/common/page_alloc.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
xen/common/page_alloc.c +15 -7
index b1edef87124f..80577aa4d50c 100644
@@ -518,6 +518,19 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
     return d->tot_pages;
 }
 
+/* Deduct up to the given amount of pages from the global claims of a domain */
+static unsigned long deduct_global_claims(struct domain *d,
+                                          unsigned long reduction)
+{
+    reduction = min(reduction, d->outstanding_pages + 0UL);
+    ASSERT(reduction <= outstanding_claims);
+
+    outstanding_claims -= reduction;
+    d->outstanding_pages -= reduction;
+
+    return reduction;
+}
+
 int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
 {
     int ret = -ENOMEM;
@@ -535,8 +548,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
     /* pages==0 means "unset" the claim. */
     if ( pages == 0 )
     {
-        outstanding_claims -= d->outstanding_pages;
-        d->outstanding_pages = 0;
+        deduct_global_claims(d, d->outstanding_pages);
         ret = 0;
         goto out;
     }
@@ -1067,11 +1079,7 @@ static struct page_info *alloc_heap_pages(
          * the domain being destroyed before creation is finished.  Losing part
          * of the claim makes no difference.
          */
-        unsigned long outstanding = min(d->outstanding_pages + 0UL, request);
-
-        BUG_ON(outstanding > outstanding_claims);
-        outstanding_claims -= outstanding;
-        d->outstanding_pages -= outstanding;
+        deduct_global_claims(d, request);
     }
 
     check_low_mem_virq();
Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH v6 1/7] xen/mm: Refactor claim deduction for later functional changes

Quoted 8 lines · Bernhard Kaindl

Refactor claim deduction to make the claims accounting model easier to follow ahead of later functional changes.

Three new callers will need to deduct claims, and two of them will also need the number of pages deducted to be returned.

No functional change.

Quoted 7 lines

---
History:

Functionally unchanged since v4, only minor cleanups have been applied and:
- Updated the function name deduct_global_claims() to follow standard naming.
- Moved the other function into another commit as it had no users here.

Is this true? In v4 ...

xen/common/page_alloc.c unsigned long domain_adjust_tot_pages(struct domain *d, long pages) · line 526

Quoted 12 lines
xen/common/page_alloc.c +6 -0
@@ -518,6 +518,19 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
     return d->tot_pages;
 }
 
+/* Deduct up to the given amount of pages from the global claims of a domain */
+static unsigned long deduct_global_claims(struct domain *d,
+                                          unsigned long reduction)
+{
+    reduction = min(reduction, d->outstanding_pages + 0UL);
+    ASSERT(reduction <= outstanding_claims);

... this was still BUG_ON(), matching ...

xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1072

Quoted 7 lines
xen/common/page_alloc.c +0 -3
@@ -1067,11 +1079,7 @@ static struct page_info *alloc_heap_pages(
          * the domain being destroyed before creation is finished.  Losing part
          * of the claim makes no difference.
          */
-        unsigned long outstanding = min(d->outstanding_pages + 0UL, request);
-
-        BUG_ON(outstanding > outstanding_claims);

... the original code. Changing this may be okay (albeit I'm unconvinced), but it would want justifying in the description then.

As to the rename to deduct_global_claims(): With that, wouldn't its 2nd parameter then better also change to "deduction"? Furthermore, "global" in the name is ambiguous: It may mean "not per-node", but it may also mean "not per-domain". The v4 name didn't have such an issue.

One other, wider aspect (which I may or may not have mentioned before):
The mix of unsigned long vs unsigned int for page counts is concerning. It is why the not overly nice "+ 0UL" is needed. I wonder if we wouldn't do ourselves a favor if we first normalized all that. Considering that systems (and hence guests) only ever get larger, it likely should all be unsigned long.

Jan

#3 lore raw

RE: [PATCH v6 1/7] xen/mm: Refactor claim deduction for later functional changes

Quoted 4 lines · Jan Beulich

As to the rename to deduct_global_claims(): With that, wouldn't its 2nd parameter then better also change to "deduction"? Furthermore, "global" in the name is ambiguous: It may mean "not per-node", but it may also mean "not per-domain". The v4 name didn't have such an issue.

I see the point about 'global'. While the struct domain argument provides context, the term is indeed too generic.

In this logic, 'global' was intended to refer to the opposite of node-specific claims. While the legacy codebase uses 'no-node' or NUMA_NO_NODE as a sentinel, I find those terms ambiguous for this new logic; they often imply a "missing" assignment rather than an explicit "any-node" policy.

'Node-agnostic' better describes the architectural intent: that these claims are valid regardless of node locality. To resolve the ambiguity, I will replace 'global' with 'node-agnostic' across the board (design documentation, code, and tests).

Specifically, I will:

Rename the function to deduct_node_agnostic_claims().

Update the second parameter to 'deduction' for consistency.

Update the function comment to explicitly define the scope.

/* Deduct from the domain's node-agnostic (non-per-node) claims pool */ static unsigned long deduct_node_agnostic_claims(struct domain *d,
unsigned long deduction)

While 'global' was shorter, 'node-agnostic' is much more descriptive of the actual logic and the node-locality (or lack thereof) being addressed, avoiding the potential confusion associated with 'no-node'.

For consistency, the corresponding renames across the series will be:

+--------------------------------+---------------------------------------+
| Original Term                  | New Term                              |
+--------------------------------+---------------------------------------+
| "global claims"                | "node-agnostic claims"                |
| d->global_claims               | d->node_agnostic_claims               |
| XEN_DOMCTL_CLAIM_MEMORY_GLOBAL | XEN_DOMCTL_CLAIM_MEMORY_NODE_AGNOSTIC |
| deduct_global_claims()         | deduct_node_agnostic_claims()         |
+--------------------------------+---------------------------------------+

I believe these changes result in less ambiguous language universally. Jan, could you Ack these renames for the next version of the series?

Bernhard

#4 lore raw

Re: [PATCH v6 1/7] xen/mm: Refactor claim deduction for later functional changes

Quoted 17 lines · Bernhard Kaindl
Quoted 4 lines · Jan Beulich

As to the rename to deduct_global_claims(): With that, wouldn't its 2nd parameter then better also change to "deduction"? Furthermore, "global" in the name is ambiguous: It may mean "not per-node", but it may also mean "not per-domain". The v4 name didn't have such an issue.

I see the point about 'global'. While the struct domain argument provides context, the term is indeed too generic.

In this logic, 'global' was intended to refer to the opposite of node-specific claims. While the legacy codebase uses 'no-node' or NUMA_NO_NODE as a sentinel, I find those terms ambiguous for this new logic; they often imply a "missing" assignment rather than an explicit "any-node" policy.

Quoted 8 lines

'Node-agnostic' better describes the architectural intent: that these claims are valid regardless of node locality. To resolve the ambiguity, I will replace 'global' with 'node-agnostic' across the board (design documentation, code, and tests).

Specifically, I will:

Rename the function to deduct_node_agnostic_claims().

Or deduct_host_claims() (short for deduct_host_wide_claims())?

Jan

Quoted 28 lines

Update the second parameter to 'deduction' for consistency.

Update the function comment to explicitly define the scope.

/* Deduct from the domain's node-agnostic (non-per-node) claims pool */ static unsigned long deduct_node_agnostic_claims(struct domain *d,
unsigned long deduction)

While 'global' was shorter, 'node-agnostic' is much more descriptive of the actual logic and the node-locality (or lack thereof) being addressed, avoiding the potential confusion associated with 'no-node'.

For consistency, the corresponding renames across the series will be:

+--------------------------------+---------------------------------------+
| Original Term                  | New Term                              |
+--------------------------------+---------------------------------------+
| "global claims"                | "node-agnostic claims"                |
| d->global_claims               | d->node_agnostic_claims               |
| XEN_DOMCTL_CLAIM_MEMORY_GLOBAL | XEN_DOMCTL_CLAIM_MEMORY_NODE_AGNOSTIC |
| deduct_global_claims()         | deduct_node_agnostic_claims()         |
+--------------------------------+---------------------------------------+

I believe these changes result in less ambiguous language universally. Jan, could you Ack these renames for the next version of the series?

Bernhard

#5 lore raw

RE: [PATCH v6 1/7] xen/mm: Refactor claim deduction for later functional changes

Quoted 10 lines · Jan Beulich
Quoted 8 lines

'Node-agnostic' better describes the architectural intent: that these claims are valid regardless of node locality. To resolve the ambiguity, I will replace 'global' with 'node-agnostic' across the board (design documentation, code, and tests).

Specifically, I will:

Rename the function to deduct_node_agnostic_claims().

Or deduct_host_claims() (short for deduct_host_wide_claims())?

Thanks, yes, I think host_claims is the better choice.

I also plan to make these helpers explicitly domain-scoped and switch from "deduct_" to "release_". This feels more natural in this context and avoids the finance-style wording.

The functions will become:
- domain_release_host_claims()
- domain_release_node_claims()

This clarifies the domain scope upfront and uses the more appropriate action.

I will send these updates with the v7 series of design, code, and tests.

Bernhard

#6 lore raw

RE: [PATCH v6 1/7] xen/mm: Refactor claim deduction for later functional changes

In reply to Jan Beulich

Hi Jan,

The mix of unsigned long vs unsigned int for page counts is concerning. [...]
I wonder if we wouldn't do ourselves a favor if we first normalized all that.

I agree. While I omitted this from v5/v6 to keep these claims series minimal (I had in in v4), addressing the type inconsistency first is the cleaner path.

I have submitted a standalone prerequisite patch here:
https://lists.xenproject.org/archives/html/xen-devel/2026-04/msg01134.html

As noted in that submission, this converts total_avail_pages and outstanding_claims to unsigned long and adjusts the ASSERT() logic to account for the move away from signed types.

Once the standalone patch is accepted, I can send a v7 of the claims series built on top of it.

Best regards,
Bernhard

#7 lore raw

PATCH v6 2/7 xen/mm: Allow free pages to cover a claims shortfall

In reply to Bernhard Kaindl

Allow an allocation to proceed when free, unclaimed memory can cover a claims shortfall.

In preparation for NUMA-aware claims, refactor this check into a reusable helper so the same logic can be applied to NUMA nodes.

---

Changes since v4: Extracted into a dedicated patch and merged the formerly separate functions into one, as suggested by Jan Beulich.

---
 xen/common/page_alloc.c | 41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)
xen/common/page_alloc.c +38 -3
index 80577aa4d50c..a67839413319 100644
@@ -868,6 +868,42 @@ static void check_and_stop_scrub(struct page_info *head)
     }
 }
 
+/*
+ * Allow the request when unclaimed pages suffice, or when a refcounted
+ * domain's outstanding claims cover the shortfall.
+ */
+static bool claims_permit_request(const struct domain *d,
+                                  unsigned long avail_pages,
+                                  unsigned long competing_claims,
+                                  unsigned int memflags,
+                                  unsigned long requested_pages)
+{
+    unsigned long unclaimed_pages;
+
+    ASSERT(spin_is_locked(&heap_lock));
+    ASSERT(avail_pages >= competing_claims);
+
+    /* Start from the free pages not already claimed by other domains. */
+    unclaimed_pages = avail_pages - competing_claims;
+
+    /* Allow the request to proceed when unclaimed pages suffice. */
+    if ( requested_pages <= unclaimed_pages )
+        return true;
+
+    /*
+     * If unclaimed pages are insufficient, only a refcounted domain allocation
+     * may use claims to cover the shortfall.
+     */
+    if ( !d || (memflags & MEMF_no_refcount) )
+        return false;
+
+    /*
+     * Allow the request to proceed when combination of unclaimed pages and the
+     * claims held by the domain cover the shortfall for the requested_pages.
+     */
+    return requested_pages <= unclaimed_pages + d->outstanding_pages;
+}
+
 static struct page_info *get_free_buddy(unsigned int zone_lo,
                                         unsigned int zone_hi,
                                         unsigned int order, unsigned int memflags,
@@ -1012,9 +1048,8 @@ static struct page_info *alloc_heap_pages(
      * Claimed memory is considered unavailable unless the request
      * is made by a domain with sufficient unclaimed pages.
      */
-    if ( (outstanding_claims + request > total_avail_pages) &&
-          ((memflags & MEMF_no_refcount) ||
-           !d || d->outstanding_pages < request) )
+    if ( !claims_permit_request(d, total_avail_pages, outstanding_claims,
+                                memflags, request) )
     {
         spin_unlock(&heap_lock);
         return NULL;
Signature · 1 line
2.39.5
#8 lore raw

Re: [PATCH v6 2/7] xen/mm: Allow free pages to cover a claims shortfall

Quoted 6 lines · Bernhard Kaindl

Allow an allocation to proceed when free, unclaimed memory can cover a claims shortfall.

In preparation for NUMA-aware claims, refactor this check into a reusable helper so the same logic can be applied to NUMA nodes.

Quoted 7 lines

---

Changes since v4: Extracted into a dedicated patch and merged the formerly separate functions into one, as suggested by Jan Beulich.

I did ask for the splitting out, no question. I can't find anything towards the functional change though in my v4 replies, and with that being the main aspect here I think Suggested-by: would credit me for something I didn't do or say.

xen/common/page_alloc.c static void check_and_stop_scrub(struct page_info *head) · line 873

Quoted 9 lines
xen/common/page_alloc.c +3 -0
@@ -868,6 +868,42 @@ static void check_and_stop_scrub(struct page_info *head)
     }
 }
 
+/*
+ * Allow the request when unclaimed pages suffice, or when a refcounted
+ * domain's outstanding claims cover the shortfall.

Nit: It's not the domain which is refcounted here (the refcounting there is something entirely different), but the allocation.

xen/common/page_alloc.c static void check_and_stop_scrub(struct page_info *head) · line 879

Quoted 6 lines
xen/common/page_alloc.c +6 -0
+ */
+static bool claims_permit_request(const struct domain *d,
+                                  unsigned long avail_pages,
+                                  unsigned long competing_claims,
+                                  unsigned int memflags,
+                                  unsigned long requested_pages)

I think it is good practice to have the main input parameter(s) first. That would be "requested_pages" here plus perhaps "memflags". The rest is auxiliary data to perform the needed calculation.

May I further suggest to drop _pages everywhere?

I'm further not happy about "competing" in the parameter name: This includes claims for this very domain as well, and if there's no other claim then there's nothing "competing" at all.

xen/common/page_alloc.c static void check_and_stop_scrub(struct page_info *head) · line 887

Quoted 8 lines
xen/common/page_alloc.c +8 -0
+{
+    unsigned long unclaimed_pages;
+
+    ASSERT(spin_is_locked(&heap_lock));
+    ASSERT(avail_pages >= competing_claims);
+
+    /* Start from the free pages not already claimed by other domains. */
+    unclaimed_pages = avail_pages - competing_claims;

This could easily be the initializer of the variable.

Jan

#9 lore raw

PATCH v6 3/7 xen/mm: Optimise getting free page counts per NUMA node

In reply to Bernhard Kaindl

From: Alejandro Vallejo <[email protected]>

Introduce per-node free page counters to improve the efficiency of avail_node_heap_pages():

- It no longer needs to iterate over all zones in a node.

- It is used by the numainfo hypercall and the debug key 'u' to display NUMA information in the printk buffer.

- It will also be needed by node-specific claims to determine the number of free pages in a node in the hot path of get_free_buddy() without looping over all zones.

No functional change.

---

Applied Jan's review:
https://lists.xenproject.org/archives/html/xen-devel/2026-03/msg00144.html

Changes:
- Removed accessor macro
- Abandoned conversion to unsigned long

---
 xen/common/page_alloc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
xen/common/page_alloc.c +18 -1
index a67839413319..28c424072d25 100644
@@ -485,7 +485,20 @@ static unsigned long node_need_scrub[MAX_NUMNODES];
 
 static unsigned long *avail[MAX_NUMNODES];
 static long total_avail_pages;
+/*
+ * Sum of the free pages in all zones of that node.
+ * Provided via sysctl by NUMA node placement decisions of domain builders and
+ * for monitoring. It is also logged with debug-key 'u' for NUMA debugging.
+ */
+static long node_avail_pages[MAX_NUMNODES];
 
+/*
+ * The global heap lock, protecting access to the heap and related structures.
+ * It protects the heap and claims of the buddy allocator and d->*claims.
+ * The locking order is: d->page_alloc_lock (optional) -> heap_lock
+ * - Numerous external callers holding d->page_alloc_lock call functions
+ *   taking the heap_lock. Note: Violating it would cause an ABBA deadlock.
+ */
 static DEFINE_SPINLOCK(heap_lock);
 static long outstanding_claims; /* total outstanding claims by all domains */
 
@@ -1092,6 +1105,8 @@ static struct page_info *alloc_heap_pages(
         }
     }
 
+    ASSERT(node_avail_pages[node] >= request);
+    node_avail_pages[node] -= request;
     ASSERT(avail[node][zone] >= request);
     avail[node][zone] -= request;
     total_avail_pages -= request;
@@ -1282,6 +1297,7 @@ static int reserve_offlined_page(struct page_info *head)
         if ( !page_state_is(cur_head, offlined) )
             continue;
 
+        node_avail_pages[node]--;
         avail[node][zone]--;
         total_avail_pages--;
         ASSERT(total_avail_pages >= 0);
@@ -1606,6 +1622,7 @@ static void free_heap_pages(
         }
     }
 
+    node_avail_pages[node] += 1 << order;
     avail[node][zone] += 1 << order;
     total_avail_pages += 1 << order;
     if ( need_scrub )
@@ -2873,7 +2890,7 @@ unsigned long avail_domheap_pages_region(
 
 unsigned long avail_node_heap_pages(unsigned int nodeid)
 {
-    return avail_heap_pages(MEMZONE_XEN, NR_ZONES -1, nodeid);
+    return node_avail_pages[nodeid];
 }
 
 
Signature · 1 line
2.39.5
#10 lore raw

PATCH v6 4/7 xen/mm: Split outstanding claims into global and node totals

In reply to Bernhard Kaindl

Replace d->outstanding_pages with d->global_claims and add d->node_claims as the aggregate of the domain's node-specific claims.

Keep the allocator hot path efficient and report the combined claims state using the two new fields.

No functional change.

---
 xen/common/domctl.c     |  2 +-
 xen/common/page_alloc.c | 33 ++++++++++++++++-----------------
 xen/include/xen/sched.h |  7 +++++--
 3 files changed, 22 insertions(+), 20 deletions(-)
xen/common/domctl.c +1 -1
index 93738931c575..2cc5a4ff32fd 100644
@@ -97,7 +97,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
 
     info->tot_pages         = domain_tot_pages(d);
     info->max_pages         = d->max_pages;
-    info->outstanding_pages = d->outstanding_pages;
+    info->outstanding_pages = d->global_claims + d->node_claims;
 #ifdef CONFIG_MEM_SHARING
     info->shr_pages         = atomic_read(&d->shr_pages);
 #endif
xen/common/page_alloc.c +16 -17
index 28c424072d25..ee4942f93373 100644
@@ -535,11 +535,11 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
 static unsigned long deduct_global_claims(struct domain *d,
                                           unsigned long reduction)
 {
-    reduction = min(reduction, d->outstanding_pages + 0UL);
+    reduction = min(reduction, d->global_claims + 0UL);
     ASSERT(reduction <= outstanding_claims);
 
     outstanding_claims -= reduction;
-    d->outstanding_pages -= reduction;
+    d->global_claims -= reduction;
 
     return reduction;
 }
@@ -552,8 +552,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
     /*
      * Two locks are needed here:
      *  - d->page_alloc_lock: protects accesses to d->{tot,max,extra}_pages.
-     *  - heap_lock: protects accesses to d->outstanding_pages, total_avail_pages
-     *    and outstanding_claims.
+     *  - heap_lock: Protects accesses to the claims and avail_pages state.
      */
     nrspin_lock(&d->page_alloc_lock);
     spin_lock(&heap_lock);
@@ -561,13 +560,13 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
     /* pages==0 means "unset" the claim. */
     if ( pages == 0 )
     {
-        deduct_global_claims(d, d->outstanding_pages);
+        deduct_global_claims(d, d->global_claims);
         ret = 0;
         goto out;
     }
 
-    /* only one active claim per domain please */
-    if ( d->outstanding_pages )
+    /* Reject updating global claims and we can't update node claims */
+    if ( d->global_claims || d->node_claims )
     {
         ret = -EINVAL;
         goto out;
@@ -594,8 +593,8 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
         goto out;
 
     /* yay, claim fits in available memory, stake the claim, success! */
-    d->outstanding_pages = claim;
-    outstanding_claims += d->outstanding_pages;
+    d->global_claims = claim;
+    outstanding_claims += claim;
     ret = 0;
 
 out:
@@ -891,7 +890,7 @@ static bool claims_permit_request(const struct domain *d,
                                   unsigned int memflags,
                                   unsigned long requested_pages)
 {
-    unsigned long unclaimed_pages;
+    unsigned long unclaimed_pages, applicable_claims;
 
     ASSERT(spin_is_locked(&heap_lock));
     ASSERT(avail_pages >= competing_claims);
@@ -910,11 +909,13 @@ static bool claims_permit_request(const struct domain *d,
     if ( !d || (memflags & MEMF_no_refcount) )
         return false;
 
+    applicable_claims = d->global_claims;
+
     /*
      * Allow the request to proceed when combination of unclaimed pages and the
      * claims held by the domain cover the shortfall for the requested_pages.
      */
-    return requested_pages <= unclaimed_pages + d->outstanding_pages;
+    return requested_pages <= unclaimed_pages + applicable_claims;
 }
 
 static struct page_info *get_free_buddy(unsigned int zone_lo,
@@ -1112,18 +1113,16 @@ static struct page_info *alloc_heap_pages(
     total_avail_pages -= request;
     ASSERT(total_avail_pages >= 0);
 
-    if ( d && d->outstanding_pages && !(memflags & MEMF_no_refcount) )
+    if ( d && d->global_claims && !(memflags & MEMF_no_refcount) )
     {
         /*
          * Adjust claims in the same locked region where total_avail_pages is
          * adjusted, not doing so would lead to a window where the amount of
          * free memory (avail - claimed) would be incorrect.
          *
-         * Note that by adjusting the claimed amount here it's possible for
-         * pages to fail to be assigned to the claiming domain while already
-         * having been subtracted from d->outstanding_pages.  Such claimed
-         * amount is then lost, as the pages that fail to be assigned to the
-         * domain are freed without replenishing the claim.  This is fine given
+         * Note, after redeeming claims for the allocation here, assign_pages()
+         * could fail. The domain looses The redeemed claims as the not assigned
+         * pages are freed without replenishing the claim.  This is fine given
          * claims are only to be used during physmap population as part of
          * domain build, and any failure in assign_pages() there will result in
          * the domain being destroyed before creation is finished.  Losing part
xen/include/xen/sched.h +5 -2
index 212c7d765c3e..2995c99aa34a 100644
@@ -413,8 +413,11 @@ struct domain
     unsigned int     tot_pages;
 
     unsigned int     xenheap_pages;     /* pages allocated from Xen heap */
-    /* Pages claimed but not possessed, protected by global heap_lock. */
-    unsigned int     outstanding_pages;
+
+    /* All claims are protected by the heap_lock */
+    unsigned int     global_claims;     /* Global Host-level claims */
+    unsigned int     node_claims;       /* Sum of the Node-specific claims */
+
     unsigned int     max_pages;         /* maximum value for domain_tot_pages() */
     unsigned int     extra_pages;       /* pages not included in domain_tot_pages() */
 
Signature · 1 line
2.39.5
#11 lore raw

Re: [PATCH v6 4/7] xen/mm: Split outstanding claims into global and node totals

Quoted 5 lines · Bernhard Kaindl

Replace d->outstanding_pages with d->global_claims and add d->node_claims as the aggregate of the domain's node-specific claims.

Keep the allocator hot path efficient and report the combined claims state using the two new fields.

The truly new field (node_claims) is in fact dead code (as per Misra's definition of the term). It therefore doesn't feel quite right that it is being introduced without (really) being used.

xen/common/page_alloc.c int domain_set_outstanding_pages(struct domain *d, unsigned long pages) · line 558

Quoted 10 lines
xen/common/page_alloc.c +1 -2
@@ -552,8 +552,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
     /*
      * Two locks are needed here:
      *  - d->page_alloc_lock: protects accesses to d->{tot,max,extra}_pages.
-     *  - heap_lock: protects accesses to d->outstanding_pages, total_avail_pages
-     *    and outstanding_claims.
+     *  - heap_lock: Protects accesses to the claims and avail_pages state.
      */
     nrspin_lock(&d->page_alloc_lock);
     spin_lock(&heap_lock);

By removing the use of d-> from the bullet point, you make the result appear to all be only global state. Imo the fields still wants mentioning like it was before.

Quoted 7 lines
xen/common/page_alloc.c +1 -1
@@ -561,13 +560,13 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
     /* pages==0 means "unset" the claim. */
     if ( pages == 0 )
     {
-        deduct_global_claims(d, d->outstanding_pages);
+        deduct_global_claims(d, d->global_claims);
         ret = 0;

xen/common/page_alloc.c int domain_set_outstanding_pages(struct domain *d, unsigned long pages) · line 572

Quoted 10 lines
xen/common/page_alloc.c +2 -2
         goto out;
     }
 
-    /* only one active claim per domain please */
-    if ( d->outstanding_pages )
+    /* Reject updating global claims and we can't update node claims */
+    if ( d->global_claims || d->node_claims )
     {
         ret = -EINVAL;
         goto out;

Is there anything wrong with the original comment (apart from style)? Especially the new "we can't" feels misleading - if we indeed can't, this is something that could be fixed. Isn't more like we may not fiddle with node claims here? Plus mentioning node claims when they aren't a thing yet is somewhat odd, too. Remember: Patches in a series may go if with arbitrarily large gaps in between.

Quoted 12 lines
xen/common/page_alloc.c +1 -1
@@ -891,7 +890,7 @@ static bool claims_permit_request(const struct domain *d,
                                   unsigned int memflags,
                                   unsigned long requested_pages)
 {
-    unsigned long unclaimed_pages;
+    unsigned long unclaimed_pages, applicable_claims;
 
     ASSERT(spin_is_locked(&heap_lock));
     ASSERT(avail_pages >= competing_claims);
@@ -910,11 +909,13 @@ static bool claims_permit_request(const struct domain *d,
     if ( !d || (memflags & MEMF_no_refcount) )
         return false;

xen/common/page_alloc.c static bool claims_permit_request(const struct domain *d, · line 919

Quoted 10 lines
xen/common/page_alloc.c +3 -1
 
+    applicable_claims = d->global_claims;
+
     /*
      * Allow the request to proceed when combination of unclaimed pages and the
      * claims held by the domain cover the shortfall for the requested_pages.
      */
-    return requested_pages <= unclaimed_pages + d->outstanding_pages;
+    return requested_pages <= unclaimed_pages + applicable_claims;
 }

I don't follow what use these two hunks are here.

Quoted 9 lines
xen/common/page_alloc.c +1 -1
@@ -1112,18 +1113,16 @@ static struct page_info *alloc_heap_pages(
     total_avail_pages -= request;
     ASSERT(total_avail_pages >= 0);
 
-    if ( d && d->outstanding_pages && !(memflags & MEMF_no_refcount) )
+    if ( d && d->global_claims && !(memflags & MEMF_no_refcount) )
     {
         /*
          * Adjust claims in the same locked region where total_avail_pages is

xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1124

Quoted 10 lines
xen/common/page_alloc.c +2 -5
          * adjusted, not doing so would lead to a window where the amount of
          * free memory (avail - claimed) would be incorrect.
          *
-         * Note that by adjusting the claimed amount here it's possible for
-         * pages to fail to be assigned to the claiming domain while already
-         * having been subtracted from d->outstanding_pages.  Such claimed
-         * amount is then lost, as the pages that fail to be assigned to the
-         * domain are freed without replenishing the claim.  This is fine given
+         * Note, after redeeming claims for the allocation here, assign_pages()
+         * could fail. The domain looses The redeemed claims as the not assigned

Nit: ... loses the ...

xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 1128

Quoted 4 lines
xen/common/page_alloc.c +1 -0
+         * pages are freed without replenishing the claim.  This is fine given
          * claims are only to be used during physmap population as part of
          * domain build, and any failure in assign_pages() there will result in
          * the domain being destroyed before creation is finished.  Losing part

I'm not convinced this comment needs fiddling with. There's nothing obviously wrong, and I don't see an obvious improvement from the changes.

Jan

#12 lore raw

PATCH v6 5/7 xen/mm: Introduce NUMA-aware memory claim sets

In reply to Bernhard Kaindl

Extend Xen's memory claim handling to support claim sets spanning multiple NUMA nodes.

Earlier review raised the concern that claims would need to evolve from a single claim into a multi-node model. Roger Pau Monné described the core requirement well:

Quoted 3 lines

Ideally, we would need to introduce a new hypercall that allows making claims from multiple nodes in a single locked region, as to ensure success or failure in an atomic way.

-- Roger Pau Monné

Implement that model.

A claim set can contain multiple node-specific claims and an optional global claim for memory that may come from any NUMA node. The new domctl installs the full claim set atomically, and the allocator is updated so that claim checks and claim consumption follow the new semantics.

This adds:

1. Installing multi-node claim sets atomically,
2. protecting claimed pages from other claim requests and allocations,
3. redeeming claims for allocations with claims,
4. while keeping the legacy claim interface without functional changes.

---
The v2 design document submitted ahead of this series may help with review. It explains the background, design rationale, and implementation details.

Rendered version:
https://bernhard-xen.readthedocs.io/en/claim-sets-v2-design/designs/claims

Many thanks to everyone who contributed to the earlier work and review, especially Alejandro Vallejo, Jan Beulich, Andrew Cooper, Roger Pau Monné, Marcus Granado, and Edwin Török.

Thanks,

Bernhard

---
 tools/include/xenctrl.h             |   4 +
 tools/libs/ctrl/xc_domain.c         |  38 ++++
 xen/common/domctl.c                 |  54 ++++++
 xen/common/page_alloc.c             | 277 +++++++++++++++++++++++++++-
 xen/include/public/domctl.h         |  32 ++++
 xen/include/public/memory.h         |   9 +
 xen/include/xen/mm.h                |   3 +
 xen/include/xen/sched.h             |   6 +
 xen/xsm/flask/hooks.c               |   1 +
 xen/xsm/flask/policy/access_vectors |   1 +
 10 files changed, 420 insertions(+), 5 deletions(-)
tools/include/xenctrl.h +4 -0
index d5dbf69c8968..a0a9f2143b32 100644
@@ -2659,6 +2659,10 @@ int xc_domain_set_llc_colors(xc_interface *xch, uint32_t domid,
                              const uint32_t *llc_colors,
                              uint32_t num_llc_colors);
 
+int xc_domain_claim_memory(xc_interface *xch, uint32_t domid,
+                           uint32_t nr_claims,
+                           memory_claim_t *claims);
+
 #if defined(__arm__) || defined(__aarch64__)
 int xc_dt_overlay(xc_interface *xch, void *overlay_fdt,
                   uint32_t overlay_fdt_size, uint8_t overlay_op);
tools/libs/ctrl/xc_domain.c +38 -0
index 01c0669c8863..32cd91187d44 100644
@@ -1070,6 +1070,44 @@ int xc_domain_remove_from_physmap(xc_interface *xch,
     return xc_memory_op(xch, XENMEM_remove_from_physmap, &xrfp, sizeof(xrfp));
 }
 
+/* Claim the guest memory for a domain before starting the domain build */
+int xc_domain_claim_memory(xc_interface *xch,
+                           uint32_t domid,
+                           uint32_t nr_claims,
+                           memory_claim_t *claims)
+{
+    struct xen_domctl domctl = {};
+    DECLARE_HYPERCALL_BOUNCE(claims, sizeof(*claims) * nr_claims,
+                             XC_HYPERCALL_BUFFER_BOUNCE_IN);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, claims) )
+        return -1;
+
+    domctl.cmd = XEN_DOMCTL_claim_memory;
+    domctl.domain = domid;
+    domctl.u.claim_memory.nr_claims = nr_claims;
+    set_xen_guest_handle(domctl.u.claim_memory.claims, claims);
+
+    ret = do_domctl(xch, &domctl);
+
+    xc_hypercall_bounce_post(xch, claims);
+
+    return ret;
+}
+
+/*
+ * Legacy API for claiming pages, replaced by xc_domain_claim_memory()
+ *
+ * Note: This hypercall is deprecated by xc_domain_claim_memory()
+ * which provides the same claim semantics described above, and thus can be
+ * used as drop-in replacement and is extended for NUMA-node-specific claims.
+ * This hypercall should not be used by new code.
+ *
+ * See the following documentation pages for more information:
+ * docs/guest-guide/dom/DOMCTL_claim_memory.rst
+ * docs/guest-guide/mem/XENMEM_claim_pages.rst
+ */
 int xc_domain_claim_pages(xc_interface *xch,
                                uint32_t domid,
                                unsigned long nr_pages)
xen/common/domctl.c +54 -0

66 lines not on this page · raw message

xen/common/page_alloc.c +272 -5

345 lines not on this page · raw message

xen/include/public/domctl.h +32 -0
index 8f6708c0a7cd..a4f08248e6ee 100644
@@ -1276,6 +1276,36 @@ struct xen_domctl_get_domain_state {
     uint64_t unique_id;      /* Unique domain identifier. */
 };
 
+struct xen_memory_claim {
+    uint64_aligned_t pages; /* Number of pages to claim */
+    uint32_t target; /* Node and/or claim type like legacy or a global claim */
+    uint32_t pad;    /* Explicit padding: Reserved, initialize to 0 on input */
+};
+typedef struct xen_memory_claim memory_claim_t;
+DEFINE_XEN_GUEST_HANDLE(memory_claim_t);
+
+/* Special claim targets for the target field of memory_claim_t */
+#define XEN_DOMCTL_CLAIM_MEMORY_LEGACY 0x40000000U /* No node, legacy claim */
+#define XEN_DOMCTL_CLAIM_MEMORY_GLOBAL 0x80000000U /* No node, global claim */
+
+/*
+ * XEN_DOMCTL_claim_memory
+ *
+ * Claim memory for a guest domain. It sets aside an amount of memory
+ * (it is not pre-allocated) for the purpose of satisfying future memory
+ * allocation requests for building the guest's physical address space.
+ * Memory can be claimed on a set of nodes, or globally (without node
+ * affinity), or with legacy behavior. The set of claims is a claim set. See
+ * docs/guest-guide/dom/DOMCTL_claim_memory.rsti and docs/designs/claims/.
+ */
+struct xen_domctl_claim_memory {
+    /* IN: Array of struct xen_memory_claim */
+    XEN_GUEST_HANDLE_64(memory_claim_t) claims;
+    /* IN: Number of claims in the claims array handle. */
+    uint32_t nr_claims;
+    uint32_t pad;  /* Explicit padding: Reserved, initialize to 0 on input */
+};
+
 struct xen_domctl {
 /* Stable domctl ops: interface_version is required to be 0.  */
     uint32_t cmd;
@@ -1368,6 +1398,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_gsi_permission                88
 #define XEN_DOMCTL_set_llc_colors                89
 #define XEN_DOMCTL_get_domain_state              90 /* stable interface */
+#define XEN_DOMCTL_claim_memory                  91
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
@@ -1436,6 +1467,7 @@ struct xen_domctl {
 #endif
         struct xen_domctl_set_llc_colors    set_llc_colors;
         struct xen_domctl_get_domain_state  get_domain_state;
+        struct xen_domctl_claim_memory      claim_memory;
         uint8_t                             pad[128];
     } u;
 };
xen/include/public/memory.h +9 -0
index bd9fc37b5297..ccec095f8660 100644
@@ -569,6 +569,15 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_sharing_op_t);
  * for 10, only 7 additional pages are claimed.
  *
  * Caller must be privileged or the hypercall fails.
+ *
+ * Note: This hypercall is deprecated by XEN_DOMCTL_claim_memory
+ * which provides the same claim semantics described above, and thus can be
+ * used as drop-in replacement and is extended for NUMA-node-specific claims.
+ * This hypercall should not be used by new code.
+ *
+ * See the following documentation pages for more information:
+ * docs/guest-guide/dom/DOMCTL_claim_memory.rst
+ * docs/guest-guide/mem/XENMEM_claim_pages.rst
  */
 #define XENMEM_claim_pages                  24
 
xen/include/xen/mm.h +3 -0
index b80bec00c124..b2d6a6f266ba 100644
@@ -69,6 +69,7 @@
 #include <xen/list.h>
 #include <xen/spinlock.h>
 #include <xen/perfc.h>
+#include <public/domctl.h>
 #include <public/memory.h>
 
 struct page_info;
@@ -131,6 +132,8 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns);
 /* Claim handling */
 unsigned long __must_check domain_adjust_tot_pages(struct domain *d,
     long pages);
+int domain_install_claim_set(struct domain *d, unsigned int nr_claims,
+                             memory_claim_t *claims);
 int domain_set_outstanding_pages(struct domain *d, unsigned long pages);
 void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages);
 
xen/include/xen/sched.h +6 -0
index 2995c99aa34a..d31f4546e3b0 100644
@@ -417,6 +417,12 @@ struct domain
     /* All claims are protected by the heap_lock */
     unsigned int     global_claims;     /* Global Host-level claims */
     unsigned int     node_claims;       /* Sum of the Node-specific claims */
+    /*
+     * struct domain is allocated in a dedicated page with more than enough
+     * spare capacity. It's efficient to use that page to store the
+     * per-node claims in it instead allocating a separate array for it.
+     */
+    unsigned int     claims[MAX_NUMNODES]; /* Array of per-NUMA-node claims */
 
     unsigned int     max_pages;         /* maximum value for domain_tot_pages() */
     unsigned int     extra_pages;       /* pages not included in domain_tot_pages() */
xen/xsm/flask/hooks.c +1 -0
index 28522dcbd271..9e999ac1ba73 100644
@@ -651,6 +651,7 @@ static int cf_check flask_domctl(struct domain *d, unsigned int cmd,
 
     /* These have individual XSM hooks (common/domctl.c) */
     case XEN_DOMCTL_getdomaininfo:
+    case XEN_DOMCTL_claim_memory:
     case XEN_DOMCTL_scheduler_op:
     case XEN_DOMCTL_irq_permission:
     case XEN_DOMCTL_iomem_permission:
xen/xsm/flask/policy/access_vectors +1 -0
index bbb9c117ec4a..e7defa117a16 100644
@@ -216,6 +216,7 @@ class domain2
 # XEN_DOMCTL_scheduler_op with XEN_DOMCTL_SCHEDOP_putinfo
     setscheduler
 # XENMEM_claim_pages
+# XEN_DOMCTL_claim_memory
     setclaim
 # XEN_DOMCTL_cacheflush
     cacheflush
Signature · 1 line
2.39.5
#13 lore raw

PATCH v6 6/7 tools/ocaml/libs/xc: Add an OCaml binding for NUMA-aware claims

In reply to Bernhard Kaindl

Add an OCaml binding for xc_domain_claim_memory() so the XEN_DOMCTL_claim_memory hypercall can be used from OCaml.

This allows OCaml toolstacks to place NUMA-aware memory claims for domains as well as host-wide claims.

tools/ocaml/libs/xc/xenctrl.ml/mli:
- Add claim record type and domain_claim_memory external.

tools/ocaml/libs/xc/xenctrl_stubs.c:
- Validate claim count and arguments.
- Marshal the OCaml claim array to memory_claim_t[].
- Map node/target of -1 to XEN_DOMCTL_CLAIM_MEMORY_GLOBAL.

---
 tools/ocaml/libs/xc/xenctrl.ml      | 11 +++++++
 tools/ocaml/libs/xc/xenctrl.mli     | 11 +++++++
 tools/ocaml/libs/xc/xenctrl_stubs.c | 47 +++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
tools/ocaml/libs/xc/xenctrl.ml +11 -0
index 97108b9d861a..680cd8ec5449 100644
@@ -370,6 +370,17 @@ external domain_deassign_device: handle -> domid -> (int * int * int * int) -> u
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
   = "stub_xc_domain_test_assign_device"
 
+(* OCaml binding for xc_domain_claim_memory(): Install claim sets for a domain,
+   target is either a NUMA node or -1 for no node - memory from any node). *)
+
+type claim =
+  {
+    pages: int64;   (* Number of pages to claim *)
+    target: int32;  (* Target: NUMA node ID, or -1 for a flexible claim *)
+  }
+external domain_claim_memory: handle -> domid -> claim array -> unit
+  = "stub_xc_domain_claim_memory"
+
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
   = "stub_xc_version_compile_info"
tools/ocaml/libs/xc/xenctrl.mli +11 -0
index 9fccb2c2c287..8a7c53a09d97 100644
@@ -297,6 +297,17 @@ external domain_deassign_device: handle -> domid -> (int * int * int * int) -> u
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
   = "stub_xc_domain_test_assign_device"
 
+(* OCaml binding for xc_domain_claim_memory(): Install claim sets for a domain,
+   target is either a NUMA node or -1 for no node - memory from any node). *)
+
+type claim =
+  {
+    pages: int64;   (* Number of pages to claim *)
+    target: int32;  (* Target: NUMA node ID, or -1 for a flexible claim *)
+  }
+external domain_claim_memory: handle -> domid -> claim array -> unit
+  = "stub_xc_domain_claim_memory"
+
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
tools/ocaml/libs/xc/xenctrl_stubs.c +47 -0

53 lines not on this page · raw message

Signature · 1 line
2.39.5
#14 lore raw

PATCH v6 7/7 tools/tests/mem-claim: Add a test suite for the memory claim API

In reply to Bernhard Kaindl

Add a comprehensive test suite for the xc_domain_claim_memory() API that covers argument validation and the protection semantics of memory claims across domains and NUMA nodes.

The suite verifies claim behaviour both globally and per-node, and checks how claims interact with allocations and replacement semantics.

Key checks include:

- Argument validation and correct errno handling for invalid inputs.
- NUMA-aware claim sets, covering node-specific and global targets.
- Replacement semantics after allocations (global and node-scoped).
- Inter-domain protection and claim movement across NUMA nodes.

---
 tools/tests/mem-claim/.gitignore          |   1 +
 tools/tests/mem-claim/Makefile            |  17 +-
 tools/tests/mem-claim/accounting-1.h      | 401 +++++++++
 tools/tests/mem-claim/input-phase1.h      | 171 ++++
 tools/tests/mem-claim/input-phase2.h      |  91 ++
 tools/tests/mem-claim/libtestclaims.c     | 995 ++++++++++++++++++++++
 tools/tests/mem-claim/libtestclaims.h     | 202 +++++
 tools/tests/mem-claim/test-claim-memory.c | 129 +++
 8 files changed, 2000 insertions(+), 7 deletions(-)
 create mode 100644 tools/tests/mem-claim/accounting-1.h
 create mode 100644 tools/tests/mem-claim/input-phase1.h
 create mode 100644 tools/tests/mem-claim/input-phase2.h
 create mode 100644 tools/tests/mem-claim/libtestclaims.c
 create mode 100644 tools/tests/mem-claim/libtestclaims.h
 create mode 100644 tools/tests/mem-claim/test-claim-memory.c
tools/tests/mem-claim/.gitignore +1 -0
index cfcee00b819b..08365576b22b 100644
@@ -1 +1,2 @@
 test-mem-claim
+test-claim-memory
tools/tests/mem-claim/Makefile +10 -7
index 76ba3e3c8bef..77decd4b0d05 100644
@@ -1,14 +1,16 @@
 XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGET := test-mem-claim
+TARGETS := test-mem-claim test-claim-memory
+
+LIB_OBJ := libtestclaims.o
 
 .PHONY: all
-all: $(TARGET)
+all: $(TARGETS)
 
 .PHONY: clean
 clean:
-	$(RM) -- *.o $(TARGET) $(DEPS_RM)
+	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
@@ -17,11 +19,11 @@ distclean: clean
 .PHONY: install
 install: all
 	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
-	$(INSTALL_PROG) $(TARGET) $(DESTDIR)$(LIBEXEC)/tests
+	$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC)/tests
 
 .PHONY: uninstall
 uninstall:
-	$(RM) -- $(DESTDIR)$(LIBEXEC)/tests/$(TARGET)
+	$(RM) -- $(patsubst %,$(DESTDIR)$(LIBEXEC)/tests/%,$(TARGETS))
 
 CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(CFLAGS_libxenctrl)
@@ -32,7 +34,8 @@ LDFLAGS += $(APPEND_LDFLAGS)
 
 %.o: Makefile
 
-$(TARGET): test-mem-claim.o
-	$(CC) -o $@ $< $(LDFLAGS)
+
+$(TARGETS): %: %.o $(LIB_OBJ)
+	$(CC) -o $@ $^ $(LDFLAGS)
 
 -include $(DEPS_INCLUDE)
tools/tests/mem-claim/accounting-1.h new file +401 -0

401 lines not on this page · raw message

tools/tests/mem-claim/input-phase1.h new file +171 -0

171 lines not on this page · raw message

tools/tests/mem-claim/input-phase2.h new file +91 -0

91 lines not on this page · raw message

tools/tests/mem-claim/libtestclaims.c new file +995 -0

995 lines not on this page · raw message

tools/tests/mem-claim/libtestclaims.h new file +202 -0

202 lines not on this page · raw message

tools/tests/mem-claim/test-claim-memory.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.39.5