mm: only set fault addrsss' access bit in do_anonymous_page
Subsystems (2)
RFC PATCH 1/1 mm: only set fault addrsss' access bit in do_anonymous_page
When do_anonymous_page() creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.
This causes an issue where the Referenced field in /proc/pid/smaps cannot distinguish whether a page was actually accessed.
So here introduces a new interface, set_anon_ptes(), which only sets the access bit for the PTE corresponding to the faulting address. This allows accurate tracking of page access status in /proc/pid/smaps before memory reclaim scan the folios.
During memory reclaim: folio_referenced() checks and clears the access bits of PTEs, rmap verifies all PTEs under a folio. If any PTE mapped subpage of folio has access bit set, the folio is retained during reclaim. So only set the access bit for the faulting PTE in do_anonymous_page() is safe, as it does not interfere with reclaim decisions.
The patch only supports architectures without custom set_ptes() implementations (e.g., x86). ARM64 and other architectures are not yet supported.
Additionally, I have some questions regarding the contiguous page tables for 64K huge pages on the ARM64 architecture.
'commit 4602e5757bcc ("arm64/mm: wire up PTE_CONT for user mappings")' described as following:
Quoted 4 lines
Since a contpte block only has a single access and dirty bit, the semantic here changes slightly; when getting a pte (e.g.
ptep_get()) that is part of a contpte mapping, the access and dirty information are pulled from the block (so all ptes in the block return the same access/dirty info).
While the ARM64 manual states:
Quoted 3 lines
If hardware updates a translation table entry, and if the Contiguous bit in that entry is 1, then the members in a group of contiguous translation table entries can have different AF, AP[2], and S2AP[1] values.
Does this mean the 16 PTEs are not necessary to share same AF for ARM?
Currently, for ARM64 huge pages with contiguous page tables enabled, the access and dirty bits for 64K huge pages are actually folded in software.
However, I haven't found whether these access and dirty bits affect the TLB coalescing of contiguous page tables. If they do not affect it, I think ARM64 can also set the access bit only for the PTE corresponding to the actual fault address in do_anonymous_page().
--- include/linux/pgtable.h | 28 ++++++++++++++++++++++++++++ mm/memory.c | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-)
include/linux/pgtable.h +28 -0
@@ -302,6 +302,34 @@ static inline void set_ptes(struct mm_struct *mm, unsigned long addr,#endif #define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) +#ifndef set_ptes +static inline void set_anon_ptes (struct mm_struct *mm,unsigned long addr, +unsigned long fault_addr,pte_t *ptep,pte_t pte,unsigned int nr) +{ +bool young =pte_young (pte); + +page_table_check_ptes_set (mm, ptep, pte, nr); + +for (;;) { +if (young && addr == fault_addr) + pte =pte_mkyoung (pte); +else + pte =pte_mkold (pte); + +set_pte (ptep, pte); +if (--nr ==0 ) +break ; + + addr +=PAGE_SIZE ; + ptep++; + pte =pte_next_pfn (pte); + } +} +#else +#define set_anon_ptes (mm, addr, fault_addr, ptep, pte, nr) \ + set_ptes(mm, addr, ptep, pte, nr) +#endif +#ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address, pte_t *ptep,
mm/memory.c +1 -1
@@ -5273,7 +5273,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) setpte:if (vmf_orig_pte_uffd_wp (vmf)) entry =pte_mkuffd_wp (entry); -set_ptes (vma->vm_mm, addr, vmf->pte, entry, nr_pages); +set_anon_ptes (vma->vm_mm, addr, vmf->address, vmf->pte, entry, nr_pages);/* No need to invalidate - it was non-present before */ update_mmu_cache_range (vmf, vma, addr, vmf->pte, nr_pages);
Signature · 1 line
2.45.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Wenchao,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Wenchao-Hao/mm-only-set-fault-addrsss-access-bit-in-do_anonymous_page/20260210-123706 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20260210043456.2137482-1-haowenchao22%40gmail.com patch subject: [RFC PATCH] mm: only set fault addrsss' access bit in do_anonymous_page config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20260210/[email protected]/config) compiler: or1k-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260210/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/mm.h:32,
from include/linux/pid_namespace.h:7, from include/linux/ptrace.h:10, from arch/openrisc/kernel/asm-offsets.c:29:
include/linux/pgtable.h: In function 'set_anon_ptes':
>> include/linux/pgtable.h:432:39: error: passing argument 2 of 'page_table_check_ptes_set' makes integer from pointer without a cast [-Wint-conversion]
432 | page_table_check_ptes_set(mm, ptep, pte, nr);
| ^~~~
| |
| pte_t *
In file included from include/linux/pgtable.h:18:
include/linux/page_table_check.h:140:60: note: expected 'long unsigned int' but argument is of type 'pte_t *'
140 | unsigned long addr, pte_t *ptep,
| ~~~~~~~~~~~~~~^~~~
>> include/linux/pgtable.h:432:45: error: incompatible type for argument 3 of 'page_table_check_ptes_set'
432 | page_table_check_ptes_set(mm, ptep, pte, nr);
| ^~~
| |
| pte_t
include/linux/page_table_check.h:140:73: note: expected 'pte_t *' but argument is of type 'pte_t'
140 | unsigned long addr, pte_t *ptep,
| ~~~~~~~^~~~
include/linux/pgtable.h:432:50: error: incompatible type for argument 4 of 'page_table_check_ptes_set'
432 | page_table_check_ptes_set(mm, ptep, pte, nr);
| ^~
| |
| unsigned int
include/linux/page_table_check.h:141:52: note: expected 'pte_t' but argument is of type 'unsigned int'
141 | pte_t pte, unsigned int nr)
| ~~~~~~^~~
>> include/linux/pgtable.h:432:9: error: too few arguments to function 'page_table_check_ptes_set'; expected 5, have 4
432 | page_table_check_ptes_set(mm, ptep, pte, nr);
| ^~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/page_table_check.h:139:20: note: declared here
139 | static inline void page_table_check_ptes_set(struct mm_struct *mm,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
make[3]: *** [scripts/Makefile.build:182: arch/openrisc/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [Makefile:1314: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/page_table_check_ptes_set +432 include/linux/pgtable.h
425
426 #ifndef set_ptes
427 static inline void set_anon_ptes(struct mm_struct *mm, unsigned long addr,
428 unsigned long fault_addr, pte_t *ptep, pte_t pte, unsigned int nr)
429 {
430 bool young = pte_young(pte);
431
> 432 page_table_check_ptes_set(mm, ptep, pte, nr);
433
434 for (;;) {
435 if (young && addr == fault_addr)
436 pte = pte_mkyoung(pte);
437 else
438 pte = pte_mkold(pte);
439
440 set_pte(ptep, pte);
441 if (--nr == 0)
442 break;
443
444 addr += PAGE_SIZE;
445 ptep++;
446 pte = pte_next_pfn(pte);
447 }
448 }
449 #else
450 #define set_anon_ptes(mm, addr, fault_addr, ptep, pte, nr) \
451 set_ptes(mm, addr, ptep, pte, nr)
452 #endif
453
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Wenchao,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Wenchao-Hao/mm-only-set-fault-addrsss-access-bit-in-do_anonymous_page/20260210-123706 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20260210043456.2137482-1-haowenchao22%40gmail.com patch subject: [RFC PATCH] mm: only set fault addrsss' access bit in do_anonymous_page config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260210/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260210/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from arch/x86/kernel/asm-offsets.c:14:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:21:
In file included from include/linux/mm.h:32:
>> include/linux/pgtable.h:432:45: error: too few arguments to function call, expected 5, have 4
432 | page_table_check_ptes_set(mm, ptep, pte, nr);
| ~~~~~~~~~~~~~~~~~~~~~~~~~ ^
include/linux/page_table_check.h:139:20: note: 'page_table_check_ptes_set' declared here
139 | static inline void page_table_check_ptes_set(struct mm_struct *mm,
| ^ ~~~~~~~~~~~~~~~~~~~~~
140 | unsigned long addr, pte_t *ptep,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141 | pte_t pte, unsigned int nr)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.
make[3]: *** [scripts/Makefile.build:182: arch/x86/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors.
make[2]: *** [Makefile:1314: prepare0] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +432 include/linux/pgtable.h
425
426 #ifndef set_ptes
427 static inline void set_anon_ptes(struct mm_struct *mm, unsigned long addr,
428 unsigned long fault_addr, pte_t *ptep, pte_t pte, unsigned int nr)
429 {
430 bool young = pte_young(pte);
431
> 432 page_table_check_ptes_set(mm, ptep, pte, nr);
433
434 for (;;) {
435 if (young && addr == fault_addr)
436 pte = pte_mkyoung(pte);
437 else
438 pte = pte_mkold(pte);
439
440 set_pte(ptep, pte);
441 if (--nr == 0)
442 break;
443
444 addr += PAGE_SIZE;
445 ptep++;
446 pte = pte_next_pfn(pte);
447 }
448 }
449 #else
450 #define set_anon_ptes(mm, addr, fault_addr, ptep, pte, nr) \
451 set_ptes(mm, addr, ptep, pte, nr)
452 #endif
453
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
David Hildenbrand (Arm)
maintainerQuoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.
What is the use case that cares about that?
What we have right now is the exact same behavior as if you would get a PMD THP that has a single access+dirty bit at fault time.
Also, architectures that support transparent PTE coalescing will not be able to coalesce until all PTE bits are equal.
This level of imprecision is to be expected with large folios that only have a single access+dirty bit.
Signature · 3 lines
Cheers, David
Quoted 10 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from /proc/pid/smaps is a relatively low-cost method.
Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the do_anonymous_page function, making it hard to distinguish whether pre-allocated pages were truly accessed.
Quoted 9 lines
What we have right now is the exact same behavior as if you would get a PMD THP that has a single access+dirty bit at fault time.
Also, architectures that support transparent PTE coalescing will not be able to coalesce until all PTE bits are equal.
This level of imprecision is to be expected with large folios that only have a single access+dirty bit.
Thanks a lot for the response.
I saw this description in the ARM manual, “D8.5.5 Use of the Contiguous bit with hardware updates to the translation tables”:
Quoted 3 lines
If hardware updates a translation table entry, and if the Contiguous bit in that entry is 1, then the members in a group of contiguous translation table entries can have different AF, AP[2], and S2AP[1] values.
Does this mean that after hardware aggregates multiple PTEs, it can still independently set the AF and other flag bits corresponding to specific sub-PTE?
If so, can software also set different AF bits for a group of 16 PTEs without affecting the transparent PTE coalescing function?
The reason I have this confusion is that there is such a description in “D8.7.1 The Contiguous bit:”
Quoted 3 lines
Software is required to ensure that all of the adjacent translation table entries for the contiguous region point to a contiguous OA range with consistent attributes and permissions.
It does not specify whether attributes and permissions include the AF bit.
Quoted 4 lines
--
Cheers,David
Quoted 39 lines · Wenchao Hao
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.Quoted 9 lines
What we have right now is the exact same behavior as if you would get a PMD THP that has a single access+dirty bit at fault time.
Also, architectures that support transparent PTE coalescing will not be able to coalesce until all PTE bits are equal.
This level of imprecision is to be expected with large folios that only have a single access+dirty bit.
Thanks a lot for the response.
I saw this description in the ARM manual, “D8.5.5 Use of the Contiguous bit with hardware updates to the translation tables”:
Quoted 6 lines
Quoted 3 lines
If hardware updates a translation table entry, and if the Contiguous bit in that entry is 1, then the members in a group of contiguous translation table entries can have different AF, AP[2], and S2AP[1] values.
Does this mean that after hardware aggregates multiple PTEs, it can still independently set the AF and other flag bits corresponding to specific sub-PTE?
Yes. Hardware can update access and dirty bits per-pte. It is the job of software to aggregate them.
Quoted 3 lines
If so, can software also set different AF bits for a group of 16 PTEs without affecting the transparent PTE coalescing function?
Yes. See set_ptes -> __contpte_try_fold: look at pte_mkold(pte_mkclean()). We ignore the a/d bits while constructing the next expected pte.
Quoted 13 lines
The reason I have this confusion is that there is such a description in “D8.7.1 The Contiguous bit:”
Quoted 3 lines
Software is required to ensure that all of the adjacent translation table entries for the contiguous region point to a contiguous OA range with consistent attributes and permissions.
It does not specify whether attributes and permissions include the AF bit.
Quoted 4 lines
--
Cheers,David
Quoted 53 lines · Dev Jain
Quoted 39 lines · Wenchao Hao
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.Quoted 9 lines
What we have right now is the exact same behavior as if you would get a PMD THP that has a single access+dirty bit at fault time.
Also, architectures that support transparent PTE coalescing will not be able to coalesce until all PTE bits are equal.
This level of imprecision is to be expected with large folios that only have a single access+dirty bit.
Thanks a lot for the response.
I saw this description in the ARM manual, “D8.5.5 Use of the Contiguous bit with hardware updates to the translation tables”:
Quoted 6 lines
Quoted 3 lines
If hardware updates a translation table entry, and if the Contiguous bit in that entry is 1, then the members in a group of contiguous translation table entries can have different AF, AP[2], and S2AP[1] values.
Does this mean that after hardware aggregates multiple PTEs, it can still independently set the AF and other flag bits corresponding to specific sub-PTE?
Yes. Hardware can update access and dirty bits per-pte. It is the job of software to aggregate them.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
If so, can software also set different AF bits for a group of 16 PTEs without affecting the transparent PTE coalescing function?
Yes. See
set_ptes->__contpte_try_fold: look at pte_mkold(pte_mkclean()). We ignore the a/d bits while constructing the next expected pte.
Thank you for your answer. I think we can now get the following conclusion:
From a hardware perspective, after the PTE continuous bit is set, the access and dirty flags of the PTE do not affect the transparent PTE coalescing function.
Quoted 13 lines
Quoted 13 lines
The reason I have this confusion is that there is such a description in “D8.7.1 The Contiguous bit:”
Quoted 3 lines
Software is required to ensure that all of the adjacent translation table entries for the contiguous region point to a contiguous OA range with consistent attributes and permissions.
It does not specify whether attributes and permissions include the AF bit.
Quoted 4 lines
--
Cheers,David
Quoted 53 lines · Wenchao Hao
Quoted 52 lines · Dev Jain
Quoted 39 lines · Wenchao Hao
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.Quoted 9 lines
What we have right now is the exact same behavior as if you would get a PMD THP that has a single access+dirty bit at fault time.
Also, architectures that support transparent PTE coalescing will not be able to coalesce until all PTE bits are equal.
This level of imprecision is to be expected with large folios that only have a single access+dirty bit.
Thanks a lot for the response.
I saw this description in the ARM manual, “D8.5.5 Use of the Contiguous bit with hardware updates to the translation tables”:
Quoted 6 lines
Quoted 3 lines
If hardware updates a translation table entry, and if the Contiguous bit in that entry is 1, then the members in a group of contiguous translation table entries can have different AF, AP[2], and S2AP[1] values.
Does this mean that after hardware aggregates multiple PTEs, it can still independently set the AF and other flag bits corresponding to specific sub-PTE?
Yes. Hardware can update access and dirty bits per-pte. It is the job of software to aggregate them.
Quoted 2 lines
If so, can software also set different AF bits for a group of 16 PTEs without affecting the transparent PTE coalescing function?
Quoted 7 lines
Quoted 3 lines
Yes. See
set_ptes->__contpte_try_fold: look at pte_mkold(pte_mkclean()). We ignore the a/d bits while constructing the next expected pte.Thank you for your answer. I think we can now get the following conclusion:
From a hardware perspective, after the PTE continuous bit is set, the access and dirty flags of the PTE do not affect the transparent PTE coalescing function.
Keep in mind that this is the case in software - there is also transparent coalescing done by hardware, and I am not aware of the spec for that.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
The reason I have this confusion is that there is such a description in “D8.7.1 The Contiguous bit:”
Quoted 3 lines
Software is required to ensure that all of the adjacent translation table entries for the contiguous region point to a contiguous OA range with consistent attributes and permissions.
It does not specify whether attributes and permissions include the AF bit.
Quoted 4 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainerQuoted 10 lines · Wenchao Hao
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.
Quoted 7 lines
Quoted 2 lines
What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.
Right. And that imprecision is to be expected when you opt-in into something that manages memory in other granularity and only has a single a/d bit: a large folio.
Sure, individual PTEs *might* have independent a/d bits, but the underlying thing (folio) has only a single one. And optimizations that build on top (pte coalescing) reuse that principle that having a single logical a/d bit is fine.
Quoted 9 lines
Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.
The deferred shrinker uses a much simpler mechanism: if the page content is zero, likely it was over-allocated and never used later.
It's not completely lightweight (scan pages for 0 content), but is reliable, independent of the mapping type (PMD, cont-pte, whatever) and independent of any access/dirty bits, leaving performance unharmed.
When you say "I want to figure out the proportion of memory waste", are we talking about a debug feature?
Signature · 3 lines
Cheers, David
Quoted 42 lines · David Hildenbrand (Arm)
Quoted 10 lines · Wenchao Hao
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.Quoted 7 lines
Quoted 2 lines
What is the use case that cares about that?
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Right. And that imprecision is to be expected when you opt-in into something that manages memory in other granularity and only has a single a/d bit: a large folio.
Sure, individual PTEs *might* have independent a/d bits, but the underlying thing (folio) has only a single one. And optimizations that build on top (pte coalescing) reuse that principle that having a single logical a/d bit is fine.
Quoted 9 lines
Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.The deferred shrinker uses a much simpler mechanism: if the page content is zero, likely it was over-allocated and never used later.
Quoted 7 lines
It's not completely lightweight (scan pages for 0 content), but is reliable, independent of the mapping type (PMD, cont-pte, whatever) and independent of any access/dirty bits, leaving performance unharmed.
When you say "I want to figure out the proportion of memory waste", are we talking about a debug feature?
Thanks for your explanation. I now understand the design logic.
What I’m proposing is mainly for debugging. After enabling 64K large folio on Android, we observed increased application memory footprint, especially for anonymous pages.
Since Android app memory usage depends on runtime scenarios, we cannot confirm if the growth is directly caused by large folio. We want to analyze memory
usage via the Referenced field in /proc/[pid]/smaps.
However, with the current 64K anonymous large folio mapping implementation, the Referenced field does not reflect actual page access activity correctly.
This is why I’m sending this RFC patch.
Quoted 4 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainerQuoted 44 lines · Wenchao Hao
Quoted 32 lines · David Hildenbrand (Arm)
Quoted 7 lines · Wenchao Hao
On Tue, Feb 10, 2026 at 5:07 PM David Hildenbrand (Arm) <[email protected]> wrote:
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Right. And that imprecision is to be expected when you opt-in into something that manages memory in other granularity and only has a single a/d bit: a large folio.
Sure, individual PTEs *might* have independent a/d bits, but the underlying thing (folio) has only a single one. And optimizations that build on top (pte coalescing) reuse that principle that having a single logical a/d bit is fine.
Quoted 9 lines
Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.The deferred shrinker uses a much simpler mechanism: if the page content is zero, likely it was over-allocated and never used later.
Quoted 7 lines
It's not completely lightweight (scan pages for 0 content), but is reliable, independent of the mapping type (PMD, cont-pte, whatever) and independent of any access/dirty bits, leaving performance unharmed.
When you say "I want to figure out the proportion of memory waste", are we talking about a debug feature?
Thanks for your explanation. I now understand the design logic.
Quoted 8 lines
What I’m proposing is mainly for debugging. After enabling 64K large folio on Android, we observed increased application memory footprint, especially for anonymous pages.
Since Android app memory usage depends on runtime scenarios, we cannot confirm if the growth is directly caused by large folio. We want to analyze memory
usage via theReferencedfield in/proc/[pid]/smaps.
Scanning for zero-filled pages will be much easier and more reliable. For a debug feature good enough.
I'm wondering what the best interface for something like that could be: we don't want to make "/proc/[pid]/smaps" slower for all users.
Maybe we could for debug kernels.
For example, adding with CONFIG_DEBUG_KERNEL a new entry
Anon_Zero:
counter that just tests whether the page content of an anonymous page is all zeroes could be doable.
Signature · 3 lines
Cheers, David
Quoted 61 lines · David Hildenbrand (Arm)
Quoted 44 lines · Wenchao Hao
Quoted 32 lines · David Hildenbrand (Arm)
Quoted 7 lines · Wenchao Hao
On Tue, Feb 10, 2026 at 5:07 PM David Hildenbrand (Arm) <[email protected]> wrote:
We have enabled 64KB large folios on Android devices, which may introduce some memory waste. I want to figure out the proportion of memory waste caused by large folios. Reading the "Referenced" field from
/proc/pid/smapsis a relatively low-cost method.Right. And that imprecision is to be expected when you opt-in into something that manages memory in other granularity and only has a single a/d bit: a large folio.
Sure, individual PTEs *might* have independent a/d bits, but the underlying thing (folio) has only a single one. And optimizations that build on top (pte coalescing) reuse that principle that having a single logical a/d bit is fine.
Quoted 9 lines
Additionally, considering future hot/cold page identification, we aim to detect 64KB large folios where some pages are actually unaccessed and split them into normal pages to avoid memory waste.
However, the current large folio implementation sets the access bit for all page table entries (PTEs) of the large folio in the
do_anonymous_pagefunction, making it hard to distinguish whether pre-allocated pages were truly accessed.The deferred shrinker uses a much simpler mechanism: if the page content is zero, likely it was over-allocated and never used later.
Quoted 7 lines
It's not completely lightweight (scan pages for 0 content), but is reliable, independent of the mapping type (PMD, cont-pte, whatever) and independent of any access/dirty bits, leaving performance unharmed.
When you say "I want to figure out the proportion of memory waste", are we talking about a debug feature?
Thanks for your explanation. I now understand the design logic.
Quoted 8 lines
What I’m proposing is mainly for debugging. After enabling 64K large folio on Android, we observed increased application memory footprint, especially for anonymous pages.
Since Android app memory usage depends on runtime scenarios, we cannot confirm if the growth is directly caused by large folio. We want to analyze memory
usage via theReferencedfield in/proc/[pid]/smaps.Scanning for zero-filled pages will be much easier and more reliable. For a debug feature good enough.
I'm wondering what the best interface for something like that could be:
we don't want to make "/proc/[pid]/smaps" slower for all users.
Quoted 9 lines
Maybe we could for debug kernels.
For example, adding with
CONFIG_DEBUG_KERNELa new entry
Anon_Zero:counter that just tests whether the page content of an anonymous page is all zeroes could be doable.
Apologies for the delayed reply – I was just writing a demo to verify the approach you mentioned.
Using the CONFIG_DEBUG_KERNEL compile-time macro to isolate this feature is indeed an excellent idea.
However, in engineering practice, it requires recompiling and replacing the kernel,
which can be cumbersome. Could we instead use a dynamic switch to control whether scan for zero-filled pages when reading /proc/[pid]/smaps?
Quoted 4 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainerQuoted 37 lines · Wenchao Hao
Quoted 22 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
On Wed, Feb 11, 2026 at 5:05 PM David Hildenbrand (Arm) <[email protected]> wrote:
Thanks for your explanation. I now understand the design logic.
Quoted 8 lines
What I’m proposing is mainly for debugging. After enabling 64K large folio on Android, we observed increased application memory footprint, especially for anonymous pages.
Since Android app memory usage depends on runtime scenarios, we cannot confirm if the growth is directly caused by large folio. We want to analyze memory
usage via theReferencedfield in/proc/[pid]/smaps.Scanning for zero-filled pages will be much easier and more reliable. For a debug feature good enough.
I'm wondering what the best interface for something like that could be:
we don't want to make "/proc/[pid]/smaps" slower for all users.Quoted 9 lines
Maybe we could for debug kernels.
For example, adding with
CONFIG_DEBUG_KERNELa new entry
Anon_Zero:counter that just tests whether the page content of an anonymous page is all zeroes could be doable.
Apologies for the delayed reply – I was just writing a demo to verify the approach you mentioned.
Quoted 7 lines
Using the
CONFIG_DEBUG_KERNELcompile-time macro to isolate this feature is indeed an excellent idea.However, in engineering practice, it requires recompiling and replacing the kernel,
which can be cumbersome. Could we instead use a dynamic switch to control whether scan for zero-filled pages when reading /proc/[pid]/smaps?
Maybe a kernel cmdline option could do? Selectively enabling it for some PIDs only is not really possible, but also, maybe it's not really needed.
Signature · 3 lines
Cheers, David
Quoted 42 lines · David Hildenbrand (Arm)
Quoted 40 lines · Wenchao Hao
Quoted 22 lines · David Hildenbrand (Arm)
Quoted 5 lines · Wenchao Hao
On Wed, Feb 11, 2026 at 5:05 PM David Hildenbrand (Arm) <[email protected]> wrote:
Thanks for your explanation. I now understand the design logic.
Quoted 8 lines
What I’m proposing is mainly for debugging. After enabling 64K large folio on Android, we observed increased application memory footprint, especially for anonymous pages.
Since Android app memory usage depends on runtime scenarios, we cannot confirm if the growth is directly caused by large folio. We want to analyze memory
usage via theReferencedfield in/proc/[pid]/smaps.Scanning for zero-filled pages will be much easier and more reliable. For a debug feature good enough.
I'm wondering what the best interface for something like that could be:
we don't want to make "/proc/[pid]/smaps" slower for all users.Quoted 9 lines
Maybe we could for debug kernels.
For example, adding with
CONFIG_DEBUG_KERNELa new entry
Anon_Zero:counter that just tests whether the page content of an anonymous page is all zeroes could be doable.
Apologies for the delayed reply – I was just writing a demo to verify the approach you mentioned.
Using the
CONFIG_DEBUG_KERNELcompile-time macro to isolate this feature is indeed an excellent idea.
Quoted 6 lines
Quoted 4 lines
However, in engineering practice, it requires recompiling and replacing the kernel,
which can be cumbersome. Could we instead use a dynamic switch to control whether scan for zero-filled pages when reading /proc/[pid]/smaps?Maybe a kernel cmdline option could do?
Kernel command line parameters can meet our requirements.
Quoted 1 line
Selectively enabling it for some PIDs only is not really possible, but also, maybe it's not really needed.
Yes, it is unnecessary to do that.
By the way, will you send a new patch for this, or shall I take care of it? Thanks.
Quoted 5 lines
--
Cheers,David
David Hildenbrand (Arm)
maintainerQuoted 18 lines · Wenchao Hao
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 13 lines · Wenchao Hao
On Thu, Feb 12, 2026 at 4:54 PM David Hildenbrand (Arm) <[email protected]> wrote:
Apologies for the delayed reply – I was just writing a demo to verify the approach you mentioned.
Using the
CONFIG_DEBUG_KERNELcompile-time macro to isolate this feature is indeed an excellent idea.However, in engineering practice, it requires recompiling and replacing the kernel,
which can be cumbersome. Could we instead use a dynamic switch to control whether scan for zero-filled pages when reading /proc/[pid]/smaps?
Quoted 7 lines
Quoted 1 line
Maybe a kernel cmdline option could do?
Kernel command line parameters can meet our requirements.
Quoted 1 line
Selectively enabling it for some PIDs only is not really possible, but also, maybe it's not really needed.
Yes, it is unnecessary to do that.
By the way, will you send a new patch for this, or shall I take care of it?
You :)
Signature · 3 lines
Cheers, David
Quoted 11 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.So here introduces a new interface,
set_anon_ptes(), which only sets the access bit for the PTE corresponding to the faulting address. This allows accurate tracking of page access status in/proc/pid/smapsbefore memory reclaim scan the folios.
Quoted 5 lines
During memory reclaim:
folio_referenced()checks and clears the access bits of PTEs, rmap verifies all PTEs under a folio. If any PTE mapped subpage of folio has access bit set, the folio is retained during reclaim. So only set the access bit for the faulting PTE indo_anonymous_page()is safe, as it does not interfere with reclaim decisions.
We had similar discussion about faultaround and briefly made it produce old ptes, but it caused performance regression as old ptes require additional pagewalk to set accessed bit on touch. It got reverted, but arch can opt-in for setting up old ptes for non-fault address.
See commits:
5c0a85fad949 ("mm: make faultaround produce old ptes")315d09bf30c2 ("Revert "mm: make faultaround produce old ptes"") 46bdb4277f98 ("mm: Allow architectures to request 'old' entries when prefaulting")
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 24 lines · Kiryl Shutsemau
Quoted 11 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.So here introduces a new interface,
set_anon_ptes(), which only sets the access bit for the PTE corresponding to the faulting address. This allows accurate tracking of page access status in/proc/pid/smapsbefore memory reclaim scan the folios.Quoted 5 lines
During memory reclaim:
folio_referenced()checks and clears the access bits of PTEs, rmap verifies all PTEs under a folio. If any PTE mapped subpage of folio has access bit set, the folio is retained during reclaim. So only set the access bit for the faulting PTE indo_anonymous_page()is safe, as it does not interfere with reclaim decisions.We had similar discussion about faultaround and briefly made it produce old ptes, but it caused performance regression as old ptes require additional pagewalk to set accessed bit on touch. It got reverted, but arch can opt-in for setting up old ptes for non-fault address.
Quoted 6 lines
See commits:
5c0a85fad949("mm: make faultaround produce old ptes")315d09bf30c2("Revert "mm: make faultaround produce old ptes"")46bdb4277f98("mm: Allow architectures to request 'old' entries when prefaulting")
It does look similar—our modifications both revolve around whether pre-mapped PTEs should be marked as "new."
Was there any analysis into why your changes led to performance regressions? This could help guide whether my modifications are meaningful, and perhaps I could reference your approach to implement similar changes for different architectures.
Quoted 2 lines
--
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 27 lines · Wenchao Hao
Quoted 26 lines · Kiryl Shutsemau
Quoted 11 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.So here introduces a new interface,
set_anon_ptes(), which only sets the access bit for the PTE corresponding to the faulting address. This allows accurate tracking of page access status in/proc/pid/smapsbefore memory reclaim scan the folios.Quoted 5 lines
During memory reclaim:
folio_referenced()checks and clears the access bits of PTEs, rmap verifies all PTEs under a folio. If any PTE mapped subpage of folio has access bit set, the folio is retained during reclaim. So only set the access bit for the faulting PTE indo_anonymous_page()is safe, as it does not interfere with reclaim decisions.We had similar discussion about faultaround and briefly made it produce old ptes, but it caused performance regression as old ptes require additional pagewalk to set accessed bit on touch. It got reverted, but arch can opt-in for setting up old ptes for non-fault address.
See commits:
Quoted 8 lines
Quoted 4 lines
5c0a85fad949("mm: make faultaround produce old ptes")315d09bf30c2("Revert "mm: make faultaround produce old ptes"")46bdb4277f98("mm: Allow architectures to request 'old' entries when prefaulting")It does look similar—our modifications both revolve around whether pre-mapped PTEs should be marked as "new."
Was there any analysis into why your changes led to performance regressions?
As I mentioned, my theory was that it is due to an additional pagewalks CPU has to do to flip access bit when it touches the memory, but I didn't profile it to confirm.
Signature · 1 line
Kiryl Shutsemau / Kirill A. Shutemov
Quoted 33 lines · Kiryl Shutsemau
Quoted 31 lines · Wenchao Hao
Quoted 30 lines · Kiryl Shutsemau
Quoted 11 lines · Wenchao Hao
When
do_anonymous_page()creates mappings for huge pages, it currently sets the access bit for all mapped PTEs (Page Table Entries) by default.This causes an issue where the Referenced field in
/proc/pid/smapscannot distinguish whether a page was actually accessed.So here introduces a new interface,
set_anon_ptes(), which only sets the access bit for the PTE corresponding to the faulting address. This allows accurate tracking of page access status in/proc/pid/smapsbefore memory reclaim scan the folios.Quoted 5 lines
During memory reclaim:
folio_referenced()checks and clears the access bits of PTEs, rmap verifies all PTEs under a folio. If any PTE mapped subpage of folio has access bit set, the folio is retained during reclaim. So only set the access bit for the faulting PTE indo_anonymous_page()is safe, as it does not interfere with reclaim decisions.We had similar discussion about faultaround and briefly made it produce old ptes, but it caused performance regression as old ptes require additional pagewalk to set accessed bit on touch. It got reverted, but arch can opt-in for setting up old ptes for non-fault address.
See commits:
5c0a85fad949("mm: make faultaround produce old ptes")315d09bf30c2("Revert "mm: make faultaround produce old ptes"")46bdb4277f98("mm: Allow architectures to request 'old' entries when prefaulting")
Quoted 9 lines
Quoted 4 lines
It does look similar—our modifications both revolve around whether pre-mapped PTEs should be marked as "new."
Was there any analysis into why your changes led to performance regressions?
As I mentioned, my theory was that it is due to an additional pagewalks CPU has to do to flip access bit when it touches the memory, but I didn't profile it to confirm.
Thanks for your reply.
My change is mainly for debugging purposes and targeted at huge pages. The only place I can see that might relate to the access bit of contiguous huge pages is memory reclaim.
However, the huge page reclaim logic checks the access status of the entire folio, so my conclusion is that this change should not affect performance.
As for the overhead of the CPU flipping access bits you mentioned, it cannot be determined at this point.
Quoted 2 lines
--
Kiryl Shutsemau / Kirill A. Shutemov