From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 676CBECD6E9 for ; Wed, 11 Feb 2026 21:39:39 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fBBfK3bR5z2xHX; Thu, 12 Feb 2026 08:39:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1770817554; cv=none; b=HLNb7N5aW8fMiyKFieVEkPiLD01hDcKN0Ha8ciC74C/sEsf1A+ADivppMosPp15DFwM6Jk71C+4/I3IN2jEHRsHoe4PO6i9eg8uDWyzHdWXEaSCa4kHog8/xtlEz5/kSBXBjzoSEjex7qn6cp7cGSxyBugsr4SMxVdsBlQAR+OrFC9L6gtuh/r+1yvfuhualCFfcHOer+l5v85hepMjof6UCwvgCxKbymNFk1UJheOWhBowlMyUnn9R/WbhI8wYMP6uBqafTY8MhpYF+vq2c5ZzPfwNn5X+apt6C59FUkUR6PjFFQZRX8O+NQYimcQN/GggJHl5BfsESo6aH7Pvyjw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1770817554; c=relaxed/relaxed; bh=AvbV/7yBLNX8l/Q3y3FXi6sUQ6jYM1ujaQvV+NINbwk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ortbRWqs+VcFXJAR2ddmAM77QURumQQlbYRAJiIADIGhIZeO0Tj1T1Ah5afjMn2Vi7S2Z823RtGxYvnxJQX9B4kqEsXCtvqP2mrasz3Sr4/MezBCCKkuNVb2n6NKOGLaNtEU+5tEGS8Gra1v0IcWiK94ceAiH2GwAL6IcjD79rZ3r9OYcTHBjc14FVO9jXy8mqAqlyc2Yw4mSIAurYoo76ShllDkMAHLT86R02VWYqKUQbt3B1zKZpe9COS6BYwiAr2h42S3hpRa2Pb74Yc7HFEo/1e/l+ZlgAx5++1zLsitYDGhihXyswxtMQ4AnOwJaeQaYDwUj+eRWuBBXF7+ag== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=KTkCq28T; dkim-atps=neutral; spf=pass (client-ip=95.215.58.177; helo=out-177.mta1.migadu.com; envelope-from=usama.arif@linux.dev; receiver=lists.ozlabs.org) smtp.mailfrom=linux.dev Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=KTkCq28T; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.dev (client-ip=95.215.58.177; helo=out-177.mta1.migadu.com; envelope-from=usama.arif@linux.dev; receiver=lists.ozlabs.org) X-Greylist: delayed 428 seconds by postgrey-1.37 at boromir; Thu, 12 Feb 2026 00:45:50 AEDT Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fB07f6j7dz2xlM for ; Thu, 12 Feb 2026 00:45:50 +1100 (AEDT) Message-ID: <735c0277-2155-47f5-a650-b4c8a0a2e6fc@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770817101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AvbV/7yBLNX8l/Q3y3FXi6sUQ6jYM1ujaQvV+NINbwk=; b=KTkCq28TEAtcHJtPGFZ/oKU8vD4gE8s1v/eM0FDHslaVRDzQDOvgbM71iCr6Pzgy+Spxsz evXRXBoMAsjI/Ec6zEqMkgSSphZQpvv9wrKwI5q/izSGw5wgkZUgK6soksEZU9HWq9rx3W FPXHMoVaAFe+ylRDS4SuNauNPCVGj+I= Date: Wed, 11 Feb 2026 13:38:17 +0000 X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Subject: Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time Content-Language: en-GB To: "David Hildenbrand (Arm)" , Andrew Morton , lorenzo.stoakes@oracle.com, willy@infradead.org, linux-mm@kvack.org Cc: fvdl@google.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, vbabka@suse.cz, lance.yang@linux.dev, linux-kernel@vger.kernel.org, kernel-team@meta.com, Madhavan Srinivasan , Michael Ellerman , linuxppc-dev@lists.ozlabs.org References: <20260211125507.4175026-1-usama.arif@linux.dev> <20260211125507.4175026-2-usama.arif@linux.dev> <13ab56cb-7fdb-4ee4-9170-f9f4fa4b6e37@kernel.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: <13ab56cb-7fdb-4ee4-9170-f9f4fa4b6e37@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 11/02/2026 13:25, David Hildenbrand (Arm) wrote: > CCing ppc folks > > On 2/11/26 13:49, Usama Arif wrote: >> When the kernel creates a PMD-level THP mapping for anonymous pages, >> it pre-allocates a PTE page table and deposits it via >> pgtable_trans_huge_deposit(). This deposited table is withdrawn during >> PMD split or zap. The rationale was that split must not fail—if the >> kernel decides to split a THP, it needs a PTE table to populate. >> >> However, every anon THP wastes 4KB (one page table page) that sits >> unused in the deposit list for the lifetime of the mapping. On systems >> with many THPs, this adds up to significant memory waste. The original >> rationale is also not an issue. It is ok for split to fail, and if the >> kernel can't find an order 0 allocation for split, there are much bigger >> problems. On large servers where you can easily have 100s of GBs of THPs, >> the memory usage for these tables is 200M per 100G. This memory could be >> used for any other usecase, which include allocating the pagetables >> required during split. >> >> This patch removes the pre-deposit for anonymous pages on architectures >> where arch_needs_pgtable_deposit() returns false (every arch apart from >> powerpc, and only when radix hash tables are not enabled) and allocates >> the PTE table lazily—only when a split actually occurs. The split path >> is modified to accept a caller-provided page table. >> >> PowerPC exception: >> >> It would have been great if we can completely remove the pagetable >> deposit code and this commit would mostly have been a code cleanup patch, >> unfortunately PowerPC has hash MMU, it stores hash slot information in >> the deposited page table and pre-deposit is necessary. All deposit/ >> withdraw paths are guarded by arch_needs_pgtable_deposit(), so PowerPC >> behavior is unchanged with this patch. On a better note, >> arch_needs_pgtable_deposit will always evaluate to false at compile time >> on non PowerPC architectures and the pre-deposit code will not be >> compiled in. > > Is there a way to remove this? It's always been a confusing hack, now it's unpleasant to have around :) I spent some time researching this (I havent worked with PowerPC before) as I really wanted to get rid of all the pre-deposit code. I cant really see a way without removing PMD THP support. I was going to CC the PowerPC maintainers but I see that you already did! > > In particular, seeing that radix__pgtable_trans_huge_deposit() just 1:1 copied generic pgtable_trans_huge_deposit() hurts my belly. > > > IIUC, hash is mostly used on legacy power systems, radix on newer ones. > Yes that is what I found as well. > So one obvious solution: remove PMD THP support for hash MMUs along with all this hacky deposit code. > I would be happy with that! > > the "vma_is_anonymous(vma) && !arch_needs_pgtable_deposit()" and similar checks need to be wrapped in a reasonable helper and likely this all needs to get cleaned up further. Ack. The code will definitely look a lot lot cleaner and wont have much of this if we decide to remove PMD THP support for hash MMU. > > The implementation if the generic pgtable_trans_huge_deposit and the radix handlers etc must be removed. If any code would trigger them it would be a bug. > > If we have to keep this around, pgtable_trans_huge_deposit() should likely get renamed to arch_pgtable_trans_huge_deposit() etc, as there will not be generic support for it. > Ack.