__vmf_anon_prepare(9)
π __vmf_anon_prepare β like, the Kernel API Manual page, bestie β¨
okay so we're in the <pink>Kernel API Manual</pink> today and the star of the show is __vmf_anon_prepare(9) π buckle up.
πΈ NAME πΈ
__vmf_anon_prepare β literally just Prepare to handle an anonymous fault. that's the whole vibe π«Ά
β¨ SYNOPSIS β¨
vm_fault_t __vmf_anon_prepare (struct vm_fault *vmf );
like yes, that's it, that's the signature π
π¦ ARGUMENTS π¦
vmfβ thevm_faultdescriptor that got handed to you straight from the fault handler. it's giving "here u go, do something with this" π
π DESCRIPTION π
okay so picture this: you're in a fault handler and you're about to insert an anonymous page into a VMA. the move here is to call this function β __vmf_anon_prepare β and not anon_vma_prepare. lowkey important distinction, iykyk π
now here's the part where you gotta pay attention π if this VMA doesn't already have an associated anon_vma, and you're only protected by the per-VMA lock, then the caller must retry with the mmap_lock held. no cap, that's a requirement.
why?? because __anon_vma_prepare is gonna go look at adjacent VMAs to figure out whether this VMA can share its anon_vma, and that is not safe to do when all you're holding is the per-VMA lock for this VMA. π like genuinely not safe. so don't.
π RETURN π
0β slay, fault handling can proceed β¨- any other value β should be returned to the caller. that's it, hand it back π«Ά
π SEE ALSO π
Kernel file ./mm/memory.c β and honestly the whole friend group:
free_pgd_range(9)free_pgtables(9)__vm_normal_page(9)vm_normal_page(9)vm_normal_folio(9)vm_normal_page_pmd(9)vm_normal_folio_pmd(9)vm_normal_page_pud(9)restore_exclusive_pte(9)cond_install_uffd_wp_ptes(9)zap_vma_for_reaping(9)unmap_vmas(9)zap_vma_range_batched(9)zap_vma_range(9)zap_special_vma_range(9)vm_insert_pages(9)vm_insert_page(9)vm_map_pages(9)vm_map_pages_zero(9)vmf_insert_pfn_prot(9)vmf_insert_pfn(9)remap_pfn_range(9)vm_iomap_memory(9)finish_mkwrite_fault(9)unmap_mapping_folio(9)unmap_mapping_pages(9)unmap_mapping_range(9)set_pte_range(9)finish_fault(9)mm_account_fault(9)follow_pfnmap_start(9)follow_pfnmap_end(9)generic_access_phys(9)access_remote_vm(9)copy_remote_vm_str(9)folio_zero_user(9)
and that's the page!! πβ¨ this little baby lives in ./mm and the version is dated October 2026, filed under __vmf_anon_prepare(9) β mwah, go forth and prepare those anon VMAs correctly bestie π§ββοΈπ
π
π¦ 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