* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
[not found] ` <20260211125507.4175026-2-usama.arif@linux.dev>
@ 2026-02-11 13:25 ` David Hildenbrand (Arm)
2026-02-11 13:38 ` Usama Arif
2026-02-12 12:13 ` Ritesh Harjani
0 siblings, 2 replies; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-02-11 13:25 UTC (permalink / raw)
To: Usama Arif, Andrew Morton, lorenzo.stoakes, willy, linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
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 :)
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.
So one obvious solution: remove PMD THP support for hash MMUs along with
all this hacky deposit code.
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.
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.
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
2026-02-11 13:25 ` [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time David Hildenbrand (Arm)
@ 2026-02-11 13:38 ` Usama Arif
2026-02-12 12:13 ` Ritesh Harjani
1 sibling, 0 replies; 6+ messages in thread
From: Usama Arif @ 2026-02-11 13:38 UTC (permalink / raw)
To: David Hildenbrand (Arm), Andrew Morton, lorenzo.stoakes, willy,
linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
2026-02-11 13:25 ` [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time David Hildenbrand (Arm)
2026-02-11 13:38 ` Usama Arif
@ 2026-02-12 12:13 ` Ritesh Harjani
2026-02-12 15:25 ` Usama Arif
2026-02-12 15:39 ` David Hildenbrand (Arm)
1 sibling, 2 replies; 6+ messages in thread
From: Ritesh Harjani @ 2026-02-12 12:13 UTC (permalink / raw)
To: David Hildenbrand (Arm), Usama Arif, Andrew Morton,
lorenzo.stoakes, willy, linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
"David Hildenbrand (Arm)" <david@kernel.org> writes:
> CCing ppc folks
>
Thanks David!
> 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 :)
>
Hash MMU on PowerPC works fundamentally different than other MMUs
(unlike Radix MMU on PowerPC). So yes, it requires few tricks to fit
into the Linux's multi-level SW page table model. ;)
> In particular, seeing that radix__pgtable_trans_huge_deposit() just 1:1
> copied generic pgtable_trans_huge_deposit() hurts my belly.
>
On PowerPC, pgtable_t can be a pte fragment.
typedef pte_t *pgtable_t;
That means a single page can be shared among other PTE page tables. So, we
cannot use page->lru which the generic implementation uses. I guess due
to this, there is a slight change in implementation of
radix__pgtable_trans_huge_deposit().
Doing a grep search, I think that's the same for sparc and s390 as well.
>
> IIUC, hash is mostly used on legacy power systems, radix on newer ones.
>
> So one obvious solution: remove PMD THP support for hash MMUs along with
> all this hacky deposit code.
>
Unfortunately, please no. There are real customers using Hash MMU on
Power9 and even on older generations and this would mean breaking Hash
PMD THP support for them.
>
> 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.
>
> 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.
>
Sure, I think after this patch series, the radix__pgtable_trans_huge_deposit()
will mostly be a dead code anyways. I will spend some time going
through this series and will also give it a test on powerpc HW (with
both Hash and Radix MMU).
I guess, we should also look at removing pgtable_trans_huge_deposit() and
pgtable_trans_huge_withdraw() implementations from s390 and sparc, since
those too will be dead code after this.
> 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.
>
Sure. That make sense since PowerPC Hash MMU will still need this.
-ritesh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
2026-02-12 12:13 ` Ritesh Harjani
@ 2026-02-12 15:25 ` Usama Arif
2026-02-12 15:39 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 6+ messages in thread
From: Usama Arif @ 2026-02-12 15:25 UTC (permalink / raw)
To: Ritesh Harjani (IBM), David Hildenbrand (Arm), Andrew Morton,
lorenzo.stoakes, willy, linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
On 12/02/2026 12:13, Ritesh Harjani (IBM) wrote:
> "David Hildenbrand (Arm)" <david@kernel.org> writes:
>
>> CCing ppc folks
>>
>
> Thanks David!
>
>> 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 :)
>>
>
> Hash MMU on PowerPC works fundamentally different than other MMUs
> (unlike Radix MMU on PowerPC). So yes, it requires few tricks to fit
> into the Linux's multi-level SW page table model. ;)
>
>
>> In particular, seeing that radix__pgtable_trans_huge_deposit() just 1:1
>> copied generic pgtable_trans_huge_deposit() hurts my belly.
>>
>
> On PowerPC, pgtable_t can be a pte fragment.
>
> typedef pte_t *pgtable_t;
>
> That means a single page can be shared among other PTE page tables. So, we
> cannot use page->lru which the generic implementation uses. I guess due
> to this, there is a slight change in implementation of
> radix__pgtable_trans_huge_deposit().
>
> Doing a grep search, I think that's the same for sparc and s390 as well.
>
>>
>> IIUC, hash is mostly used on legacy power systems, radix on newer ones.
>>
>> So one obvious solution: remove PMD THP support for hash MMUs along with
>> all this hacky deposit code.
>>
>
> Unfortunately, please no. There are real customers using Hash MMU on
> Power9 and even on older generations and this would mean breaking Hash
> PMD THP support for them.
>
>
Thanks for confirming! I will keep the pagetable deposit for powerpc
in the next revision.
I will rename pgtable_trans_huge_deposit to arch_pgtable_trans_huge_deposit
and move it to arch/powerpc. It will an empty function for the rest of the
architectures.
>>
>> 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.
>>
>> 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.
>>
>
> Sure, I think after this patch series, the radix__pgtable_trans_huge_deposit()
> will mostly be a dead code anyways. I will spend some time going
> through this series and will also give it a test on powerpc HW (with
> both Hash and Radix MMU).
>
> I guess, we should also look at removing pgtable_trans_huge_deposit() and
> pgtable_trans_huge_withdraw() implementations from s390 and sparc, since
> those too will be dead code after this.
>
>
>> 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.
>>
>
> Sure. That make sense since PowerPC Hash MMU will still need this.
>
> -ritesh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
2026-02-12 12:13 ` Ritesh Harjani
2026-02-12 15:25 ` Usama Arif
@ 2026-02-12 15:39 ` David Hildenbrand (Arm)
2026-02-12 16:46 ` Ritesh Harjani
1 sibling, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-02-12 15:39 UTC (permalink / raw)
To: Ritesh Harjani (IBM), Usama Arif, Andrew Morton, lorenzo.stoakes,
willy, linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
>>
>> Is there a way to remove this? It's always been a confusing hack, now
>> it's unpleasant to have around :)
>>
>
> Hash MMU on PowerPC works fundamentally different than other MMUs
> (unlike Radix MMU on PowerPC). So yes, it requires few tricks to fit
> into the Linux's multi-level SW page table model. ;)
:)
>
>> In particular, seeing that radix__pgtable_trans_huge_deposit() just 1:1
>> copied generic pgtable_trans_huge_deposit() hurts my belly.
>>
>
> On PowerPC, pgtable_t can be a pte fragment.
>
> typedef pte_t *pgtable_t;
>
> That means a single page can be shared among other PTE page tables. So, we
> cannot use page->lru which the generic implementation uses. I guess due
> to this, there is a slight change in implementation of
> radix__pgtable_trans_huge_deposit().
Ah, did not spot this difference, but makes sense. Still ugly, but make
sense. Fortunately it would go away with this RFC.
>
> Doing a grep search, I think that's the same for sparc and s390 as well.
... and I also did not realize that s390x+sparc have separate
implementations we can now get rid of as well.
>
>>
>> IIUC, hash is mostly used on legacy power systems, radix on newer ones.
>>
>> So one obvious solution: remove PMD THP support for hash MMUs along with
>> all this hacky deposit code.
>>
>
> Unfortunately, please no. There are real customers using Hash MMU on
> Power9 and even on older generations and this would mean breaking Hash
> PMD THP support for them.
>
I was expecting this answer :)
>
>>
>> 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.
>>
>> 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.
>>
>
> Sure, I think after this patch series, the radix__pgtable_trans_huge_deposit()
> will mostly be a dead code anyways. I will spend some time going
> through this series and will also give it a test on powerpc HW (with
> both Hash and Radix MMU).
Thanks! The series will grow quite a bit I think, so retesting new
revisions will be very appreciated!
>
> I guess, we should also look at removing pgtable_trans_huge_deposit() and
> pgtable_trans_huge_withdraw() implementations from s390 and sparc, since
> those too will be dead code after this.
Exactly.
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time
2026-02-12 15:39 ` David Hildenbrand (Arm)
@ 2026-02-12 16:46 ` Ritesh Harjani
0 siblings, 0 replies; 6+ messages in thread
From: Ritesh Harjani @ 2026-02-12 16:46 UTC (permalink / raw)
To: David Hildenbrand (Arm), Usama Arif, Andrew Morton,
lorenzo.stoakes, willy, linux-mm
Cc: fvdl, hannes, riel, shakeel.butt, kas, baohua, dev.jain,
baolin.wang, npache, Liam.Howlett, ryan.roberts, vbabka,
lance.yang, linux-kernel, kernel-team, Madhavan Srinivasan,
Michael Ellerman, linuxppc-dev
"David Hildenbrand (Arm)" <david@kernel.org> writes:
>
> Thanks! The series will grow quite a bit I think, so retesting new
> revisions will be very appreciated!
>
Definitely. Thanks!
-ritesh
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-02-12 17:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260211125507.4175026-1-usama.arif@linux.dev>
[not found] ` <20260211125507.4175026-2-usama.arif@linux.dev>
2026-02-11 13:25 ` [RFC 1/2] mm: thp: allocate PTE page tables lazily at split time David Hildenbrand (Arm)
2026-02-11 13:38 ` Usama Arif
2026-02-12 12:13 ` Ritesh Harjani
2026-02-12 15:25 ` Usama Arif
2026-02-12 15:39 ` David Hildenbrand (Arm)
2026-02-12 16:46 ` Ritesh Harjani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox