Linux 内核 内存管理Linux 内核内存布局 ④ ( ARM64 架构体系内存分布 | 内核启动源码 start_kernel | 内存初始化 mm_init | mem_init )

一年好景君须记,最是橙黄橘绿时。这篇文章主要讲述Linux 内核 内存管理Linux 内核内存布局 ④ ( ARM64 架构体系内存分布 | 内核启动源码 start_kernel | 内存初始化 mm_init | mem_init )相关的知识,希望能为你提供帮助。




文章目录

  • ??一、ARM64 架构体系内存分布??
  • ??二、Linux 内核启动源码 start_kernel??
  • ??三、内存初始化源码 mm_init??
  • ??四、内存初始化源码 mem_init??


【Linux 内核 内存管理Linux 内核内存布局 ④ ( ARM64 架构体系内存分布 | 内核启动源码 start_kernel | 内存初始化 mm_init | mem_init )】







一、ARM64 架构体系内存分布

ARM64 架构 的 " 物理地址 " 有 484848 位 , 理论上最大 " 寻址空间 " 为 256256256 TB ;
ARM64 架构 的 " 虚拟地址 " 也是 最大支持484848 位 寻址地址 ;




Linux 内核 将 " 地址空间 " 划分为 : 内核空间 和 用户空间 ;
① 内核空间 ( Kernel Space ) : 寻址范围 0x FFFF 0000 0000 0000 ~ 0x FFFF FFFF FFFF FFFF ;
② 用户空间 ( User Space ) : 寻址范围 0x 0000 0000 0000 0000 ~ 0x 0000 FFFF FFFF FFFF ;




如下图所示 :

上图中的 " 不规范地址空间 " 是不允许使用的 内存空间 ;












二、Linux 内核启动源码 start_kernel

在 Linux 内核初始化完成后 , 会在 " 初始化内存 " 时 , 输出 内存布局 ;
Linux 内核启动源码是定义在 ??linux-5.6.18\\init\\main.c?? 源码中的
asmlinkage __visible void __init start_kernel(void)

函数 ;
在 Linux 内核启动方法 中 , 调用了 ??mm_init(); ?? 方法 , 参考路径 : linux-5.6.18\\init\\main.c#878
asmlinkage __visible void __init start_kernel(void)

// ...
/*
* These use large bootmem allocations and must precede
* kmem_cache_init()
*/
setup_log_buf(0);
vfs_caches_init_early();
sort_main_extable();
trap_init();
mm_init();
// ...






Linux 内核 启动源码 ( 仅做参考 ) :
asmlinkage __visible void __init start_kernel(void)

char *command_line;
char *after_dashes;

set_task_stack_end_magic(& init_task);
smp_setup_processor_id();
debug_objects_early_init();

cgroup_init_early();

local_irq_disable();
early_boot_irqs_disabled = true;

/*
* Interrupts are still disabled. Do necessary setups, then
* enable them.
*/
boot_cpu_init();
page_address_init();
pr_notice("%s", linux_banner);
early_security_init();
setup_arch(& command_line);
setup_boot_config(command_line);
setup_command_line(command_line);
setup_nr_cpu_ids();
setup_per_cpu_areas();
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
boot_cpu_hotplug_init();

build_all_zonelists(NULL);
page_alloc_init();

pr_notice("Kernel command line: %s\\n", saved_command_line);
/* parameters may set static keys */
jump_label_init();
parse_early_param();
after_dashes = parse_args("Booting kernel",
static_command_line, __start___param,
__stop___param - __start___param,
-1, -1, NULL, & unknown_bootoption);
if (!IS_ERR_OR_NULL(after_dashes))
parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
NULL, set_init_arg);
if (extra_init_args)
parse_args("Setting extra init args", extra_init_args,
NULL, 0, -1, -1, NULL, set_init_arg);

/*
* These use large bootmem allocations and must precede
* kmem_cache_init()
*/
setup_log_buf(0);
vfs_caches_init_early();
sort_main_extable();
trap_init();
mm_init();

