From nobody Fri Jan 2 15:31:20 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 84CE0CD8C9C for ; Tue, 10 Oct 2023 14:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233247AbjJJO4E (ORCPT ); Tue, 10 Oct 2023 10:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233174AbjJJO4C (ORCPT ); Tue, 10 Oct 2023 10:56:02 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65908AC for ; Tue, 10 Oct 2023 07:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=vp6teXUVeTaVuntNL+yXUHhW+AagRb8DJbn/Ed9G6Fo=; b=fdNeQB0CeUpgr9GoqZ7MTuVH3L u948e+D6m1yQXsjzA24hWFSX9wAD4IwF+jC1FHQbawtGknj9KCuaVIdl79D2/H0jnj5XH4nYagFuA Mnwxa7DvO1Ur62Do0KoErqvWsDQEeTHqIyC94SFFeNv9VvUjT3CULo2PhrfKhLHCEgZuxeMEdgUx9 GFIden08ogGkjv7XgNhG24AwcGYkJb2bb6pHrSxMn+bu16I9RGmgjYqe2BhCd4fME7eDdl9WdC/H+ Mr+woddq90y1e70YM4IbsLkU20BXM258bjyGLD9SLDpyYPUpgUIQ7ePzykRizhxNDCNpkISk3i1/o xz6eLFlw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qqE9K-005DpE-2o; Tue, 10 Oct 2023 14:55:54 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Peter Zijlstra , Mel Gorman , Ingo Molnar , Rik van Riel Subject: [PATCH] bounds: Support non-power-of-two CONFIG_NR_CPUS Date: Tue, 10 Oct 2023 15:55:49 +0100 Message-Id: <20231010145549.1244748-1-willy@infradead.org> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ilog2() rounds down, so for example when PowerPC 85xx sets CONFIG_NR_CPUS to 24, we will only allocate 4 bits to store the number of CPUs instead of 5. Use bits_per() instead, which rounds up. Found by code inspection. The effect of this would probably be a misaccounting when doing NUMA balancing, so to a user, it would only be a performance penalty. The effects may be more wide-spread; it's hard to tell. Signed-off-by: Matthew Wilcox (Oracle) Fixes: 90572890d202 ("mm: numa: Change page last {nid,pid} into {cpu,pid}") Cc: Peter Zijlstra Cc: Mel Gorman Cc: Ingo Molnar Cc: Rik van Riel Acked-by: Mel Gorman Reviewed-by: Rik van Riel --- kernel/bounds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bounds.c b/kernel/bounds.c index b529182e8b04..c5a9fcd2d622 100644 --- a/kernel/bounds.c +++ b/kernel/bounds.c @@ -19,7 +19,7 @@ int main(void) DEFINE(NR_PAGEFLAGS, __NR_PAGEFLAGS); DEFINE(MAX_NR_ZONES, __MAX_NR_ZONES); #ifdef CONFIG_SMP - DEFINE(NR_CPUS_BITS, ilog2(CONFIG_NR_CPUS)); + DEFINE(NR_CPUS_BITS, bits_per(CONFIG_NR_CPUS)); #endif DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t)); #ifdef CONFIG_LRU_GEN --=20 2.40.1