Skip to content

Commit c96b9e5

Browse files
tehcastertorvalds
authored andcommitted
mm/compaction: cleanup isolate_freepages()
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>
1 parent 13fb44e commit c96b9e5

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
@@ -665,40 +665,44 @@ static void isolate_freepages(struct zone *zone,
665665
struct compact_control *cc)
666666
{
667667
struct page *page;
668-
unsigned long high_pfn, low_pfn, pfn, z_end_pfn;
668+
unsigned long block_start_pfn; /* start of current pageblock */
669+
unsigned long block_end_pfn; /* end of current pageblock */
670+
unsigned long low_pfn; /* lowest pfn scanner is able to scan */
671+
unsigned long next_free_pfn; /* start pfn for scaning at next round */
669672
int nr_freepages = cc->nr_freepages;
670673
struct list_head *freelist = &cc->freepages;
671674

672675
/*
673676
* Initialise the free scanner. The starting point is where we last
674677
* successfully isolated from, zone-cached value, or the end of the
675678
* zone when isolating for the first time. We need this aligned to
676-
* the pageblock boundary, because we do pfn -= pageblock_nr_pages
677-
* in the for loop.
679+
* the pageblock boundary, because we do
680+
* block_start_pfn -= pageblock_nr_pages in the for loop.
681+
* For ending point, take care when isolating in last pageblock of a
682+
* a zone which ends in the middle of a pageblock.
678683
* The low boundary is the end of the pageblock the migration scanner
679684
* is using.
680685
*/
681-
pfn = cc->free_pfn & ~(pageblock_nr_pages-1);
686+
block_start_pfn = cc->free_pfn & ~(pageblock_nr_pages-1);
687+
block_end_pfn = min(block_start_pfn + pageblock_nr_pages,
688+
zone_end_pfn(zone));
682689
low_pfn = ALIGN(cc->migrate_pfn + 1, pageblock_nr_pages);
683690

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

693697
/*
694698
* Isolate free pages until enough are available to migrate the
695699
* pages on cc->migratepages. We stop searching if the migrate
696700
* and free page scanners meet or enough free pages are isolated.
697701
*/
698-
for (; pfn >= low_pfn && cc->nr_migratepages > nr_freepages;
699-
pfn -= pageblock_nr_pages) {
702+
for (; block_start_pfn >= low_pfn && cc->nr_migratepages > nr_freepages;
703+
block_end_pfn = block_start_pfn,
704+
block_start_pfn -= pageblock_nr_pages) {
700705
unsigned long isolated;
701-
unsigned long end_pfn;
702706

703707
/*
704708
* This can iterate a massively long zone without finding any
@@ -707,7 +711,7 @@ static void isolate_freepages(struct zone *zone,
707711
*/
708712
cond_resched();
709713

710-
if (!pfn_valid(pfn))
714+
if (!pfn_valid(block_start_pfn))
711715
continue;
712716

713717
/*
@@ -717,7 +721,7 @@ static void isolate_freepages(struct zone *zone,
717721
* i.e. it's possible that all pages within a zones range of
718722
* pages do not belong to a single zone.
719723
*/
720-
page = pfn_to_page(pfn);
724+
page = pfn_to_page(block_start_pfn);
721725
if (page_zone(page) != zone)
722726
continue;
723727

@@ -730,24 +734,18 @@ static void isolate_freepages(struct zone *zone,
730734
continue;
731735

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

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

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

0 commit comments

Comments
 (0)