vm_insert_page(9)
π vm_insert_page π
okay so welcome to the Kernel API Manual bestie, we're literally about to learn how to slide a single page into a user vma and it's gonna slay π«Ά
β¨ NAME β¨
vm_insert_page β insert single page into user vma (yes that's the whole vibe, one page, no more, no less π
)
πΈ SYNOPSIS πΈ
int vm_insert_page (struct vm_area_struct *vma , unsigned long addr ,
struct page *page );
π ARGUMENTS π
vmaβ the user vma you're mapping to, like the destination of the page's main character journey β¨addrβ the target user address of this page, aka where it's gonna live πpageβ the source kernel page, the actual star of the show π
π¦ DESCRIPTION π¦
so the whole point: this lets drivers insert individual pages they've allocated into a user vma. cute right? the zeropage is supported in some VMAs β see vm_mixed_zeropage_allowed if you wanna check the vibes π§
ok important: the page has to be a nice clean individual kernel allocation. no sneaky packaging. if you allocate a compound page, you need to have marked it as such (__GFP_COMP), or manually just split the page up yourself (seesplit_page). no shortcuts bestie π
NOTE! traditionally this was done with remap_pfn_range which took an arbitrary page protection parameter. this doesn't allow that. nope. your vma protection will have to be set up correctly, which means that if you want a shared writable mapping, you'd better ask for a shared writable mapping! like, actually ask for it. out loud. in the flags π₯
the page does not need to be reserved. ngl that's kind of a relief π
usually this function is called from f_op->mmap handler under mm->mmap_lock write-lock, so it can change vma->vm_flags. caller must set VM_MIXEDMAP on vma if it wants to call this function from other places, for example from page-fault handler. iykyk π
π RETURN π
0 on success, negative error code otherwise. that's it, that's the whole mood π
π SEE ALSO π
Kernel file ./mm/memory.c β go read it, it's iconic β¨
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_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)__vmf_anon_prepare(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)
that's the whole page bestie, ily, go insert some pages responsibly π and hey β this one's from source ./mm, dated October 2026, filed under vm_insert_page(9) in the Kernel API Manual. periodt. π
π¦ 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