Commit 7ac62185 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds

[PATCH] kswapd lockup fix

Fix some bugs in the kswapd logic which can cause kswapd lockups.

The balance_pgdat() logic is supposed to cause kswapd to loop across all zones
in the node until each zone either

	a) has enough pages free or

	b) is deemed to be in an "all pages unreclaimable" state.

In the latter case, we just give the zone a light scan on each balance_pgdat()
scan and wait for the zone to come back to life again.

But the zone->all_unreclaimable logic is broken - if the zone has no pages on
the LRU at all, we perform no scanning of that zone (of course).  So the
zone->pages_scanned is not incremented and the expression

		if (zone->pages_scanned > zone->present_pages * 2)
			zone->all_unreclaimable = 1;

never is satisfied.

The patch changes that logic to

		if (zone->pages_scanned >= (zone->nr_active +
						zone->nr_inactive) * 4)
			zone->all_unreclaimable = 1;

so if the zone has no LRU pages it will still enter the all_unreclaimable
state.


Another problem is that if the zone has no LRU pages we will tell
shrink_slab() that we scanned zero LRU pages.  This causes shrink_slab() to
scan zero slab objects, which is obviously wrong.  So change shrink_slab() to
perform a decent chunk of slab scanning in this situation.


And put a cond_resched() into the balance_pgdat() outer loop.  Probably
unnecessary, but that's what Jeff had in place when he confirmed that this
patch fixed the lockup :(
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 9ac1e4a8
...@@ -181,7 +181,7 @@ static int shrink_slab(unsigned long scanned, unsigned int gfp_mask, ...@@ -181,7 +181,7 @@ static int shrink_slab(unsigned long scanned, unsigned int gfp_mask,
struct shrinker *shrinker; struct shrinker *shrinker;
if (scanned == 0) if (scanned == 0)
return 0; scanned = SWAP_CLUSTER_MAX;
if (!down_read_trylock(&shrinker_rwsem)) if (!down_read_trylock(&shrinker_rwsem))
return 0; return 0;
...@@ -1065,7 +1065,8 @@ static int balance_pgdat(pg_data_t *pgdat, int nr_pages) ...@@ -1065,7 +1065,8 @@ static int balance_pgdat(pg_data_t *pgdat, int nr_pages)
total_reclaimed += sc.nr_reclaimed; total_reclaimed += sc.nr_reclaimed;
if (zone->all_unreclaimable) if (zone->all_unreclaimable)
continue; continue;
if (zone->pages_scanned > zone->present_pages * 2) if (zone->pages_scanned >= (zone->nr_active +
zone->nr_inactive) * 4)
zone->all_unreclaimable = 1; zone->all_unreclaimable = 1;
/* /*
* If we've done a decent amount of scanning and * If we've done a decent amount of scanning and
...@@ -1102,8 +1103,10 @@ static int balance_pgdat(pg_data_t *pgdat, int nr_pages) ...@@ -1102,8 +1103,10 @@ static int balance_pgdat(pg_data_t *pgdat, int nr_pages)
zone->prev_priority = zone->temp_priority; zone->prev_priority = zone->temp_priority;
} }
if (!all_zones_ok) if (!all_zones_ok) {
cond_resched();
goto loop_again; goto loop_again;
}
return total_reclaimed; return total_reclaimed;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment