From patchwork Mon Feb 17 15:34:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13978091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00FCFC021AA for ; Mon, 17 Feb 2025 15:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: List-Owner; bh=0/mDtlBikO57slA120u7KN6mjQODM33+MQPnGr4fUrc=; b=iLyXpbfyLizREL XBXxCZ7f4aKnbm6ldAHhpf90FIIrl6+od7FA56wOK2OBldy7F1l4lWZmj2QFsaZwWoYDZR6Tsvdmp DdiEelNgRlFYUazt6J81V5FdkaG0bqnf3LLr7V1kEMu9suug2VcwnqdeEGKunvoAKAl6n3wikDgX2 GIOnUsTFgvlwohwqFPAi59M1VhrstZ73rDFPxL8q7GPC3qfAO1RxXHtqSVZEKta/mflHKxeqefi2q am6VL351WFZtOFE6/WOFyGv4q8pecmDWdwo8+O68dLIaHkJSc2aOc11qzJndGuFgGFh7ZhU/SkfYS SfHqpZ84qYgK76SWmqPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tk3Ia-000000056sH-2XhN; Mon, 17 Feb 2025 15:44:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tk38t-000000053yn-2GLJ for linux-arm-kernel@bombadil.infradead.org; Mon, 17 Feb 2025 15:34:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=0/mDtlBikO57slA120u7KN6mjQODM33+MQPnGr4fUrc=; b=OmWudmN6Dy6ldnOVQ8c4FEJi2j +8bi+a0ZSIgGOWjOc7iMVtZn7I/aClY/xwmt8ootgGJgc6R8VZpMbUZuptJCuci+BW1/HUPY6GGkZ PtjIfHPkVtTGu8L7KfS6lQNOZOmjzpwuXjNLg/QcKdxSuBDaZqaw6sE/hUqR/hir5GIWdM0TaNKKV DNv7YLgxPN0aUYaacn609cYbqWYznBLEuiQyXLaLLHDge1UMZdEcBicmq8EV42eRDP/vup8I9BhC9 aefsBsoWRX7+CKCqsVLQBK2geJCdO/nsgY9LebG+8qsJ35xE0GBfvomrfE/f71gz0nOisGPxg32zH 6rs+TC8w==; Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tk38o-00000001qnf-2fJ9 for linux-arm-kernel@lists.infradead.org; Mon, 17 Feb 2025 15:34:42 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id A2780A41634; Mon, 17 Feb 2025 15:32:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 389B4C4CEEB; Mon, 17 Feb 2025 15:34:34 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tk394-00000003aML-0SO6; Mon, 17 Feb 2025 10:34:54 -0500 Message-ID: <20250217153453.960950584@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 17 Feb 2025 10:34:07 -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 v4 6/6] ftrace: Have ftrace pages output reflect freed pages References: <20250217153401.022858448@goodmis.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250217_153438_920287_C36F040A X-CRM114-Status: GOOD ( 16.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);