ftrace_init();

/* trace_printk can be enabled here */
early_trace_init();

/*
* Set up the scheduler prior starting any interrupts (such as the
* timer interrupt). Full topology setup happens at smp_init()
* time - but meanwhile we still have a functioning scheduler.
*/
sched_init();
/*
* Disable preemption - early bootup scheduling is extremely
* fragile until we cpu_idle() for the first time.
*/
preempt_disable();
if (WARN(!irqs_disabled(),
"Interrupts were enabled *very* early, fixing it\\n"))
local_irq_disable();
radix_tree_init();

/*
* Set up housekeeping before setting up workqueues to allow the unbound
* workqueue to take non-housekeeping into account.
*/
housekeeping_init();

/*
* Allow workqueue creation and work item queueing/cancelling
* early.Work item execution depends on kthreads and starts after
* workqueue_init().
*/
workqueue_init_early();

rcu_init();

/* Trace events are available after this */
trace_init();

if (initcall_debug)
initcall_debug_enable();

context_tracking_init();
/* init some links before init_ISA_irqs() */
early_irq_init();
init_IRQ();
tick_init();
rcu_init_nohz();
init_timers();
hrtimers_init();
softirq_init();
timekeeping_init();

/*
* For best initial stack canary entropy, prepare it after:
* - setup_arch() for any UEFI RNG entropy and boot cmdline access
* - timekeeping_init() for ktime entropy used in rand_initialize()
* - rand_initialize() to get any arch-specific entropy like RDRAND
* - add_latent_entropy() to get any latent entropy
* - adding command line entropy
*/
rand_initialize();
add_latent_entropy();
add_device_randomness(command_line, strlen(command_line));
boot_init_stack_canary();

time_init();
perf_event_init();
profile_init();
call_function_init();
WARN(!irqs_disabled(), "Interrupts were enabled early\\n");

early_boot_irqs_disabled = false;
local_irq_enable();

kmem_cache_init_late();

/*
* HACK ALERT! This is early. Were enabling the console before
* weve done PCI setups etc, and console_init() must be aware of
* this. But we do want output early, in case something goes wrong.
*/
console_init();
if (panic_later)
panic("Too many boot %s vars at `%s", panic_later,
panic_param);

lockdep_init();

/*
* Need to run this when irqs are enabled, because it wants
* to self-test [hard/soft]-irqs on/off lock inversion bugs
* too:
*/
locking_selftest();

/*
* This needs to be called before any devices perform DMA
* operations that might use the SWIOTLB bounce buffers. It will
* mark the bounce buffers as decrypted so that their usage will
* not cause "plain-text" data to be decrypted when accessed.
*/
mem_encrypt_init();

#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start & & !initrd_below_start_ok & &
page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn)
pr_crit("initrd overwritten (0x%08lx < 0x%08lx) - disabling it.\\n",
page_to_pfn(virt_to_page((void *)initrd_start)),
min_low_pfn);
initrd_start = 0;

#endif
setup_per_cpu_pageset();
numa_policy_init();
acpi_early_init();
if (late_time_init)
late_time_init();
sched_clock_init();
calibrate_delay();
pid_idr_init();
anon_vma_init();
#ifdef CONFIG_X86
if (efi_enabled(EFI_RUNTIME_SERVICES))
efi_enter_virtual_mode();
#endif
thread_stack_cache_init();
cred_init();
fork_init();
proc_caches_init();
uts_ns_init();
buffer_init();
key_init();
security_init();
dbg_late_init();
vfs_caches_init();
pagecache_init();
signals_init();
seq_file_init();
proc_root_init();
nsfs_init();
cpuset_init();
cgroup_init();
taskstats_init_early();
delayacct_init();

poking_init();
check_bugs();

acpi_subsystem_init();
arch_post_acpi_subsys_init();
sfi_init_late();

/* Do the rest non-__inited, were now alive */
arch_call_rest_init();

    推荐阅读