Cleanups and fixup for page_alloc
Subsystems (2)
v2 cover Cleanups and fixup for page_alloc
Hi all,
This series contains cleanups to remove meaningless VM_BUG_ON(), use helpers to simplify the code and remove obsolete comment. Also we avoid allocating highmem pages via alloc_pages_exact[_nid]. More details can be found in the respective changelogs. Thanks!
v1->v2:
collect Reviewed-by and Acked-by tag
preserve valid comments for free_pcppages_bulk
send patch "mm/page_alloc.c: avoid accessing uninitialized pcp page
migratetype" separately.
s/__GFP_COMP/(__GFP_COMP|__GFP_HIGHMEM)/g throughout bothalloc_pages_exact() and alloc_pages_exact_nid()
Miaohe Lin (5):
mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() mm/page_alloc.c: simplify the code by using macro K() mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk() mm/page_alloc.c: use helper function zone_spans_pfn() mm/page_alloc.c: avoid allocating highmem pages via
alloc_pages_exact[_nid]
mm/page_alloc.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-)
Signature · 1 line
2.23.0
PATCH v2 1/5 mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order()
It's meaningless to VM_BUG_ON() order != pageblock_order just after setting order to pageblock_order. Remove it.
--- mm/page_alloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
mm/page_alloc.c +1 -3
@@ -677,10 +677,8 @@ static inline int pindex_to_order(unsigned int pindex)int order = pindex /MIGRATE_PCPTYPES ;#ifdef CONFIG_TRANSPARENT_HUGEPAGE -if (order >PAGE_ALLOC_COSTLY_ORDER ) { +if (order >PAGE_ALLOC_COSTLY_ORDER ) order = pageblock_order; -VM_BUG_ON (order != pageblock_order); - }#else VM_BUG_ON (order >PAGE_ALLOC_COSTLY_ORDER );#endif
Signature · 1 line
2.23.0
PATCH v2 2/5 mm/page_alloc.c: simplify the code by using macro K()
In reply to Miaohe LinUse helper macro K() to convert the pages to the corresponding size. Minor readability improvement.
--- mm/page_alloc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +5 -7
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char }if (pages && s) -pr_info ("Freeing %s memory: %ldK\n" , - s, pages << (PAGE_SHIFT -10 )); +pr_info ("Freeing %s memory: %ldK\n" , s,K (pages));return pages; }
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)", %luK highmem" #endif")\n" , -nr_free_pages () << (PAGE_SHIFT -10 ), - physpages << (PAGE_SHIFT -10 ), +K (nr_free_pages ()),K (physpages), codesize >>10 , datasize >>10 , rosize >>10 , (init_data_size + init_code_size) >>10 , bss_size >>10 , - (physpages -totalram_pages () - totalcma_pages) << (PAGE_SHIFT -10 ), - totalcma_pages << (PAGE_SHIFT -10 ) +K (physpages -totalram_pages () - totalcma_pages), +K (totalcma_pages) #ifdef CONFIG_HIGHMEM - ,totalhigh_pages () << (PAGE_SHIFT -10 ) + ,K (totalhigh_pages ()) #endif ); }
Signature · 1 line
2.23.0
PATCH v2 3/5 mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk()
In reply to Miaohe LinThe second two paragraphs about "all pages pinned" and pages_scanned is obsolete. And There are PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP orders in pcp. So the same order assumption is not held now.
--- mm/page_alloc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
mm/page_alloc.c +1 -7
@@ -1426,14 +1426,8 @@ static inline void prefetch_buddy(struct page *page)/* * Frees a number of pages from the PCP lists -* Assumes all pages on list are in same zone, and of same order. +* Assumes all pages on list are in same zone. * count is the number of pages to free. -* -* If the zone was previously in an "all pages pinned" state then look to -* see if this freeing clears that state. -* -* And clear the zone's pages_scanned counter, to hold off the "all pages are -* pinned" detection logic. */ static void free_pcppages_bulk (struct zone *zone,int count,struct per_cpu_pages *pcp)
Signature · 1 line
2.23.0
Re: [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk()
Quoted 5 lines · Miaohe Lin
The second two paragraphs about "all pages pinned" and
pages_scannedis obsolete. And There arePAGE_ALLOC_COSTLY_ORDER+ 1 +NR_PCP_THPorders in pcp. So the same order assumption is not held now.Signed-off-by Miaohe Lin <[email protected]>
Signature · 2 lines
Mel Gorman SUSE Labs
PATCH v2 4/5 mm/page_alloc.c: use helper function zone_spans_pfn()
In reply to Miaohe LinUse helper function zone_spans_pfn() to check whether pfn is within a zone to simplify the code slightly.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -1581,7 +1581,7 @@ static void __meminit init_reserved_page(unsigned long pfn)for (zid =0 ; zid <MAX_NR_ZONES ; zid++) {struct zone *zone = &pgdat->node_zones[zid]; -if (pfn >= zone->zone_start_pfn && pfn <zone_end_pfn (zone)) +if (zone_spans_pfn (zone, pfn))break ; }__init_single_page (pfn_to_page (pfn), pfn, zid, nid);
Signature · 1 line
2.23.0
PATCH v2 5/5 mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
In reply to Miaohe LinDon't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the callers do not specify __GFP_HIGHMEM now.
--- mm/page_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/page_alloc.c +4 -4
@@ -5614,8 +5614,8 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned int order =get_order (size);unsigned long addr; -if (WARN_ON_ONCE (gfp_mask & __GFP_COMP)) - gfp_mask &= ~__GFP_COMP; +if (WARN_ON_ONCE (gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); addr =__get_free_pages (gfp_mask, order);return make_alloc_exact (addr, order, size);
@@ -5639,8 +5639,8 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask)unsigned int order =get_order (size);struct page *p; -if (WARN_ON_ONCE (gfp_mask & __GFP_COMP)) - gfp_mask &= ~__GFP_COMP; +if (WARN_ON_ONCE (gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); p =alloc_pages_node (nid, gfp_mask, order);if (!p)
Signature · 1 line
2.23.0
Re: [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
Quoted 27 lines · Miaohe Lin
Don't use with
__GFP_HIGHMEMbecausepage_address()cannot represent highmem pages withoutkmap(). Newly allocated pages would leak aspage_address()will return NULL for highmem pages here. But It works now because the callers do not specify__GFP_HIGHMEMnow.Signed-off-by Miaohe Lin <[email protected]>--- mm/page_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)mm/page_alloc.c +2
-2@@ -5614,8 +5614,8 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned int order =get_order (size);unsigned long addr; -if (WARN_ON_ONCE (gfp_mask & __GFP_COMP)) - gfp_mask &= ~__GFP_COMP; +if (WARN_ON_ONCE (gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); addr =__get_free_pages (gfp_mask, order);return make_alloc_exact (addr, order, size);
mm/page_alloc.c void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask) · line 5646
Quoted 10 lines
mm/page_alloc.c +2
-2@@ -5639,8 +5639,8 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask)unsigned int order =get_order (size);struct page *p; -if (WARN_ON_ONCE (gfp_mask & __GFP_COMP)) - gfp_mask &= ~__GFP_COMP; +if (WARN_ON_ONCE (gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); p =alloc_pages_node (nid, gfp_mask, order);if (!p)
Ideally we would convert this WARN_ON_ONCE() to pr_warn_once(), but I guess this really never ever happens on a production system and would get caught early while testing.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
Quoted 28 lines · David Hildenbrand
Quoted 27 lines · Miaohe Lin
Don't use with
__GFP_HIGHMEMbecausepage_address()cannot represent highmem pages withoutkmap(). Newly allocated pages would leak aspage_address()will return NULL for highmem pages here. But It works now because the callers do not specify__GFP_HIGHMEMnow.Signed-off-by Miaohe Lin <[email protected]>---
mm/page_alloc.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)mm/page_alloc.c +2
-1@@ -5614,8 +5614,8 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask) unsigned int order = get_order(size); unsigned long addr; - if (WARN_ON_ONCE(gfp_mask & __GFP_COMP)) - gfp_mask &= ~__GFP_COMP; + if (WARN_ON_ONCE(gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); addr = __get_free_pages(gfp_mask, order); return make_alloc_exact(addr, order, size);@@ -5639,8 +5639,8 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask) unsigned int order = get_order(size); struct page *p; - if (WARN_ON_ONCE(gfp_mask & __GFP_COMP))
Quoted 9 lines
mm/page_alloc.c void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask)
Quoted 6 lines
mm/page_alloc.c +2
-1- gfp_mask &= ~__GFP_COMP; + if (WARN_ON_ONCE(gfp_mask & (__GFP_COMP | __GFP_HIGHMEM))) + gfp_mask &= ~(__GFP_COMP | __GFP_HIGHMEM); p = alloc_pages_node(nid, gfp_mask, order); if (!p)Ideally we would convert this
WARN_ON_ONCE()topr_warn_once(), but I guess this really never ever happens on a production system and would get caught early while testing.
This patch is mainly intended to make it clear that we simply can't call alloc_pages_exact[_nid] with GFP_HIGHMEM. So this warning would never ever happens.
Quoted 2 lines
Reviewed-by David Hildenbrand <[email protected]>
Many thanks for your review and reply.