Commit 932ff6bbbdcadd85b309ef4fd59d4d8a77329b8b

Authored by Joonsoo Kim
Committed by Linus Torvalds
1 parent 372549c2a3

mm/compaction: stop the isolation when we isolate enough freepage

Currently, freepage isolation in one pageblock doesn't consider how many
freepages we isolate. When I traced flow of compaction, compaction
sometimes isolates more than 256 freepages to migrate just 32 pages.

In this patch, freepage isolation is stopped at the point that we
have more isolated freepage than isolated page for migration. This
results in slowing down free page scanner and make compaction success
rate higher.

stress-highalloc test in mmtests with non movable order 7 allocation shows
increase of compaction success rate.

Compaction success rate (Compaction success * 100 / Compaction stalls, %)
27.13 : 31.82

pfn where both scanners meets on compaction complete
(separate test due to enormous tracepoint buffer)
(zone_start=4096, zone_end=1048576)
586034 : 654378

In fact, I didn't fully understand why this patch results in such good
result. There was a guess that not used freepages are released to pcp list
and on next compaction trial we won't isolate them again so compaction
success rate would decrease. To prevent this effect, I tested with adding
pcp drain code on release_freepages(), but, it has no good effect.

Anyway, this patch reduces waste time to isolate unneeded freepages so
seems reasonable.

Vlastimil said:

: I briefly tried it on top of the pivot-changing series and with order-9
: allocations it reduced free page scanned counter by almost 10%.  No effect
: on success rates (maybe because pivot changing already took care of the
: scanners meeting problem) but the scanning reduction is good on its own.
:
: It also explains why e14c720efdd7 ("mm, compaction: remember position
: within pageblock in free pages scanner") had less than expected
: improvements.  It would only actually stop within pageblock in case of
: async compaction detecting contention.  I guess that's also why the
: infinite loop problem fixed by 1d5bfe1ffb5b affected so relatively few
: people.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: David Rientjes <rientjes@google.com>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 10 additions and 7 deletions Side-by-side Diff

... ... @@ -490,6 +490,13 @@
490 490  
491 491 /* If a page was split, advance to the end of it */
492 492 if (isolated) {
  493 + cc->nr_freepages += isolated;
  494 + if (!strict &&
  495 + cc->nr_migratepages <= cc->nr_freepages) {
  496 + blockpfn += isolated;
  497 + break;
  498 + }
  499 +
493 500 blockpfn += isolated - 1;
494 501 cursor += isolated - 1;
495 502 continue;
... ... @@ -899,7 +906,6 @@
899 906 unsigned long isolate_start_pfn; /* exact pfn we start at */
900 907 unsigned long block_end_pfn; /* end of current pageblock */
901 908 unsigned long low_pfn; /* lowest pfn scanner is able to scan */
902   - int nr_freepages = cc->nr_freepages;
903 909 struct list_head *freelist = &cc->freepages;
904 910  
905 911 /*
906 912  
... ... @@ -924,11 +930,11 @@
924 930 * pages on cc->migratepages. We stop searching if the migrate
925 931 * and free page scanners meet or enough free pages are isolated.
926 932 */
927   - for (; block_start_pfn >= low_pfn && cc->nr_migratepages > nr_freepages;
  933 + for (; block_start_pfn >= low_pfn &&
  934 + cc->nr_migratepages > cc->nr_freepages;
928 935 block_end_pfn = block_start_pfn,
929 936 block_start_pfn -= pageblock_nr_pages,
930 937 isolate_start_pfn = block_start_pfn) {
931   - unsigned long isolated;
932 938  
933 939 /*
934 940 * This can iterate a massively long zone without finding any
935 941  
... ... @@ -953,9 +959,8 @@
953 959 continue;
954 960  
955 961 /* Found a block suitable for isolating free pages from. */
956   - isolated = isolate_freepages_block(cc, &isolate_start_pfn,
  962 + isolate_freepages_block(cc, &isolate_start_pfn,
957 963 block_end_pfn, freelist, false);
958   - nr_freepages += isolated;
959 964  
960 965 /*
961 966 * Remember where the free scanner should restart next time,
... ... @@ -987,8 +992,6 @@
987 992 */
988 993 if (block_start_pfn < low_pfn)
989 994 cc->free_pfn = cc->migrate_pfn;
990   -
991   - cc->nr_freepages = nr_freepages;
992 995 }
993 996  
994 997 /*