Skip to content

Commit bb21c7c

Browse files
kosakitorvalds
authored andcommitted
vmscan: fix do_try_to_free_pages() return value when priority==0 reclaim failure
Greg Thelen reported recent Johannes's stack diet patch makes kernel hang. His test is following. mount -t cgroup none /cgroups -o memory mkdir /cgroups/cg1 echo $$ > /cgroups/cg1/tasks dd bs=1024 count=1024 if=/dev/null of=/data/foo echo $$ > /cgroups/tasks echo 1 > /cgroups/cg1/memory.force_empty Actually, This OOM hard to try logic have been corrupted since following two years old patch. commit a41f24e Author: Nishanth Aravamudan <[email protected]> Date: Tue Apr 29 00:58:25 2008 -0700 page allocator: smarter retry of costly-order allocations Original intention was "return success if the system have shrinkable zones though priority==0 reclaim was failure". But the above patch changed to "return nr_reclaimed if .....". Oh, That forgot nr_reclaimed may be 0 if priority==0 reclaim failure. And Johannes's patch 0aeb233 ("vmscan: remove all_unreclaimable scan control") made it more corrupt. Originally, priority==0 reclaim failure on memcg return 0, but this patch changed to return 1. It totally confused memcg. This patch fixes it completely. Reported-by: Greg Thelen <[email protected]> Signed-off-by: KOSAKI Motohiro <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: KAMEZAWA Hiroyuki <[email protected]> Tested-by: Greg Thelen <[email protected]> Acked-by: Balbir Singh <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9e506f7 commit bb21c7c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

mm/vmscan.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,13 +1724,13 @@ static void shrink_zone(int priority, struct zone *zone,
17241724
* If a zone is deemed to be full of pinned pages then just give it a light
17251725
* scan then give up on it.
17261726
*/
1727-
static int shrink_zones(int priority, struct zonelist *zonelist,
1727+
static bool shrink_zones(int priority, struct zonelist *zonelist,
17281728
struct scan_control *sc)
17291729
{
17301730
enum zone_type high_zoneidx = gfp_zone(sc->gfp_mask);
17311731
struct zoneref *z;
17321732
struct zone *zone;
1733-
int progress = 0;
1733+
bool all_unreclaimable = true;
17341734

17351735
for_each_zone_zonelist_nodemask(zone, z, zonelist, high_zoneidx,
17361736
sc->nodemask) {
@@ -1757,9 +1757,9 @@ static int shrink_zones(int priority, struct zonelist *zonelist,
17571757
}
17581758

17591759
shrink_zone(priority, zone, sc);
1760-
progress = 1;
1760+
all_unreclaimable = false;
17611761
}
1762-
return progress;
1762+
return all_unreclaimable;
17631763
}
17641764

17651765
/*
@@ -1782,7 +1782,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
17821782
struct scan_control *sc)
17831783
{
17841784
int priority;
1785-
unsigned long ret = 0;
1785+
bool all_unreclaimable;
17861786
unsigned long total_scanned = 0;
17871787
struct reclaim_state *reclaim_state = current->reclaim_state;
17881788
unsigned long lru_pages = 0;
@@ -1813,7 +1813,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18131813
sc->nr_scanned = 0;
18141814
if (!priority)
18151815
disable_swap_token();
1816-
ret = shrink_zones(priority, zonelist, sc);
1816+
all_unreclaimable = shrink_zones(priority, zonelist, sc);
18171817
/*
18181818
* Don't shrink slabs when reclaiming memory from
18191819
* over limit cgroups
@@ -1826,10 +1826,8 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18261826
}
18271827
}
18281828
total_scanned += sc->nr_scanned;
1829-
if (sc->nr_reclaimed >= sc->nr_to_reclaim) {
1830-
ret = sc->nr_reclaimed;
1829+
if (sc->nr_reclaimed >= sc->nr_to_reclaim)
18311830
goto out;
1832-
}
18331831

18341832
/*
18351833
* Try to write back as many pages as we just scanned. This
@@ -1849,9 +1847,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18491847
priority < DEF_PRIORITY - 2)
18501848
congestion_wait(BLK_RW_ASYNC, HZ/10);
18511849
}
1852-
/* top priority shrink_zones still had more to do? don't OOM, then */
1853-
if (ret && scanning_global_lru(sc))
1854-
ret = sc->nr_reclaimed;
1850+
18551851
out:
18561852
/*
18571853
* Now that we've scanned all the zones at this priority level, note
@@ -1877,7 +1873,14 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
18771873
delayacct_freepages_end();
18781874
put_mems_allowed();
18791875

1880-
return ret;
1876+
if (sc->nr_reclaimed)
1877+
return sc->nr_reclaimed;
1878+
1879+
/* top priority shrink_zones still had more to do? don't OOM, then */
1880+
if (scanning_global_lru(sc) && !all_unreclaimable)
1881+
return 1;
1882+
1883+
return 0;
18811884
}
18821885

18831886
unsigned long try_to_free_pages(struct zonelist *zonelist, int order,

0 commit comments

Comments
 (0)