* [PATCH] core-parking: shrink and relocate core_parking_cpunum[]
@ 2025-11-12 15:38 Jan Beulich
2026-03-06 14:20 ` Roger Pau Monné
0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2025-11-12 15:38 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
Michal Orzel, Roger Pau Monné
This NR_CPUS-dimensioned array is likely unused on most installations.
Therefore it is especially wasteful for it to consume more space than
really needed. Use the smallest possible type.
Further the array having all fields set to -1 is actually useless. Nothing
relies on it, and core_parking_remove() doesn't restore the sentinel for
vacated slots. Drop the initializers, moving the array to .bss.
Finally take the opportunity and update an adjacent variable's type, where
a fixed-width type was pretty clearly inappropriate to use.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
I assume there is a reason this is acting (mostly) as a LIFO. Else a
simple cpumask_t would suffice.
An alternative would be to use the new BRK allocator, at least for NR_CPUS
above a certain threshold.
--- a/xen/common/core_parking.c
+++ b/xen/common/core_parking.c
@@ -27,8 +27,16 @@
#define CORE_PARKING_DECREMENT 2
static DEFINE_SPINLOCK(accounting_lock);
-static uint32_t cur_idle_nums;
-static unsigned int core_parking_cpunum[NR_CPUS] = {[0 ... NR_CPUS-1] = -1};
+static unsigned int cur_idle_nums;
+static
+#if CONFIG_NR_CPUS <= (1U << BITS_PER_BYTE)
+ unsigned char
+#elif CONFIG_NR_CPUS <= (1U << (BITS_PER_BYTE * __SIZEOF_SHORT__))
+ unsigned short
+#else
+ unsigned int
+#endif
+ core_parking_cpunum[CONFIG_NR_CPUS];
struct cp_policy {
char name[30];
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] core-parking: shrink and relocate core_parking_cpunum[]
2025-11-12 15:38 [PATCH] core-parking: shrink and relocate core_parking_cpunum[] Jan Beulich
@ 2026-03-06 14:20 ` Roger Pau Monné
2026-03-09 8:01 ` Jan Beulich
0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2026-03-06 14:20 UTC (permalink / raw)
To: Jan Beulich
Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
Stefano Stabellini, Anthony PERARD, Michal Orzel
On Wed, Nov 12, 2025 at 04:38:13PM +0100, Jan Beulich wrote:
> This NR_CPUS-dimensioned array is likely unused on most installations.
> Therefore it is especially wasteful for it to consume more space than
> really needed. Use the smallest possible type.
>
> Further the array having all fields set to -1 is actually useless. Nothing
> relies on it, and core_parking_remove() doesn't restore the sentinel for
> vacated slots. Drop the initializers, moving the array to .bss.
>
> Finally take the opportunity and update an adjacent variable's type, where
> a fixed-width type was pretty clearly inappropriate to use.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> I assume there is a reason this is acting (mostly) as a LIFO. Else a
> simple cpumask_t would suffice.
>
> An alternative would be to use the new BRK allocator, at least for NR_CPUS
> above a certain threshold.
Can't we just allocate this memory using xvzalloc_array()? If we do
care about it being too big certainly allocating only when needed, and
based on the number of possible CPUs on the system would be much
better than playing games with the array type?
Thanks, Roger.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] core-parking: shrink and relocate core_parking_cpunum[]
2026-03-06 14:20 ` Roger Pau Monné
@ 2026-03-09 8:01 ` Jan Beulich
2026-03-09 9:21 ` Roger Pau Monné
0 siblings, 1 reply; 4+ messages in thread
From: Jan Beulich @ 2026-03-09 8:01 UTC (permalink / raw)
To: Roger Pau Monné
Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
Stefano Stabellini, Anthony PERARD, Michal Orzel
On 06.03.2026 15:20, Roger Pau Monné wrote:
> On Wed, Nov 12, 2025 at 04:38:13PM +0100, Jan Beulich wrote:
>> This NR_CPUS-dimensioned array is likely unused on most installations.
>> Therefore it is especially wasteful for it to consume more space than
>> really needed. Use the smallest possible type.
>>
>> Further the array having all fields set to -1 is actually useless. Nothing
>> relies on it, and core_parking_remove() doesn't restore the sentinel for
>> vacated slots. Drop the initializers, moving the array to .bss.
>>
>> Finally take the opportunity and update an adjacent variable's type, where
>> a fixed-width type was pretty clearly inappropriate to use.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> ---
>> I assume there is a reason this is acting (mostly) as a LIFO. Else a
>> simple cpumask_t would suffice.
>>
>> An alternative would be to use the new BRK allocator, at least for NR_CPUS
>> above a certain threshold.
>
> Can't we just allocate this memory using xvzalloc_array()? If we do
> care about it being too big certainly allocating only when needed, and
> based on the number of possible CPUs on the system would be much
> better than playing games with the array type?
Hmm, yes, how did it not occur to me to dynamically allocate the array?
It can't be used ahead of core_parking_init(). (Not shrinking the array
element type will still be a little wasteful, but perhaps that's
acceptable to keep the code simple.)
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] core-parking: shrink and relocate core_parking_cpunum[]
2026-03-09 8:01 ` Jan Beulich
@ 2026-03-09 9:21 ` Roger Pau Monné
0 siblings, 0 replies; 4+ messages in thread
From: Roger Pau Monné @ 2026-03-09 9:21 UTC (permalink / raw)
To: Jan Beulich
Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
Stefano Stabellini, Anthony PERARD, Michal Orzel
On Mon, Mar 09, 2026 at 09:01:35AM +0100, Jan Beulich wrote:
> On 06.03.2026 15:20, Roger Pau Monné wrote:
> > On Wed, Nov 12, 2025 at 04:38:13PM +0100, Jan Beulich wrote:
> >> This NR_CPUS-dimensioned array is likely unused on most installations.
> >> Therefore it is especially wasteful for it to consume more space than
> >> really needed. Use the smallest possible type.
> >>
> >> Further the array having all fields set to -1 is actually useless. Nothing
> >> relies on it, and core_parking_remove() doesn't restore the sentinel for
> >> vacated slots. Drop the initializers, moving the array to .bss.
> >>
> >> Finally take the opportunity and update an adjacent variable's type, where
> >> a fixed-width type was pretty clearly inappropriate to use.
> >>
> >> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> >> ---
> >> I assume there is a reason this is acting (mostly) as a LIFO. Else a
> >> simple cpumask_t would suffice.
> >>
> >> An alternative would be to use the new BRK allocator, at least for NR_CPUS
> >> above a certain threshold.
> >
> > Can't we just allocate this memory using xvzalloc_array()? If we do
> > care about it being too big certainly allocating only when needed, and
> > based on the number of possible CPUs on the system would be much
> > better than playing games with the array type?
>
> Hmm, yes, how did it not occur to me to dynamically allocate the array?
> It can't be used ahead of core_parking_init(). (Not shrinking the array
> element type will still be a little wasteful, but perhaps that's
> acceptable to keep the code simple.)
We don't shrink other similar element types based on the supported CPU
count. Iff we ever wanted to do this (which I'm not sure) we should
introduce a new typedef that generalizes the optimization rather than
open coding it (ie: cpu_id_t or similar?)
Thanks, Roger.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-09 9:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-12 15:38 [PATCH] core-parking: shrink and relocate core_parking_cpunum[] Jan Beulich
2026-03-06 14:20 ` Roger Pau Monné
2026-03-09 8:01 ` Jan Beulich
2026-03-09 9:21 ` Roger Pau Monné
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.