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 <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Zheng Yejian <[email protected]> Cc: Martin Kelly <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Alexander Gordeev <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4a3efc6 commit 264143c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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)