|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 3/8] xen/mm: redeem per-node claims for allocations
Redeeming a claim means consuming it through allocation:
each page allocated to the domain decreases its claim.
As part of the allocation, alloc_heap_pages() reduces the
domain's outstanding_pages and the global outstanding_claims.
To redeem per-node claims, reduce both the node’s outstanding
claim total and the domain’s claim on that node.
If the allocation exceeds the domain's claims on that node, to
keep the sum of assigned and claimed pages within the domain's
limit, redeem the remainder from the host-wide claims of the domain,
and if needed, from other per-node claim pools of the domain.
Redemption still precedes assign_pages(). When assignment fails,
the pages are freed without restoring the redeemed claims. This
still relies on the domain builder abandoning the failed domain
build as documented in the existing comment above the code.
With no per-node claims, redemption of claims is unchanged.
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>
---
Changes in v8:
- Refactor the submission into smaller topic-focused patches.
- Name the new helpers after the redemption steps and clarify
their comments, variable names and argument names.
- Keep availability-counter updates before claim redemption;
both remain protected by heap_lock.
- Add missing blank lines.
---
xen/common/page_alloc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 79 insertions(+), 2 deletions(-)
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index ceb074a249..df23c31d85 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -523,6 +523,75 @@ unsigned long domain_adjust_tot_pages(struct domain *d,
long pages)
return d->tot_pages;
}
+/* Redeem up to @pages of the claim on @node; return the pages redeemed. */
+static unsigned long domain_redeem_node_claim(struct domain *d,
+ unsigned int node,
+ unsigned long pages)
+{
+ ASSERT(spin_is_locked(&heap_lock));
+
+ if ( !d->node_claims )
+ return 0;
+ if ( pages > d->claims[node] )
+ pages = d->claims[node];
+
+ ASSERT(node_claimed_pages[node] >= pages);
+ ASSERT(d->node_claims >= pages);
+ ASSERT(d->outstanding_pages >= pages);
+ ASSERT(outstanding_claims >= pages);
+
+ node_claimed_pages[node] -= pages;
+ d->claims[node] -= pages;
+ d->node_claims -= pages;
+ d->outstanding_pages -= pages;
+ outstanding_claims -= pages;
+
+ return pages;
+}
+
+/* Redeem up to @pages of the host-wide claim; return the pages redeemed. */
+static unsigned long domain_redeem_host_claim(struct domain *d,
+ unsigned long pages)
+{
+ unsigned long host_claim;
+
+ ASSERT(spin_is_locked(&heap_lock));
+ ASSERT(d->outstanding_pages >= d->node_claims);
+
+ host_claim = d->outstanding_pages - d->node_claims;
+ if ( pages > host_claim )
+ pages = host_claim;
+
+ ASSERT(d->outstanding_pages >= pages);
+ ASSERT(outstanding_claims >= pages);
+
+ d->outstanding_pages -= pages;
+ outstanding_claims -= pages;
+
+ return pages;
+}
+
+/* Redeem exactly @pages from the claims on nodes other than @node. */
+static void domain_redeem_other_node_claims(struct domain *d,
+ unsigned int node,
+ unsigned long pages)
+{
+ unsigned int other;
+
+ ASSERT(spin_is_locked(&heap_lock));
+
+ for_each_online_node ( other )
+ {
+ if ( !pages )
+ break;
+
+ if ( other != node )
+ pages -= domain_redeem_node_claim(d, other, pages);
+ }
+
+ ASSERT(!pages);
+}
+
int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
{
int ret = -ENOMEM;
@@ -1114,8 +1183,16 @@ static struct page_info *alloc_heap_pages(
unsigned long outstanding = min(d->outstanding_pages + 0UL, request);
BUG_ON(outstanding > outstanding_claims);
- outstanding_claims -= outstanding;
- d->outstanding_pages -= outstanding;
+
+ /* Redeem the allocation from the domain's claim on the node first. */
+ outstanding -= domain_redeem_node_claim(d, node, outstanding);
+ /*
+ * To keep the sum of assigned pages and claims within the domain's
+ * limit, redeem the remainder from host-wide claims of the domain,
+ * and if needed, from other per-node claim pools of the domain.
+ */
+ outstanding -= domain_redeem_host_claim(d, outstanding);
+ domain_redeem_other_node_claims(d, node, outstanding);
}
check_low_mem_virq();
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |