设为首页 加入收藏

TOP

Linux-3.14.12内存管理笔记【伙伴管理算法(2)】(一)
2019-10-09 20:00:22 】 浏览:90
Tags:Linux-3.14.12 内存 管理 笔记 伙伴 算法

前面已经分析了linux内存管理算法(伙伴管理算法)的准备工作。

具体的算法初始化则回到start_kernel()函数接着往下走,下一个函数是mm_init():

【file:/init/main.c】
/*
 * Set up kernel memory allocators
 */
static void __init mm_init(void)
{
    /*
     * page_cgroup requires contiguous pages,
     * bigger than MAX_ORDER unless SPARSEMEM.
     */
    page_cgroup_init_flatmem();
    mem_init();
    kmem_cache_init();
    percpu_init_late();
    pgtable_init();
    vmalloc_init();
}

乍看仅仅是几个函数的调用,实际上这里的事情远远没这么简单。其中page_cgroup_init_flatmem()与cgroup相关,而mem_init()则是管理伙伴管理算法的初始化,此外kmem_cache_init()是用于内核slub内存分配体系的初始化,而vmalloc_init()则是用于vmalloc的初始化。

当前主要分析伙伴管理算法,则仅对mem_init()做专门的分析,其余的暂且后面再分析。

伙伴管理算法的初始化函数入口是mem_init(),其实现:

【file:/arch/x86/mm/init_32.c】
void __init mem_init(void)
{
    pci_iommu_alloc();
 
#ifdef CONFIG_FLATMEM
    BUG_ON(!mem_map);
#endif
    /*
     * With CONFIG_DEBUG_PAGEALLOC initialization of highmem pages has to
     * be done before free_all_bootmem(). Memblock use free low memory for
     * temporary data (see find_range_array()) and for this purpose can use
     * pages that was already passed to the buddy allocator, hence marked as
     * not accessible in the page tables when compiled with
     * CONFIG_DEBUG_PAGEALLOC. Otherwise order of initialization is not
     * important here.
     */
    set_highmem_pages_init();
 
    /* this will put all low memory onto the freelists */
    free_all_bootmem();
 
    after_bootmem = 1;
 
    mem_init_print_info(NULL);
    printk(KERN_INFO "virtual kernel memory layout:\n"
        " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
#ifdef CONFIG_HIGHMEM
        " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
#endif
        " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
        " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
        " .init : 0x%08lx - 0x%08lx (%4ld kB)\n"
        " .data : 0x%08lx - 0x%08lx (%4ld kB)\n"
        " .text : 0x%08lx - 0x%08lx (%4ld kB)\n",
        FIXADDR_START, FIXADDR_TOP,
        (FIXADDR_TOP - FIXADDR_START) >> 10,
 
#ifdef CONFIG_HIGHMEM
        PKMAP_BASE, PKMAP_BASE+LAST_PKMAP*PAGE_SIZE,
        (LAST_PKMAP*PAGE_SIZE) >> 10,
#endif
 
        VMALLOC_START, VMALLOC_END,
        (VMALLOC_END - VMALLOC_START) >> 20,
 
        (unsigned long)__va(0), (unsigned long)high_memory,
        ((unsigned long)high_memory - (unsigned long)__va(0)) >> 20,
 
        (unsigned long)&__init_begin, (unsigned long)&__init_end,
        ((unsigned long)&__init_end -
         (unsigned long)&__init_begin) >> 10,
 
        (unsigned long)&_etext, (unsigned long)&_edata,
        ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
 
        (unsigned long)&_text, (unsigned long)&_etext,
        ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
 
    /*
     * Check boundaries twice: Some fundamental inconsistencies can
     * be detected at build time already.
     */
#define __FIXADDR_TOP (-PAGE_SIZE)
#ifdef CONFIG_HIGHMEM
    BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START);
    BUILD_BUG_ON(VMALLOC_END > PKMAP_BASE);
#endif
#define high_memory (-128UL << 20)
    BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END);
#undef high_memory
#undef __FIXADDR_TOP
#ifdef CONFIG_RANDOMIZE_BASE
    BUILD_BUG_ON(CONFIG_RANDOMIZE_BASE_MAX_OFFSET > KERNEL_IMAGE_SIZE);
#endif
 
#ifdef CONFIG_HIGHMEM
    BUG_ON(PKMAP_BASE + LAST_PKMAP*PAGE_SIZE > FIXADDR_START);
    BUG_ON(VMALLOC_END > PKMAP_BASE);
#endif
    BUG_ON(VMALLOC_START >= VMALLOC_E
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇arm-linux-gcc下载与安装 下一篇嵌入式 02 STM32 07串口通信

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目