Commit 6ab01363 authored by Alexander Duyck's avatar Alexander Duyck Committed by Linus Torvalds

mm: use zone and order instead of free area in free_list manipulators

In order to enable the use of the zone from the list manipulator functions
I will need access to the zone pointer.  As it turns out most of the
accessors were always just being directly passed &zone->free_area[order]
anyway so it would make sense to just fold that into the function itself
and pass the zone and order as arguments instead of the free area.

In order to be able to reference the zone we need to move the declaration
of the functions down so that we have the zone defined before we define
the list manipulation functions.  Since the functions are only used in the
file mm/page_alloc.c we can just move them there to reduce noise in the
header.
Signed-off-by: default avatarAlexander Duyck <alexander.h.duyck@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDan Williams <dan.j.williams@intel.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarPankaj Gupta <pagupta@redhat.com>
Acked-by: default avatarMel Gorman <mgorman@techsingularity.net>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Luiz Capitulino <lcapitulino@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Nitesh Narayan Lal <nitesh@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Wei Wang <wei.w.wang@intel.com>
Cc: Yang Zhang <yang.zhang.wz@gmail.com>
Cc: wei qi <weiqi4@huawei.com>
Link: http://lkml.kernel.org/r/20200211224613.29318.43080.stgit@localhost.localdomainSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a2129f24
...@@ -100,29 +100,6 @@ struct free_area { ...@@ -100,29 +100,6 @@ struct free_area {
unsigned long nr_free; unsigned long nr_free;
}; };
/* Used for pages not on another list */
static inline void add_to_free_area(struct page *page, struct free_area *area,
int migratetype)
{
list_add(&page->lru, &area->free_list[migratetype]);
area->nr_free++;
}
/* Used for pages not on another list */
static inline void add_to_free_area_tail(struct page *page, struct free_area *area,
int migratetype)
{
list_add_tail(&page->lru, &area->free_list[migratetype]);
area->nr_free++;
}
/* Used for pages which are on another list */
static inline void move_to_free_area(struct page *page, struct free_area *area,
int migratetype)
{
list_move(&page->lru, &area->free_list[migratetype]);
}
static inline struct page *get_page_from_free_area(struct free_area *area, static inline struct page *get_page_from_free_area(struct free_area *area,
int migratetype) int migratetype)
{ {
...@@ -130,15 +107,6 @@ static inline struct page *get_page_from_free_area(struct free_area *area, ...@@ -130,15 +107,6 @@ static inline struct page *get_page_from_free_area(struct free_area *area,
struct page, lru); struct page, lru);
} }
static inline void del_page_from_free_area(struct page *page,
struct free_area *area)
{
list_del(&page->lru);
__ClearPageBuddy(page);
set_page_private(page, 0);
area->nr_free--;
}
static inline bool free_area_empty(struct free_area *area, int migratetype) static inline bool free_area_empty(struct free_area *area, int migratetype)
{ {
return list_empty(&area->free_list[migratetype]); return list_empty(&area->free_list[migratetype]);
......
...@@ -864,6 +864,44 @@ compaction_capture(struct capture_control *capc, struct page *page, ...@@ -864,6 +864,44 @@ compaction_capture(struct capture_control *capc, struct page *page,
} }
#endif /* CONFIG_COMPACTION */ #endif /* CONFIG_COMPACTION */
/* Used for pages not on another list */
static inline void add_to_free_list(struct page *page, struct zone *zone,
unsigned int order, int migratetype)
{
struct free_area *area = &zone->free_area[order];
list_add(&page->lru, &area->free_list[migratetype]);
area->nr_free++;
}
/* Used for pages not on another list */
static inline void add_to_free_list_tail(struct page *page, struct zone *zone,
unsigned int order, int migratetype)
{
struct free_area *area = &zone->free_area[order];
list_add_tail(&page->lru, &area->free_list[migratetype]);
area->nr_free++;
}
/* Used for pages which are on another list */
static inline void move_to_free_list(struct page *page, struct zone *zone,
unsigned int order, int migratetype)
{
struct free_area *area = &zone->free_area[order];
list_move(&page->lru, &area->free_list[migratetype]);
}
static inline void del_page_from_free_list(struct page *page, struct zone *zone,
unsigned int order)
{
list_del(&page->lru);
__ClearPageBuddy(page);
set_page_private(page, 0);
zone->free_area[order].nr_free--;
}
/* /*
* If this is not the largest possible page, check if the buddy * If this is not the largest possible page, check if the buddy
* of the next-highest order is free. If it is, it's possible * of the next-highest order is free. If it is, it's possible
...@@ -926,7 +964,6 @@ static inline void __free_one_page(struct page *page, ...@@ -926,7 +964,6 @@ static inline void __free_one_page(struct page *page,
struct capture_control *capc = task_capc(zone); struct capture_control *capc = task_capc(zone);
unsigned long uninitialized_var(buddy_pfn); unsigned long uninitialized_var(buddy_pfn);
unsigned long combined_pfn; unsigned long combined_pfn;
struct free_area *area;
unsigned int max_order; unsigned int max_order;
struct page *buddy; struct page *buddy;
bool to_tail; bool to_tail;
...@@ -964,7 +1001,7 @@ static inline void __free_one_page(struct page *page, ...@@ -964,7 +1001,7 @@ static inline void __free_one_page(struct page *page,
if (page_is_guard(buddy)) if (page_is_guard(buddy))
clear_page_guard(zone, buddy, order, migratetype); clear_page_guard(zone, buddy, order, migratetype);
else else
del_page_from_free_area(buddy, &zone->free_area[order]); del_page_from_free_list(buddy, zone, order);
combined_pfn = buddy_pfn & pfn; combined_pfn = buddy_pfn & pfn;
page = page + (combined_pfn - pfn); page = page + (combined_pfn - pfn);
pfn = combined_pfn; pfn = combined_pfn;
...@@ -998,16 +1035,15 @@ static inline void __free_one_page(struct page *page, ...@@ -998,16 +1035,15 @@ static inline void __free_one_page(struct page *page,
done_merging: done_merging:
set_page_order(page, order); set_page_order(page, order);
area = &zone->free_area[order];
if (is_shuffle_order(order)) if (is_shuffle_order(order))
to_tail = shuffle_pick_tail(); to_tail = shuffle_pick_tail();
else else
to_tail = buddy_merge_likely(pfn, buddy_pfn, page, order); to_tail = buddy_merge_likely(pfn, buddy_pfn, page, order);
if (to_tail) if (to_tail)
add_to_free_area_tail(page, area, migratetype); add_to_free_list_tail(page, zone, order, migratetype);
else else
add_to_free_area(page, area, migratetype); add_to_free_list(page, zone, order, migratetype);
} }
/* /*
...@@ -2021,13 +2057,11 @@ void __init init_cma_reserved_pageblock(struct page *page) ...@@ -2021,13 +2057,11 @@ void __init init_cma_reserved_pageblock(struct page *page)
* -- nyc * -- nyc
*/ */
static inline void expand(struct zone *zone, struct page *page, static inline void expand(struct zone *zone, struct page *page,
int low, int high, struct free_area *area, int low, int high, int migratetype)
int migratetype)
{ {
unsigned long size = 1 << high; unsigned long size = 1 << high;
while (high > low) { while (high > low) {
area--;
high--; high--;
size >>= 1; size >>= 1;
VM_BUG_ON_PAGE(bad_range(zone, &page[size]), &page[size]); VM_BUG_ON_PAGE(bad_range(zone, &page[size]), &page[size]);
...@@ -2041,7 +2075,7 @@ static inline void expand(struct zone *zone, struct page *page, ...@@ -2041,7 +2075,7 @@ static inline void expand(struct zone *zone, struct page *page,
if (set_page_guard(zone, &page[size], high, migratetype)) if (set_page_guard(zone, &page[size], high, migratetype))
continue; continue;
add_to_free_area(&page[size], area, migratetype); add_to_free_list(&page[size], zone, high, migratetype);
set_page_order(&page[size], high); set_page_order(&page[size], high);
} }
} }
...@@ -2199,8 +2233,8 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, ...@@ -2199,8 +2233,8 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order,
page = get_page_from_free_area(area, migratetype); page = get_page_from_free_area(area, migratetype);
if (!page) if (!page)
continue; continue;
del_page_from_free_area(page, area); del_page_from_free_list(page, zone, current_order);
expand(zone, page, order, current_order, area, migratetype); expand(zone, page, order, current_order, migratetype);
set_pcppage_migratetype(page, migratetype); set_pcppage_migratetype(page, migratetype);
return page; return page;
} }
...@@ -2274,7 +2308,7 @@ static int move_freepages(struct zone *zone, ...@@ -2274,7 +2308,7 @@ static int move_freepages(struct zone *zone,
VM_BUG_ON_PAGE(page_zone(page) != zone, page); VM_BUG_ON_PAGE(page_zone(page) != zone, page);
order = page_order(page); order = page_order(page);
move_to_free_area(page, &zone->free_area[order], migratetype); move_to_free_list(page, zone, order, migratetype);
page += 1 << order; page += 1 << order;
pages_moved += 1 << order; pages_moved += 1 << order;
} }
...@@ -2390,7 +2424,6 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, ...@@ -2390,7 +2424,6 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,
unsigned int alloc_flags, int start_type, bool whole_block) unsigned int alloc_flags, int start_type, bool whole_block)
{ {
unsigned int current_order = page_order(page); unsigned int current_order = page_order(page);
struct free_area *area;
int free_pages, movable_pages, alike_pages; int free_pages, movable_pages, alike_pages;
int old_block_type; int old_block_type;
...@@ -2461,8 +2494,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page, ...@@ -2461,8 +2494,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,
return; return;
single_page: single_page:
area = &zone->free_area[current_order]; move_to_free_list(page, zone, current_order, start_type);
move_to_free_area(page, area, start_type);
} }
/* /*
...@@ -3133,7 +3165,6 @@ EXPORT_SYMBOL_GPL(split_page); ...@@ -3133,7 +3165,6 @@ EXPORT_SYMBOL_GPL(split_page);
int __isolate_free_page(struct page *page, unsigned int order) int __isolate_free_page(struct page *page, unsigned int order)
{ {
struct free_area *area = &page_zone(page)->free_area[order];
unsigned long watermark; unsigned long watermark;
struct zone *zone; struct zone *zone;
int mt; int mt;
...@@ -3159,7 +3190,7 @@ int __isolate_free_page(struct page *page, unsigned int order) ...@@ -3159,7 +3190,7 @@ int __isolate_free_page(struct page *page, unsigned int order)
/* Remove page from free list */ /* Remove page from free list */
del_page_from_free_area(page, area); del_page_from_free_list(page, zone, order);
/* /*
* Set the pageblock if the isolated page is at least half of a * Set the pageblock if the isolated page is at least half of a
...@@ -8726,7 +8757,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn) ...@@ -8726,7 +8757,7 @@ __offline_isolated_pages(unsigned long start_pfn, unsigned long end_pfn)
BUG_ON(!PageBuddy(page)); BUG_ON(!PageBuddy(page));
order = page_order(page); order = page_order(page);
offlined_pages += 1 << order; offlined_pages += 1 << order;
del_page_from_free_area(page, &zone->free_area[order]); del_page_from_free_list(page, zone, order);
pfn += (1 << order); pfn += (1 << order);
} }
spin_unlock_irqrestore(&zone->lock, flags); spin_unlock_irqrestore(&zone->lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment