Skip to content

Commit d190836

Browse files
Minchan Kimtorvalds
authored andcommitted
vmscan: check all_unreclaimable in direct reclaim path
M. Vefa Bicakci reported 2.6.35 kernel hang up when hibernation on his 32bit 3GB mem machine. (https://bugzilla.kernel.org/show_bug.cgi?id=16771). Also he bisected the regression to commit bb21c7c Author: KOSAKI Motohiro <[email protected]> Date: Fri Jun 4 14:15:05 2010 -0700 vmscan: fix do_try_to_free_pages() return value when priority==0 reclaim failure At first impression, this seemed very strange because the above commit only chenged function return value and hibernate_preallocate_memory() ignore return value of shrink_all_memory(). But it's related. Now, page allocation from hibernation code may enter infinite loop if the system has highmem. The reasons are that vmscan don't care enough OOM case when oom_killer_disabled. The problem sequence is following as. 1. hibernation 2. oom_disable 3. alloc_pages 4. do_try_to_free_pages if (scanning_global_lru(sc) && !all_unreclaimable) return 1; If kswapd is not freozen, it would set zone->all_unreclaimable to 1 and then shrink_zones maybe return true(ie, all_unreclaimable is true). So at last, alloc_pages could go to _nopage_. If it is, it should have no problem. This patch adds all_unreclaimable check to protect in direct reclaim path, too. It can care of hibernation OOM case and help bailout all_unreclaimable case slightly. Signed-off-by: KOSAKI Motohiro <[email protected]> Signed-off-by: Minchan Kim <[email protected]> Reported-by: M. Vefa Bicakci <[email protected]> Reported-by: <[email protected]> Reviewed-by: Johannes Weiner <[email protected]> Tested-by: <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Acked-by: Rik van Riel <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Cc: Balbir Singh <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent eba93fc commit d190836

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

mm/vmscan.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,12 +1804,11 @@ static void shrink_zone(int priority, struct zone *zone,
18041804
* If a zone is deemed to be full of pinned pages then just give it a light
18051805
* scan then give up on it.
18061806
*/
1807-
static bool shrink_zones(int priority, struct zonelist *zonelist,
1807+
static void shrink_zones(int priority, struct zonelist *zonelist,
18081808
struct scan_control *sc)
18091809
{
18101810
struct zoneref *z;
18111811
struct zone *zone;
1812-
bool all_unreclaimable = true;
18131812

18141813
for_each_zone_zonelist_nodemask(zone, z, zonelist,
18151814
gfp_zone(sc->gfp_mask), sc->nodemask) {
@@ -1827,8 +1826,38 @@ static bool shrink_zones(int priority, struct zonelist *zonelist,
18271826
}
18281827

18291828
shrink_zone(priority, zone, sc);
1830-
all_unreclaimable = false;
18311829
}
1830+
}
1831+
1832+
static bool zone_reclaimable(struct zone *zone)
1833+
{
1834+
return zone->pages_scanned < zone_reclaimable_pages(zone) * 6;
1835+
}
1836+
1837+
/*
1838+
* As hibernation is going on, kswapd is freezed so that it can't mark
1839+
* the zone into all_unreclaimable. It can't handle OOM during hibernation.
1840+
* So let's check zone's unreclaimable in direct reclaim as well as kswapd.
1841+
*/
1842+
static bool all_unreclaimable(struct zonelist *zonelist,
1843+
struct scan_control *sc)
1844+
{
1845+
struct zoneref *z;
1846+
struct zone *zone;
1847+
bool all_unreclaimable = true;
1848+
1849+
for_each_zone_zonelist_nodemask(zone, z, zonelist,
1850+
gfp_zone(sc->gfp_mask), sc->nodemask) {
1851+
if (!populated_zone(zone))
1852+
continue;
1853+
if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
1854+
continue;
1855+
if (zone_reclaimable(zone)) {
1856+
all_unreclaimable = false;
1857+
break;
1858+
}
1859+
}
1860+
18321861
return all_unreclaimable;
18331862
}
18341863

@@ -1852,7 +1881,6 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18521881
struct scan_control *sc)
18531882
{
18541883
int priority;
1855-
bool all_unreclaimable;
18561884
unsigned long total_scanned = 0;
18571885
struct reclaim_state *reclaim_state = current->reclaim_state;
18581886
struct zoneref *z;
@@ -1869,7 +1897,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18691897
sc->nr_scanned = 0;
18701898
if (!priority)
18711899
disable_swap_token();
1872-
all_unreclaimable = shrink_zones(priority, zonelist, sc);
1900+
shrink_zones(priority, zonelist, sc);
18731901
/*
18741902
* Don't shrink slabs when reclaiming memory from
18751903
* over limit cgroups
@@ -1931,7 +1959,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
19311959
return sc->nr_reclaimed;
19321960

19331961
/* top priority shrink_zones still had more to do? don't OOM, then */
1934-
if (scanning_global_lru(sc) && !all_unreclaimable)
1962+
if (scanning_global_lru(sc) && !all_unreclaimable(zonelist, sc))
19351963
return 1;
19361964

19371965
return 0;
@@ -2197,8 +2225,7 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order)
21972225
total_scanned += sc.nr_scanned;
21982226
if (zone->all_unreclaimable)
21992227
continue;
2200-
if (nr_slab == 0 &&
2201-
zone->pages_scanned >= (zone_reclaimable_pages(zone) * 6))
2228+
if (nr_slab == 0 && !zone_reclaimable(zone))
22022229
zone->all_unreclaimable = 1;
22032230
/*
22042231
* If we've done a decent amount of scanning and

0 commit comments

Comments
 (0)