现在的位置: 首页 > 综合 > 正文

vmalloc分配高端物理内存

2019年01月01日 ⁄ 综合 ⁄ 共 1860字 ⁄ 字号 评论关闭

由vmalloc()分配的内存线性地址空间在VMALLOC_START之上,并且其分配的物理内存也是在896M之上的高端内存中的。

/**
*    vmalloc - allocate virtually contiguous memory
*    @size:        allocation size
*    Allocate enough pages to cover @size from the page level
*    allocator and map them into contiguous kernel virtual space.
*
*    For tight control over page level allocator and protection flags
*    use __vmalloc() instead.
*/
void *vmalloc(unsigned long size)
{
    //注意__GFP_HIGHMEM这个flag
    return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM,
PAGE_KERNEL);

}


static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
                        unsigned int order)
{
    if (unlikely(order >= MAX_ORDER))
        return NULL;

    /* Unknown node is current node */
    if (nid < 0)
        nid = numa_node_id();

    //最后调用的参数是zode_zonelists+ZONE_HIGHMEM,即是优先考虑高端内存区
    return __alloc_pages(gfp_mask, order,
        NODE_DATA(nid)->node_zonelists + gfp_zone(gfp_mask));
}

static inline enum zone_type gfp_zone(gfp_t flags)
{
#ifdef CONFIG_ZONE_DMA
    if (flags & __GFP_DMA)
        return ZONE_DMA;
#endif
#ifdef CONFIG_ZONE_DMA32
    if (flags & __GFP_DMA32)
        return ZONE_DMA32;
#endif
#ifdef CONFIG_HIGHMEM
    if (flags & __GFP_HIGHMEM) //高端内存
        return ZONE_HIGHMEM;
#endif
    return ZONE_NORMAL;
}

/*
* This is the 'heart' of the zoned buddy allocator.
*/
struct page * fastcall
__alloc_pages(gfp_t gfp_mask, unsigned int order,
        struct zonelist *zonelist)
{
    const gfp_t wait = gfp_mask & __GFP_WAIT;
    struct zone **z;
    struct page *page;
    struct reclaim_state reclaim_state;
    struct task_struct *p = current;
    int do_retry;
    int alloc_flags;
    int did_some_progress;

    might_sleep_if(wait);

    if (should_fail_alloc_page(gfp_mask, order))
        return NULL;

restart:
    z = zonelist->zones; /* the list of zones suitable for gfp_mask */

    if (unlikely(*z == NULL)) {
        /* Should this ever happen?? */
        return NULL;
    }

    page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, order,
                zonelist, ALLOC_WMARK_LOW|ALLOC_CPUSET);
    if (page)
        goto got_pg;

    ......
}
【上篇】
【下篇】

抱歉!评论已关闭.