Skip to content

Commit e0fd83a

Browse files
Peter Zijlstragregkh
authored andcommitted
mm: Move mm_cachep initialization to mm_init()
commit af80602 upstream. In order to allow using mm_alloc() much earlier, move initializing mm_cachep into mm_init(). Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9ae15aa commit e0fd83a

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

include/linux/sched/task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern void sched_dead(struct task_struct *p);
6565
void __noreturn do_task_dead(void);
6666
void __noreturn make_task_dead(int signr);
6767

68+
extern void mm_cache_init(void);
6869
extern void proc_caches_init(void);
6970

7071
extern void fork_init(void);

init/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ static void __init mm_init(void)
856856
/* Should be run after espfix64 is set up. */
857857
pti_init();
858858
kmsan_init_runtime();
859+
mm_cache_init();
859860
}
860861

861862
#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET

kernel/fork.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,10 +3018,27 @@ static void sighand_ctor(void *data)
30183018
init_waitqueue_head(&sighand->signalfd_wqh);
30193019
}
30203020

3021-
void __init proc_caches_init(void)
3021+
void __init mm_cache_init(void)
30223022
{
30233023
unsigned int mm_size;
30243024

3025+
/*
3026+
* The mm_cpumask is located at the end of mm_struct, and is
3027+
* dynamically sized based on the maximum CPU number this system
3028+
* can have, taking hotplug into account (nr_cpu_ids).
3029+
*/
3030+
mm_size = sizeof(struct mm_struct) + cpumask_size();
3031+
3032+
mm_cachep = kmem_cache_create_usercopy("mm_struct",
3033+
mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
3034+
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
3035+
offsetof(struct mm_struct, saved_auxv),
3036+
sizeof_field(struct mm_struct, saved_auxv),
3037+
NULL);
3038+
}
3039+
3040+
void __init proc_caches_init(void)
3041+
{
30253042
sighand_cachep = kmem_cache_create("sighand_cache",
30263043
sizeof(struct sighand_struct), 0,
30273044
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU|
@@ -3039,19 +3056,6 @@ void __init proc_caches_init(void)
30393056
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
30403057
NULL);
30413058

3042-
/*
3043-
* The mm_cpumask is located at the end of mm_struct, and is
3044-
* dynamically sized based on the maximum CPU number this system
3045-
* can have, taking hotplug into account (nr_cpu_ids).
3046-
*/
3047-
mm_size = sizeof(struct mm_struct) + cpumask_size();
3048-
3049-
mm_cachep = kmem_cache_create_usercopy("mm_struct",
3050-
mm_size, ARCH_MIN_MMSTRUCT_ALIGN,
3051-
SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
3052-
offsetof(struct mm_struct, saved_auxv),
3053-
sizeof_field(struct mm_struct, saved_auxv),
3054-
NULL);
30553059
vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT);
30563060
mmap_init();
30573061
nsproxy_cache_init();

0 commit comments

Comments
 (0)