Re: [RFC PATCH 03/57] mm/collapse: add collapse.h for the shared collapse state

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kernel.vger.linux-trace-kernel,org.kvack.linux-mm
Message-ID <aoQ47NMwUddi8h1M@lucifer>
On Sun, Aug 16, 2026 at 11:45:15PM +0100, Kiryl Shutsemau wrote:
> From: "Kiryl Shutsemau (Meta)" <[email protected]>
>
> Preparation for building the new collapse engine in its own file.  The
> engine and khugepaged.c need to agree on what a collapse result is and
> what state a scan carries.
>
> Move enum scan_result and struct collapse_control into a new
> mm/collapse.h.
>
> No functional change intended.
>
> Assisted-by: Claude-Code:claude-opus-5
> Signed-off-by: Kiryl Shutsemau (Meta) <[email protected]>

Any change that introduces a new file should in the same change update
MAINTAINERS (in the THP section to which this belongs :)

> ---
>  mm/collapse.h   | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
>  mm/khugepaged.c | 52 +-----------------------------------------
>  2 files changed, 61 insertions(+), 51 deletions(-)
>  create mode 100644 mm/collapse.h
>
> diff --git a/mm/collapse.h b/mm/collapse.h
> new file mode 100644
> index 000000000000..26dbac7beddd
> --- /dev/null
> +++ b/mm/collapse.h
> @@ -0,0 +1,60 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __MM_COLLAPSE_H
> +#define __MM_COLLAPSE_H
> +
> +#include <linux/nodemask.h>
> +#include <linux/pgtable.h>
> +#include <linux/types.h>
> +
> +enum scan_result {
> +	SCAN_FAIL,
> +	SCAN_SUCCEED,
> +	SCAN_NO_PTE_TABLE,
> +	SCAN_PMD_MAPPED,
> +	SCAN_EXCEED_NONE_PTE,
> +	SCAN_EXCEED_SWAP_PTE,
> +	SCAN_EXCEED_SHARED_PTE,
> +	SCAN_PTE_NON_PRESENT,
> +	SCAN_PTE_UFFD,
> +	SCAN_PTE_MAPPED_HUGEPAGE,
> +	SCAN_LACK_REFERENCED_PAGE,
> +	SCAN_PAGE_NULL,
> +	SCAN_SCAN_ABORT,
> +	SCAN_PAGE_COUNT,
> +	SCAN_PAGE_LRU,
> +	SCAN_PAGE_LOCK,
> +	SCAN_PAGE_ANON,
> +	SCAN_PAGE_LAZYFREE,
> +	SCAN_PAGE_COMPOUND,
> +	SCAN_ANY_PROCESS,
> +	SCAN_VMA_NULL,
> +	SCAN_VMA_CHECK,
> +	SCAN_ADDRESS_RANGE,
> +	SCAN_DEL_PAGE_LRU,
> +	SCAN_ALLOC_HUGE_PAGE_FAIL,
> +	SCAN_CGROUP_CHARGE_FAIL,
> +	SCAN_TRUNCATED,
> +	SCAN_PAGE_HAS_PRIVATE,
> +	SCAN_STORE_FAILED,
> +	SCAN_COPY_MC,
> +	SCAN_PAGE_FILLED,
> +	SCAN_PAGE_DIRTY_OR_WRITEBACK,
> +};
> +
> +struct collapse_control {
> +	bool is_khugepaged;
> +
> +	/* Num pages scanned per node */
> +	u32 node_load[MAX_NUMNODES];
> +
> +	/* Num pages scanned (see khugepaged_pages_to_scan) */
> +	unsigned int progress;
> +
> +	/* nodemask for allocation fallback */
> +	nodemask_t alloc_nmask;
> +
> +	/* Each bit represents a single occupied (!none/zero) page. */
> +	DECLARE_BITMAP(mthp_present_ptes, MAX_PTRS_PER_PTE);
> +};
> +
> +#endif	/* __MM_COLLAPSE_H */
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 5f7126cf42f5..804b1d35f52a 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -26,45 +26,11 @@
>  #include <linux/cleanup.h>
>
>  #include <asm/tlb.h>
> +#include "collapse.h"
>  #include "internal.h"
>  #include "page_alloc.h"
>  #include "mm_slot.h"
>
> -enum scan_result {
> -	SCAN_FAIL,
> -	SCAN_SUCCEED,
> -	SCAN_NO_PTE_TABLE,
> -	SCAN_PMD_MAPPED,
> -	SCAN_EXCEED_NONE_PTE,
> -	SCAN_EXCEED_SWAP_PTE,
> -	SCAN_EXCEED_SHARED_PTE,
> -	SCAN_PTE_NON_PRESENT,
> -	SCAN_PTE_UFFD,
> -	SCAN_PTE_MAPPED_HUGEPAGE,
> -	SCAN_LACK_REFERENCED_PAGE,
> -	SCAN_PAGE_NULL,
> -	SCAN_SCAN_ABORT,
> -	SCAN_PAGE_COUNT,
> -	SCAN_PAGE_LRU,
> -	SCAN_PAGE_LOCK,
> -	SCAN_PAGE_ANON,
> -	SCAN_PAGE_LAZYFREE,
> -	SCAN_PAGE_COMPOUND,
> -	SCAN_ANY_PROCESS,
> -	SCAN_VMA_NULL,
> -	SCAN_VMA_CHECK,
> -	SCAN_ADDRESS_RANGE,
> -	SCAN_DEL_PAGE_LRU,
> -	SCAN_ALLOC_HUGE_PAGE_FAIL,
> -	SCAN_CGROUP_CHARGE_FAIL,
> -	SCAN_TRUNCATED,
> -	SCAN_PAGE_HAS_PRIVATE,
> -	SCAN_STORE_FAILED,
> -	SCAN_COPY_MC,
> -	SCAN_PAGE_FILLED,
> -	SCAN_PAGE_DIRTY_OR_WRITEBACK,
> -};
> -
>  #define CREATE_TRACE_POINTS
>  #include <trace/events/huge_memory.h>
>
> @@ -103,22 +69,6 @@ static struct kmem_cache *mm_slot_cache __ro_after_init;
>
>  #define KHUGEPAGED_MIN_MTHP_ORDER	2
>
> -struct collapse_control {
> -	bool is_khugepaged;
> -
> -	/* Num pages scanned per node */
> -	u32 node_load[MAX_NUMNODES];
> -
> -	/* Num pages scanned (see khugepaged_pages_to_scan) */
> -	unsigned int progress;
> -
> -	/* nodemask for allocation fallback */
> -	nodemask_t alloc_nmask;
> -
> -	/* Each bit represents a single occupied (!none/zero) page. */
> -	DECLARE_BITMAP(mthp_present_ptes, MAX_PTRS_PER_PTE);
> -};
> -
>  /**
>   * struct khugepaged_scan - cursor for scanning
>   * @mm_head: the head of the mm list to scan
> --
> 2.54.0
>

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.