From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.200.36 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795989909; b=rxQrTfrkph2jhJ8Dx6tiD8f4q3siXjdksCkybcKOC4TooYtVefLf+btu9Gv6JP+FHn0F BdbiNAfVKRnVPfazCiep6uBVe8ehWfgU4mcQ4A87r+qzoXQWqgRsNpkRWFD7/61dwCrwt 7GTJ8weT9jCedDhoLgu5GIMhTgYRS4eFb4HvWgVwS519mOY2oJommUkStMfq7IP1zLABQ yM0ecfRn7dwz3+g6pyHbbZIHfXxRKQgt73/DcZqtQIpurpcFeipI27iLyhBRisO4k/zNe J/6lRXOrv6+fy3bCcjuYcx55chdLW5YWaa8ZcDPf90ED3g/m24aF2hNHYXzUzNxVImA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795989909; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=IzwngvWf9wzwD4ZWfeXVELVLQmm60Hh0gzLlcDOT1mg=; b=OiBD3TBU806BM80DygeVi3tg2GK4We0IIPI+Nz/ZuRHiZyE401jMv1oaWQdxIDU99gZ9 ih+Syq2K77CkHCjj1yJ34p/Fh53S75AQNXtbrxMmz332ipB/l6Kk40w2NJEsb1qHiq7Tk J14W44MnmYzLd4pBodkE2XHpUrKTEnIaByGaAxZxD6cl7KvLZR0hsTW04Q7tkDu4d0F+H u/xZ0yy2Zdap1STr16QE8ohszpWtE4nZvLJlt+L/eQPFdOGMXx0m/QIUbfzVmJy5raBG3 KRB/otHN0rzcbQGcc0YSn3AAYTwIE4ou0oKGQibXjDz4fSe3/cA1Top23J7O5OiuDRw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=VqTqZj6c; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.200.36 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012036.outbound.protection.outlook.com [40.107.200.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09C81606A31C; Sun, 29 Nov 2026 22:05:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 09C81606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=VqTqZj6c ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wGn0kf7S6Vzj6mHxMx462cl5oLcpEgSQoH+JNR0A7r+gCVy5kF+ImIeao9mPESa5fhCI65MkcB8lcxLNKfgRzdL1VqrIIUQ7/HLqKQapKF+aq4vQWWHhGWsVcJPcOja6482UUgMuREwwH5/7U2S5ltK4FFLw//JLNtueT0PuJeg9FqCS9E2X2wXCHtHaXuoF+AIKCXmaC4UcpQLtXAAj5UCdqvgJWeEEuWILnzKpmCZEU8/nMl47h96PaXDjSdUXLSwDcc2nm2jkQZiKGnQyZMmim8P0CvfqQy+fBXJxYe6+Bfve/6haitJaIno9uPQ7U42Xnt6+ZQ2COM0D23Y86g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IzwngvWf9wzwD4ZWfeXVELVLQmm60Hh0gzLlcDOT1mg=; b=nl4dviGo6eYvamxIwUKsN26Yup22WDGhJvUdHZo1Qm2BRMrW1y+Kc/wEdSFVa/QRRkL7PNNKnhMYwYXjuRTPUvSZ9TKg4f90eQ3MfnRjssA49U/kG4i3o4RjzblBq2nAf7d4kR7SRWHac+x3oQyUxvOHdp1g57i2BzGbc2sSnzQNHiKk0GBMA1uyZcO9qAM6jtD1vqlPW6ptW6IHz/YtSeSBOoHQhfV9cK3dgvFtyBqYbw9uLneMWeRPbA7IOeabytSDF74LwmC9cWhdqCilu6AiXU2a2zfMjIbZz5mls5g6A6a2zWUO/X/zmhkXPg3v6huZyJqyuLPTKrIkCzNJUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IzwngvWf9wzwD4ZWfeXVELVLQmm60Hh0gzLlcDOT1mg=; b=VqTqZj6cpHZy2h8z+2+4MraZXK1fgp+RW2oVe2oYjhM8vumtaWUlnddNPpLjvbkuK99+n1l5IPeGufM/orE3HpQ4qyBwcg/RxjBlAvLFc14NfzsYTggpF9DzQIhvcXvdHVhLK3lwwyLNFOIhpK6M58pFNUim+eiG1K1KpY3Pckq3t4c3BAnONjINJqEto1XV8LgOTSZgZ+1RvNGYNjVb5uhOL2p4AEyibJIFnS46qZpqg3m6kXL61jL5PqNBh08PXT5G7p9KMQUu8pC/NuL37ClYgw1DUGRe8c3zBA6hnpwCGh2iuYqXWG81x0/tFYBjbfs3Z9w9AqYTz6lhbJuM5w== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SN6PR12MB2814.namprd12.prod.outlook.com (2603:10b6:805:72::33) by IA4PR12MB9762.namprd12.prod.outlook.com (2603:10b6:208:5d3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Sun, 29 Nov 2026 22:05:04 +0000 Received: from SN6PR12MB2814.namprd12.prod.outlook.com ([fe80::9a18:413c:9702:8f59]) by SN6PR12MB2814.namprd12.prod.outlook.com ([fe80::9a18:413c:9702:8f59%6]) with mapi id 15.21.0662.007; Sun, 29 Nov 2026 22:05:04 +0000 Date: Sun, 29 Nov 2026 17:05:02 -0500 From: Yury Norov To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Rasmus Villemoes , David Hildenbrand , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Muchun Song , Oscar Salvador , Johannes Weiner , Kairui Song , Thomas Bogendoerfer , "Rafael J. Wysocki" , Len Brown , Jens Axboe , Peter Zijlstra , Mel Gorman , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-mips@vger.kernel.org, linux-acpi@vger.kernel.org, linux-block@vger.kernel.org, linux-trace-kernel@vger.kernel.org, "Liam R. Howlett" , Axel Rasmussen , Baolin Wang , Baoquan He , Barry Song , Linus Torvalds , Lorenzo Stoakes , Michal Hocko , Mike Rapoport , Qi Zheng , Shakeel Butt , Suren Baghdasaryan , Vlastimil Babka , Wei Xu , Yuanchu Xie , Yury Norov Subject: Re: [PATCH 00/11] nodemask: switch to runtime nr_node_ids Message-ID: References: <20261127230128.111933-1-ynorov@nvidia.com> <20261128154039.e898002e7af1e8af883c6c8a@linux-foundation.org> <20261128202010.18f36e612d57eda194a6c534@linux-foundation.org> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261128202010.18f36e612d57eda194a6c534@linux-foundation.org> X-ClientProxiedBy: BN9PR03CA0704.namprd03.prod.outlook.com (2603:10b6:408:ef::19) To SN6PR12MB2814.namprd12.prod.outlook.com (2603:10b6:805:72::33) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR12MB2814:EE_|IA4PR12MB9762:EE_ X-MS-Office365-Filtering-Correlation-Id: 72a6f761-982c-48a5-ef3f-08df4e64d244 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|10070799003|376014|7416014|10067099003|56012099006|261026121527099003|261026140227099003|261028144727099003|261022075727099003|261022113327099003|261022105027099003|261021123027099003|261021121427099003|261102123227099003|261009223027099003|18002099003|22082099003|11063799006|4143699003|6133799003; X-Microsoft-Antispam-Message-Info: +bOUlBI34sL+gfb04gHWdKa5V23ZINU14pLWWFn004yCkFHedpxfCl/JhquocE/JplfQGV512c1fNrti9OiPf9kefEA8bCy71B7+FBgJmTInwuU9Eb9CMdmLIDhSRCVn143UbtOZRaLCsDrU1gQE+LcpJw1IsySwTfTnkCAJMwEZ4KU15YEfncKuGb1hJgtTdtC9iHmjjnhdpAPRE4Az1mqPnRVd4JKjvivzysSroNxzrj4sshn6hPnbIrFd+rSbnK0kyWaU1clfHgpCdRNPVyK/HWiMJ1cXs1pyPcwBqAFmii22rHQgQLVNn8S0gQmusxK+xbXDLiU7u9A2fQD/hAolD+TEbxF8EpQecW6XGC0zlbcGuWFyEvavDG9EqySLNXGzmCp5AZc/lMU68Xle55GN7HdeEuabyg2h16buU1tkVa6+NGADeZENNac/gkJgRB/dXuvS0b74pndET3mhTXBYBTRo3pFBKgXdvLf40YywpCIsRrveEBjXRyG2caNMz5k8UdYaPHk4xfnd7yGC6Jb8mLtyYCABZaU+NOiEvN4D3UozkTRSOxNqE0BjhqpEC8QR34C5i+i7skY60aSbNTR/0gDywb+GgnWR6dhFrsTrmOCgqQlZUWxkjclZxCZXR8csfooET+JoeXnT7DYem/Rxs4U7hDNjcayDWRQa4HA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2814.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(1800799024)(10070799003)(376014)(7416014)(10067099003)(56012099006)(261026121527099003)(261026140227099003)(261028144727099003)(261022075727099003)(261022113327099003)(261022105027099003)(261021123027099003)(261021121427099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(11063799006)(4143699003)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?xiGwWY/MBoFPZaRGEjiAtZlKRmMMCo52emY/T4YCKcm5lpn42AJNRnnKptUa?= =?us-ascii?Q?IToVHhk66/K6twGnvoqZJ/MuRSI29NXePPrUY8VHX0oH/B5J/rfCZX0YPQRO?= =?us-ascii?Q?adcoFYHOI0DcNh0n+pLpzT6c+PglEHr8PhRCmKoNk7nNZ0ppkLBOCfy9OV9r?= =?us-ascii?Q?Pwe30oWQDNYMEmw+uf6nE1Irq5ksBbPis2LUl8lMTQFJdtiWwdY/Yicuc3yh?= =?us-ascii?Q?cv1m/ykkQefuqrwsrjdz/QJ7stgdeuUOsKqpYyu6w5bQfHpI5dfw5wO9E4yO?= =?us-ascii?Q?6cFpAxUwPVi0pkcZlFVSzqoaAYWcgZYIySg5NhxXtJ1s8QlQWk9wkhdM12Ln?= =?us-ascii?Q?8V+gWoRxgWKgu7xdFVTlVtb1p5Npj/sluW8iOdXDoy9bfo/Gl7vuiiHSPPik?= =?us-ascii?Q?wg2bj2nMAVcP/OPiyUzvhpHSWRmA/IahXUyPttVtAPSWbP9Z7LEUGRXm1VaG?= =?us-ascii?Q?299cwjUMlnIxLWn+4uq4JgEQP8qpE69JW1yLOLEd61ZbB/BhAbtxCkmw565f?= =?us-ascii?Q?/Fo0H9xWsdjTxjJVStZSbqJLqar3HAfWokk7Cm5jMXQuK3kys5ewbhFuAHow?= =?us-ascii?Q?iUNHHiCksQLlehh803wo7g7C3jPq7bCKAXHAghfU+UVYDz9kZaH3pL/S6S19?= =?us-ascii?Q?sYZqFsvZH+tds1DVEm5mGTfOn6PsQm0fLQzTpOFugwTyMFoFfS8VDy5rSNET?= =?us-ascii?Q?VDyBy1pWp4XjrbzTWC6LqtqAjTgq63ImU+srLJ2HCjX8DN7ujMQUHjFY+/3w?= =?us-ascii?Q?IFTwy7yu+5iW+ZXpj5vWZXDkEl1dfN17DkmDSevYccDUi/mRdYe3EO3pnvok?= =?us-ascii?Q?FhfsPBumRK/Ij4X16PSn+d7jR7YsawwVB9NZX88t/8dg1x3xBI7gJJU+XFRl?= =?us-ascii?Q?+1pkK2SHjrv1J5ZawXysJinyUz3wboSgKoytH6QPSCcgQ0dhuvdd6aPFnN/u?= =?us-ascii?Q?XnvYmiDUBQAuwqc2arS5vXUCrJgSmctrSww7jrP893UfUmdcP45LPuj2fqjv?= =?us-ascii?Q?zkEidQ6Kky6HJZOdr1U0A/4pGcLhH7+sP3VjEqBsZ4s1Et83+F1V6uAik5qe?= =?us-ascii?Q?uhUl8ZNVFPF+K6nQMPZlC0vKVNCoNEy9DRz/PE5hbPxwCZl22ySai8CGMtUC?= =?us-ascii?Q?8NKD/xPMELJuOLTvSsEKlQsRjx1m97d9Du9Ye7GTM6qupUyJarU5YhTheMTQ?= =?us-ascii?Q?JbecwNLpCREr3ujJXKQTAtAfin5ybLXCSz7wJ+8fXnkc4Y9spF5+9m7OW72d?= =?us-ascii?Q?4QKUjKqqgLKmvOv4ULW83RbjsGAWJJkOVdV6QhV1Qw0hW1ki0wjGAP0sKDZ6?= =?us-ascii?Q?nV4gdvXkGS2KngXt3ExLNDKGi+CYpH35oqsmdF37y2nokDe+YAvfl2RzqD+J?= =?us-ascii?Q?2r9pHelmDX5C/QSNf+458tWfDh2gPX4evSSfKHrVMy0se+tIhYg/gl/Cxcqb?= =?us-ascii?Q?Dalu71t5XyU7y1cn2P3bJzgUwApD/cgKPsPkBig0UXiQZY+sbDg/xcdS5tL7?= =?us-ascii?Q?F7gAzf7DgZDM7KxUSmCcAOdulKhLAC9IE/QUrdCV9hzp/EAaTuC0oq55O7FF?= =?us-ascii?Q?JBU+YpPkc9UppqEu98o+GdLbVBxp/2SxYKiYryLXVG+6f4B4WWyCkkzFlDVF?= =?us-ascii?Q?iEttAWfZBzDIlF0PxNushYMa14Bpgs9JzKtxfaiE+vvtpMGbA7WhXGvZ8OOo?= =?us-ascii?Q?vs9vDyaI4xEqiUfM4Y19xUddVgmxNktw05wwMwhlEPE5jbrGHAXNgNIvegLq?= =?us-ascii?Q?FI+sUnwWzTjV7kOYHpyNOb4h60GsoB2gK77Pa0iQQ3r+u/ytxsfU?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72a6f761-982c-48a5-ef3f-08df4e64d244 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2814.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2026 22:05:04.4870 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jPxY+aa4FlrAftITlmbRPd1dnr7Iy+ZXN83Lh7ggMoEHMixJ+qB3KlSF2xr98OGIAPHmBEtbJDzVKWhXNOwGfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR12MB9762 On Sat, Nov 28, 2026 at 08:20:10PM -0800, Andrew Morton wrote: > On Sat, 28 Nov 2026 22:01:46 -0500 Yury Norov wrote: > > > I would suggest another experiment. Let's on the system boot print a > > message like: > > > > The kernel is configured to support for up to 1024 NUMA nodes, while > > the actual number of nodes on this system is 2. This leaves 99.8% of > > the allocated resources unused. Please consider reconfiguring. > > > > We can show it, say, at 90% rate or higher, and wait until this will start > > showing up in the people's boot logs. :) > > I love it - you're a troll after my own heart. > > I guess we could try it as a standalone thing with lots of convincing > justifications. Are you able to estimate the cost of these wasted > resources? Yes, let me think about it for a few days, and I'll figure something out. > otoh, I'm sure our downstream have considered all this and have good > reasons for these configurations so we should find out what those > reasons are before adding shouty things to dmesg, I agree with Linus' comment on this. > ditto NR_CPUS? > > Who NR_CPUS > Mainline default 64 > RHEL 8192 > SUSE 8192 > Oracle UEK 8192 > Ubuntu 8192 > Debian 8192 > Fedora 8192 > AWS (Amazon Linux) 8192 > Google (COS) 512 > Microsoft (Azure Linux) 8192 > Meta unknown > Tencent (CubeSandbox) 128 > > Seems that as long as the machine gets nr_cpu_ids reasonably correct, > the main cost here is one bit/cpu in the task_struct: 1k. Which is not > insignificant. In aec6487e994d2, Ingo says each supported CPU eats ~8KB. It's 10 years old measurements, though. I'll recalculate it myself. I think, the best solution for distros would be providing whatever kernel they want (but please better than now), then once loaded build it against localmodconfig, or similar. I would like at least to have such an option. Our local{yes,mod}config doesn't trim NR_CPUS and MAX_NUMNODES to the actual values, though. The attached patch teaches it to do that. Thanks, Yury >From 44c8589f38d5eb73b0eec64fff7f3602e3ff50cd Mon Sep 17 00:00:00 2001 From: Yury Norov Date: Sun, 29 Nov 2026 16:13:32 -0500 Subject: [PATCH] kconfig: trim CPU and NUMA limits in local configuration targets localmodconfig and localyesconfig trim module selections but retain the CPU and NUMA limits inherited from their base configuration. Distribution configurations can reserve much more capacity than the local machine needs. Add a conf --localconfig option and use it from both targets. Skip topology adjustments when LSMOD is supplied, since the module list may describe another machine. Signed-off-by: Yury Norov --- Documentation/admin-guide/README.rst | 7 +- scripts/kconfig/Makefile | 8 +- scripts/kconfig/conf.c | 144 +++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/README.rst b/Documentation/admin-guide/README.rst index 77fec1de6dc8..973facd8197c 100644 --- a/Documentation/admin-guide/README.rst +++ b/Documentation/admin-guide/README.rst @@ -201,9 +201,10 @@ Configuring the kernel "make randconfig" Create a ./.config file by setting symbol values to random values. - "make localmodconfig" Create a config based on current config and - loaded modules (lsmod). Disables any module - option that is not needed for the loaded modules. + "make localmodconfig" Create a config based on current config, possible + number of CPUs and NUMA nodes, and loaded modules + (lsmod). Disables any module option that is not + needed for the loaded modules. To create a localmodconfig for another machine, store the lsmod of that machine into a file diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 5baf1c44ffa2..1f79c5bf988f 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -55,18 +55,20 @@ endef $(foreach c, config menuconfig nconfig gconfig xconfig, $(eval $(call config_rule,$(c)))) +# A supplied module list may describe another machine's topology. +localconfig-flag := $(if $(filter undefined,$(origin LSMOD)),--localconfig) + PHONY += localmodconfig localyesconfig localyesconfig localmodconfig: $(obj)/conf $(Q)$(PERL) $(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config $(Q)if [ -f .config ]; then \ - cmp -s .tmp.config .config || \ (mv -f .config .config.old.1; \ mv -f .tmp.config .config; \ - $< $(silent) --oldconfig $(Kconfig); \ + $< $(silent) $(localconfig-flag) --oldconfig $(Kconfig); \ mv -f .config.old.1 .config.old) \ else \ mv -f .tmp.config .config; \ - $< $(silent) --oldconfig $(Kconfig); \ + $< $(silent) $(localconfig-flag) --oldconfig $(Kconfig); \ fi $(Q)rm -f .tmp.config diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 31c6fd25e6ec..000e6014af58 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -636,9 +636,132 @@ static void check_conf(struct menu *menu) check_conf(child); } +static int lastnum(const unsigned char *str, size_t len) +{ + const unsigned char *start, *end = str + len; + unsigned int ret = 0, pos = 1, d; + + if (end > str && end[-1] == '\n') + end--; + + for (start = end; start > str && isdigit(start[-1]); start--, pos *= 10) { + d = start[-1] - '0'; + ret += d * pos; + } + + if (start == end || (start > str && start[-1] != ',' && start[-1] != '-')) + return -1; + + return ret; +} + +static int local_capacity(const char *path) +{ + FILE *fp; + unsigned char *buf = NULL; + size_t size = 0; + ssize_t len; + int highest = -1; + + fp = fopen(path, "r"); + if (!fp) + return 0; + + len = getline((char **)&buf, &size, fp); + if (len >= 0) + highest = lastnum(buf, len); + + free(buf); + fclose(fp); + return highest + 1; +} + +static unsigned int ceil_log2(unsigned int value) +{ + if (value <= 1) + return 0; + + return sizeof(value) * CHAR_BIT - __builtin_clz(value - 1); +} + +static void conf_local_maxnumnodes(void) +{ + struct symbol *numa, *nodes_shift; + struct property *range; + unsigned int nodes, shift; + unsigned long min; + char buf[32]; + + numa = sym_find("NUMA"); + if (!numa) + return; + + nodes = local_capacity("/sys/devices/system/node/possible"); + if (!nodes) { + fprintf(stderr, "Cannot get number of NUMA nodes\n"); + return; + } + + sym_calc_value(numa); + if (nodes == 1) { + sym_set_tristate_value(numa, no); + return; + } + + nodes_shift = sym_find("NODES_SHIFT"); + if (!nodes_shift || sym_get_tristate_value(numa) != yes) + return; + + sym_calc_value(nodes_shift); + shift = ceil_log2(nodes); + range = sym_get_range_prop(nodes_shift); + if (range) { + min = strtoul(sym_get_string_value(range->expr->left.sym), + NULL, 10); + if (shift < min) + shift = min; + } + snprintf(buf, sizeof(buf), "%u", shift); + if (!sym_set_string_value(nodes_shift, buf)) + fprintf(stderr, "Cannot set NODES_SHIFT to local capacity %u\n", shift); +} + +static void conf_local_nr_cpus(void) +{ + struct symbol *smp, *nr_cpus; + unsigned int cpus; + char buf[32]; + + smp = sym_find("SMP"); + if (!smp) + return; + + cpus = local_capacity("/sys/devices/system/cpu/possible"); + if (!cpus) { + fprintf(stderr, "Cannot get number of CPUs\n"); + return; + } + + sym_calc_value(smp); + if (cpus == 1) { + sym_set_tristate_value(smp, no); + return; + } + + nr_cpus = sym_find("NR_CPUS"); + + if (nr_cpus && sym_get_tristate_value(smp) == yes) { + sym_calc_value(nr_cpus); + snprintf(buf, sizeof(buf), "%u", cpus); + if (!sym_set_string_value(nr_cpus, buf)) + fprintf(stderr, "Cannot set NR_CPUS to local capacity %u\n", cpus); + } +} + static const struct option long_opts[] = { {"help", no_argument, NULL, 'h'}, {"silent", no_argument, NULL, 's'}, + {"localconfig", no_argument, NULL, 'l'}, {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, {"oldconfig", no_argument, &input_mode_opt, oldconfig}, {"syncconfig", no_argument, &input_mode_opt, syncconfig}, @@ -665,6 +788,7 @@ static void conf_usage(const char *progname) printf("Generic options:\n"); printf(" -h, --help Print this message and exit.\n"); printf(" -s, --silent Do not print log.\n"); + printf(" --localconfig Limit CPUs and NUMA nodes to local hardware.\n"); printf("\n"); printf("Mode options:\n"); printf(" --listnewconfig List new options\n"); @@ -696,6 +820,7 @@ int main(int ac, char **av) int opt; const char *name, *defconfig_file = NULL /* gcc uninit */; int no_conf_write = 0; + bool localconfig = false; tty_stdio = isatty(0) && isatty(1); @@ -708,6 +833,9 @@ int main(int ac, char **av) case 's': conf_set_message_callback(NULL); break; + case 'l': + localconfig = true; + break; case 0: input_mode = input_mode_opt; switch (input_mode) { @@ -805,6 +933,22 @@ int main(int ac, char **av) if (conf_errors()) exit(1); + if (localconfig) { + struct symbol *maxsmp; + + /* MAXSMP hides the CPU and node limits and forces their maxima. */ + maxsmp = sym_find("MAXSMP"); + if (maxsmp) + sym_set_tristate_value(maxsmp, no); + + /* + * Preserve the order to make sure that Kconfig doesn't reject + * disabling SMP if NUMA is still enabled. + */ + conf_local_maxnumnodes(); + conf_local_nr_cpus(); + } + if (sync_kconfig) { name = getenv("KCONFIG_NOSILENTUPDATE"); if (name && *name) { -- 2.53.0