diff options
author | Tejun Heo <tj@kernel.org> | 2009-08-14 02:00:51 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2009-08-14 02:00:51 -0400 |
commit | fd1e8a1fe2b54df6c185b4fa65f181f50b9c4d4e (patch) | |
tree | d4411507baacaa33c68be7813ad6f9e0d93a74e2 /arch/x86 | |
parent | 033e48fb82958053113178264ddb9d5038d5e38b (diff) |
percpu: introduce pcpu_alloc_info and pcpu_group_info
Till now, non-linear cpu->unit map was expressed using an integer
array which maps each cpu to a unit and used only by lpage allocator.
Although how many units have been placed in a single contiguos area
(group) is known while building unit_map, the information is lost when
the result is recorded into the unit_map array. For lpage allocator,
as all allocations are done by lpages and whether two adjacent lpages
are in the same group or not is irrelevant, this didn't cause any
problem. Non-linear cpu->unit mapping will be used for sparse
embedding and this grouping information is necessary for that.
This patch introduces pcpu_alloc_info which contains all the
information necessary for initializing percpu allocator.
pcpu_alloc_info contains array of pcpu_group_info which describes how
units are grouped and mapped to cpus. pcpu_group_info also has
base_offset field to specify its offset from the chunk's base address.
pcpu_build_alloc_info() initializes this field as if all groups are
allocated back-to-back as is currently done but this will be used to
sparsely place groups.
pcpu_alloc_info is a rather complex data structure which contains a
flexible array which in turn points to nested cpu_map arrays.
* pcpu_alloc_alloc_info() and pcpu_free_alloc_info() are provided to
help dealing with pcpu_alloc_info.
* pcpu_lpage_build_unit_map() is updated to build pcpu_alloc_info,
generalized and renamed to pcpu_build_alloc_info().
@cpu_distance_fn may be NULL indicating that all cpus are of
LOCAL_DISTANCE.
* pcpul_lpage_dump_cfg() is updated to process pcpu_alloc_info,
generalized and renamed to pcpu_dump_alloc_info(). It now also
prints which group each alloc unit belongs to.
* pcpu_setup_first_chunk() now takes pcpu_alloc_info instead of the
separate parameters. All first chunk allocators are updated to use
pcpu_build_alloc_info() to build alloc_info and call
pcpu_setup_first_chunk() with it. This has the side effect of
packing units for sparse possible cpus. ie. if cpus 0, 2 and 4 are
possible, they'll be assigned unit 0, 1 and 2 instead of 0, 2 and 4.
* x86 setup_pcpu_lpage() is updated to deal with alloc_info.
* sparc64 setup_per_cpu_areas() is updated to build alloc_info.
Although the changes made by this patch are pretty pervasive, it
doesn't cause any behavior difference other than packing of sparse
cpus. It mostly changes how information is passed among
initialization functions and makes room for more flexibility.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: David Miller <davem@davemloft.net>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/kernel/setup_percpu.c | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index 660cde133141..db5f9c49fec5 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c | |||
@@ -161,9 +161,7 @@ static ssize_t __init setup_pcpu_lpage(bool chosen) | |||
161 | { | 161 | { |
162 | size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; | 162 | size_t reserve = PERCPU_MODULE_RESERVE + PERCPU_DYNAMIC_RESERVE; |
163 | size_t dyn_size = reserve - PERCPU_FIRST_CHUNK_RESERVE; | 163 | size_t dyn_size = reserve - PERCPU_FIRST_CHUNK_RESERVE; |
164 | size_t unit_map_size, unit_size; | 164 | struct pcpu_alloc_info *ai; |
165 | int *unit_map; | ||
166 | int nr_units; | ||
167 | ssize_t ret; | 165 | ssize_t ret; |
168 | 166 | ||
169 | /* on non-NUMA, embedding is better */ | 167 | /* on non-NUMA, embedding is better */ |
@@ -177,26 +175,22 @@ static ssize_t __init setup_pcpu_lpage(bool chosen) | |||
177 | } | 175 | } |
178 | 176 | ||
179 | /* allocate and build unit_map */ | 177 | /* allocate and build unit_map */ |
180 | unit_map_size = nr_cpu_ids * sizeof(int); | 178 | ai = pcpu_build_alloc_info(PERCPU_FIRST_CHUNK_RESERVE, dyn_size, |
181 | unit_map = alloc_bootmem_nopanic(unit_map_size); | 179 | PMD_SIZE, pcpu_lpage_cpu_distance); |
182 | if (!unit_map) { | 180 | if (IS_ERR(ai)) { |
183 | pr_warning("PERCPU: failed to allocate unit_map\n"); | 181 | pr_warning("PERCPU: failed to build unit_map (%ld)\n", |
184 | return -ENOMEM; | 182 | PTR_ERR(ai)); |
183 | return PTR_ERR(ai); | ||
185 | } | 184 | } |
186 | 185 | ||
187 | ret = pcpu_lpage_build_unit_map(PERCPU_FIRST_CHUNK_RESERVE, | ||
188 | &dyn_size, &unit_size, PMD_SIZE, | ||
189 | unit_map, pcpu_lpage_cpu_distance); | ||
190 | if (ret < 0) { | ||
191 | pr_warning("PERCPU: failed to build unit_map\n"); | ||
192 | goto out_free; | ||
193 | } | ||
194 | nr_units = ret; | ||
195 | |||
196 | /* do the parameters look okay? */ | 186 | /* do the parameters look okay? */ |
197 | if (!chosen) { | 187 | if (!chosen) { |
198 | size_t vm_size = VMALLOC_END - VMALLOC_START; | 188 | size_t vm_size = VMALLOC_END - VMALLOC_START; |
199 | size_t tot_size = nr_units * unit_size; | 189 | size_t tot_size = 0; |
190 | int group; | ||
191 | |||
192 | for (group = 0; group < ai->nr_groups; group++) | ||
193 | tot_size += ai->unit_size * ai->groups[group].nr_units; | ||
200 | 194 | ||
201 | /* don't consume more than 20% of vmalloc area */ | 195 | /* don't consume more than 20% of vmalloc area */ |
202 | if (tot_size > vm_size / 5) { | 196 | if (tot_size > vm_size / 5) { |
@@ -207,12 +201,10 @@ static ssize_t __init setup_pcpu_lpage(bool chosen) | |||
207 | } | 201 | } |
208 | } | 202 | } |
209 | 203 | ||
210 | ret = pcpu_lpage_first_chunk(PERCPU_FIRST_CHUNK_RESERVE, dyn_size, | 204 | ret = pcpu_lpage_first_chunk(ai, pcpu_fc_alloc, pcpu_fc_free, |
211 | unit_size, PMD_SIZE, unit_map, nr_units, | 205 | pcpul_map); |
212 | pcpu_fc_alloc, pcpu_fc_free, pcpul_map); | ||
213 | out_free: | 206 | out_free: |
214 | if (ret < 0) | 207 | pcpu_free_alloc_info(ai); |
215 | free_bootmem(__pa(unit_map), unit_map_size); | ||
216 | return ret; | 208 | return ret; |
217 | } | 209 | } |
218 | #else | 210 | #else |