From nobody Wed Apr 8 14:46:27 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 295F1ECAAD3 for ; Fri, 9 Sep 2022 13:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231564AbiIINDh (ORCPT ); Fri, 9 Sep 2022 09:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbiIINDR (ORCPT ); Fri, 9 Sep 2022 09:03:17 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C7372ECB; Fri, 9 Sep 2022 06:03:15 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MPGKP75bpz14QN6; Fri, 9 Sep 2022 20:59:21 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 21:03:13 +0800 Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 21:03:12 +0800 From: Zhen Lei To: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , , , Masahiro Yamada , Alexei Starovoitov , Jiri Olsa , Kees Cook , Andrew Morton , "Luis Chamberlain" , CC: Zhen Lei Subject: [PATCH v2 1/8] scripts/kallsyms: don't compress symbol type when CONFIG_KALLSYMS_ALL=y Date: Fri, 9 Sep 2022 21:00:09 +0800 Message-ID: <20220909130016.727-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20220909130016.727-1-thunder.leizhen@huawei.com> References: <20220909130016.727-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, to search for a symbol, we need to expand the symbols in 'kallsyms_names' one by one, and then use the expanded string for comparison. This is very slow. In fact, we can first compress the name being looked up and then use it for comparison when traversing 'kallsyms_names'. This increases the size of 'kallsyms_names'. About 48KiB, 2.67%, on x86 with defconfig. Before: kallsyms_num_syms=3D131392, sizeof(kallsyms_names)=3D1823659 After : kallsyms_num_syms=3D131392, sizeof(kallsyms_names)=3D1872418 However, if CONFIG_KALLSYMS_ALL is not set, the size of 'kallsyms_names' does not change. Signed-off-by: Zhen Lei --- scripts/kallsyms.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index f18e6dfc68c5839..ab6fe7cd014efd1 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -60,6 +60,7 @@ static unsigned int table_size, table_cnt; static int all_symbols; static int absolute_percpu; static int base_relative; +static int sym_start_idx; =20 static int token_profit[0x10000]; =20 @@ -511,7 +512,7 @@ static void learn_symbol(const unsigned char *symbol, i= nt len) { int i; =20 - for (i =3D 0; i < len - 1; i++) + for (i =3D sym_start_idx; i < len - 1; i++) token_profit[ symbol[i] + (symbol[i + 1] << 8) ]++; } =20 @@ -520,7 +521,7 @@ static void forget_symbol(const unsigned char *symbol, = int len) { int i; =20 - for (i =3D 0; i < len - 1; i++) + for (i =3D sym_start_idx; i < len - 1; i++) token_profit[ symbol[i] + (symbol[i + 1] << 8) ]--; } =20 @@ -538,7 +539,7 @@ static unsigned char *find_token(unsigned char *str, in= t len, { int i; =20 - for (i =3D 0; i < len - 1; i++) { + for (i =3D sym_start_idx; i < len - 1; i++) { if (str[i] =3D=3D token[0] && str[i+1] =3D=3D token[1]) return &str[i]; } @@ -780,6 +781,14 @@ int main(int argc, char **argv) } else if (argc !=3D 1) usage(); =20 + /* + * Skip the symbol type, do not compress it to optimize the performance + * of finding or traversing symbols in kernel, this is good for modules + * such as livepatch. + */ + if (all_symbols) + sym_start_idx =3D 1; + read_map(stdin); shrink_table(); if (absolute_percpu) --=20 2.25.1