folio_add_anon_rmap_ptes(9)
πΈ folio_add_anon_rmap_ptes(9) β the kernel API manual, but make it make sense πΈ
okay so bestie, we're in the Kernel API Manual today and the function we're stanning is folio_add_anon_rmap_ptes. it's giving very much "plumbing but make it couture" π
let's get into it.
β¨ NAME β¨
folio_add_anon_rmap_ptes β the girl whose whole job is adding PTE mappings to a page range of an anon folio. periodt. π
π¦ SYNOPSIS π¦
void folio_add_anon_rmap_ptes (struct folio *folio , struct page *page ,
int nr_pages , struct vm_area_struct *vma , unsigned long address ,
rmap_t flags );
that's the whole signature, no cap. copy it exactly, don't get creative π
π ARGUMENTS π
folioβ the folio we're adding the mappings to. she's the main character here π«Άpageβ the first page to add. like, the starting point of the whole situation β¨nr_pagesβ the number of pages that will be mapped. the headcount, basically π₯vmaβ the vm area in which the mappings get added πΈaddressβ the user virtual address of the first page to map. where it all goes down πflagsβ the rmap flags. yes queen, flags π
π DESCRIPTION π
so the page range of folio is defined by [first_page, first_page + nr_pages) β that half-open bracket situation, iykyk π§
now the important part, and not me being dramatic, this is literally required:
the caller needs to hold the page table lock π
and in the anon_vma case, the page must be locked. why? two reasons and they're both real:
- to serialize the mapping,index checking after setting π
- to ensure that an anon folio is not being upgraded racily to a KSM folio (but KSM folios are never downgraded β love that for them, no take-backsies π)
π SEE ALSO π
kernel file ./mm/rmap.c and the whole friend group:
__anon_vma_prepare(9)anon_vma_clone(9)unlink_anon_vmas(9)page_address_in_vma(9)folio_referenced(9)mapping_wrprotect_range(9)pfn_mkclean_range(9)folio_move_anon_rmap(9)__folio_set_anon(9)__page_check_anon_rmap(9)folio_add_anon_rmap_pmd(9)folio_add_new_anon_rmap(9)folio_add_file_rmap_ptes(9)folio_add_file_rmap_pmd(9)folio_add_file_rmap_pud(9)folio_remove_rmap_ptes(9)folio_remove_rmap_pmd(9)folio_remove_rmap_pud(9)try_to_unmap(9)try_to_migrate(9)make_device_exclusive(9)__rmap_walk_file(9)
go read them all, bestie, it's a whole syllabus πβ¨
π and that's the page! this one came from the ./mm source, dated October 2026 β so go forth, hold that page table lock, and slay π
π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms