From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Bernhard Kaindl <bernhard.kaindl@citrix.com>
Cc: xen-devel@lists.xenproject.org,
Andrew Cooper <andrew.cooper3@citrix.com>,
Anthony PERARD <anthony.perard@vates.tech>,
Michal Orzel <michal.orzel@amd.com>,
Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v4 01/10] xen/page_alloc: Extract code for consuming claims into inline function
Date: Thu, 5 Mar 2026 09:21:30 +0100 [thread overview]
Message-ID: <aak9Cr6ySfc1xEj2@macbook.local> (raw)
In-Reply-To: <7dd887bc26830d6c50e5bc2606391963e65285a1.1772098423.git.bernhard.kaindl@citrix.com>
On Thu, Feb 26, 2026 at 02:29:15PM +0000, Bernhard Kaindl wrote:
> Refactor the claims consumption code in preparation for node-claims.
> Lays the groundwork for adding the consumption of NUMA claims to it.
>
> Signed-off-by: Bernhard Kaindl <bernhard.kaindl@citrix.com>
> ---
> xen/common/page_alloc.c | 56 +++++++++++++++++++++++------------------
> 1 file changed, 31 insertions(+), 25 deletions(-)
>
> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> index 588b5b99cbc7..6f7f30c64605 100644
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -518,6 +518,34 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
> return d->tot_pages;
> }
>
> +/* Release outstanding claims on the domain, host and later also node */
> +static inline
> +void release_outstanding_claims(struct domain *d, unsigned long release)
> +{
> + ASSERT(spin_is_locked(&heap_lock));
> + BUG_ON(outstanding_claims < release);
> + outstanding_claims -= release;
> + d->outstanding_pages -= release;
> +}
> +
> +/*
> + * Consume outstanding claimed pages when allocating pages for a domain.
> + * NB. The alloc could (in principle) fail in assign_pages() afterwards. In that
> + * case, the consumption is not reversed, but as claims are used only during
> + * domain build and d is destroyed if the build fails, this has no significance.
> + */
> +static inline
> +void consume_outstanding_claims(struct domain *d, unsigned long allocation)
> +{
> + if ( !d || !d->outstanding_pages )
> + return;
> + ASSERT(spin_is_locked(&heap_lock));
> +
> + /* Of course, the domain can only release up its outstanding claims */
> + allocation = min(allocation, d->outstanding_pages + 0UL);
> + release_outstanding_claims(d, allocation);
> +}
> +
> int domain_set_outstanding_pages(struct domain *d, unsigned long pages)
> {
> int ret = -ENOMEM;
> @@ -535,8 +563,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;
> + release_outstanding_claims(d, d->outstanding_pages);
> ret = 0;
> goto out;
> }
> @@ -1048,29 +1075,8 @@ 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) )
> - {
> - /*
> - * 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.
As Jan mentioned, you really need to keep this part of the comment.
Claims had been broken since its introduction because the above was
not respected, and that resulted in the accounting for free pages
being transiently incorrect while an allocation was taking place.
Thanks, Roger.
next prev parent reply other threads:[~2026-03-05 8:22 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 14:29 [PATCH v4 0/10] xen: Add NUMA-aware memory claims for domains Bernhard Kaindl
2026-02-26 14:29 ` [PATCH v4 01/10] xen/page_alloc: Extract code for consuming claims into inline function Bernhard Kaindl
2026-03-04 16:20 ` Jan Beulich
2026-03-04 18:04 ` Bernhard Kaindl
2026-03-05 8:21 ` Roger Pau Monné [this message]
2026-02-26 14:29 ` [PATCH v4 02/10] xen/page_alloc: Optimize getting per-NUMA-node free page counts Bernhard Kaindl
2026-03-04 16:31 ` Jan Beulich
2026-03-04 18:21 ` Bernhard Kaindl
2026-03-05 7:22 ` Jan Beulich
2026-02-26 14:29 ` [PATCH v4 03/10] xen/page_alloc: Implement NUMA-node-specific claims Bernhard Kaindl
2026-03-05 10:53 ` Jan Beulich
2026-03-05 13:12 ` Bernhard Kaindl
2026-03-05 13:36 ` Jan Beulich
2026-03-05 14:54 ` Bernhard Kaindl
2026-03-05 17:00 ` Jan Beulich
2026-02-26 14:29 ` [PATCH v4 04/10] xen/page_alloc: Consolidate per-node counters into avail[] array Bernhard Kaindl
2026-02-26 14:29 ` [PATCH v4 05/10] xen/domain: Add DOMCTL handler for claiming memory with NUMA awareness Bernhard Kaindl
2026-02-26 21:19 ` Teddy Astie
2026-02-26 23:16 ` Bernhard Kaindl
2026-02-27 9:39 ` Teddy Astie
2026-02-27 18:16 ` Bernhard Kaindl
2026-03-05 11:31 ` Jan Beulich
2026-04-14 15:17 ` Bernhard Kaindl
2026-04-16 6:46 ` Jan Beulich
2026-04-16 23:48 ` Bernhard Kaindl
2026-03-05 12:38 ` Roger Pau Monné
2026-03-05 12:44 ` Jan Beulich
2026-02-26 14:29 ` [PATCH v4 06/10] xsm/flask: Add XEN_DOMCTL_claim_memory to flask Bernhard Kaindl
2026-03-05 13:42 ` Jan Beulich
2026-02-26 14:29 ` [PATCH v4 07/10] tools/lib/ctrl/xc: Add xc_domain_claim_memory() to libxenctrl Bernhard Kaindl
2026-02-26 14:29 ` [PATCH v4 08/10] tools/ocaml/libs/xc: add OCaml domain_claim_memory binding Bernhard Kaindl
2026-02-26 14:29 ` [PATCH v4 09/10] tools/tests: Update the claims test to test claim_memory hypercall Bernhard Kaindl
2026-02-26 14:29 ` [PATCH v4 10/10] docs/guest-guide: document the memory claim hypercalls Bernhard Kaindl
2026-03-04 16:07 ` [PATCH v4 0/10] xen: Add NUMA-aware memory claims for domains Jan Beulich
2026-03-04 17:27 ` Bernhard Kaindl
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=aak9Cr6ySfc1xEj2@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bernhard.kaindl@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--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.