Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1908362 authored by Minchan Kim's avatar Minchan Kim Committed by Linus Torvalds
Browse files

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 bb21c7ce
  Author: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
  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: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Reported-by: default avatarM. Vefa Bicakci <bicave@superonline.com>
Reported-by: default avatar <caiqian@redhat.com>
Reviewed-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Tested-by: default avatar <caiqian@redhat.com>
Acked-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarRik van Riel <riel@redhat.com>
Acked-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: <stable@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent eba93fcc
Loading
Loading
Loading
Loading
+35 −8
Original line number Diff line number Diff line
@@ -1804,12 +1804,11 @@ static void shrink_zone(int priority, struct zone *zone,
 * If a zone is deemed to be full of pinned pages then just give it a light
 * scan then give up on it.
 */
static bool shrink_zones(int priority, struct zonelist *zonelist,
static void shrink_zones(int priority, struct zonelist *zonelist,
					struct scan_control *sc)
{
	struct zoneref *z;
	struct zone *zone;
	bool all_unreclaimable = true;

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

		shrink_zone(priority, zone, sc);
	}
}

static bool zone_reclaimable(struct zone *zone)
{
	return zone->pages_scanned < zone_reclaimable_pages(zone) * 6;
}

/*
 * As hibernation is going on, kswapd is freezed so that it can't mark
 * the zone into all_unreclaimable. It can't handle OOM during hibernation.
 * So let's check zone's unreclaimable in direct reclaim as well as kswapd.
 */
static bool all_unreclaimable(struct zonelist *zonelist,
		struct scan_control *sc)
{
	struct zoneref *z;
	struct zone *zone;
	bool all_unreclaimable = true;

	for_each_zone_zonelist_nodemask(zone, z, zonelist,
			gfp_zone(sc->gfp_mask), sc->nodemask) {
		if (!populated_zone(zone))
			continue;
		if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL))
			continue;
		if (zone_reclaimable(zone)) {
			all_unreclaimable = false;
			break;
		}
	}

	return all_unreclaimable;
}

@@ -1852,7 +1881,6 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
					struct scan_control *sc)
{
	int priority;
	bool all_unreclaimable;
	unsigned long total_scanned = 0;
	struct reclaim_state *reclaim_state = current->reclaim_state;
	struct zoneref *z;
@@ -1869,7 +1897,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
		sc->nr_scanned = 0;
		if (!priority)
			disable_swap_token();
		all_unreclaimable = shrink_zones(priority, zonelist, sc);
		shrink_zones(priority, zonelist, sc);
		/*
		 * Don't shrink slabs when reclaiming memory from
		 * over limit cgroups
@@ -1931,7 +1959,7 @@ out:
		return sc->nr_reclaimed;

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

	return 0;
@@ -2197,8 +2225,7 @@ loop_again:
			total_scanned += sc.nr_scanned;
			if (zone->all_unreclaimable)
				continue;
			if (nr_slab == 0 &&
			    zone->pages_scanned >= (zone_reclaimable_pages(zone) * 6))
			if (nr_slab == 0 && !zone_reclaimable(zone))
				zone->all_unreclaimable = 1;
			/*
			 * If we've done a decent amount of scanning and