[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] core-parking: shrink core_parking_cpunum[]


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 10 Mar 2026 10:07:30 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V59VMzch7YVpTMT8Le0sHR09r5yilpvHjOVWb5ku7Nk=; b=sd05CIU17Q8D3Z4uVVMpJPKrDaooQV4dihoKkk2DfHGiCz+D27BCNfDQPtf0QMWe3dzYCCnlXrukKtX1fgxkvwuALpuodYYB+mL1wEVxqY1LsZ1JYaMnfbl1SFB1Zr8CYrXs0EQgD3uGcnX5UUsX9UUM/tFsnBohyMeSHvKkPEiLp95G9VEarb7gGlTIwbIcR1ianSECLOshM4R6pKmFGw6UHBsuimomX36Q656XBLyuxF3MGDBusZuOmKDj+6G2RPR2eHX02YdrmjtHgsfmFv8Ns6fWTCEps3iyxUBVB/QwXFUhZEPrJrDcnXCgTU38MA16n88JjHDIBzLMXDcZ8w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ul/bd23rdLsXEPxmituoioCMijPWUsQGYsWTsEPplNmsvbCieEo4IVjXgyuNRKV/Agf+V6o5HEa0OFf3cb9N7jlFk6McypwD6+Z6qz1Ym5RD8vo1UWP5RkLzipJbWvJbPHtxQplfIr9JFaY11mhP4zVfuaoQaD1P/r3lK/+6Kw1/aUXZ0QgnUhWwJQ0BQBDBxg2RqcaJhfKIPwiOJTWeiBN/728n67+Py3jG4qyrfQejmEyWXmhdGe5FmiuqCcodiQ0yy6OXEqIWdJuRmjdQZ03uAMw/LLrsAmZlEwCalxXnLWwizIxudmTj/jKzHVjLltcyDTF2F9jA6VWhRfE1Zg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Tue, 10 Mar 2026 09:07:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

You possibly want to adjust the subject, instead of shrink I would use
"dynamically allocate" or similar.

On Mon, Mar 09, 2026 at 04:35:34PM +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. Allocate it dynamically ahead of registering the hooks.
> 
> 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 altogether, rather than replacing
> them.
> 
> Also take the opportunity and update an adjacent variable's type, where
> a fixed-width type was pretty clearly inappropriate to use.
> 
> Finally drop the redundant initializer from core_parking_init().
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> I assume there is a reason this is acting (mostly) as a LIFO. Else a
> simple cpumask_t would suffice.
> 
> num_possible_cpus() would be the more correct thing to use as array
> dimension, yet we don't maintain cpu_possible_map on x86.
> ---
> v2: Use dynamic allocation.
> 
> --- a/xen/common/core_parking.c
> +++ b/xen/common/core_parking.c
> @@ -20,6 +20,7 @@
>  #include <xen/cpumask.h>
>  #include <xen/init.h>
>  #include <xen/param.h>
> +#include <xen/xvmalloc.h>
>  
>  #include <asm/smp.h>
>  
> @@ -27,8 +28,8 @@
>  #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 unsigned int *__ro_after_init core_parking_cpunum;

Don't you need some kind of check in core_parking_remove() to prevent a
NULL pointer dereference if core_parking_cpunum hasn't been allocated?

Callers of XEN_SYSCTL_cpu_hotplug can set fn = smt_up_down_helper, and
that would call core_parking_remove().  core_parking_helper() already
contains a check that prevents accessing core_parking_cpunum if no
policy has been registered.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.