* [PATCH v2 0/5] Cleanups and fixup for page_alloc
@ 2021-09-02 12:12 Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 1/5] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() Miaohe Lin
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
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 both
alloc_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(-)
--
2.23.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/5] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order()
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
@ 2021-09-02 12:12 ` Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 2/5] mm/page_alloc.c: simplify the code by using macro K() Miaohe Lin
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
It's meaningless to VM_BUG_ON() order != pageblock_order just after
setting order to pageblock_order. Remove it.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
mm/page_alloc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 91edb930b8ab..dbb3338d9287 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/5] mm/page_alloc.c: simplify the code by using macro K()
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 1/5] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() Miaohe Lin
@ 2021-09-02 12:12 ` Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk() Miaohe Lin
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
Use helper macro K() to convert the pages to the corresponding size.
Minor readability improvement.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
mm/page_alloc.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index dbb3338d9287..d3983244f56f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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
);
}
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk()
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 1/5] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 2/5] mm/page_alloc.c: simplify the code by using macro K() Miaohe Lin
@ 2021-09-02 12:12 ` Miaohe Lin
2021-09-02 14:03 ` Mel Gorman
2021-09-02 12:12 ` [PATCH v2 4/5] mm/page_alloc.c: use helper function zone_spans_pfn() Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid] Miaohe Lin
4 siblings, 1 reply; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
The 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.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/page_alloc.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index d3983244f56f..f7fcbac2d091 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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)
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/5] mm/page_alloc.c: use helper function zone_spans_pfn()
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
` (2 preceding siblings ...)
2021-09-02 12:12 ` [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk() Miaohe Lin
@ 2021-09-02 12:12 ` Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid] Miaohe Lin
4 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
Use helper function zone_spans_pfn() to check whether pfn is within a
zone to simplify the code slightly.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Reviewed-by: David Hildenbrand <david@redhat.com>
---
mm/page_alloc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index f7fcbac2d091..9c09dcb24149 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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);
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
` (3 preceding siblings ...)
2021-09-02 12:12 ` [PATCH v2 4/5] mm/page_alloc.c: use helper function zone_spans_pfn() Miaohe Lin
@ 2021-09-02 12:12 ` Miaohe Lin
2021-09-02 12:16 ` David Hildenbrand
4 siblings, 1 reply; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:12 UTC (permalink / raw)
To: akpm
Cc: vbabka, sfr, peterz, mgorman, david, linux-mm, linux-kernel, linmiaohe
Don'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.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
mm/page_alloc.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9c09dcb24149..e1d0e27d005a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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)
--
2.23.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
2021-09-02 12:12 ` [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid] Miaohe Lin
@ 2021-09-02 12:16 ` David Hildenbrand
2021-09-02 12:45 ` Miaohe Lin
0 siblings, 1 reply; 9+ messages in thread
From: David Hildenbrand @ 2021-09-02 12:16 UTC (permalink / raw)
To: Miaohe Lin, akpm; +Cc: vbabka, sfr, peterz, mgorman, linux-mm, linux-kernel
On 02.09.21 14:12, Miaohe Lin wrote:
> Don'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.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
> mm/page_alloc.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 9c09dcb24149..e1d0e27d005a 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -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)
>
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.
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid]
2021-09-02 12:16 ` David Hildenbrand
@ 2021-09-02 12:45 ` Miaohe Lin
0 siblings, 0 replies; 9+ messages in thread
From: Miaohe Lin @ 2021-09-02 12:45 UTC (permalink / raw)
To: David Hildenbrand, akpm
Cc: vbabka, sfr, peterz, mgorman, linux-mm, linux-kernel
On 2021/9/2 20:16, David Hildenbrand wrote:
> On 02.09.21 14:12, Miaohe Lin wrote:
>> Don'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.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>> mm/page_alloc.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 9c09dcb24149..e1d0e27d005a 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -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)
>>
>
> 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.
>
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.
> Reviewed-by: David Hildenbrand <david@redhat.com>
>
Many thanks for your review and reply.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk()
2021-09-02 12:12 ` [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk() Miaohe Lin
@ 2021-09-02 14:03 ` Mel Gorman
0 siblings, 0 replies; 9+ messages in thread
From: Mel Gorman @ 2021-09-02 14:03 UTC (permalink / raw)
To: Miaohe Lin; +Cc: akpm, vbabka, sfr, peterz, david, linux-mm, linux-kernel
On Thu, Sep 02, 2021 at 08:12:40PM +0800, Miaohe Lin wrote:
> The 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.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
--
Mel Gorman
SUSE Labs
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-09-02 14:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 12:12 [PATCH v2 0/5] Cleanups and fixup for page_alloc Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 1/5] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 2/5] mm/page_alloc.c: simplify the code by using macro K() Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 3/5] mm/page_alloc.c: fix obsolete comment in free_pcppages_bulk() Miaohe Lin
2021-09-02 14:03 ` Mel Gorman
2021-09-02 12:12 ` [PATCH v2 4/5] mm/page_alloc.c: use helper function zone_spans_pfn() Miaohe Lin
2021-09-02 12:12 ` [PATCH v2 5/5] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact[_nid] Miaohe Lin
2021-09-02 12:16 ` David Hildenbrand
2021-09-02 12:45 ` Miaohe Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).