linux内存管理之初始化zonelists

本文详细介绍了Linux内存管理中初始化zonelists的过程,从start_kernel()函数开始,逐步解析ZONELIST_ORDER_NODE和ZONELIST_ORDER_ZONE的配置。文章通过代码示例展示了节点和区域的内存排序,包括movable、highmem、normal和DMA等不同类型的zone,并邀请读者一同验证和探讨可能存在的错误。
摘要由CSDN通过智能技术生成

linux内存管理代码有些改变,记录下来。

首先是初始化内存,从 init/main.c 中的__init  start_kernel()函数开始--》build_all_zonelists(NULL, NULL); -->> __build_all_zonelists(NULL) -->>

/* return values int ....just for stop_machine() */
static int __build_all_zonelists(void *data)//从_ref build_all_zonelists()函数中调用__build_all_zonelists(NULL)
{
    int nid;
    int cpu;
    pg_data_t *self = data;

#ifdef CONFIG_NUMA
    memset(node_load, 0, sizeof(node_load));//以节点为下标的数组
#endif

    if (self && !node_online(self->node_id)) {//初始化时,self=data=NULL,不执行
        build_zonelists(self);
        build_zonelist_cache(self);
    }

    for_each_online_node(nid) {//循环找到系统的所有节点
        pg_data_t *pgdat = NODE_DATA(nid);

        build_zonelists(pgdat);
        build_zonelist_cache(pgdat);
    }

    /*
     * Initialize the boot_pagesets that are going to be used
     * for bootstrapping processors. The real pagesets for
     * each zone will be allocated later when the per cpu
     * allocator is available.
     *
     * boot_pagesets are used also for bootstrapping offline
     * cpus if the system is already booted because the pagesets
     * are needed to initialize allocators on a specific cpu too.
     * F.e. the percpu allocator needs the page allocator which
     * needs the percpu allocator in order to allocate its pagesets
     * (a chicken-egg dilemma).
     */
    for_each_possible_cpu(cpu) {
        setup_pageset(&per_cpu(boot_pageset, cpu), 0);

#ifdef CONFIG_HAVE_MEMORYLESS_NODES
        /*
         * We now know the "local memory node" for each node--
         * i.e., the node of the first zone in the generic zonelist.
         * Set up numa_mem percpu variable for on-line cpus.  During
         * boot, only the boot cpu should be on-line;  we'll init the
         * secondary cpus' numa_mem as they come on-line.  During
         * node/memor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值