kernel3.10 内存预留和ioremap分析

3.10内核调试:

 /sys/kernel/debug/memblock/memory 查看内核分布
 /sys/kernel/debug/memblock/reserver  查看内核预留内存o

------------------------------------------------------------
=====>>arch/arm/mm/ioremap.c

在驱动中重新映射share mem,会导致__arm_ioremap中,判断不过,具体判断如下:
    /*
     * Don't allow RAM to be mapped - this causes problems with ARMv6+
     */
    if (WARN_ON(pfn_valid(pfn)))
        return NULL;

---------------------------------
====>>arch/arm/mm/init.c
#ifdef CONFIG_HAVE_ARCH_PFN_VALID
int pfn_valid(unsigned long pfn)
{
    return memblock_is_memory(__pfn_to_phys(pfn));
}
EXPORT_SYMBOL(pfn_valid);
#endif
-----------------------------------------------------
===>>mm/memblock.c文件中
int __init memblock_is_reserved(phys_addr_t addr)
{
    return memblock_search(&memblock.reserved, addr) != -1;
}

int __init_memblock memblock_is_memory(phys_addr_t addr)
{
    return memblock_search(&memblock.memory, addr) != -1;
}
-------------------------------------------------------------

static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr)
{
    unsigned int left = 0, right = type->cnt;

    do {
        unsigned int mid = (right + left) / 2;

        if (addr < type->regions[mid].base)
            right = mid;
        else if (addr >= (type->regions[mid].base +
                  type->regions[mid].size))
            left = mid + 1;
        else
            return mid;
    } while (left < right);
    return -1;
}


在内核启动以后,MMU将所有内存全部映射,并且将内存打上标签,该标签分为:
1. memblok.memory
   该标签是通过memblock_add()来设置的
   setup_arch()-->arm_memblock_init()-->membock_add()
2.membolk.reserver
   改标签是通过memblock_reserver()来设置的

你可能感兴趣的:(linux,内核)