do_try_to_free_pages

/*

 * This is the main entry point to direct pagereclaim.

 *

 * If a full scan of the inactive list fails tofree enough memory then we

 * are "out of memory" and somethingneeds to be killed.

 *

 * If the caller is !__GFP_FS then theprobability of a failure is reasonably

 * high - the zone may be full of dirty orunder-writeback pages, which this

 * caller can't do much about.  We kick the writeback threads and takeexplicit

 * naps in the hope that some of these pagescan be written.  But if the

 * allocating task holds filesystem locks whichprevent writeout this might not

 * work, and the allocation attempt will fail.

 *

 * returns:   0,if no pages reclaimed

 *         else,the number of pages reclaimed

 */

static unsigned long do_try_to_free_pages(struct zonelist *zonelist,

                                     struct scan_control *sc)

{

       int initial_priority = sc->priority;

       unsigned long total_scanned = 0;

       unsigned long writeback_threshold;

retry:

       delayacct_freepages_start();

 

       if(global_reclaim(sc))

              count_vm_event(ALLOCSTALL);

 

       do {

              vmpressure_prio(sc->gfp_mask,sc->target_mem_cgroup,sc->priority);

              sc->nr_scanned = 0;

              shrink_zones(zonelist, sc);

 

              total_scanned +=sc->nr_scanned;

              if (sc->nr_reclaimed >=sc->nr_to_reclaim)

                     break;

 

              if (sc->compaction_ready)

                     break;

 

              if (sc->priority <DEF_PRIORITY - 2)

                     sc->may_writepage = 1;

 

              writeback_threshold =sc->nr_to_reclaim + sc->nr_to_reclaim / 2;

              if (total_scanned >writeback_threshold) {

                     wakeup_flusher_threads(laptop_mode? 0 : total_scanned,

                                          WB_REASON_TRY_TO_FREE_PAGES);

                     sc->may_writepage = 1;

              }

       } while (--sc->priority >=0);

 

       delayacct_freepages_end();

 

       if (sc->nr_reclaimed)

              return sc->nr_reclaimed;

 

       /* Aborted reclaim to try compaction?don't OOM, then */

       if (sc->compaction_ready)

              return 1;

 

       /* Untapped cgroup reserves?  Don't OOM, retry. */

       if (!sc->may_thrash) {

              sc->priority =initial_priority;

              sc->may_thrash = 1;

              goto retry;

       }

 

       return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值