aboutsummaryrefslogtreecommitdiffstats
path: root/mm/vmscan.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/vmscan.c')
-rw-r--r--mm/vmscan.c87
1 files changed, 34 insertions, 53 deletions
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 8ed1b775bdc9..53f2f82f83ae 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -48,6 +48,7 @@
48#include <asm/div64.h> 48#include <asm/div64.h>
49 49
50#include <linux/swapops.h> 50#include <linux/swapops.h>
51#include <linux/balloon_compaction.h>
51 52
52#include "internal.h" 53#include "internal.h"
53 54
@@ -139,23 +140,11 @@ static bool global_reclaim(struct scan_control *sc)
139{ 140{
140 return !sc->target_mem_cgroup; 141 return !sc->target_mem_cgroup;
141} 142}
142
143static bool mem_cgroup_should_soft_reclaim(struct scan_control *sc)
144{
145 struct mem_cgroup *root = sc->target_mem_cgroup;
146 return !mem_cgroup_disabled() &&
147 mem_cgroup_soft_reclaim_eligible(root, root) != SKIP_TREE;
148}
149#else 143#else
150static bool global_reclaim(struct scan_control *sc) 144static bool global_reclaim(struct scan_control *sc)
151{ 145{
152 return true; 146 return true;
153} 147}
154
155static bool mem_cgroup_should_soft_reclaim(struct scan_control *sc)
156{
157 return false;
158}
159#endif 148#endif
160 149
161unsigned long zone_reclaimable_pages(struct zone *zone) 150unsigned long zone_reclaimable_pages(struct zone *zone)
@@ -1125,7 +1114,8 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
1125 LIST_HEAD(clean_pages); 1114 LIST_HEAD(clean_pages);
1126 1115
1127 list_for_each_entry_safe(page, next, page_list, lru) { 1116 list_for_each_entry_safe(page, next, page_list, lru) {
1128 if (page_is_file_cache(page) && !PageDirty(page)) { 1117 if (page_is_file_cache(page) && !PageDirty(page) &&
1118 !isolated_balloon_page(page)) {
1129 ClearPageActive(page); 1119 ClearPageActive(page);
1130 list_move(&page->lru, &clean_pages); 1120 list_move(&page->lru, &clean_pages);
1131 } 1121 }
@@ -2176,11 +2166,9 @@ static inline bool should_continue_reclaim(struct zone *zone,
2176 } 2166 }
2177} 2167}
2178 2168
2179static int 2169static void shrink_zone(struct zone *zone, struct scan_control *sc)
2180__shrink_zone(struct zone *zone, struct scan_control *sc, bool soft_reclaim)
2181{ 2170{
2182 unsigned long nr_reclaimed, nr_scanned; 2171 unsigned long nr_reclaimed, nr_scanned;
2183 int groups_scanned = 0;
2184 2172
2185 do { 2173 do {
2186 struct mem_cgroup *root = sc->target_mem_cgroup; 2174 struct mem_cgroup *root = sc->target_mem_cgroup;
@@ -2188,17 +2176,15 @@ __shrink_zone(struct zone *zone, struct scan_control *sc, bool soft_reclaim)
2188 .zone = zone, 2176 .zone = zone,
2189 .priority = sc->priority, 2177 .priority = sc->priority,
2190 }; 2178 };
2191 struct mem_cgroup *memcg = NULL; 2179 struct mem_cgroup *memcg;
2192 mem_cgroup_iter_filter filter = (soft_reclaim) ?
2193 mem_cgroup_soft_reclaim_eligible : NULL;
2194 2180
2195 nr_reclaimed = sc->nr_reclaimed; 2181 nr_reclaimed = sc->nr_reclaimed;
2196 nr_scanned = sc->nr_scanned; 2182 nr_scanned = sc->nr_scanned;
2197 2183
2198 while ((memcg = mem_cgroup_iter_cond(root, memcg, &reclaim, filter))) { 2184 memcg = mem_cgroup_iter(root, NULL, &reclaim);
2185 do {
2199 struct lruvec *lruvec; 2186 struct lruvec *lruvec;
2200 2187
2201 groups_scanned++;
2202 lruvec = mem_cgroup_zone_lruvec(zone, memcg); 2188 lruvec = mem_cgroup_zone_lruvec(zone, memcg);
2203 2189
2204 shrink_lruvec(lruvec, sc); 2190 shrink_lruvec(lruvec, sc);
@@ -2218,7 +2204,8 @@ __shrink_zone(struct zone *zone, struct scan_control *sc, bool soft_reclaim)
2218 mem_cgroup_iter_break(root, memcg); 2204 mem_cgroup_iter_break(root, memcg);
2219 break; 2205 break;
2220 } 2206 }
2221 } 2207 memcg = mem_cgroup_iter(root, memcg, &reclaim);
2208 } while (memcg);
2222 2209
2223 vmpressure(sc->gfp_mask, sc->target_mem_cgroup, 2210 vmpressure(sc->gfp_mask, sc->target_mem_cgroup,
2224 sc->nr_scanned - nr_scanned, 2211 sc->nr_scanned - nr_scanned,
@@ -2226,37 +2213,6 @@ __shrink_zone(struct zone *zone, struct scan_control *sc, bool soft_reclaim)
2226 2213
2227 } while (should_continue_reclaim(zone, sc->nr_reclaimed - nr_reclaimed, 2214 } while (should_continue_reclaim(zone, sc->nr_reclaimed - nr_reclaimed,
2228 sc->nr_scanned - nr_scanned, sc)); 2215 sc->nr_scanned - nr_scanned, sc));
2229
2230 return groups_scanned;
2231}
2232
2233
2234static void shrink_zone(struct zone *zone, struct scan_control *sc)
2235{
2236 bool do_soft_reclaim = mem_cgroup_should_soft_reclaim(sc);
2237 unsigned long nr_scanned = sc->nr_scanned;
2238 int scanned_groups;
2239
2240 scanned_groups = __shrink_zone(zone, sc, do_soft_reclaim);
2241 /*
2242 * memcg iterator might race with other reclaimer or start from
2243 * a incomplete tree walk so the tree walk in __shrink_zone
2244 * might have missed groups that are above the soft limit. Try
2245 * another loop to catch up with others. Do it just once to
2246 * prevent from reclaim latencies when other reclaimers always
2247 * preempt this one.
2248 */
2249 if (do_soft_reclaim && !scanned_groups)
2250 __shrink_zone(zone, sc, do_soft_reclaim);
2251
2252 /*
2253 * No group is over the soft limit or those that are do not have
2254 * pages in the zone we are reclaiming so we have to reclaim everybody
2255 */
2256 if (do_soft_reclaim && (sc->nr_scanned == nr_scanned)) {
2257 __shrink_zone(zone, sc, false);
2258 return;
2259 }
2260} 2216}
2261 2217
2262/* Returns true if compaction should go ahead for a high-order request */ 2218/* Returns true if compaction should go ahead for a high-order request */
@@ -2320,6 +2276,8 @@ static bool shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
2320{ 2276{
2321 struct zoneref *z; 2277 struct zoneref *z;
2322 struct zone *zone; 2278 struct zone *zone;
2279 unsigned long nr_soft_reclaimed;
2280 unsigned long nr_soft_scanned;
2323 bool aborted_reclaim = false; 2281 bool aborted_reclaim = false;
2324 2282
2325 /* 2283 /*
@@ -2359,6 +2317,18 @@ static bool shrink_zones(struct zonelist *zonelist, struct scan_control *sc)
2359 continue; 2317 continue;
2360 } 2318 }
2361 } 2319 }
2320 /*
2321 * This steals pages from memory cgroups over softlimit
2322 * and returns the number of reclaimed pages and
2323 * scanned pages. This works for global memory pressure
2324 * and balancing, not for a memcg's limit.
2325 */
2326 nr_soft_scanned = 0;
2327 nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone,
2328 sc->order, sc->gfp_mask,
2329 &nr_soft_scanned);
2330 sc->nr_reclaimed += nr_soft_reclaimed;
2331 sc->nr_scanned += nr_soft_scanned;
2362 /* need some check for avoid more shrink_zone() */ 2332 /* need some check for avoid more shrink_zone() */
2363 } 2333 }
2364 2334
@@ -2952,6 +2922,8 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
2952{ 2922{
2953 int i; 2923 int i;
2954 int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */ 2924 int end_zone = 0; /* Inclusive. 0 = ZONE_DMA */
2925 unsigned long nr_soft_reclaimed;
2926 unsigned long nr_soft_scanned;
2955 struct scan_control sc = { 2927 struct scan_control sc = {
2956 .gfp_mask = GFP_KERNEL, 2928 .gfp_mask = GFP_KERNEL,
2957 .priority = DEF_PRIORITY, 2929 .priority = DEF_PRIORITY,
@@ -3066,6 +3038,15 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
3066 3038
3067 sc.nr_scanned = 0; 3039 sc.nr_scanned = 0;
3068 3040
3041 nr_soft_scanned = 0;
3042 /*
3043 * Call soft limit reclaim before calling shrink_zone.
3044 */
3045 nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone,
3046 order, sc.gfp_mask,
3047 &nr_soft_scanned);
3048 sc.nr_reclaimed += nr_soft_reclaimed;
3049
3069 /* 3050 /*
3070 * There should be no need to raise the scanning 3051 * There should be no need to raise the scanning
3071 * priority if enough pages are already being scanned 3052 * priority if enough pages are already being scanned