Skip to contentSkip to conversation

How to allocate per-cpu data for online CPUs only (and safely)?

DISCUSSION Martin Peschke 1 participant 1 message Feb 21, 2006

lore
Share & tools
lore
#0 lore raw

I am trying to optimize the memory footprint of some code of mine.
It's been using per-cpu data and alloc_percpu() so far. The latter has the disadvantage of getting hold of memory for CPU's which aren't there (yet).

I could imagine using CPU-hotplug notifications as triggers for additional allocations or for cleaning up unneeded memory. But alloc_percpu() appears to conflict with that idea.

I was briefly tempted to derive some code from alloc_percpu() more to my liking, until I was scared off by this comment in alloc_percpu():

/*
* Cannot use for_each_online_cpu since a cpu may come online
* and we have no way of figuring out how to fix the array
* that we have allocated then....
*/

Well, and then there is kernel/profile.c, for example, which boldly ignors alloc_percpu()'s qualms and allocates and releases per-cpu data as needed.

Is that the way to go?
If so, why alloc_percpu()'s reservations?
Or, does that comment imply that the exploiter isn't expected to take care of CPU hotplug events? Am I missing anything?

Thank you.

Martin