zoukankan      html  css  js  c++  java
  • ARM32 Linux kernel virtual address space

     http://thinkiii.blogspot.jp/2014/02/arm32-linux-kernel-virtual-address-space.html

     
    The 32-bit ARM CPU can address up to 2^32 = 4GB address*. It's not big enough in present days, since the size of available DRAM on computing devices is growing fast and the memory usage of application is growing as well.

    In Linux kernel implementation, user space and kernel must coexist in the same 4GB virtual address space. It means both user space and kernel can use less than 4GB virtual address space. 
    Linux kernel provides 3 different split of virtual address spaces: VMSPLIT_3G, VMSPLIT_2G, VMSPLIT_1G.


    Linux virtual address space options


     The default configuration is VMSPLIT_3G, as you can see, kernel space starts from 0xC0000000 to 0xFFFFFFFF and user space starts from 0x00000000 to 0xC0000000.

    Let's take a closer look of the VMSPLIT_3G mapping:
     
    kernel space

    We can observe the kernel virtual address by checking the boot log (dmesg) or take a look at arch/arm/mm/init.c.
    lowmem: The memory that have 1-to-1 mapping between virtual and physical address. It means the virtual and physical address are both configuous, and this good property makes the virtual to physical address translation very easy. If we have a virtual address from lowmem, we can find out its physical address by simple shift. (see __pa() and __va()).

    vmalloc: The vmalloc memory is only virtually contiguous.

    fixmap/pkmap: create fast mapping of a single page for kernel. Most used in file system.

    modules: The virtual address for module loading and executing. kernel modules are loaded into this part of virtual memory.

    user space

    The code for deterring user space virtual address is in arch/arm/mm/mmap.c
    The user space have two different kind of mmap layout: legacy and non-legacy. Legacy layout sets the base of mmap(TASK_UNMAPPED_BASE) and the mmap grows in bottom-up manner; on the other case, non-legacy set the mmap base from TASK_SIZE - 128MB with some random shift for security reasons).


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    void arch_pick_mmap_layout(struct mm_struct *mm)
    {
            unsigned long random_factor = 0UL;
     
            /* 8 bits of randomness in 20 address space bits */
            if ((current->flags & PF_RANDOMIZE) &&
                !(current->personality & ADDR_NO_RANDOMIZE))
                    random_factor = (get_random_int() % (1 << 8)) << PAGE_SHIFT;
            if (mmap_is_legacy()) {
                    mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
                    mm->get_unmapped_area = arch_get_unmapped_area;
            } else {
                    mm->mmap_base = mmap_base(random_factor);
                    mm->get_unmapped_area = arch_get_unmapped_area_topdown;
            }

    The user space virtual address layout looks like:

    32-bit user virtual address space layout

    *ARM has LPAE (Large Physical Address Extension) mode that can address up to 1TB.
     
  • 相关阅读:
    vue前端使用JsonViewer进行json展示
    vue代理服务器proxy配置
    'vue-cli-service' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    Python中的高阶函数和内置高阶函数(abs,map,reduce,sorted,filter)
    Ant Design Vue 通过v-decorator实现数据绑定
    Vue脚手架(vue-cli)搭建和目录结构详解
    如何使用Postman从XML提取变量
    【已解决】Vue格式化js自动加上冒号和分号
    vue.js安装与搭建
    Python函数中如何返回多个值?
  • 原文地址:https://www.cnblogs.com/zengkefu/p/6783466.html
Copyright © 2011-2022 走看看