diff options
author | Rik van Riel <riel@surriel.com> | 2018-07-16 15:03:31 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-07-17 03:35:30 -0400 |
commit | c1a2f7f0c06454387c2cd7b93ff1491c715a8c69 (patch) | |
tree | f3b3cce7e45b2bab54681b23a3947a445ae38a37 /kernel/fork.c | |
parent | 37c45b2354cb2270f246679bedd8bf798cca351c (diff) |
mm: Allocate the mm_cpumask (mm->cpu_bitmap[]) dynamically based on nr_cpu_ids
The mm_struct always contains a cpumask bitmap, regardless of
CONFIG_CPUMASK_OFFSTACK. That means the first step can be to
simplify things, and simply have one bitmask at the end of the
mm_struct for the mm_cpumask.
This does necessitate moving everything else in mm_struct into
an anonymous sub-structure, which can be randomized when struct
randomization is enabled.
The second step is to determine the correct size for the
mm_struct slab object from the size of the mm_struct
(excluding the CPU bitmap) and the size the cpumask.
For init_mm we can simply allocate the maximum size this
kernel is compiled for, since we only have one init_mm
in the system, anyway.
Pointer magic by Mike Galbraith, to evade -Wstringop-overflow
getting confused by the dynamically sized array.
Tested-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Rik van Riel <riel@surriel.com>
Signed-off-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Rik van Riel <riel@surriel.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kernel-team@fb.com
Cc: luto@kernel.org
Link: http://lkml.kernel.org/r/20180716190337.26133-2-riel@surriel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 9440d61b925c..5b64c1b8461e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -2253,6 +2253,8 @@ static void sighand_ctor(void *data) | |||
2253 | 2253 | ||
2254 | void __init proc_caches_init(void) | 2254 | void __init proc_caches_init(void) |
2255 | { | 2255 | { |
2256 | unsigned int mm_size; | ||
2257 | |||
2256 | sighand_cachep = kmem_cache_create("sighand_cache", | 2258 | sighand_cachep = kmem_cache_create("sighand_cache", |
2257 | sizeof(struct sighand_struct), 0, | 2259 | sizeof(struct sighand_struct), 0, |
2258 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| | 2260 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| |
@@ -2269,15 +2271,16 @@ void __init proc_caches_init(void) | |||
2269 | sizeof(struct fs_struct), 0, | 2271 | sizeof(struct fs_struct), 0, |
2270 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, | 2272 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, |
2271 | NULL); | 2273 | NULL); |
2274 | |||
2272 | /* | 2275 | /* |
2273 | * FIXME! The "sizeof(struct mm_struct)" currently includes the | 2276 | * The mm_cpumask is located at the end of mm_struct, and is |
2274 | * whole struct cpumask for the OFFSTACK case. We could change | 2277 | * dynamically sized based on the maximum CPU number this system |
2275 | * this to *only* allocate as much of it as required by the | 2278 | * can have, taking hotplug into account (nr_cpu_ids). |
2276 | * maximum number of CPU's we can ever have. The cpumask_allocation | ||
2277 | * is at the end of the structure, exactly for that reason. | ||
2278 | */ | 2279 | */ |
2280 | mm_size = sizeof(struct mm_struct) + cpumask_size(); | ||
2281 | |||
2279 | mm_cachep = kmem_cache_create_usercopy("mm_struct", | 2282 | mm_cachep = kmem_cache_create_usercopy("mm_struct", |
2280 | sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN, | 2283 | mm_size, ARCH_MIN_MMSTRUCT_ALIGN, |
2281 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, | 2284 | SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, |
2282 | offsetof(struct mm_struct, saved_auxv), | 2285 | offsetof(struct mm_struct, saved_auxv), |
2283 | sizeof_field(struct mm_struct, saved_auxv), | 2286 | sizeof_field(struct mm_struct, saved_auxv), |