Commit 5e4084a627820bd6a8d94bca6acb878e5308716c
Committed by
Jiri Slaby
1 parent
0d9b792442
Exists in
ti-linux-3.12.y
and in
2 other branches
mm/compaction: do not count migratepages when unnecessary
commit f8c9301fa5a2a8b873c67f2a3d8230d5c13f61b7 upstream. During compaction, update_nr_listpages() has been used to count remaining non-migrated and free pages after a call to migrage_pages(). The freepages counting has become unneccessary, and it turns out that migratepages counting is also unnecessary in most cases. The only situation when it's needed to count cc->migratepages is when migrate_pages() returns with a negative error code. Otherwise, the non-negative return value is the number of pages that were not migrated, which is exactly the count of remaining pages in the cc->migratepages list. Furthermore, any non-zero count is only interesting for the tracepoint of mm_compaction_migratepages events, because after that all remaining unmigrated pages are put back and their count is set to 0. This patch therefore removes update_nr_listpages() completely, and changes the tracepoint definition so that the manual counting is done only when the tracepoint is enabled, and only when migrate_pages() returns a negative error code. Furthermore, migrate_pages() and the tracepoints won't be called when there's nothing to migrate. This potentially avoids some wasted cycles and reduces the volume of uninteresting mm_compaction_migratepages events where "nr_migrated=0 nr_failed=0". In the stress-highalloc mmtest, this was about 75% of the events. The mm_compaction_isolate_migratepages event is better for determining that nothing was isolated for migration, and this one was just duplicating the info. Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Cc: Christoph Lameter <cl@linux.com> Cc: Rik van Riel <riel@redhat.com> Acked-by: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Mel Gorman <mgorman@suse.de> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Showing 2 changed files with 28 additions and 28 deletions Side-by-side Diff
include/trace/events/compaction.h
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | #define _TRACE_COMPACTION_H |
6 | 6 | |
7 | 7 | #include <linux/types.h> |
8 | +#include <linux/list.h> | |
8 | 9 | #include <linux/tracepoint.h> |
9 | 10 | #include <trace/events/gfpflags.h> |
10 | 11 | |
11 | 12 | |
... | ... | @@ -47,10 +48,11 @@ |
47 | 48 | |
48 | 49 | TRACE_EVENT(mm_compaction_migratepages, |
49 | 50 | |
50 | - TP_PROTO(unsigned long nr_migrated, | |
51 | - unsigned long nr_failed), | |
51 | + TP_PROTO(unsigned long nr_all, | |
52 | + int migrate_rc, | |
53 | + struct list_head *migratepages), | |
52 | 54 | |
53 | - TP_ARGS(nr_migrated, nr_failed), | |
55 | + TP_ARGS(nr_all, migrate_rc, migratepages), | |
54 | 56 | |
55 | 57 | TP_STRUCT__entry( |
56 | 58 | __field(unsigned long, nr_migrated) |
... | ... | @@ -58,7 +60,22 @@ |
58 | 60 | ), |
59 | 61 | |
60 | 62 | TP_fast_assign( |
61 | - __entry->nr_migrated = nr_migrated; | |
63 | + unsigned long nr_failed = 0; | |
64 | + struct list_head *page_lru; | |
65 | + | |
66 | + /* | |
67 | + * migrate_pages() returns either a non-negative number | |
68 | + * with the number of pages that failed migration, or an | |
69 | + * error code, in which case we need to count the remaining | |
70 | + * pages manually | |
71 | + */ | |
72 | + if (migrate_rc >= 0) | |
73 | + nr_failed = migrate_rc; | |
74 | + else | |
75 | + list_for_each(page_lru, migratepages) | |
76 | + nr_failed++; | |
77 | + | |
78 | + __entry->nr_migrated = nr_all - nr_failed; | |
62 | 79 | __entry->nr_failed = nr_failed; |
63 | 80 | ), |
64 | 81 |
mm/compaction.c
... | ... | @@ -820,22 +820,6 @@ |
820 | 820 | cc->nr_freepages++; |
821 | 821 | } |
822 | 822 | |
823 | -/* | |
824 | - * We cannot control nr_migratepages fully when migration is running as | |
825 | - * migrate_pages() has no knowledge of of compact_control. When migration is | |
826 | - * complete, we count the number of pages on the list by hand. | |
827 | - */ | |
828 | -static void update_nr_listpages(struct compact_control *cc) | |
829 | -{ | |
830 | - int nr_migratepages = 0; | |
831 | - struct page *page; | |
832 | - | |
833 | - list_for_each_entry(page, &cc->migratepages, lru) | |
834 | - nr_migratepages++; | |
835 | - | |
836 | - cc->nr_migratepages = nr_migratepages; | |
837 | -} | |
838 | - | |
839 | 823 | /* possible outcome of isolate_migratepages */ |
840 | 824 | typedef enum { |
841 | 825 | ISOLATE_ABORT, /* Abort compaction now */ |
... | ... | @@ -1030,7 +1014,6 @@ |
1030 | 1014 | migrate_prep_local(); |
1031 | 1015 | |
1032 | 1016 | while ((ret = compact_finished(zone, cc)) == COMPACT_CONTINUE) { |
1033 | - unsigned long nr_migrate, nr_remaining; | |
1034 | 1017 | int err; |
1035 | 1018 | |
1036 | 1019 | switch (isolate_migratepages(zone, cc)) { |
1037 | 1020 | |
1038 | 1021 | |
1039 | 1022 | |
1040 | 1023 | |
... | ... | @@ -1045,20 +1028,20 @@ |
1045 | 1028 | ; |
1046 | 1029 | } |
1047 | 1030 | |
1048 | - nr_migrate = cc->nr_migratepages; | |
1031 | + if (!cc->nr_migratepages) | |
1032 | + continue; | |
1033 | + | |
1049 | 1034 | err = migrate_pages(&cc->migratepages, compaction_alloc, |
1050 | 1035 | compaction_free, (unsigned long)cc, cc->mode, |
1051 | 1036 | MR_COMPACTION); |
1052 | - update_nr_listpages(cc); | |
1053 | - nr_remaining = cc->nr_migratepages; | |
1054 | 1037 | |
1055 | - trace_mm_compaction_migratepages(nr_migrate - nr_remaining, | |
1056 | - nr_remaining); | |
1038 | + trace_mm_compaction_migratepages(cc->nr_migratepages, err, | |
1039 | + &cc->migratepages); | |
1057 | 1040 | |
1058 | - /* Release isolated pages not migrated */ | |
1041 | + /* All pages were either migrated or will be released */ | |
1042 | + cc->nr_migratepages = 0; | |
1059 | 1043 | if (err) { |
1060 | 1044 | putback_movable_pages(&cc->migratepages); |
1061 | - cc->nr_migratepages = 0; | |
1062 | 1045 | /* |
1063 | 1046 | * migrate_pages() may return -ENOMEM when scanners meet |
1064 | 1047 | * and we want compact_finished() to detect it |