在开始之前,先看一下SSD202的内存使用范围
硬件上SSD202内置128MB内存,其中有一部分预留给MMA,MMAP以及CMA
具体的大小设置在bootargs 中
bootargs = "wt_board=WT2022 console=ttyS0,115200 rootfstype=squashfs,ubifs rootwait=1
cma=8M
LX_MEM=0x7f00000 mma_heap=mma_heap_name0,miu=0,sz=0x1000000
mma_memblock_remove=1 highres=off mmap_reserved=fb,miu=0,sz=0x300000
max_start_off=0x7C00000,max_end_off=0x7F00000";
即最大可使用内存0x7f00000=127MB,CMA占用8M,MMA使用16M,MMAP使用3M,剩下就是kernel可使用范围
预留内存相关启动日志如下:
[ 0.000000] LXmem is 0x7f00000 PHYS_OFFSET is 0x20000000
[ 0.000000] Add mem start 0x20000000 size 0x7f00000!!!!
[ 0.000000]
[ 0.000000] LX_MEM = 0x20000000, 0x7f00000 (16*7=112+15=127MB)
[ 0.000000] LX_MEM2 = 0x0, 0x0
[ 0.000000] LX_MEM3 = 0x0, 0x0
[ 0.000000] EMAC_LEN= 0x0
[ 0.000000] DRAM_LEN= 0x0
----mmap_reserved=fb,miu=0,sz=0x300000=3M
[ 0.000000] deal_with_reserved_mmap memblock_reserve success mmap_reserved_config[0].reserved_start=
[ 0.000000] 0x27c00000 == 0x27f00000 - 3M(0x00300000)
[ 0.000000]
---mma_heap=mma_heap_name0,miu=0,sz=0x1000000=16M
[ 0.000000] deal_with_reserve_mma_heap memblock_reserve success mma_config[0].reserved_start=
[ 0.000000] 0x26c00000 == 0x27c00000 - 16M(0x1000000)
---cma size = 8M
[ 0.000000] cma: Reserved 8 MiB at 0x26400000 = 0x26c00000 - 8M
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] percpu: Embedded 13 pages/cpu @c62bc000 s21208 r8192 d23848 u53248
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 28162
[ 0.000000] Kernel command line: wt_board=WT2022 console=ttyS0,115200 rootfstype=squashfs,ubifs rootwait=1 cma=8M LX_MEM=0x7f00000 mma_heap=mma_heap_na 。。。。。)
[ 0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[ 0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[ 0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.000000] Memory: 96736K/113664Kavailable (2467K kernel code, 222K rwdata, 1212K rodata, 164K init, 174K bss, 8736K reserved, 8192K cma-reserved)
从内存最顶端往下预留,最开始为3MB的MMAP,然后是16M的MMA,最后是8M的CMA区域,留给kernel的可用区域在0x26400000以下
接着看一下SSD202 kernel的虚拟映射表:
[ 0.000000] Virtual kernel memory layout:
[ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB)
[ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
[ 0.000000] vmalloc : 0xc8000000 - 0xff800000 ( 888 MB)
[ 0.000000] lowmem : 0xc0000000 - 0xc7f00000 ( 127 MB)
[ 0.000000] modules : 0xbf800000 - 0xc0000000 ( 8 MB)
[ 0.000000] .text : 0xc0008000 - 0xc02710a8 (2469 kB)
[ 0.000000] .init : 0xc03c3000 - 0xc03ec000 ( 164 kB)
[ 0.000000] .data : 0xc03ec000 - 0xc0423bd8 ( 223 kB)
[ 0.000000] .bss : 0xc0425000 - 0xc04509e0 ( 175 kB)
vector为中断向量映射区,位于内存最高端区域
fixmap为固定映射区,即虚拟地址固定,主要的kernel初始化阶段使用,比如console,dtb等以及热补丁应用
vmalloc,虚拟内存申请的地址范围,用于给vmalloc/ioremap动态分配内存
lowmem是线性映射区,1:1映射到物理地址
vmalloc区域和lowmem区域之间有一个1MB的hole,可以防止vmalloc越界
.text、.init、.data、.bss都属于lowmem区域&#