vm_insert_page(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 (see split_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 ✨


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