学习Linux内核内存管理要看的布局图

本文详细介绍了Linux内核内存管理的布局,包括内核空间与用户空间的划分、kernel image空间、vmalloc区域、ZONE_NORMAL和ZONE_HIGHMEM的划分,以及swapper_pg_dir、fixmap、vector、pkmap和modules等部分的详细解析,帮助理解内存管理框架。
摘要由CSDN通过智能技术生成

内核内存布局图对于理解内存管理至关重要,有了布局图对于理解内存管理初始化,以及虚拟内存,各种内存分配都有辅助作用。

所以可以用一张图来总领,然后逐个介绍每一段的来历,作用等等。

内核内存布局图和内存管理框架图是不同视角的内存管理框图,还包括后面介绍的用户空间内存布局图。

1. 内核内存布局图框图

2. 内核内存布局打印

在内核基本完成内存初始化工作,整体布局稳定之后,start_kernel-->mm_init-->mem_init打印了一段内存layout。

Vexpress平台打印如下:

Memory: 1031428K/1048576K available (4787K kernel code, 156K rwdata, 1364K rodata, 1348K init, 166K bss, 17148K reserved, 0K cma-reserved, 270336K highmem)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xf0000000 - 0xff000000   ( 240 MB)
    lowmem  : 0xc0000000 - 0xef800000   ( 760 MB)
    pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
    modules : 0xbf000000 - 0xbfe00000   (  14 MB)
      .text : 0xc0008000 - 0xc060a09c   (6153 kB)
      .init : 0xc060b000 - 0xc075c000   (1348 kB)
      .data : 0xc075c000 - 0xc07833c0   ( 157 kB)
       .bss : 0xc07833c0 - 0xc07acbf0   ( 167 kB)

这里面的地址都是虚拟地址,其中lowmem是线性映射区。

线性映射区的意思是0xc0000000 - 0xef800000这段虚拟地址,和0x60000000 - 0x8f800000这段物理地址是一一对应的。

.text、.init、.data、.bss都属于lowmem区域,也即ZONE_NORMAL;vector、fixmap、vmalloc属于ZONE_HIGHMEM区域。

pkmap、modules属于用户空间。

void __init mem_init(void)
{
#ifdef CONFIG_HAVE_TCM
    /* These pointers are filled in on TCM detection */
    extern u32 dtcm_end;
    extern u32 itcm_end;
#endif

    set_max_mapnr(pfn_to_page(max_pfn) - mem_map);

    /* this will put all unused low memory onto the freelists */
    free_unused_memmap();
    free_all_bootmem();

#ifdef CONFIG_SA1111
    /* now that our DMA memory is actually so designated, we can free it */
    free_reserved_area(__va(PHYS_OFFSET), swapper_pg_dir, -1, NULL);
#endif

    free_highpages();

    mem_init_print_info(NULL);

#define MLK(b, t) b, t, ((t) - (b)) >> 10
#define MLM(b, t) b, t, ((t) - (b)) >> 20
#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), SZ_1K)

    pr_notice("Virtual kernel memory layout:\n"
            "    vector  : 0x%08lx - 0x%08lx   (%4ld kB)\n"
#ifdef CONFIG_HAVE_TCM
            "    DTCM    : 0x%08lx - 0x%08lx   (%4ld kB)\n"
            "    ITCM    : 0x%08lx - 0x%08lx   (%4ld kB)\n"
#endif
            "    fixmap  : 0x%08lx - 0x%08lx   (%4ld kB)\n"
            "    vmalloc : 0x%08lx - 0x%08lx   (%4ld MB)\n"
            "    lowmem  : 0x%08lx - 0x%08lx   (%4ld MB)\n"
#ifdef CONFIG_HIGHMEM
            "    pkmap   : 0x%08lx - 0x%08lx   (%4ld MB)\n"
#endif
#ifdef CONFIG_MODULES
            "    modules : 0x%08lx - 0x%08lx   (%4ld MB)\n"
#endif
            "      .text : 0x%p" " - 0x%p" "   (
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值