vm_map_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’œ vm_map_pages β€” the vm_map_pages(9) glow-up

okay so bestie, welcome to the Kernel API Manual entry for vm_map_pages, and trust me when I say this little function is doing the most for your mmap handler. grab a strawberry πŸ“ and let's get into it.


✨ NAME ✨

vm_map_pages β€” maps a range of kernel pages, and it starts with a non zero offset, which is kind of the whole personality trait here. no cap.


🌸 SYNOPSIS 🌸

int vm_map_pages (struct vm_area_struct *vma , struct page **pages ,
unsigned long num );

that's the whole signature, periodt. it returns an int, and it takes exactly three things. slay.


πŸŽ€ ARGUMENTS πŸŽ€

  • vma β€” the user vma you're mapping into. it's the vibe check of address spaces, and it's the one getting the pages.
  • pages β€” a pointer to an array of source kernel pages. literally the pages. the raw material. πŸ‘‘
  • num β€” how many pages are in that page array. the count. don't get it wrong bestie, it's unsigned long.

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does it actually do? it maps an object made of num pages, and it caters to the user's requested vm_pgoff while doing it. iykyk. ✨

here's the part you actually need to remember, so listen up: if we fail to insert any page into the vma, the function returns immediately β€” and it leaves any previously inserted pages exactly where they are. it does not clean up after itself. πŸ’€

so what do you do about it? depends on where you're calling from:

  • Callers from the mmap handler may immediately return the error β€” because their caller will destroy the vma, which removes any successfully inserted pages for them. easy. 🫢
  • Other callers should make their own arrangements for calling unmap_region. that's on you, bestie. no one's coming to save you. πŸ™ˆ
fr fr, do not sleep on that cleanup step. the function will not do it for you.

🧚 CONTEXT 🧚

process context. called by mmap handlers. that's it, that's the vibe. 🌈


⭐ RETURN ⭐

0 on success, and an error code otherwise. iconic behaviour, honestly. πŸ’…


πŸ”₯ SEE ALSO πŸ”₯

kernel file ./mm/memory.c, plus the whole friend group:


and that's the page!! πŸ’– this one lives in ./mm and it's dated October 2026 β€” go forth and map your pages responsibly, bestie. main character energy only. πŸ¦‹βœ¨

πŸ“¦ where this page comes from