Skip to content

Commit 5adc5be

Browse files
gormanmLinus Torvalds
authored andcommitted
Bias the placement of kernel pages at lower PFNs
This patch chooses blocks with lower PFNs when placing kernel allocations. This is particularly important during fallback in low memory situations to stop unmovable pages being placed throughout the entire address space. Signed-off-by: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9ef9acb commit 5adc5be

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

mm/page_alloc.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,23 @@ int move_freepages_block(struct zone *zone, struct page *page, int migratetype)
765765
return move_freepages(zone, start_page, end_page, migratetype);
766766
}
767767

768+
/* Return the page with the lowest PFN in the list */
769+
static struct page *min_page(struct list_head *list)
770+
{
771+
unsigned long min_pfn = -1UL;
772+
struct page *min_page = NULL, *page;;
773+
774+
list_for_each_entry(page, list, lru) {
775+
unsigned long pfn = page_to_pfn(page);
776+
if (pfn < min_pfn) {
777+
min_pfn = pfn;
778+
min_page = page;
779+
}
780+
}
781+
782+
return min_page;
783+
}
784+
768785
/* Remove an element from the buddy allocator from the fallback list */
769786
static struct page *__rmqueue_fallback(struct zone *zone, int order,
770787
int start_migratetype)
@@ -795,8 +812,11 @@ static struct page *__rmqueue_fallback(struct zone *zone, int order,
795812
if (list_empty(&area->free_list[migratetype]))
796813
continue;
797814

815+
/* Bias kernel allocations towards low pfns */
798816
page = list_entry(area->free_list[migratetype].next,
799817
struct page, lru);
818+
if (unlikely(start_migratetype != MIGRATE_MOVABLE))
819+
page = min_page(&area->free_list[migratetype]);
800820
area->nr_free--;
801821

802822
/*

0 commit comments

Comments
 (0)