Skip to contentSkip to conversation

PERCPU : __percpu_alloc_mask() can dynamically size percpu_data storage

PATCH In review Eric Dumazet 2 participants 2 messages Nov 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PERCPU : __percpu_alloc_mask() can dynamically size percpu_data storage

Instead of allocating a fix sized array of NR_CPUS pointers for percpu_data, we can use nr_cpu_ids, which is generally < NR_CPUS.

 include/linux/percpu.h |    2 +-
 mm/allocpercpu.c       |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/percpu.h +1 -1
index 926adaa..1702ab5 100644
@@ -34,7 +34,7 @@
 #ifdef CONFIG_SMP
 
 struct percpu_data {
-	void *ptrs[NR_CPUS];
+	void *ptrs[1];
 };
 
 #define __percpu_disguise(pdata) (struct percpu_data *)~(unsigned long)(pdata)
mm/allocpercpu.c +1 -1
index 00b0262..7e58322 100644
@@ -98,7 +98,7 @@ EXPORT_SYMBOL_GPL(__percpu_populate_mask);
  */
 void *__percpu_alloc_mask(size_t size, gfp_t gfp, cpumask_t *mask)
 {
-	void *pdata = kzalloc(sizeof(struct percpu_data), gfp);
+	void *pdata = kzalloc(nr_cpu_ids * sizeof(void *), gfp);
 	void *__pdata = __percpu_disguise(pdata);
 
 	if (unlikely(!pdata))
#1 lore raw
Quoted 2 lines · Eric Dumazet

Instead of allocating a fix sized array of NR_CPUS pointers for percpu_data, we can use nr_cpu_ids, which is generally < NR_CPUS.

Yes we can. Could you either use [] or [0] instead of the index there? Somehow the patch vanished when I replied to it.