提交 d979677c 编写于 作者: M MinChan Kim 提交者: Linus Torvalds

mm: shrink_all_memory(): use sc.nr_reclaimed

Commit a79311c1 "vmscan: bail out of
direct reclaim after swap_cluster_max pages" moved the nr_reclaimed
counter into the scan control to accumulate the number of all reclaimed
pages in a reclaim invocation.

shrink_all_memory() can use the same mechanism. it increase code
consistency and redability.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: NMinChan Kim <minchan.kim@gmail.com>
Signed-off-by: NKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: NJohannes Weiner <hannes@cmpxchg.org>
Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 0a0dd05d
...@@ -2050,16 +2050,15 @@ unsigned long global_lru_pages(void) ...@@ -2050,16 +2050,15 @@ unsigned long global_lru_pages(void)
#ifdef CONFIG_PM #ifdef CONFIG_PM
/* /*
* Helper function for shrink_all_memory(). Tries to reclaim 'nr_pages' pages * Helper function for shrink_all_memory(). Tries to reclaim 'nr_pages' pages
* from LRU lists system-wide, for given pass and priority, and returns the * from LRU lists system-wide, for given pass and priority.
* number of reclaimed pages
* *
* For pass > 3 we also try to shrink the LRU lists that contain a few pages * For pass > 3 we also try to shrink the LRU lists that contain a few pages
*/ */
static unsigned long shrink_all_zones(unsigned long nr_pages, int prio, static void shrink_all_zones(unsigned long nr_pages, int prio,
int pass, struct scan_control *sc) int pass, struct scan_control *sc)
{ {
struct zone *zone; struct zone *zone;
unsigned long ret = 0; unsigned long nr_reclaimed = 0;
for_each_populated_zone(zone) { for_each_populated_zone(zone) {
enum lru_list l; enum lru_list l;
...@@ -2082,14 +2081,16 @@ static unsigned long shrink_all_zones(unsigned long nr_pages, int prio, ...@@ -2082,14 +2081,16 @@ static unsigned long shrink_all_zones(unsigned long nr_pages, int prio,
zone->lru[l].nr_scan = 0; zone->lru[l].nr_scan = 0;
nr_to_scan = min(nr_pages, lru_pages); nr_to_scan = min(nr_pages, lru_pages);
ret += shrink_list(l, nr_to_scan, zone, nr_reclaimed += shrink_list(l, nr_to_scan, zone,
sc, prio); sc, prio);
if (ret >= nr_pages) if (nr_reclaimed >= nr_pages) {
return ret; sc->nr_reclaimed = nr_reclaimed;
return;
}
} }
} }
} }
return ret; sc->nr_reclaimed = nr_reclaimed;
} }
/* /*
...@@ -2103,7 +2104,6 @@ static unsigned long shrink_all_zones(unsigned long nr_pages, int prio, ...@@ -2103,7 +2104,6 @@ static unsigned long shrink_all_zones(unsigned long nr_pages, int prio,
unsigned long shrink_all_memory(unsigned long nr_pages) unsigned long shrink_all_memory(unsigned long nr_pages)
{ {
unsigned long lru_pages, nr_slab; unsigned long lru_pages, nr_slab;
unsigned long ret = 0;
int pass; int pass;
struct reclaim_state reclaim_state; struct reclaim_state reclaim_state;
struct scan_control sc = { struct scan_control sc = {
...@@ -2125,8 +2125,8 @@ unsigned long shrink_all_memory(unsigned long nr_pages) ...@@ -2125,8 +2125,8 @@ unsigned long shrink_all_memory(unsigned long nr_pages)
if (!reclaim_state.reclaimed_slab) if (!reclaim_state.reclaimed_slab)
break; break;
ret += reclaim_state.reclaimed_slab; sc.nr_reclaimed += reclaim_state.reclaimed_slab;
if (ret >= nr_pages) if (sc.nr_reclaimed >= nr_pages)
goto out; goto out;
nr_slab -= reclaim_state.reclaimed_slab; nr_slab -= reclaim_state.reclaimed_slab;
...@@ -2148,18 +2148,18 @@ unsigned long shrink_all_memory(unsigned long nr_pages) ...@@ -2148,18 +2148,18 @@ unsigned long shrink_all_memory(unsigned long nr_pages)
sc.may_unmap = 1; sc.may_unmap = 1;
for (prio = DEF_PRIORITY; prio >= 0; prio--) { for (prio = DEF_PRIORITY; prio >= 0; prio--) {
unsigned long nr_to_scan = nr_pages - ret; unsigned long nr_to_scan = nr_pages - sc.nr_reclaimed;
sc.nr_scanned = 0; sc.nr_scanned = 0;
ret += shrink_all_zones(nr_to_scan, prio, pass, &sc); shrink_all_zones(nr_to_scan, prio, pass, &sc);
if (ret >= nr_pages) if (sc.nr_reclaimed >= nr_pages)
goto out; goto out;
reclaim_state.reclaimed_slab = 0; reclaim_state.reclaimed_slab = 0;
shrink_slab(sc.nr_scanned, sc.gfp_mask, shrink_slab(sc.nr_scanned, sc.gfp_mask,
global_lru_pages()); global_lru_pages());
ret += reclaim_state.reclaimed_slab; sc.nr_reclaimed += reclaim_state.reclaimed_slab;
if (ret >= nr_pages) if (sc.nr_reclaimed >= nr_pages)
goto out; goto out;
if (sc.nr_scanned && prio < DEF_PRIORITY - 2) if (sc.nr_scanned && prio < DEF_PRIORITY - 2)
...@@ -2168,21 +2168,23 @@ unsigned long shrink_all_memory(unsigned long nr_pages) ...@@ -2168,21 +2168,23 @@ unsigned long shrink_all_memory(unsigned long nr_pages)
} }
/* /*
* If ret = 0, we could not shrink LRUs, but there may be something * If sc.nr_reclaimed = 0, we could not shrink LRUs, but there may be
* in slab caches * something in slab caches
*/ */
if (!ret) { if (!sc.nr_reclaimed) {
do { do {
reclaim_state.reclaimed_slab = 0; reclaim_state.reclaimed_slab = 0;
shrink_slab(nr_pages, sc.gfp_mask, global_lru_pages()); shrink_slab(nr_pages, sc.gfp_mask, global_lru_pages());
ret += reclaim_state.reclaimed_slab; sc.nr_reclaimed += reclaim_state.reclaimed_slab;
} while (ret < nr_pages && reclaim_state.reclaimed_slab > 0); } while (sc.nr_reclaimed < nr_pages &&
reclaim_state.reclaimed_slab > 0);
} }
out: out:
current->reclaim_state = NULL; current->reclaim_state = NULL;
return ret; return sc.nr_reclaimed;
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册