From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wl@xen.org>, Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH] x86/NUMA: improve memnode_shift calculation for multi node system
Date: Fri, 30 Sep 2022 11:54:49 +0000 [thread overview]
Message-ID: <21e773a0-9082-86de-be81-9fcc8ea2e07e@citrix.com> (raw)
In-Reply-To: <84f1b8e4-3927-1986-9ca7-043790ed7011@suse.com>
On 27/09/2022 17:20, Jan Beulich wrote:
> --- a/xen/arch/x86/srat.c
> +++ b/xen/arch/x86/srat.c
> @@ -413,14 +414,37 @@ acpi_numa_memory_affinity_init(const str
> node, pxm, start, end - 1,
> ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE ? " (hotplug)" : "");
>
> - node_memblk_range[num_node_memblks].start = start;
> - node_memblk_range[num_node_memblks].end = end;
> - memblk_nodeid[num_node_memblks] = node;
> + /* Keep node_memblk_range[] sorted by address. */
> + for (i = 0; i < num_node_memblks; ++i)
> + if (node_memblk_range[i].start > start ||
> + (node_memblk_range[i].start == start &&
> + node_memblk_range[i].end > end))
> + break;
> +
> + memmove(&node_memblk_range[i + 1], &node_memblk_range[i],
> + (num_node_memblks - i) * sizeof(*node_memblk_range));
> + node_memblk_range[i].start = start;
> + node_memblk_range[i].end = end;
> +
> + memmove(&memblk_nodeid[i + 1], &memblk_nodeid[i],
> + (num_node_memblks - i) * sizeof(*memblk_nodeid));
> + memblk_nodeid[i] = node;
This is now the 4th example we have of logic wanting a sorted array.
(two examples in ARM code which want to switch away from using sort(),
and the VMX MSR lists).
I was already contemplating doing a small library (static inline, or
perhaps extern inline now we've started using that) to abstract away the
insert/find/delete operations and their decidedly non-trivial pointer
operations.
The secondary purpose was to be able to do some actual unit tests of the
library, so we can be rather better assured of correctness.
For this case, and the two ARM cases, the firmware data is supposed to
be sorted to begin with, so the search-for-insertion loop should look at
the num_node_memblks entry first because the overwhelming common case is
that the end is the correct place to put it. If not, it should binary
search backwards rather than doing a linear search.
Obviously not work for 4.17, but there's a lot of value in such a library.
~Andrew
next prev parent reply other threads:[~2022-09-30 11:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 16:20 [PATCH] x86/NUMA: improve memnode_shift calculation for multi node system Jan Beulich
2022-09-30 8:25 ` Roger Pau Monné
2022-09-30 8:36 ` Jan Beulich
2022-09-30 10:03 ` Roger Pau Monné
2022-09-30 10:50 ` Jan Beulich
2022-09-30 11:25 ` Roger Pau Monné
2022-09-30 11:54 ` Andrew Cooper [this message]
2022-09-30 12:05 ` 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=21e773a0-9082-86de-be81-9fcc8ea2e07e@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wl@xen.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.