本文共 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/