Skip to content

Commit 88a2a4a

Browse files
Eric DumazetLinus Torvalds
authored andcommitted
[PATCH] percpu data: only iterate over possible CPUs
percpu_data blindly allocates bootmem memory to store NR_CPUS instances of cpudata, instead of allocating memory only for possible cpus. As a preparation for changing that, we need to convert various 0 -> NR_CPUS loops to use for_each_cpu(). (The above only applies to users of asm-generic/percpu.h. powerpc has gone it alone and is presently only allocating memory for present CPUs, so it's currently corrupting memory). Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: James Bottomley <James.Bottomley@steeleye.com> Acked-by: Ingo Molnar <mingo@elte.hu> Cc: Jens Axboe <axboe@suse.de> Cc: Anton Blanchard <anton@samba.org> Acked-by: William Irwin <wli@holomorphy.com> Cc: Andi Kleen <ak@muc.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent cef5076 commit 88a2a4a

File tree

11 files changed

+17
-16
lines changed

11 files changed

+17
-16
lines changed

arch/i386/kernel/nmi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int __init check_nmi_watchdog(void)
138138
if (nmi_watchdog == NMI_LOCAL_APIC)
139139
smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
140140

141-
for (cpu = 0; cpu < NR_CPUS; cpu++)
141+
for_each_cpu(cpu)
142142
prev_nmi_count[cpu] = per_cpu(irq_stat, cpu).__nmi_count;
143143
local_irq_enable();
144144
mdelay((10*1000)/nmi_hz); // wait 10 ticks

block/ll_rw_blk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,7 @@ int __init blk_dev_init(void)
34533453
iocontext_cachep = kmem_cache_create("blkdev_ioc",
34543454
sizeof(struct io_context), 0, SLAB_PANIC, NULL, NULL);
34553455

3456-
for (i = 0; i < NR_CPUS; i++)
3456+
for_each_cpu(i)
34573457
INIT_LIST_HEAD(&per_cpu(blk_cpu_done, i));
34583458

34593459
open_softirq(BLOCK_SOFTIRQ, blk_done_softirq, NULL);

drivers/scsi/scsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ static int __init init_scsi(void)
12451245
if (error)
12461246
goto cleanup_sysctl;
12471247

1248-
for (i = 0; i < NR_CPUS; i++)
1248+
for_each_cpu(i)
12491249
INIT_LIST_HEAD(&per_cpu(scsi_done_q, i));
12501250

12511251
devfs_mk_dir("scsi");

fs/file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ static void __devinit fdtable_defer_list_init(int cpu)
379379
void __init files_defer_init(void)
380380
{
381381
int i;
382-
/* Really early - can't use for_each_cpu */
383-
for (i = 0; i < NR_CPUS; i++)
382+
for_each_cpu(i)
384383
fdtable_defer_list_init(i);
385384
}

kernel/sched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6109,7 +6109,7 @@ void __init sched_init(void)
61096109
runqueue_t *rq;
61106110
int i, j, k;
61116111

6112-
for (i = 0; i < NR_CPUS; i++) {
6112+
for_each_cpu(i) {
61136113
prio_array_t *array;
61146114

61156115
rq = cpu_rq(i);

mm/page_alloc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,18 +1213,21 @@ static void __get_page_state(struct page_state *ret, int nr, cpumask_t *cpumask)
12131213
{
12141214
int cpu = 0;
12151215

1216-
memset(ret, 0, sizeof(*ret));
1216+
memset(ret, 0, nr * sizeof(unsigned long));
12171217
cpus_and(*cpumask, *cpumask, cpu_online_map);
12181218

12191219
cpu = first_cpu(*cpumask);
12201220
while (cpu < NR_CPUS) {
12211221
unsigned long *in, *out, off;
12221222

1223+
if (!cpu_isset(cpu, *cpumask))
1224+
continue;
1225+
12231226
in = (unsigned long *)&per_cpu(page_states, cpu);
12241227

12251228
cpu = next_cpu(cpu, *cpumask);
12261229

1227-
if (cpu < NR_CPUS)
1230+
if (likely(cpu < NR_CPUS))
12281231
prefetch(&per_cpu(page_states, cpu));
12291232

12301233
out = (unsigned long *)ret;
@@ -1886,8 +1889,7 @@ static void setup_pagelist_highmark(struct per_cpu_pageset *p,
18861889
* not check if the processor is online before following the pageset pointer.
18871890
* Other parts of the kernel may not check if the zone is available.
18881891
*/
1889-
static struct per_cpu_pageset
1890-
boot_pageset[NR_CPUS];
1892+
static struct per_cpu_pageset boot_pageset[NR_CPUS];
18911893

18921894
/*
18931895
* Dynamically allocate memory for the

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3237,7 +3237,7 @@ static int __init net_dev_init(void)
32373237
* Initialise the packet receive queues.
32383238
*/
32393239

3240-
for (i = 0; i < NR_CPUS; i++) {
3240+
for_each_cpu(i) {
32413241
struct softnet_data *queue;
32423242

32433243
queue = &per_cpu(softnet_data, i);

net/core/utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void __init net_random_init(void)
121121
{
122122
int i;
123123

124-
for (i = 0; i < NR_CPUS; i++) {
124+
for_each_cpu(i) {
125125
struct nrnd_state *state = &per_cpu(net_rand_state,i);
126126
__net_srandom(state, i+jiffies);
127127
}
@@ -133,7 +133,7 @@ static int net_random_reseed(void)
133133
unsigned long seed[NR_CPUS];
134134

135135
get_random_bytes(seed, sizeof(seed));
136-
for (i = 0; i < NR_CPUS; i++) {
136+
for_each_cpu(i) {
137137
struct nrnd_state *state = &per_cpu(net_rand_state,i);
138138
__net_srandom(state, seed[i]);
139139
}

net/ipv4/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int fold_prot_inuse(struct proto *proto)
4949
int res = 0;
5050
int cpu;
5151

52-
for (cpu = 0; cpu < NR_CPUS; cpu++)
52+
for_each_cpu(cpu)
5353
res += proto->stats[cpu].inuse;
5454

5555
return res;

net/ipv6/proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int fold_prot_inuse(struct proto *proto)
3838
int res = 0;
3939
int cpu;
4040

41-
for (cpu=0; cpu<NR_CPUS; cpu++)
41+
for_each_cpu(cpu)
4242
res += proto->stats[cpu].inuse;
4343

4444
return res;

0 commit comments

Comments
 (0)