aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlastimil Babka <vbabka@suse.cz>2016-10-07 19:57:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-07 21:46:27 -0400
commit9861a62c335cd34a2b6b25aaaf5898e8370299ec (patch)
tree4eb21fe16acfb2e229422de1927bfcb152781829
parentf2b8228c5f99a92bc07efd36f8dc840e0705a266 (diff)
mm, compaction: create compact_gap wrapper
Compaction uses a watermark gap of (2UL << order) pages at various places and it's not immediately obvious why. Abstract it through a compact_gap() wrapper to create a single place with a thorough explanation. [vbabka@suse.cz: clarify the comment of compact_gap()] Link: http://lkml.kernel.org/r/7b6aed1f-fdf8-2063-9ff4-bbe4de712d37@suse.cz Link: http://lkml.kernel.org/r/20160810091226.6709-9-vbabka@suse.cz Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Tested-by: Lorenzo Stoakes <lstoakes@gmail.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: David Rientjes <rientjes@google.com> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/compaction.h23
-rw-r--r--mm/compaction.c7
-rw-r--r--mm/vmscan.c6
3 files changed, 29 insertions, 7 deletions
diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index a1fba9994728..585d55cb0dc0 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -58,6 +58,29 @@ enum compact_result {
58 58
59struct alloc_context; /* in mm/internal.h */ 59struct alloc_context; /* in mm/internal.h */
60 60
61/*
62 * Number of free order-0 pages that should be available above given watermark
63 * to make sure compaction has reasonable chance of not running out of free
64 * pages that it needs to isolate as migration target during its work.
65 */
66static inline unsigned long compact_gap(unsigned int order)
67{
68 /*
69 * Although all the isolations for migration are temporary, compaction
70 * free scanner may have up to 1 << order pages on its list and then
71 * try to split an (order - 1) free page. At that point, a gap of
72 * 1 << order might not be enough, so it's safer to require twice that
73 * amount. Note that the number of pages on the list is also
74 * effectively limited by COMPACT_CLUSTER_MAX, as that's the maximum
75 * that the migrate scanner can have isolated on migrate list, and free
76 * scanner is only invoked when the number of isolated free pages is
77 * lower than that. But it's not worth to complicate the formula here
78 * as a bigger gap for higher orders than strictly necessary can also
79 * improve chances of compaction success.
80 */
81 return 2UL << order;
82}
83
61#ifdef CONFIG_COMPACTION 84#ifdef CONFIG_COMPACTION
62extern int sysctl_compact_memory; 85extern int sysctl_compact_memory;
63extern int sysctl_compaction_handler(struct ctl_table *table, int write, 86extern int sysctl_compaction_handler(struct ctl_table *table, int write,
diff --git a/mm/compaction.c b/mm/compaction.c
index e2618ac062a6..bbf41ee99142 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1391,11 +1391,10 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order,
1391 return COMPACT_SUCCESS; 1391 return COMPACT_SUCCESS;
1392 1392
1393 /* 1393 /*
1394 * Watermarks for order-0 must be met for compaction. Note the 2UL. 1394 * Watermarks for order-0 must be met for compaction to be able to
1395 * This is because during migration, copies of pages need to be 1395 * isolate free pages for migration targets.
1396 * allocated and for a short time, the footprint is higher
1397 */ 1396 */
1398 watermark = low_wmark_pages(zone) + (2UL << order); 1397 watermark = low_wmark_pages(zone) + compact_gap(order);
1399 if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx, 1398 if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx,
1400 alloc_flags, wmark_target)) 1399 alloc_flags, wmark_target))
1401 return COMPACT_SKIPPED; 1400 return COMPACT_SKIPPED;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 981fc84e7434..2a6978a07d56 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2480,7 +2480,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat,
2480 * If we have not reclaimed enough pages for compaction and the 2480 * If we have not reclaimed enough pages for compaction and the
2481 * inactive lists are large enough, continue reclaiming 2481 * inactive lists are large enough, continue reclaiming
2482 */ 2482 */
2483 pages_for_compaction = (2UL << sc->order); 2483 pages_for_compaction = compact_gap(sc->order);
2484 inactive_lru_pages = node_page_state(pgdat, NR_INACTIVE_FILE); 2484 inactive_lru_pages = node_page_state(pgdat, NR_INACTIVE_FILE);
2485 if (get_nr_swap_pages() > 0) 2485 if (get_nr_swap_pages() > 0)
2486 inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON); 2486 inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON);
@@ -2612,7 +2612,7 @@ static inline bool compaction_ready(struct zone *zone, struct scan_control *sc)
2612 * there is a buffer of free pages available to give compaction 2612 * there is a buffer of free pages available to give compaction
2613 * a reasonable chance of completing and allocating the page 2613 * a reasonable chance of completing and allocating the page
2614 */ 2614 */
2615 watermark = high_wmark_pages(zone) + (2UL << sc->order); 2615 watermark = high_wmark_pages(zone) + compact_gap(sc->order);
2616 watermark_ok = zone_watermark_ok_safe(zone, 0, watermark, sc->reclaim_idx); 2616 watermark_ok = zone_watermark_ok_safe(zone, 0, watermark, sc->reclaim_idx);
2617 2617
2618 /* 2618 /*
@@ -3169,7 +3169,7 @@ static bool kswapd_shrink_node(pg_data_t *pgdat,
3169 * excessive reclaim. Assume that a process requested a high-order 3169 * excessive reclaim. Assume that a process requested a high-order
3170 * can direct reclaim/compact. 3170 * can direct reclaim/compact.
3171 */ 3171 */
3172 if (sc->order && sc->nr_reclaimed >= 2UL << sc->order) 3172 if (sc->order && sc->nr_reclaimed >= compact_gap(sc->order))
3173 sc->order = 0; 3173 sc->order = 0;
3174 3174
3175 return sc->nr_scanned >= sc->nr_to_reclaim; 3175 return sc->nr_scanned >= sc->nr_to_reclaim;