All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Bernhard Kaindl <bernhard.kaindl@citrix.com>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Julien Grall" <julien@xen.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Alejandro Vallejo" <agarciav@amd.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v7 1/3] xen/mm: Introduce per-node free page counter
Date: Thu, 25 Jun 2026 15:04:53 +0200	[thread overview]
Message-ID: <ca45cbd3-8f39-4017-b2f9-e69b8a708188@suse.com> (raw)
In-Reply-To: <a0b83b0781319009c3862389469dc59db59e0b29.1778272036.git.bernhard.kaindl@citrix.com>

On 08.05.2026 22:27, Bernhard Kaindl wrote:
> From: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> 
> Add node_avail_pages[], updated under heap_lock in sync with
> avail[node][zone] to cache the per-node sum of free pages.
> 
> Use it in avail_node_heap_pages() to avoid summing all zones on each
> call. Guard it with nodeid < MAX_NUMNODES and node_online(nodeid).
> 
> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> Signed-off-by: Bernhard Kaindl <bernhard.kaindl@citrix.com>
> ---
> This patch was originally sent by Alejandro Vallejo:
> https://lists.xenproject.org/archives/html/xen-devel/2025-03/msg01130.html
> 
> I use node_avail_pages[] in avail_node_heap_pages() as an optimisation.
> 
> Verification of the changes:
> 
> 1. node_avail_pages[node] is updated whenever avail[node][zone] changes,
>    so the two remain in sync.
> 
> 2. avail_node_heap_pages() previously summed all zones of a node and now
>    returns node_avail_pages[node], so the same free buddy pages are
>    counted.
> 
> 3. avail_node_heap_pages() returns 0 for offline nodes and for nodes
>    >= MAX_NUMNODES as before.
> 
> 4. avail_node_heap_pages(-1) returned the sum from all nodes, equal
>    to total_avail_pages, but this is not used by current callers.
>    avail_heap_pages(z, z, -1) is used by other callers for that instead.
>    To avoid dead code, a check for -1 to implement this is not added.
> 
> Update locations:
> 
> - free_heap_pages() increments node_avail_pages[node] alongside
>   avail[node][zone] when pages are freed, including during heap
>   initialisation.
> 
> - alloc_heap_pages() decrements node_avail_pages[node] alongside
>   avail[node][zone] when pages are allocated.
> 
> - reserve_offlined_page() decrements node_avail_pages[node] alongside
>   avail[node][zone] when pages are offlined.
> 
> Colored pages do not go through the buddy allocator.
> Since they do not update avail[node][zone], they are
> not reflected in node_avail_pages[node] either.
> 
> N.B. Current callers already iterate over online nodes only.
> 
> Changes since v6:
> - Preserved the 0 return for offline nodes and nodes >= MAX_NUMNODES.

Hard to identify what v6 was (and who, if anyone, asked for the change) when,
afaict, the patch subject changed.

Reviewed-by: Jan Beulich <jbeulich@suse.com>
with ...

> @@ -2831,7 +2837,9 @@ unsigned long avail_domheap_pages_region(
>  
>  unsigned long avail_node_heap_pages(unsigned int nodeid)
>  {
> -    return avail_heap_pages(MEMZONE_XEN, NR_ZONES -1, nodeid);
> +    if ( nodeid < MAX_NUMNODES && node_online(nodeid) )
> +        return node_avail_pages[nodeid];
> +    return 0;
>  }

... a blank line inserted ahead of the "main" (not really here, just by its
indentation) return.

One other remark: With the function called from just a sysctl and a
keyhandler, the direct array access is likely fine. Generally it would
want to be array_access_nospec() though, when accessible from guests.

Jan


  reply	other threads:[~2026-06-25 13:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 20:27 [PATCH v7 0/3] xen/mm: Introduce NUMA-aware memory claim sets Bernhard Kaindl
2026-05-08 20:27 ` [PATCH v7 1/3] xen/mm: Introduce per-node free page counter Bernhard Kaindl
2026-06-25 13:04   ` Jan Beulich [this message]
2026-05-08 20:27 ` [PATCH v7 2/3] xen/mm: Introduce NUMA-aware memory claim sets Bernhard Kaindl
2026-06-25 13:30   ` Jan Beulich
2026-05-08 20:27 ` [PATCH v7 3/3] tools/ocaml: Add OCaml binding for NUMA " Bernhard Kaindl
2026-05-11  9:39   ` Jan Beulich
2026-05-28  8:37     ` Bernhard Kaindl
2026-06-02  8:10       ` Jan Beulich

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=ca45cbd3-8f39-4017-b2f9-e69b8a708188@suse.com \
    --to=jbeulich@suse.com \
    --cc=agarciav@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=bernhard.kaindl@citrix.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.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.