Skip to content

Commit 264143c

Browse files
committed
ftrace: Have ftrace pages output reflect freed pages
The amount of memory that ftrace uses to save the descriptors to manage the functions it can trace is shown at output. But if there are a lot of functions that are skipped because they were weak or the architecture added holes into the tables, then the extra pages that were allocated are freed. But these freed pages are not reflected in the numbers shown, and they can even be inconsistent with what is reported: ftrace: allocating 57482 entries in 225 pages ftrace: allocated 224 pages with 3 groups The above shows the number of original entries that are in the mcount_loc section and the pages needed to save them (225), but the second output reflects the number of pages that were actually used. The two should be consistent as: ftrace: allocating 56739 entries in 224 pages ftrace: allocated 224 pages with 3 groups The above also shows the accurate number of entires that were actually stored and does not include the entries that were removed. Cc: bpf <bpf@vger.kernel.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nicolas@fjasle.eu> Cc: Zheng Yejian <zhengyejian1@huawei.com> Cc: Martin Kelly <martin.kelly@crowdstrike.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Link: https://lore.kernel.org/20250218200023.221100846@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 4a3efc6 commit 264143c

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

kernel/trace/ftrace.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7006,13 +7006,16 @@ static int ftrace_process_locs(struct module *mod,
70067006
unsigned long addr;
70077007
unsigned long kaslr;
70087008
unsigned long flags = 0; /* Shut up gcc */
7009+
unsigned long pages;
70097010
int ret = -ENOMEM;
70107011

70117012
count = end - start;
70127013

70137014
if (!count)
70147015
return 0;
70157016

7017+
pages = DIV_ROUND_UP(count, ENTRIES_PER_PAGE);
7018+
70167019
/*
70177020
* Sorting mcount in vmlinux at build time depend on
70187021
* CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in
@@ -7124,6 +7127,8 @@ static int ftrace_process_locs(struct module *mod,
71247127
for (pg = pg_unuse; pg; pg = pg->next)
71257128
remaining += 1 << pg->order;
71267129

7130+
pages -= remaining;
7131+
71277132
skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE);
71287133

71297134
/*
@@ -7137,6 +7142,13 @@ static int ftrace_process_locs(struct module *mod,
71377142
synchronize_rcu();
71387143
ftrace_free_pages(pg_unuse);
71397144
}
7145+
7146+
if (!mod) {
7147+
count -= skipped;
7148+
pr_info("ftrace: allocating %ld entries in %ld pages\n",
7149+
count, pages);
7150+
}
7151+
71407152
return ret;
71417153
}
71427154

@@ -7782,9 +7794,6 @@ void __init ftrace_init(void)
77827794
goto failed;
77837795
}
77847796

7785-
pr_info("ftrace: allocating %ld entries in %ld pages\n",
7786-
count, DIV_ROUND_UP(count, ENTRIES_PER_PAGE));
7787-
77887797
ret = ftrace_process_locs(NULL,
77897798
__start_mcount_loc,
77907799
__stop_mcount_loc);

0 commit comments

Comments
 (0)