Skip to content

Commit e644c10

Browse files
tehcasterJiri Slaby
authored andcommitted
mm/compaction: cleanup isolate_freepages()
commit c96b9e5 upstream. isolate_freepages() is currently somewhat hard to follow thanks to many looks like it is related to the 'low_pfn' variable, but in fact it is not. This patch renames the 'high_pfn' variable to a hopefully less confusing name, and slightly changes its handling without a functional change. A comment made obsolete by recent changes is also updated. [akpm@linux-foundation.org: comment fixes, per Minchan] [iamjoonsoo.kim@lge.com: cleanups] Signed-off-by: Vlastimil Babka <vbabka@suse.cz> 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> Cc: Michal Nazarewicz <mina86@mina86.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Christoph Lameter <cl@linux.com> Cc: Rik van Riel <riel@redhat.com> Cc: Dongjun Shin <d.j.shin@samsung.com> Cc: Sunghwan Yun <sunghwan.yun@samsung.com> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.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>
1 parent 87db4a8 commit e644c10

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

‎mm/compaction.c‎

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -663,40 +663,44 @@ static void isolate_freepages(struct zone *zone,
663663
struct compact_control *cc)
664664
{
665665
struct page *page;
666-
unsigned long high_pfn, low_pfn, pfn, z_end_pfn;
666+
unsigned long block_start_pfn; /* start of current pageblock */
667+
unsigned long block_end_pfn; /* end of current pageblock */
668+
unsigned long low_pfn; /* lowest pfn scanner is able to scan */
669+
unsigned long next_free_pfn; /* start pfn for scaning at next round */
667670
int nr_freepages = cc->nr_freepages;
668671
struct list_head *freelist = &cc->freepages;
669672

670673
/*
671674
* Initialise the free scanner. The starting point is where we last
672675
* successfully isolated from, zone-cached value, or the end of the
673676
* zone when isolating for the first time. We need this aligned to
674-
* the pageblock boundary, because we do pfn -= pageblock_nr_pages
675-
* in the for loop.
677+
* the pageblock boundary, because we do
678+
* block_start_pfn -= pageblock_nr_pages in the for loop.
679+
* For ending point, take care when isolating in last pageblock of a
680+
* a zone which ends in the middle of a pageblock.
676681
* The low boundary is the end of the pageblock the migration scanner
677682
* is using.
678683
*/
679-
pfn = cc->free_pfn & ~(pageblock_nr_pages-1);
684+
block_start_pfn = cc->free_pfn & ~(pageblock_nr_pages-1);
685+
block_end_pfn = min(block_start_pfn + pageblock_nr_pages,
686+
zone_end_pfn(zone));
680687
low_pfn = ALIGN(cc->migrate_pfn + 1, pageblock_nr_pages);
681688

682689
/*
683-
* Take care that if the migration scanner is at the end of the zone
684-
* that the free scanner does not accidentally move to the next zone
685-
* in the next isolation cycle.
690+
* If no pages are isolated, the block_start_pfn < low_pfn check
691+
* will kick in.
686692
*/
687-
high_pfn = min(low_pfn, pfn);
688-
689-
z_end_pfn = zone_end_pfn(zone);
693+
next_free_pfn = 0;
690694

691695
/*
692696
* Isolate free pages until enough are available to migrate the
693697
* pages on cc->migratepages. We stop searching if the migrate
694698
* and free page scanners meet or enough free pages are isolated.
695699
*/
696-
for (; pfn >= low_pfn && cc->nr_migratepages > nr_freepages;
697-
pfn -= pageblock_nr_pages) {
700+
for (; block_start_pfn >= low_pfn && cc->nr_migratepages > nr_freepages;
701+
block_end_pfn = block_start_pfn,
702+
block_start_pfn -= pageblock_nr_pages) {
698703
unsigned long isolated;
699-
unsigned long end_pfn;
700704

701705
/*
702706
* This can iterate a massively long zone without finding any
@@ -705,7 +709,7 @@ static void isolate_freepages(struct zone *zone,
705709
*/
706710
cond_resched();
707711

708-
if (!pfn_valid(pfn))
712+
if (!pfn_valid(block_start_pfn))
709713
continue;
710714

711715
/*
@@ -715,7 +719,7 @@ static void isolate_freepages(struct zone *zone,
715719
* i.e. it's possible that all pages within a zones range of
716720
* pages do not belong to a single zone.
717721
*/
718-
page = pfn_to_page(pfn);
722+
page = pfn_to_page(block_start_pfn);
719723
if (page_zone(page) != zone)
720724
continue;
721725

@@ -728,24 +732,18 @@ static void isolate_freepages(struct zone *zone,
728732
continue;
729733

730734
/* Found a block suitable for isolating free pages from */
731-
732-
/*
733-
* Take care when isolating in last pageblock of a zone which
734-
* ends in the middle of a pageblock.
735-
*/
736-
end_pfn = min(pfn + pageblock_nr_pages, z_end_pfn);
737-
isolated = isolate_freepages_block(cc, pfn, end_pfn,
738-
freelist, false);
735+
isolated = isolate_freepages_block(cc, block_start_pfn,
736+
block_end_pfn, freelist, false);
739737
nr_freepages += isolated;
740738

741739
/*
742740
* Record the highest PFN we isolated pages from. When next
743741
* looking for free pages, the search will restart here as
744742
* page migration may have returned some pages to the allocator
745743
*/
746-
if (isolated) {
744+
if (isolated && next_free_pfn == 0) {
747745
cc->finished_update_free = true;
748-
high_pfn = max(high_pfn, pfn);
746+
next_free_pfn = block_start_pfn;
749747
}
750748
}
751749

@@ -756,10 +754,10 @@ static void isolate_freepages(struct zone *zone,
756754
* If we crossed the migrate scanner, we want to keep it that way
757755
* so that compact_finished() may detect this
758756
*/
759-
if (pfn < low_pfn)
760-
cc->free_pfn = max(pfn, zone->zone_start_pfn);
761-
else
762-
cc->free_pfn = high_pfn;
757+
if (block_start_pfn < low_pfn)
758+
next_free_pfn = cc->migrate_pfn;
759+
760+
cc->free_pfn = next_free_pfn;
763761
cc->nr_freepages = nr_freepages;
764762
}
765763

0 commit comments

Comments
 (0)