• Johannes Weiner's avatar
    vmscan: clip swap_cluster_max in shrink_all_memory() · 9786bf84
    Johannes Weiner authored
    shrink_inactive_list() scans in sc->swap_cluster_max chunks until it hits
    the scan limit it was passed.
    	do {
    	} while (nr_scanned < max_scan);
    This assumes that swap_cluster_max is not bigger than the scan limit
    because the latter is checked only after at least one iteration.
    In shrink_all_memory() sc->swap_cluster_max is initialized to the overall
    reclaim goal in the beginning but not decreased while reclaim is making
    progress which leads to subsequent calls to shrink_inactive_list()
    reclaiming way too much in the one iteration that is done unconditionally.
    Set sc->swap_cluster_max always to the proper goal before doing
    While the current shrink_all_memory() happily reclaims more than actually
    requested, this patch fixes it to never exceed the goal:
       wanted=10000 reclaimed=13356
       wanted=10000 reclaimed=19711
       wanted=10000 reclaimed=10289
       wanted=10000 reclaimed=17306
       wanted=10000 reclaimed=10700
       wanted=10000 reclaimed=10004
       wanted=10000 reclaimed=13301
       wanted=10000 reclaimed=10976
       wanted=10000 reclaimed=10605
       wanted=10000 reclaimed=10088
       wanted=10000 reclaimed=15000
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=9599
       wanted=10000 reclaimed=8476
       wanted=10000 reclaimed=8326
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=9919
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=9624
       wanted=10000 reclaimed=10000
       wanted=10000 reclaimed=10000
       wanted=8500 reclaimed=8092
       wanted=316 reclaimed=316
    Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
    Reviewed-by: default avatarMinChan Kim <minchan.kim@gmail.com>
    Acked-by: default avatarNigel Cunningham <ncunningham@crca.org.au>
    Acked-by: default avatar"Rafael J. Wysocki" <rjw@sisk.pl>
    Reviewed-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
    Cc: Rik van Riel <riel@redhat.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>