aboutsummaryrefslogtreecommitdiffstats
path: root/mm/vmscan.c
diff options
context:
space:
mode:
authorYing Han <yinghan@google.com>2011-05-24 20:12:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-25 11:39:26 -0400
commit1495f230fa7750479c79e3656286b9183d662077 (patch)
treee5e233bb9fe1916ccc7281e7dcc71b1572fb22c5 /mm/vmscan.c
parenta09ed5e00084448453c8bada4dcd31e5fbfc2f21 (diff)
vmscan: change shrinker API by passing shrink_control struct
Change each shrinker's API by consolidating the existing parameters into shrink_control struct. This will simplify any further features added w/o touching each file of shrinker. [akpm@linux-foundation.org: fix build] [akpm@linux-foundation.org: fix warning] [kosaki.motohiro@jp.fujitsu.com: fix up new shrinker API] [akpm@linux-foundation.org: fix xfs warning] [akpm@linux-foundation.org: update gfs2] Signed-off-by: Ying Han <yinghan@google.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Minchan Kim <minchan.kim@gmail.com> Acked-by: Pavel Emelyanov <xemul@openvz.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mel@csn.ul.ie> Acked-by: Rik van Riel <riel@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Hugh Dickins <hughd@google.com> Cc: Dave Hansen <dave@linux.vnet.ibm.com> Cc: Steven Whitehouse <swhiteho@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/vmscan.c')
-rw-r--r--mm/vmscan.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e4e245ed1a5b..7e0116150dc7 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -202,6 +202,14 @@ void unregister_shrinker(struct shrinker *shrinker)
202} 202}
203EXPORT_SYMBOL(unregister_shrinker); 203EXPORT_SYMBOL(unregister_shrinker);
204 204
205static inline int do_shrinker_shrink(struct shrinker *shrinker,
206 struct shrink_control *sc,
207 unsigned long nr_to_scan)
208{
209 sc->nr_to_scan = nr_to_scan;
210 return (*shrinker->shrink)(shrinker, sc);
211}
212
205#define SHRINK_BATCH 128 213#define SHRINK_BATCH 128
206/* 214/*
207 * Call the shrink functions to age shrinkable caches 215 * Call the shrink functions to age shrinkable caches
@@ -223,15 +231,14 @@ EXPORT_SYMBOL(unregister_shrinker);
223 * Returns the number of slab objects which we shrunk. 231 * Returns the number of slab objects which we shrunk.
224 */ 232 */
225unsigned long shrink_slab(struct shrink_control *shrink, 233unsigned long shrink_slab(struct shrink_control *shrink,
234 unsigned long nr_pages_scanned,
226 unsigned long lru_pages) 235 unsigned long lru_pages)
227{ 236{
228 struct shrinker *shrinker; 237 struct shrinker *shrinker;
229 unsigned long ret = 0; 238 unsigned long ret = 0;
230 unsigned long scanned = shrink->nr_scanned;
231 gfp_t gfp_mask = shrink->gfp_mask;
232 239
233 if (scanned == 0) 240 if (nr_pages_scanned == 0)
234 scanned = SWAP_CLUSTER_MAX; 241 nr_pages_scanned = SWAP_CLUSTER_MAX;
235 242
236 if (!down_read_trylock(&shrinker_rwsem)) { 243 if (!down_read_trylock(&shrinker_rwsem)) {
237 /* Assume we'll be able to shrink next time */ 244 /* Assume we'll be able to shrink next time */
@@ -244,8 +251,8 @@ unsigned long shrink_slab(struct shrink_control *shrink,
244 unsigned long total_scan; 251 unsigned long total_scan;
245 unsigned long max_pass; 252 unsigned long max_pass;
246 253
247 max_pass = (*shrinker->shrink)(shrinker, 0, gfp_mask); 254 max_pass = do_shrinker_shrink(shrinker, shrink, 0);
248 delta = (4 * scanned) / shrinker->seeks; 255 delta = (4 * nr_pages_scanned) / shrinker->seeks;
249 delta *= max_pass; 256 delta *= max_pass;
250 do_div(delta, lru_pages + 1); 257 do_div(delta, lru_pages + 1);
251 shrinker->nr += delta; 258 shrinker->nr += delta;
@@ -272,9 +279,9 @@ unsigned long shrink_slab(struct shrink_control *shrink,
272 int shrink_ret; 279 int shrink_ret;
273 int nr_before; 280 int nr_before;
274 281
275 nr_before = (*shrinker->shrink)(shrinker, 0, gfp_mask); 282 nr_before = do_shrinker_shrink(shrinker, shrink, 0);
276 shrink_ret = (*shrinker->shrink)(shrinker, this_scan, 283 shrink_ret = do_shrinker_shrink(shrinker, shrink,
277 gfp_mask); 284 this_scan);
278 if (shrink_ret == -1) 285 if (shrink_ret == -1)
279 break; 286 break;
280 if (shrink_ret < nr_before) 287 if (shrink_ret < nr_before)
@@ -2072,8 +2079,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
2072 lru_pages += zone_reclaimable_pages(zone); 2079 lru_pages += zone_reclaimable_pages(zone);
2073 } 2080 }
2074 2081
2075 shrink->nr_scanned = sc->nr_scanned; 2082 shrink_slab(shrink, sc->nr_scanned, lru_pages);
2076 shrink_slab(shrink, lru_pages);
2077 if (reclaim_state) { 2083 if (reclaim_state) {
2078 sc->nr_reclaimed += reclaim_state->reclaimed_slab; 2084 sc->nr_reclaimed += reclaim_state->reclaimed_slab;
2079 reclaim_state->reclaimed_slab = 0; 2085 reclaim_state->reclaimed_slab = 0;
@@ -2456,8 +2462,7 @@ loop_again:
2456 end_zone, 0)) 2462 end_zone, 0))
2457 shrink_zone(priority, zone, &sc); 2463 shrink_zone(priority, zone, &sc);
2458 reclaim_state->reclaimed_slab = 0; 2464 reclaim_state->reclaimed_slab = 0;
2459 shrink.nr_scanned = sc.nr_scanned; 2465 nr_slab = shrink_slab(&shrink, sc.nr_scanned, lru_pages);
2460 nr_slab = shrink_slab(&shrink, lru_pages);
2461 sc.nr_reclaimed += reclaim_state->reclaimed_slab; 2466 sc.nr_reclaimed += reclaim_state->reclaimed_slab;
2462 total_scanned += sc.nr_scanned; 2467 total_scanned += sc.nr_scanned;
2463 2468
@@ -3025,7 +3030,6 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
3025 } 3030 }
3026 3031
3027 nr_slab_pages0 = zone_page_state(zone, NR_SLAB_RECLAIMABLE); 3032 nr_slab_pages0 = zone_page_state(zone, NR_SLAB_RECLAIMABLE);
3028 shrink.nr_scanned = sc.nr_scanned;
3029 if (nr_slab_pages0 > zone->min_slab_pages) { 3033 if (nr_slab_pages0 > zone->min_slab_pages) {
3030 /* 3034 /*
3031 * shrink_slab() does not currently allow us to determine how 3035 * shrink_slab() does not currently allow us to determine how
@@ -3041,7 +3045,7 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
3041 unsigned long lru_pages = zone_reclaimable_pages(zone); 3045 unsigned long lru_pages = zone_reclaimable_pages(zone);
3042 3046
3043 /* No reclaimable slab or very low memory pressure */ 3047 /* No reclaimable slab or very low memory pressure */
3044 if (!shrink_slab(&shrink, lru_pages)) 3048 if (!shrink_slab(&shrink, sc.nr_scanned, lru_pages))
3045 break; 3049 break;
3046 3050
3047 /* Freed enough memory */ 3051 /* Freed enough memory */