Chinaunix首页 | 论坛 | 博客
  • 博客访问: 437366
  • 博文数量: 123
  • 博客积分: 2686
  • 博客等级: 少校
  • 技术积分: 1349
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-23 22:11
文章分类
文章存档

2012年(3)

2011年(10)

2010年(100)

2009年(10)

我的朋友

分类: LINUX

2010-10-18 15:31:06

The function checks whether the number of free pages is less than the desired minimum plus emergency reserved specified in lowmem_reseve. If not, the code iterates all orders less than the current order and subtracts all pages in current zone from free_pages. At the same time, the required number of free pages is halved each time. The allocation is freed when not enough pages are present after iterating over all low-memory zones.


/*
 * Return 1 if free pages are above 'mark'. This takes into account the order
 * of the allocation.
 */

int zone_watermark_ok(struct zone *z, int order, unsigned long mark,
         int classzone_idx, int alloc_flags)
{
    /* free_pages my go negative - that's OK */
    long min = mark;
    long free_pages = zone_page_state(z, NR_FREE_PAGES) - (1 << order) + 1;
    int o;

    if (alloc_flags & ALLOC_HIGH)
        min -= min / 2;
    if (alloc_flags & ALLOC_HARDER)
        min -= min / 4;

    if (free_pages <= min + z->lowmem_reserve[classzone_idx])
        return 0;
    for (o = 0; o < order; o++) {
        /* At the next order, this order's pages become unavailable */
        free_pages -= z->free_area[o].nr_free << o;

        /* Require fewer higher order pages to be free */
        min >>= 1;

        if (free_pages <= min)
            return 0;
    }
    return 1;
}



zone_page_state allows for access per-zone statistics. In this case, the number of free pages is obtained.

static inline unsigned long zone_page_state(struct zone *zone,
                    enum zone_stat_item item)
{
    long x = atomic_long_read(&zone->vm_stat[item]);
#ifdef CONFIG_SMP
    if (x < 0)
        x = 0;
#endif
    return x;
}


阅读(1147) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~