vm_insert_pages(9)
π vm_insert_pages β Kernel API Manual, bestie edition
okay so bestie, gather round, because this one's a banger. We're in the Kernel API Manual today and the star of the show is vm_insert_pages(9). Yes it's a mouthful, no we're not changing it, it's iconic like that. π
β¨ NAME β¨
vm_insert_pages β insert multiple pages into user vma, batching the pmd lock. that's it. that's the whole vibe. lowkey a whole function in one line. π
πΈ SYNOPSIS πΈ
int vm_insert_pages (struct vm_area_struct *vma , unsigned long addr ,
struct page **pages , unsigned long *num );
copy it exactly, don't be cute with it, the compiler is not your friend like that. π«Ά
π¦ ARGUMENTS π¦
vmaβ the user vma to map to. this is the destination, the main character we're all here for.addrβ target start user address of these pages. the starting line, literally.pagesβ source kernel pages. the goods. the actual pages being brought over. β¨numβ the sneaky two-faced one, bestie, watch out:- in: number of pages to map.
- out: number of pages that were *not* mapped. and
0means all pages were successfully mapped. so zero is the good outcome here, which feels illegal but okay we roll with it. π
π DESCRIPTION π
Preferred over vm_insert_page when inserting multiple pages. like, if you've got a whole friend group of pages, don't send them one at a time, use this one. batching the pmd lock is the entire point and it ate. π₯
In case of error, we may have mapped a subset of the provided pages. It is the caller's responsibility to account for this case. not me warning you that a partial mapping can absolutely happen and then just... handing you the bill. π this is on you to handle, bestie, no cap. check your num and do the math.
The same restrictions apply as in vm_insert_page. same rules, different friend. if you don't know them, go read that one β iykyk. π
π SEE ALSO π
The kernel file ./mm/memory.c is where all this lives, and honestly the whole ./mm girlies are here for the cross-references:
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_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)__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 squad. every single one. don't skip anybody, that's rude. π
π§ sign-off π§
okay that's the page!! this one's chilling in ./mm and the manual itself is dated October 2026 β the version info in the footer says Kernel API Manual and the date, and since we're being cute about it: consider it stamped, signed, and blessed. go map some pages bestie, you're gonna 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