From patchwork Thu Feb 13 16:20:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13973664 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 835CB280A26; Thu, 13 Feb 2025 16:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739463696; cv=none; b=SIXaHKd0b9FfxE3/l0a1TeecwEUfFxrcmHHYidy5veZi7yjstb2J9Csr+jfDacA8AAYXCosgFIqzAe8csl/nEeR1WD6plP85gJkCBrwYd5WghWAeEgviKR1+PS8ZY3IyXuE4h7INDxetKhv1Go+vqL0l4B+XEpWfMgh2ZUUxjeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739463696; c=relaxed/simple; bh=h5HZDvjlSble8n9tutmQYNXJ8OyrHiQ1Z2innQWa9XE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ErB+bdoobo5sTU46GX4z3JdThx62/WS5rf9uawDJKrHu4AnxCbH+MLLfflZEylvnVIrNxGkyh/fpiYoY6iMDpI1AD9EhwJeryoQUW1QZrVwLfc4UwxWkDC5pVIVHVFnjRQNk8paY/TEv4OA+7Mc/tRaqW9Zkd4BrP6D8Wxtx7gE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 006D4C4CEE7; Thu, 13 Feb 2025 16:21:36 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tibyE-00000001qcx-21Ty; Thu, 13 Feb 2025 11:21:46 -0500 Message-ID: <20250213162146.332262157@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 13 Feb 2025 11:20:53 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf , linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org Cc: 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 Subject: [PATCH v3 6/6] ftrace: Have ftrace pages output reflect freed pages References: <20250213162047.306074881@goodmis.org> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 55d28c060784..fa7c3417d995 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7006,6 +7006,7 @@ static int ftrace_process_locs(struct module *mod, unsigned long addr; unsigned long kaslr; unsigned long flags = 0; /* Shut up gcc */ + unsigned long pages; int ret = -ENOMEM; count = end - start; @@ -7013,6 +7014,8 @@ static int ftrace_process_locs(struct module *mod, 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 @@ -7125,6 +7128,8 @@ static int ftrace_process_locs(struct module *mod, remaining += 1 << pg->order; } + pages -= remaining; + skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE); /* @@ -7138,6 +7143,13 @@ static int ftrace_process_locs(struct module *mod, 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; } @@ -7783,9 +7795,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);