[lkml]   [2008]   [Oct]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 14/35] cpumask: add nr_cpumask_bits
When nr_cpu_ids is set to CONFIG_NR_CPUS then references to nr_cpu_ids
will return the maximum index of the configured NR_CPUS (+1) instead
of the maximum index of the possible number of cpus (+1). This results
in extra unused memory being allocated by functions that are setting up
arrays of structs to keep track of per cpu items.

Since we do want to keep the ability to use constants for the cpu bit
operators on smaller systems (which are generally much faster assembler
ops), we introduce a separate "nr_cpumask_bits" to replace "nr_cpu_ids"
only for the inline assembly ops. This will be a constant when
CONFIG_CPUMASK_OFFSTACK is undefined and a variable when it is defined.

Thus "nr_cpu_ids" reverts back to being a variable representing the
maximum possible cpu (+1), except in the non-SMP case where it is a
constant value of 1. The relationship between the related variables
and constants is: (1 <= nr_cpu_ids <= nr_cpumask_bits <= NR_CPUS).

Signed-off-by: Mike Travis <>
arch/x86/kernel/setup_percpu.c | 7 ++++---
include/linux/cpumask.h | 8 ++++++++
2 files changed, 12 insertions(+), 3 deletions(-)

--- linux-2.6.28.orig/arch/x86/kernel/setup_percpu.c
+++ linux-2.6.28/arch/x86/kernel/setup_percpu.c
@@ -155,6 +155,10 @@ void __init setup_per_cpu_areas(void)
printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n",

+ printk(KERN_DEBUG
+ "NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n",
+ NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids);
for_each_possible_cpu(cpu) {
ptr = __alloc_bootmem(size, align,
@@ -183,9 +187,6 @@ void __init setup_per_cpu_areas(void)
memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);

- printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d, nr_node_ids %d\n",
- NR_CPUS, nr_cpu_ids, nr_node_ids);
/* Setup percpu data maps */

--- linux-2.6.28.orig/include/linux/cpumask.h
+++ linux-2.6.28/include/linux/cpumask.h
@@ -197,6 +197,14 @@ extern int nr_cpu_ids;
#define nr_cpu_ids NR_CPUS

+/* The number of bits to hand to the bitmask ops. */
+/* This produces more efficient code. */
+#define nr_cpumask_bits NR_CPUS
+#define nr_cpumask_bits nr_cpu_ids
static inline void cpumask_set_cpu(int cpu, volatile struct cpumask *dstp)
set_bit(cpu, dstp->bits);

 \ /
  Last update: 2008-10-23 04:15    [W:0.167 / U:4.768 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site