From 556d74a39f7ddb60d998a161ca49bdd463d16a2a Mon Sep 17 00:00:00 2001 From: Baolin Wang Date: Sat, 11 May 2024 21:11:50 +0800 Subject: [PATCH 1/2] mm: page_alloc: use the correct THP order for THP PCP next inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9OCYO CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6303d1c553c8d758f068de70a41668622b7a917c -------------------------------- Commit 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") extends the PCP allocator to store THP pages, and it determines whether to cache THP pages in PCP by comparing with pageblock_order. But the pageblock_order is not always equal to THP order. It might also be MAX_PAGE_ORDER, which could prevent PCP from caching THP pages. Therefore, using HPAGE_PMD_ORDER instead to determine the need for caching THP for PCP will fix this issue Link: https://lkml.kernel.org/r/a25c9e14cd03907d5978b60546a69e6aa3fc2a7d.1712151833.git.baolin.wang@linux.alibaba.com Fixes: 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") Signed-off-by: Baolin Wang Acked-by: Vlastimil Babka Cc: Mel Gorman Reviewed-by: Barry Song Signed-off-by: Andrew Morton Signed-off-by: Liu Shixin --- mm/page_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e92509d4a5d6..b4baf8e1fdab 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -529,7 +529,7 @@ static inline unsigned int order_to_pindex(int migratetype, int order) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (order > PAGE_ALLOC_COSTLY_ORDER) { - VM_BUG_ON(order != pageblock_order); + VM_BUG_ON(order != HPAGE_PMD_ORDER); return NR_LOWORDER_PCP_LISTS; } #else @@ -545,7 +545,7 @@ static inline int pindex_to_order(unsigned int pindex) #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (pindex == NR_LOWORDER_PCP_LISTS) - order = pageblock_order; + order = HPAGE_PMD_ORDER; #else VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); #endif @@ -558,7 +558,7 @@ static inline bool pcp_allowed_order(unsigned int order) if (order <= PAGE_ALLOC_COSTLY_ORDER) return true; #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (order == pageblock_order) + if (order == HPAGE_PMD_ORDER) return true; #endif return false; -- Gitee From ab31417533418b2c76eea1528769687a5a02d082 Mon Sep 17 00:00:00 2001 From: Liu Shixin Date: Sat, 11 May 2024 21:11:51 +0800 Subject: [PATCH 2/2] mm: prepare more high-order pages to be stored on the per-cpu lists hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I9OCYO -------------------------------- Both the file pages and anonymous pages support large folio, high-order pages except HPAGE_PMD_ORDER(PMD_SHIFT - PAGE_SHIFT) will be allocated frequently which will increase the zone lock contention, allow high-order pages on pcp lists could alleviate the big zone lock contention. Similar with lower order pages(order <= 3), allows one more high-order pages to be stored on the per-cpu lists. But as commit 44042b449872 ("mm/page_alloc: allow high-order pages to be stored on the per-cpu lists") pointed, it may not win in all the scenes, so this don't allow higher-order pages to be added to PCP list, it will add a control to enable or disable it in future. The struct per_cpu_pages increases in size from 256(4 cache lines) to 320 bytes (5 cache lines) on arm64 with defconfig. Signed-off-by: Kefeng Wang Signed-off-by: Liu Shixin --- include/linux/mmzone.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index a394cbe31c59..bcf4fd4ab824 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -684,10 +684,12 @@ enum zone_watermarks { */ #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define NR_PCP_THP 1 +#define NR_PCP_ORDERS (PAGE_ALLOC_COSTLY_ORDER + 2) #else #define NR_PCP_THP 0 +#define NR_PCP_ORDERS (PAGE_ALLOC_COSTLY_ORDER + 1) #endif -#define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1)) +#define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * NR_PCP_ORDERS) #define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP) #define min_wmark_pages(z) (z->_watermark[WMARK_MIN] + z->watermark_boost) -- Gitee