From patchwork Fri Nov 25 12:24:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 25971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3978751wrr; Fri, 25 Nov 2022 04:31:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf51AP1nbCFbG8859ilyY7X2MhaSJBShsvFKO/wqLhyL5Xiq8E4CN3TBtsfgD4vICEZ19hrq X-Received: by 2002:a17:906:1682:b0:78d:6ba1:74dd with SMTP id s2-20020a170906168200b0078d6ba174ddmr32945645ejd.119.1669379465397; Fri, 25 Nov 2022 04:31:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669379465; cv=none; d=google.com; s=arc-20160816; b=e8OxVscn0ccoeF+cIQNon1Hid0viS8sVcCSjSpar87Mx7c75AzAaiuAhXg+zvrgH8Q jAodrTfJwcT1N7e6aVJetpIWclVSbM/U/xbghiN66TDsUlFxyq0FnuuE231Jck4oaMOV lyx4+0r38PMJRsFD3sOUsDwOxnvk1ucPYrdRw3aR0+lNWOIyuQKvfmY3GDODulR8n5tM +9aDkW8/fQSgMVhzh9Yk0YhRN2wljFZJ8z1IBENj0xjsBoPqtx5gGssvohM8K49q+RHX 76prsPpi39NkeG3M6vIeJnviORLeRtDP0nPKaoreA/xud8318qs1ETmy9jaQxmyAM/X3 Ra6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RlG5JNM/2fHjw2Db+Zc6WfpvLX4HjCE9oPzkR3La0Oc=; b=xzo6/gZ9TGaI13A3bpGXnxqT0Min3PmpCijglF3m60InbHmCKjm90Ek0Ql1qTcE+pV 6utFSdO2gD8453KhMbjRBNV4GWCUWzRJgdZQIhHCTXHOOKwzSHayOYed3TOzqoJzFXnF 0p2I666F/44c1TojUFELzUtjJYENQeI0/k5E52VElR8yQpKDx4bCmh97Vl07ITHFRAs3 odzAZWRu2qjce9x7igcVIuXhBpO/ZxoBcUIZk+T+mcQMSSwsDZ8oUCUQNeph2bIM8V1P y1yBRqpEiX5r9zQ6THsh/KvtfXzU8wC8gfYCOw3bncw4cjfJN6VpHA3eY9vU2UJQ7tNf cUOA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz16-20020a0564021d5000b0046a341e2c1fsi3342886edb.500.2022.11.25.04.30.41; Fri, 25 Nov 2022 04:31:05 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229972AbiKYMY1 (ORCPT + 99 others); Fri, 25 Nov 2022 07:24:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiKYMYS (ORCPT ); Fri, 25 Nov 2022 07:24:18 -0500 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D823D4A5BE for ; Fri, 25 Nov 2022 04:24:12 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id yXkRoPBKkY4XVyXkZoE20z; Fri, 25 Nov 2022 13:24:11 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 25 Nov 2022 13:24:11 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: Sunil Goutham , Linu Cherian , Geetha sowjanya , Jerin Jacob , hariprasad , Subbaraya Sundeep , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netdev@vger.kernel.org Subject: [PATCH 4/5] octeontx2-af: Fix the size of memory allocated for the 'id_bmap' bitmap Date: Fri, 25 Nov 2022 13:24:00 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750471242139362785?= X-GMAIL-MSGID: =?utf-8?q?1750471242139362785?= This allocation is really spurious. The size of the bitmap is 'tot_ids' and it is used as such in the driver. So we could expect something like: table->id_bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(table->tot_ids), sizeof(long), GFP_KERNEL); However, when the bitmap is allocated, we allocate: BITS_TO_LONGS(table->tot_ids) * table->tot_ids ~= table->tot_ids / 32 * table->tot_ids ~= table->tot_ids^2 / 32 It is proportional to the square of 'table->tot_ids' which seems to potentially be big. Allocate the expected amount of memory, and switch to the bitmap API to have it more straightforward. Signed-off-by: Christophe JAILLET --- This patch is speculative. If I'm right, I'm curious to know if 'able->tot_ids' can really get big (I'm just guessing) , and if yes, how much. --- drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c index 3f94b620ef5a..ae34746341c4 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_hash.c @@ -1914,8 +1914,8 @@ int rvu_npc_exact_init(struct rvu *rvu) dev_dbg(rvu->dev, "%s: Allocated bitmap for 32 entry cam\n", __func__); table->tot_ids = (table->mem_table.depth * table->mem_table.ways) + table->cam_table.depth; - table->id_bmap = devm_kcalloc(rvu->dev, BITS_TO_LONGS(table->tot_ids), - table->tot_ids, GFP_KERNEL); + table->id_bmap = devm_bitmap_zalloc(rvu->dev, table->tot_ids, + GFP_KERNEL); if (!table->id_bmap) return -ENOMEM;