This code still slow than original. when calling reclaim path, new allocation is almost always
fail. then, your code almost always invoke all cpu batch invalidation. i.e. many ipi.
I don't know this code. Does that happen often?Do we really need to
optimize the out-of-memory path?
But I should have used on_each_cpu_cond() helper which does this for us
(except it falls back to individial IPIs) which would make this code
neater.
2) When CONFIG_CPUMASK_OFFSTACK=n and NR_CPUS is relatively large, cpumask on stack may
cause stack overflow. because of, alloc_pages() can be called from
very deep call stack.
You can't have large NR_CPUS without CONFIG_CPUMASK_OFFSTACK=y,
otherwise you'll get many other stack overflows, too.
Original code put cpumask bss instead stack then. :-)
Yes, and this is what it looks like if we convert it directly, but I
still don't want to encourage people to do this :(
Cheers,
Rusty.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1179,7 +1179,7 @@ void drain_all_pages(void)
* Allocate in the BSS so we wont require allocation in
* direct reclaim path for CONFIG_CPUMASK_OFFSTACK=y
*/
- static cpumask_t cpus_with_pcps;
+ static DECLARE_BITMAP(cpus_with_pcps, NR_CPUS);
/*
* We don't care about racing with CPU hotplug event
@@ -1197,11 +1197,12 @@ void drain_all_pages(void)
}
}
if (has_pcps)
- cpumask_set_cpu(cpu,&cpus_with_pcps);
+ cpumask_set_cpu(cpu, to_cpumask(cpus_with_pcps));
else
- cpumask_clear_cpu(cpu,&cpus_with_pcps);
+ cpumask_clear_cpu(cpu, to_cpumask(cpus_with_pcps));
}
- on_each_cpu_mask(&cpus_with_pcps, drain_local_pages, NULL, 1);
+ on_each_cpu_mask(to_cpumask(cpus_with_pcps),
+ drain_local_pages, NULL, 1);
}