重读页面的回收处理笔记2

在跟踪代码的过程中,我们可以看到alloc-page就是分配一个page。

我们在接着看代码:

函数:__alloc_pages_internal,我们可以看到注释:

/*
 * This is the 'heart' of the zoned buddy allocator.
 */

从上面知道这个函数的地位了。首先会去唤醒kswapd的内核线成。

wakeup_kswapd。


接着:

unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
                                gfp_t gfp_mask)
{
    struct scan_control sc = {
        .gfp_mask = gfp_mask,
        .may_writepage = !laptop_mode,
        .swap_cluster_max = SWAP_CLUSTER_MAX,
        .may_swap = 1,
        .swappiness = vm_swappiness,
        .order = order,
        .mem_cgroup = NULL,
        .isolate_pages = isolate_pages_global,
    };

    return do_try_to_free_pages(zonelist, &sc);
}
上面只是一种想当于人为的去释放pages。kswapd是内存回收的守护内核线程。


下面是kswapd的动作:

static unsigned long balance_pgdat(pg_data_t *pgdat, int order)
{
    int all_zones_ok;
    int priority;
    int i;
    unsigned long total_scanned;
    unsigned long nr_reclaimed;
    struct reclaim_state *reclaim_state = current->reclaim_state;
    struct scan_control sc = {
        .gfp_mask = GFP_KERNEL,
        .may_swap = 1,
        .swap_cluster_max = SWAP_CLUSTER_MAX,
        .swappiness = vm_swappiness,
        .order = order,
        .mem_cgroup = NULL,
        .isolate_pages = isolate_pages_global,
    };
  


shrink_zone

         shrink_active_list

         shrink_inactive_list


shrink_slab

我们在前一篇文章说了slab页面没有放在page cache中,所以有一个独立的  shrink_slab函数来处理

 

对于page cache的处理。

shrink_active_list,我们也同样看看该函数的说明:

/*
 * This moves pages from the active list to the inactive list.
 *
 * We move them the other way if the page is referenced by one or more
 * processes, from rmap.
 *
 * If the pages are mostly unmapped, the processing is fast and it is
 * appropriate to hold zone->lru_lock across the whole operation.  But if
 * the pages are mapped, the processing is slow (page_referenced()) so we
 * should drop zone->lru_lock around each page.  It's impossible to balance
 * this, so instead we remove the pages from the LRU while processing them.
 * It is safe to rely on PG_active against the non-LRU pages in here because
 * nobody will play with that bit on a non-LRU page.
 *
 * The downside is that we have to touch page->_count against each page.
 * But we had to alter page->flags anyway.
 */

 

 

而函数: shrink_inactive_list的说明:

/*
 * shrink_inactive_list() is a helper for shrink_zone().  It returns the number
 * of reclaimed pages
 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值