|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 2/8] xen/mm: release per-node claims in domain_set_outstanding_pages()
domain_set_outstanding_pages(d, 0) releases a domain's claim
during destruction and when a domain builder (using libxenguest)
finishes populating the domain’s physmap.
It does not release per-node claims yet. Leaving those claims
recorded would keep the corresponding memory unavailable to
other allocations:
1. Extend this code path to subtract the domain's per-node claims
from node_claimed_pages[] and detach its claims array.
2. Introduce d->node_claims as the cached sum of d->claims[] to
avoid scanning the remainder of d->claims[] when the domain
has no further per-node claims.
3. Detach d->claims while holding heap_lock, which protects the
per-node claims. Free the array after dropping the lock,
since xvfree() can acquire the same lock.
Note: Per-node claims are included in d->outstanding_pages,
so the existing update of outstanding_claims also removes
those pages from the host-wide claim total.
When the domain has no per-node claims, the existing behavior
remains 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>
---
v8:
- Refactor the submission into smaller topic-focused patches.
- Release per-node claims inline rather than through helpers.
---
xen/include/xen/sched.h | 2 ++
xen/common/page_alloc.c | 26 ++++++++++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 2ee5354bae..b2b00c3077 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;
+ /* Cached sum of per-node claims, protected by global heap_lock. */
+ unsigned int node_claims;
/* Per-node claims array or NULL, protected by global heap_lock. */
unsigned int *claims;
unsigned int max_pages; /* maximum value for
domain_tot_pages() */
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index fba5a907e3..ceb074a249 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -527,12 +527,14 @@ int domain_set_outstanding_pages(struct domain *d,
unsigned long pages)
{
int ret = -ENOMEM;
unsigned long claim, avail_pages;
+ unsigned int *old_claims = NULL;
/*
* 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 d->outstanding_pages,
+ * d->node_claims, d->claims[], total_avail_pages, outstanding_claims,
+ * and node_claimed_pages[].
*/
nrspin_lock(&d->page_alloc_lock);
spin_lock(&heap_lock);
@@ -540,6 +542,25 @@ int domain_set_outstanding_pages(struct domain *d,
unsigned long pages)
/* pages==0 means "unset" the claim. */
if ( pages == 0 )
{
+ unsigned int node;
+
+ /* Release per-node claims included in d->outstanding_pages. */
+ ASSERT(d->outstanding_pages >= d->node_claims);
+ if ( d->claims )
+ for_each_online_node ( node )
+ {
+ if ( !d->node_claims )
+ break;
+
+ ASSERT(node_claimed_pages[node] >= d->claims[node]);
+ node_claimed_pages[node] -= d->claims[node];
+ d->node_claims -= d->claims[node];
+ }
+ ASSERT(!d->node_claims);
+
+ /* Detach d->claims; xvfree() can take heap_lock, so free it later. */
+ old_claims = d->claims;
+ d->claims = NULL;
outstanding_claims -= d->outstanding_pages;
d->outstanding_pages = 0;
ret = 0;
@@ -581,6 +602,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned
long pages)
out:
spin_unlock(&heap_lock);
nrspin_unlock(&d->page_alloc_lock);
+ xvfree(old_claims);
return ret;
}
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |