[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()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
  • From: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
  • Date: Tue, 01 Dec 2026 18:29:42 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6nrbX/cklIzLAkdgntjtSKVdc6PUmEQihyWsJryKXD8=; b=ItwPrbPx3b7j9m+YL3br8960BVWtu3XwV4XZhR1Q7P9618WA9Yk/eNum8UR18+qnoRYVGEDR5GOb5OgWJrAcQ1JbyTZfy6lbTy4bynj44YO6OTKaxSMaQpdBOLgTVQcDbkYGqC+t4seZKOaF9erZ6Q0g6d96iKfOOPkVXevDd5dXPRMLUc2iQbgbyHn0c+4KEnajOyLYKHg5y3Su+XOWh+snwlG29VQHtFFsm2ys8Sw2LY8KK5SwMWvvSUthJHCvDOM17xp1uJOyPPfMmhSL3Z92CpkoiwkFa92IK2Np/MzMM7OzPn4z+MB0cLIDibwPefD1T81HfRtQU1mGu9uYOA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Oos6HoORvA0SlzRTlpTtfy2LYaZjlB40EWnDKNVN4ZMSho0ln+qvtC7EBG+dAql233kS2m/z8jQ5EHKeZE8D2q8zB4VNvMF3QFa3Uxtm+L/3mZ4Rstfbq5brtF6c3quwW3nc/eXKJ7RyRNsOOAO4+4l2gU9pYWbtut2NpavzItBezNP3qQMzyNGk9w6wKO22lziGclcb9zPwW0z4xtvLssTPLE3xyXMUQjfTg3S63BBc4uKw6HPhOIQ4F2N6p4VQbGAOwb3MqtaDYDuqggqV3cbTpErKAIAo0hswtKzsR+BO6I49LO6qyhyBv0Nd5/4t+9aX+tXwf03eq9ohIeqzEQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Community Manager <community.manager@xxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Bernhard Kaindl <contact@xxxxxxxxxxxxxxxxxxx>, Bernhard Kaindl <bernhard.kaindl@xxxxxxxxxx>
  • Delivery-date: Tue, 01 Dec 2026 17:30:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.