Commit ab755bf4 authored by Baolin Wang's avatar Baolin Wang Committed by Andrew Morton

mm: compaction: update the cc->nr_migratepages when allocating or freeing the freepages

Currently we will use 'cc->nr_freepages >= cc->nr_migratepages' comparison
to ensure that enough freepages are isolated in isolate_freepages(),
however it just decreases the cc->nr_freepages without updating
cc->nr_migratepages in compaction_alloc(), which will waste more CPU
cycles and cause too many freepages to be isolated.

So we should also update the cc->nr_migratepages when allocating or
freeing the freepages to avoid isolating excess freepages.  And I can see
fewer free pages are scanned and isolated when running thpcompact on my
Arm64 server:

                                       k6.7         k6.7_patched
Ops Compaction pages isolated      120692036.00   118160797.00
Ops Compaction migrate scanned     131210329.00   154093268.00
Ops Compaction free scanned       1090587971.00  1080632536.00
Ops Compact scan efficiency               12.03          14.26

Moreover, I did not see an obvious latency improvements, this is likely
because isolating freepages is not the bottleneck in the thpcompact test
case.

                              k6.7                  k6.7_patched
Amean     fault-both-1      1089.76 (   0.00%)     1080.16 *   0.88%*
Amean     fault-both-3      1616.48 (   0.00%)     1636.65 *  -1.25%*
Amean     fault-both-5      2266.66 (   0.00%)     2219.20 *   2.09%*
Amean     fault-both-7      2909.84 (   0.00%)     2801.90 *   3.71%*
Amean     fault-both-12     4861.26 (   0.00%)     4733.25 *   2.63%*
Amean     fault-both-18     7351.11 (   0.00%)     6950.51 *   5.45%*
Amean     fault-both-24     9059.30 (   0.00%)     9159.99 *  -1.11%*
Amean     fault-both-30    10685.68 (   0.00%)    11399.02 *  -6.68%*

Link: https://lkml.kernel.org/r/6440493f18da82298152b6305d6b41c2962a3ce6.1708409245.git.baolin.wang@linux.alibaba.comSigned-off-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: default avatarMel Gorman <mgorman@techsingularity.net>
Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d1d86ce2
...@@ -78,10 +78,10 @@ DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_fast_isolate_freepage ...@@ -78,10 +78,10 @@ DEFINE_EVENT(mm_compaction_isolate_template, mm_compaction_fast_isolate_freepage
#ifdef CONFIG_COMPACTION #ifdef CONFIG_COMPACTION
TRACE_EVENT(mm_compaction_migratepages, TRACE_EVENT(mm_compaction_migratepages,
TP_PROTO(struct compact_control *cc, TP_PROTO(unsigned int nr_migratepages,
unsigned int nr_succeeded), unsigned int nr_succeeded),
TP_ARGS(cc, nr_succeeded), TP_ARGS(nr_migratepages, nr_succeeded),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(unsigned long, nr_migrated) __field(unsigned long, nr_migrated)
...@@ -90,7 +90,7 @@ TRACE_EVENT(mm_compaction_migratepages, ...@@ -90,7 +90,7 @@ TRACE_EVENT(mm_compaction_migratepages,
TP_fast_assign( TP_fast_assign(
__entry->nr_migrated = nr_succeeded; __entry->nr_migrated = nr_succeeded;
__entry->nr_failed = cc->nr_migratepages - nr_succeeded; __entry->nr_failed = nr_migratepages - nr_succeeded;
), ),
TP_printk("nr_migrated=%lu nr_failed=%lu", TP_printk("nr_migrated=%lu nr_failed=%lu",
......
...@@ -1796,6 +1796,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) ...@@ -1796,6 +1796,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data)
dst = list_entry(cc->freepages.next, struct folio, lru); dst = list_entry(cc->freepages.next, struct folio, lru);
list_del(&dst->lru); list_del(&dst->lru);
cc->nr_freepages--; cc->nr_freepages--;
cc->nr_migratepages--;
return dst; return dst;
} }
...@@ -1811,6 +1812,7 @@ static void compaction_free(struct folio *dst, unsigned long data) ...@@ -1811,6 +1812,7 @@ static void compaction_free(struct folio *dst, unsigned long data)
list_add(&dst->lru, &cc->freepages); list_add(&dst->lru, &cc->freepages);
cc->nr_freepages++; cc->nr_freepages++;
cc->nr_migratepages++;
} }
/* possible outcome of isolate_migratepages */ /* possible outcome of isolate_migratepages */
...@@ -2433,7 +2435,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) ...@@ -2433,7 +2435,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
unsigned long last_migrated_pfn; unsigned long last_migrated_pfn;
const bool sync = cc->mode != MIGRATE_ASYNC; const bool sync = cc->mode != MIGRATE_ASYNC;
bool update_cached; bool update_cached;
unsigned int nr_succeeded = 0; unsigned int nr_succeeded = 0, nr_migratepages;
/* /*
* These counters track activities during zone compaction. Initialize * These counters track activities during zone compaction. Initialize
...@@ -2551,11 +2553,17 @@ compact_zone(struct compact_control *cc, struct capture_control *capc) ...@@ -2551,11 +2553,17 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
pageblock_start_pfn(cc->migrate_pfn - 1)); pageblock_start_pfn(cc->migrate_pfn - 1));
} }
/*
* Record the number of pages to migrate since the
* compaction_alloc/free() will update cc->nr_migratepages
* properly.
*/
nr_migratepages = cc->nr_migratepages;
err = migrate_pages(&cc->migratepages, compaction_alloc, err = migrate_pages(&cc->migratepages, compaction_alloc,
compaction_free, (unsigned long)cc, cc->mode, compaction_free, (unsigned long)cc, cc->mode,
MR_COMPACTION, &nr_succeeded); MR_COMPACTION, &nr_succeeded);
trace_mm_compaction_migratepages(cc, nr_succeeded); trace_mm_compaction_migratepages(nr_migratepages, nr_succeeded);
/* All pages were either migrated or will be released */ /* All pages were either migrated or will be released */
cc->nr_migratepages = 0; cc->nr_migratepages = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment