Thread (119 messages) flat view 119 messages, 9 authors, 8d ago
COOLING8d

[RFC PATCH 41/57] mm/collapse: give collapse its own trace header

From: Kiryl Shutsemau <hidden>
Date: 2026-08-16 22:47:35
Also in: bpf, linux-kselftest, linux-mm, lkml
Subsystem: bpf [general] (safe dynamic programs and tools), kernel selftest framework, memory management, memory management - misc, memory management - thp (transparent huge page), the rest, tracing · Maintainers: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Shuah Khan, Shuah Khan, Andrew Morton, David Hildenbrand, Linus Torvalds, Steven Rostedt, Masami Hiramatsu

From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>

Every event in include/trace/events/huge_memory.h is a collapse event, and
all but one is emitted from mm/collapse.c.  The header is named for
huge_memory.c, which emits none of them, and the tracepoints are built by
khugepaged.c, which emits one.

Rename it to trace/events/collapse.h, with TRACE_SYSTEM to match, and
build the tracepoints in collapse.c.

Two things follow.  The pass names a candidate event prints are needed
only where the tracepoints are built, so enum collapse_pass moves out of
mm/collapse.h into collapse.c.  And khugepaged.c becomes an ordinary
includer, for the one event it does emit.

The tracefs directory moves with the trace system: events/huge_memory
becomes events/collapse, so anything enabling those events by system name
has to follow.

khugepaged's own selftest does that, and is updated here.  So are the two
other in-tree references to the old name: the MAINTAINERS entry for the
header, and the group raw_tp_null_args[] keeps its collapse entries under.

Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
---
 MAINTAINERS                                     |  2 +-
 .../trace/events/{huge_memory.h => collapse.h}  |  8 ++++----
 kernel/bpf/btf.c                                |  6 +++---
 mm/collapse.c                                   | 17 ++++++++++++++++-
 mm/collapse.h                                   | 13 -------------
 mm/khugepaged.c                                 |  3 +--
 .../selftests/mm/khugepaged_sync_check.c        | 10 +++++-----
 tools/testing/selftests/mm/vm_util.c            |  2 +-
 8 files changed, 31 insertions(+), 30 deletions(-)
 rename include/trace/events/{huge_memory.h => collapse.h} (98%)
diff --git a/MAINTAINERS b/MAINTAINERS
index 0f513b42bc18..7c179b333e4e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17273,7 +17273,7 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-transparent-hugepage
 F:	Documentation/admin-guide/mm/transhuge.rst
 F:	include/linux/huge_mm.h
 F:	include/linux/khugepaged.h
-F:	include/trace/events/huge_memory.h
+F:	include/trace/events/collapse.h
 F:	mm/huge_memory.c
 F:	mm/khugepaged.c
 F:	mm/mm_slot.h
diff --git a/include/trace/events/huge_memory.h b/include/trace/events/collapse.h
similarity index 98%
rename from include/trace/events/huge_memory.h
rename to include/trace/events/collapse.h
index 6aabf4235648..a3af5d8cc9aa 100644
--- a/include/trace/events/huge_memory.h
+++ b/include/trace/events/collapse.h
@@ -1,9 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #undef TRACE_SYSTEM
-#define TRACE_SYSTEM huge_memory
+#define TRACE_SYSTEM collapse
 
-#if !defined(__HUGE_MEMORY_H) || defined(TRACE_HEADER_MULTI_READ)
-#define __HUGE_MEMORY_H
+#if !defined(_TRACE_COLLAPSE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_COLLAPSE_H
 
 #include  <linux/tracepoint.h>
 
@@ -282,5 +282,5 @@ TRACE_EVENT(mm_khugepaged_scan,
 		__entry->full_scan_finished)
 );
 
-#endif /* __HUGE_MEMORY_H */
+#endif /* _TRACE_COLLAPSE_H */
 #include <trace/define_trace.h>
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 22fc8f974be2..505bdbb534e4 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6683,6 +6683,9 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
 	{ "cachefiles_ondemand_cread", 0x1 },
 	{ "cachefiles_ondemand_fd_write", 0x1 },
 	{ "cachefiles_ondemand_fd_release", 0x1 },
+	/* collapse */
+	{ "mm_collapse_scan_file", 0x10 },
+	{ "mm_collapse_file", 0x10 },
 	/* ext4, from ext4__mballoc event class */
 	{ "ext4_mballoc_discard", 0x10 },
 	{ "ext4_mballoc_free", 0x10 },
@@ -6702,9 +6705,6 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
 	{ "time_out_leases", 0x10 },
 	/* host1x */
 	{ "host1x_cdma_push_gather", 0x10000 },
-	/* huge_memory */
-	{ "mm_collapse_scan_file", 0x10 },
-	{ "mm_collapse_file", 0x10 },
 	/* kmem */
 	{ "mm_page_alloc", 0x1 },
 	{ "mm_page_pcpu_drain", 0x1 },
diff --git a/mm/collapse.c b/mm/collapse.c
index 6c17c83a4e21..952e3f62d920 100644
--- a/mm/collapse.c
+++ b/mm/collapse.c
@@ -26,10 +26,25 @@
 #include <linux/vmstat.h>
 
 #include <asm/tlb.h>
-#include <trace/events/huge_memory.h>
 #include "collapse.h"
 #include "internal.h"
 
+/*
+ * Which pass of a round reached a verdict on a candidate.  Named by the trace
+ * header, which only this file builds, so it need not be shared.
+ */
+enum collapse_pass {
+	COLLAPSE_PASS_ALLOC,
+	COLLAPSE_PASS_REVALIDATE,
+	COLLAPSE_PASS_FAULTIN,
+	COLLAPSE_PASS_FREEZE,
+	COLLAPSE_PASS_COPY,
+	COLLAPSE_PASS_INSTALL,
+};
+
+#define CREATE_TRACE_POINTS
+#include <trace/events/collapse.h>
+
 /*
  * Anonymous collapse, in rounds.
  *
diff --git a/mm/collapse.h b/mm/collapse.h
index 4af7bb9c4261..9e2cec1f250b 100644
--- a/mm/collapse.h
+++ b/mm/collapse.h
@@ -16,19 +16,6 @@
 struct collapse_candidate;
 struct collapse_retry;
 
-/*
- * Which pass of a round reached a verdict on a candidate.  Only collapse.c
- * produces these; the trace header khugepaged.c builds names them.
- */
-enum collapse_pass {
-	COLLAPSE_PASS_ALLOC,
-	COLLAPSE_PASS_REVALIDATE,
-	COLLAPSE_PASS_FAULTIN,
-	COLLAPSE_PASS_FREEZE,
-	COLLAPSE_PASS_COPY,
-	COLLAPSE_PASS_INSTALL,
-};
-
 enum scan_result {
 	SCAN_FAIL,
 	SCAN_SUCCEED,
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 967cc472b6dc..f3a7aad5e8f2 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -31,8 +31,7 @@
 #include "page_alloc.h"
 #include "mm_slot.h"
 
-#define CREATE_TRACE_POINTS
-#include <trace/events/huge_memory.h>
+#include <trace/events/collapse.h>
 
 static struct task_struct *khugepaged_thread __read_mostly;
 static DEFINE_MUTEX(khugepaged_mutex);
diff --git a/tools/testing/selftests/mm/khugepaged_sync_check.c b/tools/testing/selftests/mm/khugepaged_sync_check.c
index 45001996b57a..4c37b697d3dd 100644
--- a/tools/testing/selftests/mm/khugepaged_sync_check.c
+++ b/tools/testing/selftests/mm/khugepaged_sync_check.c
@@ -41,7 +41,7 @@ static unsigned long hpage_pmd_size;
 /*
  * Each step switches the events off again, but a helper can still give up
  * on us in between (a failing sysfs write ends the test from inside
- * thp_write_num()), and huge_memory events left on are the whole machine's
+ * thp_write_num()), and collapse events left on are the whole machine's
  * problem, not this test's.
  */
 static void trace_events_off(void)
@@ -118,7 +118,7 @@ static void one_step(int iteration)
 	if (tracing_clear_trace())
 		ksft_exit_fail_msg("Cannot clear the trace buffer\n");
 	if (tracing_events_enable(trace_events_fd, true))
-		ksft_exit_fail_msg("Cannot enable huge_memory events\n");
+		ksft_exit_fail_msg("Cannot enable collapse events\n");
 
 	if (madvise(p, hpage_pmd_size, MADV_HUGEPAGE))
 		ksft_exit_fail_perror("madvise(MADV_HUGEPAGE)");
@@ -127,7 +127,7 @@ static void one_step(int iteration)
 
 	/* Off before anything that can give up: the events are system-wide. */
 	if (tracing_events_enable(trace_events_fd, false))
-		ksft_exit_fail_msg("Cannot disable huge_memory events\n");
+		ksft_exit_fail_msg("Cannot disable collapse events\n");
 	if (!passed)
 		ksft_exit_fail_msg("khugepaged did not complete a full pass\n");
 
@@ -164,9 +164,9 @@ int main(void)
 	kpageflags_fd = open("/proc/kpageflags", O_RDONLY);
 	if (kpageflags_fd < 0)
 		ksft_exit_skip("open(\"/proc/kpageflags\") requires root\n");
-	trace_events_fd = tracing_events_open("huge_memory");
+	trace_events_fd = tracing_events_open("collapse");
 	if (trace_events_fd < 0)
-		ksft_exit_skip("huge_memory events require tracefs and root\n");
+		ksft_exit_skip("collapse events require tracefs and root\n");
 	atexit(trace_events_off);
 
 	ksft_set_plan(NR_ITERATIONS);
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index ee1334778391..32cba59ae49c 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -601,7 +601,7 @@ bool is_range_backed_by_folio_orders(char *start, size_t len, int order,
 #define TRACEFS_ROOT "/sys/kernel/tracing"
 
 /*
- * Open the enable file of one ftrace event subsystem (e.g. "huge_memory").
+ * Open the enable file of one ftrace event subsystem (e.g. "collapse").
  * Returns a descriptor for tracing_events_enable(), or -1 if tracefs or the
  * subsystem is not there.  The events are system-wide state: whoever
  * switches them on owns them until it switches them off, including on the
-- 
2.54.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help