From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A8043A1E92; Thu, 2 Jul 2026 16:47:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783010857; cv=none; b=gV+qmfLEaPmcJp+BiUsF69i9cstUfb8+DJUN5z+PodREB6dw/0jDN1dn9jz0QI3a8Dl/qEcOYHsB9yQCr9bQy4NLWxI5YIs3L7pcGVnvd+Brb+ouIqEvshD+y5URpUPc54YH5DxyHakLSOAs38dEa4D8rsG90FFo5bSylOfY6+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783010857; c=relaxed/simple; bh=ybo5kdtIQbzoMR+nPjRZuspSA4FLEX0OUpqlmyXR5i4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rpXu3gLGRVTPtmgv4VA5F2il6266xltqCPZzvAPxg0yH3p7Z0PHe8REmWvyTOAymSm0tEJ4vCX+8t86uifrngyNWEyKJG4zsC4JYfgIx2jCHQNnfuvr3ABtttVZYavYaqdTc+ydreSUMF1U/lOu+c9WKLFfu920iCJoz2dUSusE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Z5+oWD2u; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Z5+oWD2u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58C5D1F000E9; Thu, 2 Jul 2026 16:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1783010856; bh=V6n5C7vOKkzekwiNi/nVdZaccRf0/knKkOshOolO/F0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z5+oWD2u+RnS2SBjZVu6oJxZc/JfSLPt/VlX3G2+gHUvNEyYSGyr541M72Wr6TDGh 4FmuzNuZ8YvWm5p68xqyABbTWgaCcgrSlQQyoJrMxyVG5LPly4V+Ar1oMeEvG6XQGz GdkbUNPSYKmguBqep2abrEKomIo4mX0Qr2qM2Kl8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, bpf , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Linus Torvalds , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Zheng Yejian , Martin Kelly , Christophe Leroy , Josh Poimboeuf , Heiko Carstens , Catalin Marinas , Will Deacon , Vasily Gorbik , Alexander Gordeev , "Steven Rostedt (Google)" , Andrey Grodzovsky Subject: [PATCH 6.6 064/175] ftrace: Have ftrace pages output reflect freed pages Date: Thu, 2 Jul 2026 18:19:25 +0200 Message-ID: <20260702155117.143529381@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260702155115.766838875@linuxfoundation.org> References: <20260702155115.766838875@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt [ Upstream commit 264143c4e54412095f4b615e65bf736fc3c60af0 ] 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 Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Peter Zijlstra Cc: Linus Torvalds Cc: Masahiro Yamada Cc: Nathan Chancellor Cc: Nicolas Schier Cc: Zheng Yejian Cc: Martin Kelly Cc: Christophe Leroy Cc: Josh Poimboeuf Cc: Heiko Carstens Cc: Catalin Marinas Cc: Will Deacon Cc: Vasily Gorbik Cc: Alexander Gordeev Link: https://lore.kernel.org/20250218200023.221100846@goodmis.org Signed-off-by: Steven Rostedt (Google) Signed-off-by: Andrey Grodzovsky Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6527,6 +6527,7 @@ static int ftrace_process_locs(struct mo unsigned long addr; unsigned long kaslr; unsigned long flags = 0; /* Shut up gcc */ + unsigned long pages; int ret = -ENOMEM; count = end - start; @@ -6534,6 +6535,8 @@ static int ftrace_process_locs(struct mo if (!count) return 0; + pages = DIV_ROUND_UP(count, ENTRIES_PER_PAGE); + /* * Sorting mcount in vmlinux at build time depend on * CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in @@ -6645,6 +6648,8 @@ static int ftrace_process_locs(struct mo for (pg = pg_unuse; pg; pg = pg->next) remaining += 1 << pg->order; + pages -= remaining; + skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE); /* @@ -6658,6 +6663,13 @@ static int ftrace_process_locs(struct mo synchronize_rcu(); ftrace_free_pages(pg_unuse); } + + if (!mod) { + count -= skipped; + pr_info("ftrace: allocating %ld entries in %ld pages\n", + count, pages); + } + return ret; } @@ -7315,9 +7327,6 @@ void __init ftrace_init(void) goto failed; } - pr_info("ftrace: allocating %ld entries in %ld pages\n", - count, DIV_ROUND_UP(count, ENTRIES_PER_PAGE)); - ret = ftrace_process_locs(NULL, __start_mcount_loc, __stop_mcount_loc);