博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
do_try_to_free_pages
阅读量:4153 次
发布时间:2019-05-25

本文共 1830 字,大约阅读时间需要 6 分钟。

/*

 * 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;

}

转载地址:http://qxqti.baihongyu.com/

你可能感兴趣的文章
程序员失误造成服务停用3小时,只得到半月辞退补偿,发帖喊冤
查看>>
码农:很多人称我“技术”,感觉这是不尊重!纠正无果后果断辞职
查看>>
php程序员看过来,这老外是在吐糟你吗?看看你中了几点!
查看>>
为什么说程序员是“培训班出来的”就是鄙视呢?
查看>>
码农吐糟同事:写代码低调点不行么?空格回车键与你有仇吗?
查看>>
阿里p8程序员四年提交6000次代码的确有功,但一次错误让人唏嘘!
查看>>
一道技术问题引起的遐想,最后得出结论技术的本质是多么的朴实!
查看>>
985硕士:非科班自学编程感觉还不如培训班出来的,硕士白读了?
查看>>
你准备写代码到多少岁?程序员们是这么回答的!
查看>>
码农:和产品对一天需求,产品经理的需求是对完了,可我代码呢?
查看>>
程序员过年回家该怎么给亲戚朋友解释自己的职业?
查看>>
技术架构师的日常工作是什么?网友:搭框架,写公共方法?
查看>>
第四章 微信飞机大战
查看>>
九度:题目1008:最短路径问题
查看>>
九度Online Judge
查看>>
九度:题目1027:欧拉回路
查看>>
九度:题目1012:畅通工程
查看>>
九度:题目1017:还是畅通工程
查看>>
九度:题目1034:寻找大富翁
查看>>
第六章 背包问题——01背包
查看>>