From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DEE7311C38 for ; Tue, 23 Jun 2026 07:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782201011; cv=none; b=Ie8c+aATVf8ZW3OWB+RQPxzM86U9NjcGfvbvVOuDHnR656e6FnQGE2+x3fXcdrBdjcNHhQvIm9s3DGZt/uWO6kGk9H0M5uCGJ6QVjAnPo6lEHAHoXoM6UfKD+GxFaLQv4Nefq4obmgfg/kbrZamqcgHVlTFHl6w3JZw+Bf0p22s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782201011; c=relaxed/simple; bh=DTeW4JsjItQS5QbJsk6kISZZnm3zVJTHyeXIrMgPT/4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jrAbnwmahqGD5nfR5+fJSQ0xAVn+SBgGO6/n7LSjbYk7XC5vrKrt+kD3bTh1rhy++m0YIjVFyxDbXBiuvUhvglKwyMhSypvVUsAipvFB41fiQRB1PEQKpqmgOvVVtZb+Iw+cDcRLThg0cds+zaqePanRcx2ibYmR5T+RA3h2j1c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OPR4U6tK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OPR4U6tK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06E281F000E9; Tue, 23 Jun 2026 07:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782201010; bh=aRZgnHp3vWPKvY+OhddSqzZ6Xb2MgcroWOqVWlw/iSM=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=OPR4U6tKdwXmWBc8A9pDEZwar5IrIaNRo0eFZlmF5sh7Yll8uDpailB1OGPW/e2ba pJkVpUXosNijxf4wqTWliWYpab5dBPb+sWyE9e8MwGPs6Ejcqq/ynzmnfjqklSENPJ /yPi8PXmbMbAM1B5ie8+tWfHSHNlk28Ta5iVTFnlpqbqnAvHCzWHWNewqOyS1o1atO ReLaqZbdEjQM7N7oi5gR4Ev793oSPNyd7aoPU0GzzoQx4L+7PwCz7ay1MCMUStC/Pk eoJ5VrPy5YAb5J4PzWUeczMtIZYUYXS58IkpF+oYjDD5trjTHpX1DfjYeJUIGtu+/5 azh4kB0ilrlXQ== Message-ID: Date: Tue, 23 Jun 2026 09:50:00 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 00/13] Dynamic Kernel Stacks To: Zach O'Keefe , Thomas Gleixner Cc: Dave Hansen , "H. Peter Anvin" , David Stevens , Pasha Tatashin , Linus Walleij , Will Deacon , Quentin Perret , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Andy Lutomirski , Xin Li , Peter Zijlstra , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Uladzislau Rezki , Kees Cook , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox References: <20260424191456.2679717-1-stevensd@google.com> <6369e5ce-74e3-4c68-8053-d7d7d21b6955@zytor.com> <87pl1md7h0.ffs@fw13> <87qzm2b39k.ffs@fw13> <87mrwon5uw.ffs@fw13> From: "David Hildenbrand (Arm)" Content-Language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ZBd08ILnKcj7XKZkLU5FkoA0udEBvQ0f9QLNyyy3DZMCQWcwRuj1m73D sq8DEFBdZ5eEkj1dCyx+t/ga6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 6/23/26 01:00, Zach O'Keefe wrote: > On Sat, Jun 20, 2026 at 4:34 PM Thomas Gleixner wrote: > > Thomas, thanks for taking the time, as always, for such a thoughtful response. > >> On Sat, Jun 20 2026 at 12:33, Zach O'Keefe wrote: >>> >>> Ya, that's my concern as well, as I don't have a good intuition for >>> how perf critical kernel #PF is for real workloads. If this is your >>> primary concern, I'll take that as a _good_ thing ; i.e. there's >>> nothing architecturally stopping us from doing this downgrade safely. >>> We'll still need the analysis, but that can be a later stage -- we're >>> more than happy to get this data for all. >> >> No. That's not a later stage optional requirement. >> >> You have a PoC which works for you otherwise you wouldn't have posted >> it. So you can trivially microbenchmark the costs of the >> up/downgrade. And that's critical information for us but also for >> you. If the costs are significant then you really have to think about >> the tradeoffs. >> >> Care to read Documentation/process/* carefully? It applies to you as it >> applies to anyone else. >> >>> >>> This is actually the most understood aspect. With O(100B) active tasks >>> fleetwide at any point, it only takes an average savings of O(10KiB) >>> per task to get to 1PiB. At least for our fleet, we know the % of >>> tasks that use only 4KiB, 8KiB, or require the full 16KiB, and the >>> math confirms that we expect O(PiB) aggregate savings. The % of stacks >>> requiring the full 16KiB is minuscule, but it still occurs at a rate >>> higher than what we can tolerate for SO panics. Given the vast >>> majority of stacks never exceed the first 4KiB, this enables the >>> significant opportunity. >> >> I know that the potential savings are well understood and my >> understanding of math is sufficient to calculate how much tasks and >> average saving it takes to save 1PiB on a fleet. >> >> That's a no-brainer, but this is an aggregate saving, which sounds WOW >> but does not tell much about anything else. >> >> 1) What's the actual percentage of savings in relation to the overall >> memory? >> >> 2) Does the saving allow you to get more stuff done on a machine, pack >> more threads on it? >> >> 3) Can you actually downsize the memory on the machines? >> >> 4) What is the performance tradeoff for that? >> >> IOW, you fail to tell what the actual benefit of such an intrusive >> change is. Just boasting an aggregate Petabyte number does not tell >> anything at all. >> >> Let me give you a trivial example with a scenario which I have access >> to: >> >> 256 CPUs >> 256 GiB Memory >> 64k Threads >> >> Let's assume the full saving of 12k per thread. That sums up to >> >> 64k * 12k = 768MB of memory >> >> which is 0.29% of the total 256 GiB of memory. Not so impressive as the >> petabyte aggregate number, right? >> >> The workload consumes about 80% of the overall memory and is already >> constraint on close to 100% CPU utilization. >> >> Now let's assume that the runtime overhead of this amounts to 1% then >> this is a net loss. >> >> Let me turn that around and use a made up example assuming the 1Mio >> threads per compute unit taken from some reply in this thread. >> >> Now the full saving of 12k per thread amounts to: >> >> 1M * 12k = 12G >> >> which is 4.7% of the overall available memory. Agreed that's a >> substantial number. >> >> That 12G saving does not do anything in terms of hardware downsizing. >> >> The only way that has a benefit is when the system is constraint by >> overall memory consumption, but has quite some compute capacity left. >> >> IOW, if 1M threads hit the memory limit that means that the savings in >> kernel stack consumed memory allows you to add about 4% (~40k) more >> threads. If that ups the CPU utilization accordingly then yes, I can see >> the benefit. But TBH, if that's the case then you are trying to fix a >> user space implementation problem in the kernel. >> >> That said you really have to describe the scenarios where there is a >> benefit and I do not buy this "fleet level" argument at all because >> there is no single fleet which has a uniform workload distribution. > > These are good thoughts, thank you. Perhaps I've been too biased by > our particular environment—apologies for that. > > We (mostly) punt this problem to cluster-level scheduling, which > ironically exploits this non-uniformity of workload dynamics to > appropriately bin-pack machines and materialize these small savings. > > In the general case, I guess a lot hinges on that overhead cost -- in > the best (memory-constrained) case. > >> Aside of that. If your argument holds that there are only a few >> scenarios which require a deep stack, then we are better off to identify >> them and fix them up rather than trying to hack around the occacional >> insanity of deep stack usage by adding complexity for complexity sake. >> >> As you say that you have numbers of your fleet which confirm that the >> vast majority of the stack depth is below 4k, you can surely figure out >> the information which call chains are actually exceeding the limit. >> >> I prefer to fix such shitty code and downgrade the stacksize in general >> instead of papering over the underlying issues which probably have been >> ignored for years if not decades. >> >> Have you ever thought about that instead of adding complexity with a >> dubious value? There was some (hallway?) talk at LSF/MM about possibly removing direct reclaim, similar to how other operating systems handle it. Now, I don't know how feasible it is (I guess devil is in the detail ;) ), or any details how that would work, but direct reclaim was repeatedly called out as one of the main reasons we can get huge stacks. So I guess direct reclaim (incl. compaction) is one of the main problematic pieces. Are we aware of other scenarios where we (easily) trigger consumption of larger stacks? Wild idea: as a first step to test the waters, use smaller stacks on selected kernel threads and disallow direct reclaim/compaction if the stack for the thread is small? -- Cheers, David