[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <300be96e-6029-42eb-b284-e659d815ee8a@lucifer.local>
Date: Wed, 20 Aug 2025 11:38:50 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Nico Pache <npache@...hat.com>
Cc: linux-mm@...ck.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
david@...hat.com, ziy@...dia.com, baolin.wang@...ux.alibaba.com,
Liam.Howlett@...cle.com, ryan.roberts@....com, dev.jain@....com,
corbet@....net, rostedt@...dmis.org, mhiramat@...nel.org,
mathieu.desnoyers@...icios.com, akpm@...ux-foundation.org,
baohua@...nel.org, willy@...radead.org, peterx@...hat.com,
wangkefeng.wang@...wei.com, usamaarif642@...il.com,
sunnanyong@...wei.com, vishal.moola@...il.com,
thomas.hellstrom@...ux.intel.com, yang@...amperecomputing.com,
kirill.shutemov@...ux.intel.com, aarcange@...hat.com,
raquini@...hat.com, anshuman.khandual@....com, catalin.marinas@....com,
tiwai@...e.de, will@...nel.org, dave.hansen@...ux.intel.com,
jack@...e.cz, cl@...two.org, jglisse@...gle.com, surenb@...gle.com,
zokeefe@...gle.com, hannes@...xchg.org, rientjes@...gle.com,
mhocko@...e.com, rdunlap@...radead.org, hughd@...gle.com
Subject: Re: [PATCH v10 08/13] khugepaged: avoid unnecessary mTHP collapse
attempts
On Tue, Aug 19, 2025 at 07:42:00AM -0600, Nico Pache wrote:
> There are cases where, if an attempted collapse fails, all subsequent
> orders are guaranteed to also fail. Avoid these collapse attempts by
> bailing out early.
>
> Signed-off-by: Nico Pache <npache@...hat.com>
> ---
> mm/khugepaged.c | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 6a4cf7e4a7cc..7d9b5100bea1 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1389,10 +1389,39 @@ static int collapse_scan_bitmap(struct mm_struct *mm, unsigned long address,
> ret = collapse_huge_page(mm, address, referenced, unmapped,
> cc, mmap_locked, order,
> offset * KHUGEPAGED_MIN_MTHP_NR);
> - if (ret == SCAN_SUCCEED) {
> +
> + /*
> + * Analyze failure reason to determine next action:
> + * - goto next_order: try smaller orders in same region
> + * - continue: try other regions at same order
> + * - break: stop all attempts (system-wide failure)
> + */
> + switch (ret) {
> + /* Cases were we should continue to the next region */
> + case SCAN_SUCCEED:
> collapsed += (1 << order);
Yeah as bot noticed (and clang locally)
This needs a break or fallthrough.
> + case SCAN_PAGE_RO:
> + case SCAN_PTE_MAPPED_HUGEPAGE:
> continue;
> + /* Cases were lower orders might still succeed */
> + case SCAN_LACK_REFERENCED_PAGE:
> + case SCAN_EXCEED_NONE_PTE:
> + case SCAN_EXCEED_SWAP_PTE:
> + case SCAN_EXCEED_SHARED_PTE:
> + case SCAN_PAGE_LOCK:
> + case SCAN_PAGE_COUNT:
> + case SCAN_PAGE_LRU:
> + case SCAN_PAGE_NULL:
> + case SCAN_DEL_PAGE_LRU:
> + case SCAN_PTE_NON_PRESENT:
> + case SCAN_PTE_UFFD_WP:
> + case SCAN_ALLOC_HUGE_PAGE_FAIL:
> + goto next_order;
> + /* All other cases should stop collapse attempts */
> + default:
> + break;
Wouldn't it be better to not have this so the compiler asserts that you
have all cases listed here?
> }
> + break;
> }
>
> next_order:
> --
> 2.50.1
>
Powered by blists - more mailing lists