From patchwork Wed Feb 19 15:18:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13982436 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 859231F462D; Wed, 19 Feb 2025 15:18:40 +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=1739978320; cv=none; b=T2+htAusYordsWL/8Z4wqCwK4qw3a1WcQdeH91F2VQJt2/fEzGK9sOqDeNfJUuyT/xH2byYy8bIriTU9LDOYnl+mLYi1yjrKbqHHrWIPTYfKpi2eCtlVhusJlhnrdkONcmx1tcnAPJ1iLofdSj+aNsC6Y+X+LJZjpzoaPEov5LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739978320; c=relaxed/simple; bh=ZRPURUeCAkTDmo+Kg/vefAHs6hoBKvDj93aPdKVfbJw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=fQJNMoy6xqmclFm+9czCfEXtFI3IOFaUUsPY23aS3tHW1nkJNVpeVmSuCFrY4CwH9YqJy/bFu+EqA5Ck+EThDa8uNechkU+orC2YLjiLqhu6wx2YnvGdq9EtBPitdWPh8/5vQ6RC2zpCqK4YwVgYOkWcKC8Rtd/FdD/epb/wWuo= 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 5DE14C4CEE8; Wed, 19 Feb 2025 15:18:40 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tklqq-00000004bbG-42cL; Wed, 19 Feb 2025 10:19:04 -0500 Message-ID: <20250219151904.814826218@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 19 Feb 2025 10:18:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , bpf , 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: [for-next][PATCH 6/6] ftrace: Have ftrace pages output reflect freed pages References: <20250219151815.734900568@goodmis.org> Precedence: bulk X-Mailing-List: bpf@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. 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) --- 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 e657013424aa..27c8def2139d 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 @@ -7124,6 +7127,8 @@ static int ftrace_process_locs(struct module *mod, for (pg = pg_unuse; pg; pg = pg->next) remaining += 1 << pg->order; + pages -= remaining; + skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE); /* @@ -7137,6 +7142,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; } @@ -7782,9 +7794,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);