kernel: 5.10
arch: arm64
memblocks_present
/*
* Mark all memblocks as present using memory_present().
* This is a convenience function that is useful to mark all of the systems
* memory as present during initialization.
*/
static void __init memblocks_present(void)
{
unsigned long start, end;
int i, nid;
for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
memory_present(nid, start, end);
}
根据对for_each_mem_pfn_range的分析,memblocks_present实际就是遍历memblock.memory下的所有memblock_region区域,将每个memblock_region区域按section划分,创建对应的mem_section结构体,且通过mem_section的section_mem_map标记为在线状态
memory_present
/* Record a memory area against a node. */
static void __init memory_present(int nid, unsigned long start, unsigned long end)
{
unsigned long pfn;
#ifdef CONFIG_SPARSEMEM_EXTREME
if (unlikely(!mem_section)) {
unsigned long size, align;
size = sizeof(struct mem_section*) * NR_SECTION_ROOTS;
align = 1 << (INTERNODE_CACHE_SHIFT);
mem_section = memblock_alloc(size, align);
if (!mem_section)
panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
__func__

本文详细解析了Linux kernel 5.10中arm64架构下,如何使用memblocks_present和memory_present函数初始化内存区域。这两个函数主要负责将系统的内存标记为可用,并按照section进行划分,创建并标记mem_section结构体。在这个过程中,涉及到sparse内存模型的数据结构,包括memblock、mem_section、section_to_node_table等,以及section的分配、状态设置等步骤。文章深入探讨了Sparse内存模型的组织和管理机制。
最低0.47元/天 解锁文章
1635

被折叠的 条评论
为什么被折叠?



