Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp260102rwi; Wed, 26 Oct 2022 00:03:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jGneKSWoBjHAInF9xumVrOgv+/GdDS/NsIgPfoItgDZeoXvRpQ4dCeU3n1r8HakLVtS/G X-Received: by 2002:a17:907:1dd8:b0:78d:cbdc:ff1f with SMTP id og24-20020a1709071dd800b0078dcbdcff1fmr35438768ejc.412.1666767806654; Wed, 26 Oct 2022 00:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666767806; cv=none; d=google.com; s=arc-20160816; b=UoGpt2Ep/W1ZY/Hx21EqUPkjfj0Vtea10sJ1Ll0kWVJKRjR9VInMAbr0FGD5YVixVJ imBhpYUd9upih8tN3Ciw8vIAmvESaoKMO4vsZDsKyU8U5AZY3K3+2ctD6bOZBLgItR9G nYJ5RWxXpmtFxySWbRVZteqknqkka9obNYuen3OYaULNB9tM48B6bKA5HVcUhw9YyIiO mRD+Ss7P4nO9wZR4/Wgm7sPDMG6/uZXPXqocQRlpheX0qx31IE2e9oAOWkb3/8S+OkBH EYUfBLdh/6ultW834dpg5BwgHERpr55uLQeu5goWRdqn2C1/CJRpmOimdcleoJ3UOeP5 VfAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=EqUYKmYC7tGXp5qMDniXpXM9WaldlVnUAnrU7Ph9DBk=; b=Vq7FHVc5o2223DdvMLc4zlJutPf1vGdp1zYr1S+PWfHrxyLKK1xJJKaIcn1OfjFqPc QnpqVeFyNCdYArhmP0ylKGN0VZrE8072ABuDlBE7c0+lU92373Slm+ycqzLrz/sTs2Se E3RfbKAgb5XgTRcVioGUAa8e7WF+ulQsXjUaxJKfNW09Ysb66q6YQgG6Ap6USFeoPXgl cVixV8tKQGcrPG0v4AxuwcR+boAJEto0TAhWHnilQ69KmkOtH2QtVITUTY+8Bopa+oaO U6e5I24J/hWyDUD3HQxGmM5sP4IwfgKnzuHHVX37ctC3pVBHe4o/IpyusdkbnbE1GGYV c2Lw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he18-20020a1709073d9200b0078b96722000si2715253ejc.608.2022.10.26.00.02.46; Wed, 26 Oct 2022 00:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233118AbiJZGpB (ORCPT + 99 others); Wed, 26 Oct 2022 02:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbiJZGox (ORCPT ); Wed, 26 Oct 2022 02:44:53 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 942291A047; Tue, 25 Oct 2022 23:44:50 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MxzkL1NrmzJnGN; Wed, 26 Oct 2022 14:42:02 +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.31; Wed, 26 Oct 2022 14:44:48 +0800 Received: from [10.174.178.55] (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.31; Wed, 26 Oct 2022 14:44:47 +0800 Subject: Re: [PATCH v7 00/11] kallsyms: Optimizes the performance of lookup symbols To: Luis Chamberlain CC: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , , , Masahiro Yamada , Alexei Starovoitov , Jiri Olsa , Kees Cook , Andrew Morton , , Steven Rostedt , "Ingo Molnar" References: <20221017064950.2038-1-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: <77f1c8f0-5e67-0e57-9285-15ba613044fb@huawei.com> Date: Wed, 26 Oct 2022 14:44:36 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/10/26 1:53, Luis Chamberlain wrote: > On Wed, Oct 19, 2022 at 10:11:58PM +0800, Leizhen (ThunderTown) wrote: >> >> >> On 2022/10/19 20:01, Luis Chamberlain wrote: >>> On Mon, Oct 17, 2022 at 02:49:39PM +0800, Zhen Lei wrote: >>>> 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 patch series optimizes the performance of function kallsyms_lookup_name(), >>>> and function klp_find_object_symbol() in the livepatch module. Based on the >>>> test results, the performance overhead is reduced to 5%. That is, the >>>> performance of these functions is improved by 20 times. >>> >>> Stupid question, is a hash table in order? >> >> No hash table. >> >> All symbols are arranged in ascending order of address. For example: cat /proc/kallsyms >> >> The addresses of all symbols are stored in kallsyms_addresses[], and names of all symbols >> are stored in kallsyms_names[]. The elements in these two arrays are in a one-to-one >> relationship. For any symbol, it has the same index in both arrays. >> >> Therefore, when we look up a symbolic name based on an address, we use a binary lookup. >> However, when we look up an address based on a symbol name, we can only traverse array >> kallsyms_names[] in sequence. I think the reason why hash is not used is to save memory. > > This answers how we don't use a hash table, the question was *should* we > use one? I'm not the original author, and I can only answer now based on my understanding. Maybe the original author didn't think of the hash method, or he has weighed it out. Hash is a good solution if only performance is required and memory overhead is not considered. Using hash will increase the memory size by up to "4 * kallsyms_num_syms + 4 * ARRAY_SIZE(hashtable)" bytes, kallsyms_num_syms is about 1-2 million. Because I don't know what hash algorithm will be used, the cost of generating the hash value corresponding to the symbol name is unknown now. But I think it's gonna be small. But it definitely needs a simpler algorithm, the tool needs to implement the same hash algorithm. If the hash is not very uniform or ARRAY_SIZE(hashtable) is small, then my current approach still makes sense. So maybe hash can be deferred to the next phase of improvement. > > Luis > . > -- Regards, Zhen Lei