From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>, Guo Ren <guoren@kernel.org>,
Brian Cain <bcain@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Dinh Nguyen <dinguyen@kernel.org>,
Simon Schuster <schuster.simon@siemens-energy.com>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
Stafford Horne <shorne@gmail.com>, Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Russell King <linux@armlinux.org.uk>,
Vineet Gupta <vgupta@kernel.org>,
Michal Simek <monstr@monstr.eu>, Chris Zankel <chris@zankel.net>,
Max Filippov <jcmvbkbc@gmail.com>, Will Deacon <will@kernel.org>,
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
Nick Piggin <npiggin@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
"David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>,
Richard Henderson <richard.henderson@linaro.org>,
Matt Turner <mattst88@gmail.com>,
Magnus Lindholm <linmag7@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Helge Deller <deller@gmx.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Arnd Bergmann <arnd@arndb.de>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Shakeel Butt <shakeel.butt@linux.dev>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <rdunlap@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org,
linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-snps-arc@lists.infradead.org, linux-arch@vger.kernel.org,
sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org,
loongarch@lists.linux.dev, linux-mips@vger.kernel.org,
linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-um@lists.infradead.org,
Hugh Dickins <hughd@google.com>, Qi Zheng <qi.zheng@linux.dev>,
linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 01/12] mm/khugepaged: deposit a newly allocated page table on collapse
Date: Wed, 23 Sep 2026 10:00:54 +0100 [thread overview]
Message-ID: <arOU9k1jEMHHPEtj@gremlin> (raw)
In-Reply-To: <76b2f611-b74c-4d6d-b166-491e1cfcb9a5@kernel.org>
On Wed, Sep 23, 2026 at 10:54:07AM +0200, David Hildenbrand (Arm) wrote:
> On 9/22/26 17:35, Lorenzo Stoakes (ARM) wrote:
> > collapse_huge_page() deposits a PTE page table on PMD collapse in order
> > that it can be utilised for subsequent split operations, meaning that those
> > operations do not need to perform an allocation (as they are in a context
> > where it might be unwise).
> >
> > However the PTE page table which is deposited is the one which is currently
> > mapped by the PMD entry that is in the process of being collapsed.
> >
> > Once deposited, the PTE page table may be used in a split of any other
> > unrelated PMD entry.
> >
> > This is currently not an issue as this operation is performed with VMA/mmap
> > write lock + anon rmap locks held, so ordinary page table walkers will
> > never accidentally end up walking the wrong thing, and GUP-fast is
> > protected by an IPI via tlb_remove_table_sync_one().
> >
> > However, the series to which this commit belongs implements RCU-safe page
> > table traversal, at which point this becomes problematic.
> >
> > This can be resolved by using pte_offset_map_lock() which gates on a PTE
> > PTL and a pmd_same() check, but lockless walks are unsafe as things stand.
> >
> > Resolve this by simply allocating a new, zeroed, PTE page table to deposit
> > at the point of collapse.
> >
> > This path is already costly and an allocation has already been performed
> > for the huge folio, so this allocation is statistical noise in terms of
> > performance and memory usage at this point.
> >
> > With this PTE page table deposited, RCU-free the existing PTE page table
> > so it is safe for page table walkers to traverse within a grace period.
> >
> > This also brings this deposit case in line with all other page table
> > deposit logic which deposit a fresh page table.
> >
> > Additionally, this was the only place in the kernel that displaced a page
> > table like this, so eliminating it also helps consistency.
>
> ack
>
> >
> > An edge case for deposit exists for powerpc and its hash-based MMU - it
> > stores hash slot data in deposited page tables and zeroes them on withdraw,
> > so a zeroed deposited page table works correctly for it.
>
> I think we would have zeroed out all page table entries either way already right
> now before depositing. See clear_ptes() in
> __collapse_huge_page_copy_succeeded(). So this paragraph might just be dropped.
Yup I know, but it was there just in case people wondered about it.
But sure will drop.
>
> >
> > Since khugepaged runs as a kernel thread, do a little dance in
> > alloc_deposit_pte() to correctly charge the allocation.
> >
> > This is already done for the folio allocation via alloc_charge_folio() but
> > no such wrapper exists for a page table allocation.
> >
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > ---
> > mm/khugepaged.c | 32 ++++++++++++++++++++++++++++++--
> > 1 file changed, 30 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > index f49a6710933b..dab421f8233e 100644
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -1278,6 +1278,23 @@ static enum scan_result alloc_charge_folio(struct folio **foliop, struct mm_stru
> > return SCAN_SUCCEED;
> > }
> >
> > +static pgtable_t alloc_deposit_pte(struct mm_struct *mm)
>
> alloc_deposit_pte_table or alloc_deposit_pgtable
>
> should be clearer.
The inevitable naming nit :)
Yup agreed, I have tried to be consistent in saying 'pte page table' in commit
msg etc. to differentiate an entry so that's fair, will fix up.
>
> > +{
> > + /*
> > + * khugepaged is run from a kernel thread, so need to manually set the
> > + * correct memcg so the allocation gets charged correctly.
> > + */
> > + struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm);
> > + struct mem_cgroup *old_memcg = set_active_memcg(memcg);
> > + pgtable_t pgtable;
> > +
> > + pgtable = pte_alloc_one(mm);
> > +> + set_active_memcg(old_memcg);
>
> I'm no memcg expert but that looks good to me.
Yeah, it mirrors the pattern elsewhere.
>
> > + mem_cgroup_put(memcg);
> > + return pgtable;
> > +}
> > +
>
> With the fixup
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks!
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
WARNING: multiple messages have this Message-ID (diff)
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>, Guo Ren <guoren@kernel.org>,
Brian Cain <bcain@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Dinh Nguyen <dinguyen@kernel.org>,
Simon Schuster <schuster.simon@siemens-energy.com>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
Stafford Horne <shorne@gmail.com>, Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Russell King <linux@armlinux.org.uk>,
Vineet Gupta <vgupta@kernel.org>,
Michal Simek <monstr@monstr.eu>, Chris Zankel <chris@zankel.net>,
Max Filippov <jcmvbkbc@gmail.com>, Will Deacon <will@kernel.org>,
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
Nick Piggin <npiggin@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
"David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>,
Richard Henderson <richard.henderson@linaro.org>,
Matt Turner <mattst88@gmail.com>,
Magnus Lindholm <linmag7@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Helge Deller <deller@gmx.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Arnd Bergmann <arnd@arndb.de>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Shakeel Butt <shakeel.butt@linux.dev>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <rdunlap@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org,
linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-snps-arc@lists.infradead.org, linux-arch@vger.kernel.org,
sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org,
loongarch@lists.linux.dev, linux-mips@vger.kernel.org,
linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-um@lists.infradead.org,
Hugh Dickins <hughd@google.com>, Qi Zheng <qi.zheng@linux.dev>,
linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 01/12] mm/khugepaged: deposit a newly allocated page table on collapse
Date: Wed, 23 Sep 2026 10:00:54 +0100 [thread overview]
Message-ID: <arOU9k1jEMHHPEtj@gremlin> (raw)
In-Reply-To: <76b2f611-b74c-4d6d-b166-491e1cfcb9a5@kernel.org>
On Wed, Sep 23, 2026 at 10:54:07AM +0200, David Hildenbrand (Arm) wrote:
> On 9/22/26 17:35, Lorenzo Stoakes (ARM) wrote:
> > collapse_huge_page() deposits a PTE page table on PMD collapse in order
> > that it can be utilised for subsequent split operations, meaning that those
> > operations do not need to perform an allocation (as they are in a context
> > where it might be unwise).
> >
> > However the PTE page table which is deposited is the one which is currently
> > mapped by the PMD entry that is in the process of being collapsed.
> >
> > Once deposited, the PTE page table may be used in a split of any other
> > unrelated PMD entry.
> >
> > This is currently not an issue as this operation is performed with VMA/mmap
> > write lock + anon rmap locks held, so ordinary page table walkers will
> > never accidentally end up walking the wrong thing, and GUP-fast is
> > protected by an IPI via tlb_remove_table_sync_one().
> >
> > However, the series to which this commit belongs implements RCU-safe page
> > table traversal, at which point this becomes problematic.
> >
> > This can be resolved by using pte_offset_map_lock() which gates on a PTE
> > PTL and a pmd_same() check, but lockless walks are unsafe as things stand.
> >
> > Resolve this by simply allocating a new, zeroed, PTE page table to deposit
> > at the point of collapse.
> >
> > This path is already costly and an allocation has already been performed
> > for the huge folio, so this allocation is statistical noise in terms of
> > performance and memory usage at this point.
> >
> > With this PTE page table deposited, RCU-free the existing PTE page table
> > so it is safe for page table walkers to traverse within a grace period.
> >
> > This also brings this deposit case in line with all other page table
> > deposit logic which deposit a fresh page table.
> >
> > Additionally, this was the only place in the kernel that displaced a page
> > table like this, so eliminating it also helps consistency.
>
> ack
>
> >
> > An edge case for deposit exists for powerpc and its hash-based MMU - it
> > stores hash slot data in deposited page tables and zeroes them on withdraw,
> > so a zeroed deposited page table works correctly for it.
>
> I think we would have zeroed out all page table entries either way already right
> now before depositing. See clear_ptes() in
> __collapse_huge_page_copy_succeeded(). So this paragraph might just be dropped.
Yup I know, but it was there just in case people wondered about it.
But sure will drop.
>
> >
> > Since khugepaged runs as a kernel thread, do a little dance in
> > alloc_deposit_pte() to correctly charge the allocation.
> >
> > This is already done for the folio allocation via alloc_charge_folio() but
> > no such wrapper exists for a page table allocation.
> >
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > ---
> > mm/khugepaged.c | 32 ++++++++++++++++++++++++++++++--
> > 1 file changed, 30 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > index f49a6710933b..dab421f8233e 100644
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -1278,6 +1278,23 @@ static enum scan_result alloc_charge_folio(struct folio **foliop, struct mm_stru
> > return SCAN_SUCCEED;
> > }
> >
> > +static pgtable_t alloc_deposit_pte(struct mm_struct *mm)
>
> alloc_deposit_pte_table or alloc_deposit_pgtable
>
> should be clearer.
The inevitable naming nit :)
Yup agreed, I have tried to be consistent in saying 'pte page table' in commit
msg etc. to differentiate an entry so that's fair, will fix up.
>
> > +{
> > + /*
> > + * khugepaged is run from a kernel thread, so need to manually set the
> > + * correct memcg so the allocation gets charged correctly.
> > + */
> > + struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm);
> > + struct mem_cgroup *old_memcg = set_active_memcg(memcg);
> > + pgtable_t pgtable;
> > +
> > + pgtable = pte_alloc_one(mm);
> > +> + set_active_memcg(old_memcg);
>
> I'm no memcg expert but that looks good to me.
Yeah, it mirrors the pattern elsewhere.
>
> > + mem_cgroup_put(memcg);
> > + return pgtable;
> > +}
> > +
>
> With the fixup
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks!
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc
WARNING: multiple messages have this Message-ID (diff)
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Liam R. Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>, Guo Ren <guoren@kernel.org>,
Brian Cain <bcain@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Dinh Nguyen <dinguyen@kernel.org>,
Simon Schuster <schuster.simon@siemens-energy.com>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
Stafford Horne <shorne@gmail.com>, Rich Felker <dalias@libc.org>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Russell King <linux@armlinux.org.uk>,
Vineet Gupta <vgupta@kernel.org>,
Michal Simek <monstr@monstr.eu>, Chris Zankel <chris@zankel.net>,
Max Filippov <jcmvbkbc@gmail.com>, Will Deacon <will@kernel.org>,
"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
Nick Piggin <npiggin@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
"David S. Miller" <davem@davemloft.net>,
Andreas Larsson <andreas@gaisler.com>,
Richard Henderson <richard.henderson@linaro.org>,
Matt Turner <mattst88@gmail.com>,
Magnus Lindholm <linmag7@gmail.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Helge Deller <deller@gmx.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Arnd Bergmann <arnd@arndb.de>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Jason Gunthorpe <jgg@ziepe.ca>,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
Yoshinori Sato <ysato@users.sourceforge.jp>,
Shakeel Butt <shakeel.butt@linux.dev>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <rdunlap@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org,
linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-snps-arc@lists.infradead.org, linux-arch@vger.kernel.org,
sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org,
loongarch@lists.linux.dev, linux-mips@vger.kernel.org,
linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-um@lists.infradead.org,
Hugh Dickins <hughd@google.com>, Qi Zheng <qi.zheng@linux.dev>,
linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 01/12] mm/khugepaged: deposit a newly allocated page table on collapse
Date: Wed, 23 Sep 2026 10:00:54 +0100 [thread overview]
Message-ID: <arOU9k1jEMHHPEtj@gremlin> (raw)
In-Reply-To: <76b2f611-b74c-4d6d-b166-491e1cfcb9a5@kernel.org>
On Wed, Sep 23, 2026 at 10:54:07AM +0200, David Hildenbrand (Arm) wrote:
> On 9/22/26 17:35, Lorenzo Stoakes (ARM) wrote:
> > collapse_huge_page() deposits a PTE page table on PMD collapse in order
> > that it can be utilised for subsequent split operations, meaning that those
> > operations do not need to perform an allocation (as they are in a context
> > where it might be unwise).
> >
> > However the PTE page table which is deposited is the one which is currently
> > mapped by the PMD entry that is in the process of being collapsed.
> >
> > Once deposited, the PTE page table may be used in a split of any other
> > unrelated PMD entry.
> >
> > This is currently not an issue as this operation is performed with VMA/mmap
> > write lock + anon rmap locks held, so ordinary page table walkers will
> > never accidentally end up walking the wrong thing, and GUP-fast is
> > protected by an IPI via tlb_remove_table_sync_one().
> >
> > However, the series to which this commit belongs implements RCU-safe page
> > table traversal, at which point this becomes problematic.
> >
> > This can be resolved by using pte_offset_map_lock() which gates on a PTE
> > PTL and a pmd_same() check, but lockless walks are unsafe as things stand.
> >
> > Resolve this by simply allocating a new, zeroed, PTE page table to deposit
> > at the point of collapse.
> >
> > This path is already costly and an allocation has already been performed
> > for the huge folio, so this allocation is statistical noise in terms of
> > performance and memory usage at this point.
> >
> > With this PTE page table deposited, RCU-free the existing PTE page table
> > so it is safe for page table walkers to traverse within a grace period.
> >
> > This also brings this deposit case in line with all other page table
> > deposit logic which deposit a fresh page table.
> >
> > Additionally, this was the only place in the kernel that displaced a page
> > table like this, so eliminating it also helps consistency.
>
> ack
>
> >
> > An edge case for deposit exists for powerpc and its hash-based MMU - it
> > stores hash slot data in deposited page tables and zeroes them on withdraw,
> > so a zeroed deposited page table works correctly for it.
>
> I think we would have zeroed out all page table entries either way already right
> now before depositing. See clear_ptes() in
> __collapse_huge_page_copy_succeeded(). So this paragraph might just be dropped.
Yup I know, but it was there just in case people wondered about it.
But sure will drop.
>
> >
> > Since khugepaged runs as a kernel thread, do a little dance in
> > alloc_deposit_pte() to correctly charge the allocation.
> >
> > This is already done for the folio allocation via alloc_charge_folio() but
> > no such wrapper exists for a page table allocation.
> >
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > ---
> > mm/khugepaged.c | 32 ++++++++++++++++++++++++++++++--
> > 1 file changed, 30 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > index f49a6710933b..dab421f8233e 100644
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -1278,6 +1278,23 @@ static enum scan_result alloc_charge_folio(struct folio **foliop, struct mm_stru
> > return SCAN_SUCCEED;
> > }
> >
> > +static pgtable_t alloc_deposit_pte(struct mm_struct *mm)
>
> alloc_deposit_pte_table or alloc_deposit_pgtable
>
> should be clearer.
The inevitable naming nit :)
Yup agreed, I have tried to be consistent in saying 'pte page table' in commit
msg etc. to differentiate an entry so that's fair, will fix up.
>
> > +{
> > + /*
> > + * khugepaged is run from a kernel thread, so need to manually set the
> > + * correct memcg so the allocation gets charged correctly.
> > + */
> > + struct mem_cgroup *memcg = get_mem_cgroup_from_mm(mm);
> > + struct mem_cgroup *old_memcg = set_active_memcg(memcg);
> > + pgtable_t pgtable;
> > +
> > + pgtable = pte_alloc_one(mm);
> > +> + set_active_memcg(old_memcg);
>
> I'm no memcg expert but that looks good to me.
Yeah, it mirrors the pattern elsewhere.
>
> > + mem_cgroup_put(memcg);
> > + return pgtable;
> > +}
> > +
>
> With the fixup
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks!
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-09-23 9:01 UTC|newest]
Thread overview: 188+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 15:35 [PATCH v4 00/12] mm: make userland page table freeing RCU-safe Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 01/12] mm/khugepaged: deposit a newly allocated page table on collapse Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:54 ` sashiko-bot
2026-09-23 2:24 ` Lance Yang
2026-09-23 2:24 ` Lance Yang
2026-09-23 2:24 ` Lance Yang
2026-09-23 7:09 ` Lorenzo Stoakes (ARM)
2026-09-23 7:09 ` Lorenzo Stoakes (ARM)
2026-09-23 7:09 ` Lorenzo Stoakes (ARM)
2026-09-23 7:14 ` Lorenzo Stoakes (ARM)
2026-09-23 7:14 ` Lorenzo Stoakes (ARM)
2026-09-23 7:14 ` Lorenzo Stoakes (ARM)
2026-09-23 7:24 ` Lance Yang
2026-09-23 7:24 ` Lance Yang
2026-09-23 7:24 ` Lance Yang
2026-09-23 19:53 ` Andrew Morton
2026-09-23 19:53 ` Andrew Morton
2026-09-23 19:53 ` Andrew Morton
2026-09-24 3:28 ` Baolin Wang
2026-09-24 3:28 ` Baolin Wang
2026-09-24 3:28 ` Baolin Wang
2026-09-23 8:54 ` David Hildenbrand (Arm)
2026-09-23 8:54 ` David Hildenbrand (Arm)
2026-09-23 8:54 ` David Hildenbrand (Arm)
2026-09-23 9:00 ` Lorenzo Stoakes (ARM) [this message]
2026-09-23 9:00 ` Lorenzo Stoakes (ARM)
2026-09-23 9:00 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 02/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for most 2-level architectures Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:56 ` sashiko-bot
2026-09-23 4:39 ` Lance Yang
2026-09-23 4:39 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 03/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for MMU riscv Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:45 ` sashiko-bot
2026-09-23 6:15 ` Lance Yang
2026-09-23 6:15 ` Lance Yang
2026-09-23 6:15 ` Lance Yang
2026-09-23 7:05 ` Lorenzo Stoakes (ARM)
2026-09-23 7:05 ` Lorenzo Stoakes (ARM)
2026-09-23 7:05 ` Lorenzo Stoakes (ARM)
2026-09-23 7:17 ` Lance Yang
2026-09-23 7:17 ` Lance Yang
2026-09-23 7:17 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 04/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for MMU arm Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:50 ` sashiko-bot
2026-09-23 8:05 ` Lance Yang
2026-09-23 8:05 ` Lance Yang
2026-09-23 8:05 ` Lance Yang
2026-09-23 8:15 ` Lorenzo Stoakes (ARM)
2026-09-23 8:15 ` Lorenzo Stoakes (ARM)
2026-09-23 8:15 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 05/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for arc, microblaze, xtensa Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:48 ` sashiko-bot
2026-09-23 8:43 ` Lance Yang
2026-09-23 8:43 ` Lance Yang
2026-09-23 8:43 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 06/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc64 Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:47 ` sashiko-bot
2026-09-23 8:54 ` Lance Yang
2026-09-23 8:54 ` Lance Yang
2026-09-23 8:54 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 07/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for m68k-coldfire Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:48 ` sashiko-bot
2026-09-23 9:13 ` Lance Yang
2026-09-23 9:13 ` Lance Yang
2026-09-23 9:13 ` Lance Yang
2026-09-23 11:31 ` Greg Ungerer
2026-09-23 11:31 ` Greg Ungerer
2026-09-23 11:31 ` Greg Ungerer
2026-09-23 11:36 ` Lorenzo Stoakes (ARM)
2026-09-23 11:36 ` Lorenzo Stoakes (ARM)
2026-09-23 11:36 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 08/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sh-X2 Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:49 ` sashiko-bot
2026-09-23 11:54 ` Lance Yang
2026-09-23 11:54 ` Lance Yang
2026-09-23 11:54 ` Lance Yang
2026-09-23 11:56 ` Lorenzo Stoakes (ARM)
2026-09-23 11:56 ` Lorenzo Stoakes (ARM)
2026-09-23 11:56 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 09/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for m68k-motorola Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:52 ` sashiko-bot
2026-09-23 13:16 ` Lance Yang
2026-09-23 13:16 ` Lance Yang
2026-09-23 13:16 ` Lance Yang
2026-09-23 13:21 ` Lorenzo Stoakes (ARM)
2026-09-23 13:21 ` Lorenzo Stoakes (ARM)
2026-09-23 13:21 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` [PATCH v4 10/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc32 Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:55 ` sashiko-bot
2026-09-24 2:41 ` Lance Yang
2026-09-24 2:41 ` Lance Yang
2026-09-24 2:41 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 11/12] mm: make userland page table freeing RCU-safe Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 16:01 ` sashiko-bot
2026-09-23 9:04 ` David Hildenbrand (Arm)
2026-09-23 9:04 ` David Hildenbrand (Arm)
2026-09-23 9:04 ` David Hildenbrand (Arm)
2026-09-23 9:06 ` Lorenzo Stoakes (ARM)
2026-09-23 9:06 ` Lorenzo Stoakes (ARM)
2026-09-23 9:06 ` Lorenzo Stoakes (ARM)
2026-09-23 9:13 ` David Hildenbrand (Arm)
2026-09-23 9:13 ` David Hildenbrand (Arm)
2026-09-23 9:13 ` David Hildenbrand (Arm)
2026-09-23 11:48 ` Lorenzo Stoakes (ARM)
2026-09-23 11:48 ` Lorenzo Stoakes (ARM)
2026-09-23 11:48 ` Lorenzo Stoakes (ARM)
2026-09-23 13:38 ` David Hildenbrand (Arm)
2026-09-23 13:38 ` David Hildenbrand (Arm)
2026-09-23 13:38 ` David Hildenbrand (Arm)
2026-09-23 13:43 ` Lorenzo Stoakes (ARM)
2026-09-23 13:43 ` Lorenzo Stoakes (ARM)
2026-09-23 13:43 ` Lorenzo Stoakes (ARM)
2026-09-24 2:55 ` Lance Yang
2026-09-24 2:55 ` Lance Yang
2026-09-24 2:55 ` Lance Yang
2026-09-22 15:35 ` [PATCH v4 12/12] mm: change the contract for free_pgtables(), update docs Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:35 ` Lorenzo Stoakes (ARM)
2026-09-22 15:49 ` sashiko-bot
2026-09-23 9:08 ` David Hildenbrand (Arm)
2026-09-23 9:08 ` David Hildenbrand (Arm)
2026-09-23 9:08 ` David Hildenbrand (Arm)
2026-09-23 11:55 ` Lorenzo Stoakes (ARM)
2026-09-23 11:55 ` Lorenzo Stoakes (ARM)
2026-09-23 11:55 ` Lorenzo Stoakes (ARM)
2026-09-24 3:26 ` Lance Yang
2026-09-24 3:26 ` Lance Yang
2026-09-24 3:26 ` Lance Yang
2026-09-24 7:54 ` Lorenzo Stoakes (ARM)
2026-09-24 7:54 ` Lorenzo Stoakes (ARM)
2026-09-24 7:54 ` Lorenzo Stoakes (ARM)
2026-09-22 16:42 ` [PATCH v4 00/12] mm: make userland page table freeing RCU-safe Matthew Wilcox
2026-09-22 16:42 ` Matthew Wilcox
2026-09-22 16:42 ` Matthew Wilcox
2026-09-22 17:22 ` Lorenzo Stoakes (ARM)
2026-09-22 17:22 ` Lorenzo Stoakes (ARM)
2026-09-22 17:22 ` Lorenzo Stoakes (ARM)
2026-09-22 23:00 ` Andrew Morton
2026-09-22 23:00 ` Andrew Morton
2026-09-22 23:00 ` Andrew Morton
2026-09-23 7:04 ` Lorenzo Stoakes (ARM)
2026-09-23 7:04 ` Lorenzo Stoakes (ARM)
2026-09-23 7:04 ` Lorenzo Stoakes (ARM)
2026-09-23 20:01 ` Andrew Morton
2026-09-23 20:01 ` Andrew Morton
2026-09-23 20:01 ` Andrew Morton
2026-09-23 8:45 ` David Hildenbrand (Arm)
2026-09-23 8:45 ` David Hildenbrand (Arm)
2026-09-23 8:45 ` David Hildenbrand (Arm)
2026-09-23 9:04 ` Lorenzo Stoakes (ARM)
2026-09-23 9:04 ` Lorenzo Stoakes (ARM)
2026-09-23 9:04 ` Lorenzo Stoakes (ARM)
2026-09-23 9:15 ` David Hildenbrand (Arm)
2026-09-23 9:15 ` David Hildenbrand (Arm)
2026-09-23 9:15 ` David Hildenbrand (Arm)
2026-09-23 9:39 ` Vlastimil Babka (SUSE)
2026-09-23 9:39 ` Vlastimil Babka (SUSE)
2026-09-23 9:39 ` Vlastimil Babka (SUSE)
2026-09-23 11:39 ` Lorenzo Stoakes (ARM)
2026-09-23 11:39 ` Lorenzo Stoakes (ARM)
2026-09-23 11:39 ` Lorenzo Stoakes (ARM)
2026-09-23 19:59 ` Andrew Morton
2026-09-23 19:59 ` Andrew Morton
2026-09-23 19:59 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=arOU9k1jEMHHPEtj@gremlin \
--to=ljs@kernel.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=andreas@gaisler.com \
--cc=aneesh.kumar@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=aou@eecs.berkeley.edu \
--cc=arnd@arndb.de \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bcain@kernel.org \
--cc=borntraeger@linux.ibm.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=chleroy@kernel.org \
--cc=chris@zankel.net \
--cc=corbet@lwn.net \
--cc=dalias@libc.org \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=david@kernel.org \
--cc=deller@gmx.de \
--cc=dev.jain@arm.com \
--cc=dinguyen@kernel.org \
--cc=geert@linux-m68k.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=gor@linux.ibm.com \
--cc=guoren@kernel.org \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=hughd@google.com \
--cc=jcmvbkbc@gmail.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=johannes@sipsolutions.net \
--cc=jonas@southpole.se \
--cc=kas@kernel.org \
--cc=kernel@xen0n.name \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linmag7@gmail.com \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-um@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=loongarch@lists.linux.dev \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=mattst88@gmail.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=monstr@monstr.eu \
--cc=mpe@ellerman.id.au \
--cc=nico.pache@linux.dev \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=rdunlap@infradead.org \
--cc=richard.henderson@linaro.org \
--cc=richard@nod.at \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=schuster.simon@siemens-energy.com \
--cc=shakeel.butt@linux.dev \
--cc=shorne@gmail.com \
--cc=sparclinux@vger.kernel.org \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=surenb@google.com \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=vgupta@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=ysato@users.sourceforge.jp \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.