Skip to content

Commit af80602

Browse files
Peter Zijlstrahansendc
authored andcommitted
mm: Move mm_cachep initialization to mm_init()
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]
1 parent 97e3d26 commit af80602

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
@@ -860,6 +860,7 @@ static void __init mm_init(void)
860860
/* Should be run after espfix64 is set up. */
861861
pti_init();
862862
kmsan_init_runtime();
863+
mm_cache_init();
863864
}
864865

865866
#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET

kernel/fork.c

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

3018-
void __init proc_caches_init(void)
3018+
void __init mm_cache_init(void)
30193019
{
30203020
unsigned int mm_size;
30213021

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

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

0 commit comments

Comments
 (0)