From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
To: xen-devel@lists.xenproject.org
Cc: "Alejandro Vallejo" <alejandro.vallejo@cloud.com>,
"Bernhard Kaindl" <bernhard.kaindl@cloud.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Tamas K Lengyel" <tamas@tklengyel.com>
Subject: [PATCH 04/11] xen: Add node argument to domain_{adjust_tot_pages,set_outstanding_pages}()
Date: Fri, 14 Mar 2025 17:24:55 +0000 [thread overview]
Message-ID: <20250314172502.53498-5-alejandro.vallejo@cloud.com> (raw)
In-Reply-To: <20250314172502.53498-1-alejandro.vallejo@cloud.com>
domain_adjust_tot_pages() decreases the outstanding claims of a domain
as pages are allocated, so that'll need to take into account the node in
which an allocation is done. Deallocations just pass NUMA_NO_NODE.
domain_set_outstanding_pages() takes the node on which to to stake an
exact-node claim, or NUMA_NO_NODE if it's a non-exact claim.
Not a functional change, as neither function uses the arguments for
anything yet. It's a prerequisite to simplify for the following patch
that introduces per-node claim counts.
Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
xen/arch/x86/mm.c | 3 ++-
xen/arch/x86/mm/mem_sharing.c | 4 ++--
xen/common/domain.c | 2 +-
xen/common/grant_table.c | 4 ++--
xen/common/memory.c | 6 ++++--
xen/common/page_alloc.c | 17 ++++++++++++-----
xen/include/xen/mm.h | 6 ++++--
7 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index bfdc8fb01949..89f87d013099 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -4458,7 +4458,8 @@ int steal_page(
page_list_del(page, &d->page_list);
/* Unlink from original owner. */
- if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
+ if ( !(memflags & MEMF_no_refcount) &&
+ !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1) )
drop_dom_ref = true;
nrspin_unlock(&d->page_alloc_lock);
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index da28266ef076..2551c0d86e80 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -720,7 +720,7 @@ static int page_make_sharable(struct domain *d,
if ( !validate_only )
{
page_set_owner(page, dom_cow);
- drop_dom_ref = !domain_adjust_tot_pages(d, -1);
+ drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1);
page_list_del(page, &d->page_list);
}
@@ -766,7 +766,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
ASSERT(page_get_owner(page) == dom_cow);
page_set_owner(page, d);
- if ( domain_adjust_tot_pages(d, 1) == 1 )
+ if ( domain_adjust_tot_pages(d, page_to_nid(page), 1) == 1 )
get_knownalive_domain(d);
page_list_add_tail(page, &d->page_list);
nrspin_unlock(&d->page_alloc_lock);
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 585fd726a941..72d8d62bc1e8 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1205,7 +1205,7 @@ int domain_kill(struct domain *d)
rspin_barrier(&d->domain_lock);
argo_destroy(d);
vnuma_destroy(d->vnuma);
- domain_set_outstanding_pages(d, 0);
+ domain_set_outstanding_pages(d, NUMA_NO_NODE, 0);
/* fallthrough */
case DOMDYING_dying:
rc = domain_teardown(d);
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 6c77867f8cdd..d8c5321185c6 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -2403,7 +2403,7 @@ gnttab_transfer(
}
/* Okay, add the page to 'e'. */
- if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
+ if ( unlikely(domain_adjust_tot_pages(e, page_to_nid(page), 1) == 1) )
get_knownalive_domain(e);
/*
@@ -2429,7 +2429,7 @@ gnttab_transfer(
* page in the page total
*/
nrspin_lock(&e->page_alloc_lock);
- drop_dom_ref = !domain_adjust_tot_pages(e, -1);
+ drop_dom_ref = !domain_adjust_tot_pages(e, NUMA_NO_NODE, -1);
nrspin_unlock(&e->page_alloc_lock);
if ( okay /* i.e. e->is_dying due to the surrounding if() */ )
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 8ca4e1a8425b..1ab0bac4e7da 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -773,7 +773,8 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
nrspin_lock(&d->page_alloc_lock);
drop_dom_ref = (dec_count &&
- !domain_adjust_tot_pages(d, -dec_count));
+ !domain_adjust_tot_pages(d, NUMA_NO_NODE,
+ -dec_count));
nrspin_unlock(&d->page_alloc_lock);
if ( drop_dom_ref )
@@ -1680,7 +1681,8 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
rc = xsm_claim_pages(XSM_PRIV, d);
if ( !rc )
- rc = domain_set_outstanding_pages(d, reservation.nr_extents);
+ rc = domain_set_outstanding_pages(d, NUMA_NO_NODE,
+ reservation.nr_extents);
rcu_unlock_domain(d);
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 733b0300a767..9243c4f51370 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -491,7 +491,8 @@ static unsigned long pernode_avail_pages[MAX_NUMNODES];
static DEFINE_SPINLOCK(heap_lock);
static long outstanding_claims; /* total outstanding claims by all domains */
-unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
+unsigned long domain_adjust_tot_pages(struct domain *d, nodeid_t node,
+ long pages)
{
ASSERT(rspin_is_locked(&d->page_alloc_lock));
d->tot_pages += pages;
@@ -523,7 +524,8 @@ out:
return d->tot_pages;
}
-int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
+int domain_set_outstanding_pages(struct domain *d, nodeid_t node,
+ unsigned long pages)
{
int ret = -ENOMEM;
unsigned long avail_pages;
@@ -2600,6 +2602,8 @@ int assign_pages(
if ( !(memflags & MEMF_no_refcount) )
{
+ nodeid_t node = page_to_nid(&pg[0]);
+
if ( unlikely(d->tot_pages + nr < nr) )
{
gprintk(XENLOG_INFO,
@@ -2611,7 +2615,9 @@ int assign_pages(
goto out;
}
- if ( unlikely(domain_adjust_tot_pages(d, nr) == nr) )
+ ASSERT(node == page_to_nid(&pg[nr - 1]));
+
+ if ( unlikely(domain_adjust_tot_pages(d, node, nr) == nr) )
get_knownalive_domain(d);
}
@@ -2744,7 +2750,8 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
}
}
- drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
+ drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE,
+ -(1 << order));
rspin_unlock(&d->page_alloc_lock);
@@ -2957,7 +2964,7 @@ void free_domstatic_page(struct page_info *page)
arch_free_heap_page(d, page);
- drop_dom_ref = !domain_adjust_tot_pages(d, -1);
+ drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1);
unprepare_staticmem_pages(page, 1, scrub_debug);
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index ae1c48a61545..e577a450681c 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -64,6 +64,7 @@
#include <xen/bug.h>
#include <xen/compiler.h>
#include <xen/mm-frame.h>
+#include <xen/numa.h>
#include <xen/types.h>
#include <xen/list.h>
#include <xen/spinlock.h>
@@ -129,8 +130,9 @@ mfn_t xen_map_to_mfn(unsigned long va);
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_set_outstanding_pages(struct domain *d, unsigned long pages);
+ nodeid_t node, long pages);
+int domain_set_outstanding_pages(struct domain *d, nodeid_t node,
+ unsigned long pages);
void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages);
/* Domain suballocator. These functions are *not* interrupt-safe.*/
--
2.48.1
next prev parent reply other threads:[~2025-03-14 17:25 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 17:24 [PATCH 00/11] Add support for exact-node memory claims Alejandro Vallejo
2025-03-14 17:24 ` [PATCH 01/11] xen/memory: Mask XENMEMF_node() to 8 bits Alejandro Vallejo
2025-03-17 16:33 ` Jan Beulich
2025-03-18 16:10 ` Alejandro Vallejo
2025-03-14 17:24 ` [PATCH 02/11] xen/page_alloc: Remove `claim` from domain_set_outstanding_pages() Alejandro Vallejo
2025-06-05 16:42 ` Roger Pau Monné
2025-06-10 12:23 ` Jan Beulich
2025-06-10 12:52 ` Roger Pau Monné
2025-06-10 17:51 ` Alejandro Vallejo
2025-06-10 12:37 ` Jan Beulich
2025-03-14 17:24 ` [PATCH 03/11] xen/page_alloc: Add static per-node counts of free pages Alejandro Vallejo
2025-06-05 16:46 ` Roger Pau Monné
2025-06-11 13:35 ` Jan Beulich
2025-03-14 17:24 ` Alejandro Vallejo [this message]
2025-06-06 7:57 ` [PATCH 04/11] xen: Add node argument to domain_{adjust_tot_pages,set_outstanding_pages}() Roger Pau Monné
2025-06-11 13:43 ` Jan Beulich
2025-03-14 17:24 ` [PATCH 05/11] xen: Create per-node outstanding claims Alejandro Vallejo
2025-06-06 8:14 ` Roger Pau Monné
2025-06-06 8:36 ` Roger Pau Monné
2025-03-14 17:24 ` [PATCH 06/11] xen/page_alloc: Hook per-node claims to alloc_heap_pages() Alejandro Vallejo
2025-06-06 8:22 ` Roger Pau Monné
2025-03-14 17:24 ` [PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node Alejandro Vallejo
2025-06-06 8:34 ` Roger Pau Monné
2025-06-11 13:51 ` Jan Beulich
2025-03-14 17:24 ` [PATCH 08/11] xen/memory: Enable parsing NUMA node argument in XENMEM_claim_pages Alejandro Vallejo
2025-06-06 8:51 ` Roger Pau Monné
2025-03-14 17:25 ` [PATCH 09/11] tools/xc: Add `node` argument to xc_domain_claim_pages() Alejandro Vallejo
2025-06-06 9:02 ` Roger Pau Monné
2025-03-14 17:25 ` [PATCH 10/11] tools/xl: Expose a "claim_on_node" setting in xl.cfg Alejandro Vallejo
2025-06-06 9:00 ` Roger Pau Monné
2025-03-14 17:25 ` [PATCH 11/11] docs/man: Document the new claim_on_node option Alejandro Vallejo
2025-06-06 9:03 ` Roger Pau Monné
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250314172502.53498-5-alejandro.vallejo@cloud.com \
--to=alejandro.vallejo@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bernhard.kaindl@cloud.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=tamas@tklengyel.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.