From: Eric Dumazet Date: Thu, 23 Mar 2006 11:01:04 +0000 (-0800) Subject: [PATCH] Only allocate percpu data for possible CPUs X-Git-Tag: v2.6.17-rc1~1004 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=63872f87a151413100678f110d1556026002809e;p=platform%2Fkernel%2Flinux-3.10.git [PATCH] Only allocate percpu data for possible CPUs percpu_data blindly allocates bootmem memory to store NR_CPUS instances of cpudata, instead of allocating memory only for possible cpus. This patch saves ram, allocating num_possible_cpus() (instead of NR_CPUS) instances. Signed-off-by: Eric Dumazet Acked-by: "David S. Miller" Cc: James Bottomley Cc: Jens Axboe Acked-by: Ingo Molnar Cc: Jens Axboe Cc: Anton Blanchard Acked-by: William Irwin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/init/main.c b/init/main.c index 141e889..9cf6b30 100644 --- a/init/main.c +++ b/init/main.c @@ -333,6 +333,7 @@ static void __init setup_per_cpu_areas(void) { unsigned long size, i; char *ptr; + unsigned long nr_possible_cpus = num_possible_cpus(); /* Copy section for each CPU (we discard the original) */ size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES); @@ -340,12 +341,16 @@ static void __init setup_per_cpu_areas(void) if (size < PERCPU_ENOUGH_ROOM) size = PERCPU_ENOUGH_ROOM; #endif + ptr = alloc_bootmem(size * nr_possible_cpus); - ptr = alloc_bootmem(size * NR_CPUS); - - for (i = 0; i < NR_CPUS; i++, ptr += size) { + for (i = 0; i < NR_CPUS; i++) { + if (!cpu_possible(i)) { + __per_cpu_offset[i] = (char*)0 - __per_cpu_start; + continue; + } __per_cpu_offset[i] = ptr - __per_cpu_start; memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); + ptr += size; } } #endif /* !__GENERIC_PER_CPU */