VM_PAGE_INSERT(9)

πŸ’– VM_PAGE_INSERT(9) πŸ’–

okay bestie, welcome to the Kernel Developer's Manual page for vm_page_insert and vm_page_remove β€” yes that manual name is literally in the title up there, we're not hiding it, it's giving official. This is the page-management girlies of the VM subsystem and they are so important. Let's get into it 🫢


✨ NAME ✨

vm_page_insert, vm_page_remove β€” add/remove page from an object


🌸 SYNOPSIS 🌸

#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_page.h>

void
vm_page_insert(vm_page_t m, vm_object_t object, vm_pindex_t pindex);

void
vm_page_remove(vm_page_t m);

πŸ’… DESCRIPTION πŸ’…

So the vm_page_insert() function does exactly what it says on the tin: it adds a page to the given object at the given index. And bestie, she's thorough β€” the page gets added to both the VM page hash table and the object's list of pages. But (and this is the plot twist) the hardware page tables are not updated. Nope. Not her job.

So what happens then? Depends on the vibe:

  • If it's a user page</>, it'll just get faulted in whenever it's accessed. Chill. She'll show up when she's needed πŸ’œ
  • If it's a kernel page</>, the caller is expected to handle adding the page to the kernel's pmap. That's on you, boo. Not her problem.

And ooh, the flags β€” if PG_WRITEABLE is set in the page's flags, then OBJ_WRITEABLE and OBJ_MIGHTBEDIRTY get set in the object's flags. She's picking up on your energy and reflecting it back, no cap ✨


Now for vm_page_remove() β€” she takes the given page and removes it from its object, and from the VM page hash table too. Bye babe πŸ‘‹

⚠️ MAJOR WARNING, FR FR: the page must be busy prior to this call, or the system will panic. Not a vibe. Not a drill. Get that page busy first or everything falls apart πŸ’€

Also important: the pmap entry for the page is not removed by this function. She removes what she removes and nothing more. Know the difference.


πŸŽ€ The arguments to vm_page_insert() are:

  • m β€” the page to add to the object. Your girl.
  • object β€” the object the page should be added to. Her new home.
  • pindex β€” the index into the object the page should be at. Her assigned seat πŸ’Ί

πŸŽ€ The arguments to vm_page_remove() are:

  • m β€” the page to remove. The one saying goodbye πŸ₯Ί

🧚 IMPLEMENTATION NOTES 🧚

Okay so the index of a page in a VM object is the byte index into that same object, truncated to a page boundary. Which sounds fancy but it's giving simple math, lemme show you:

Say your page size is 4096 bytes, and the address in the object is 81944. Then the page index is 20. That's it. That's the whole trick 🌈


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Chad David <davidc@acns.ab.ca>. Iconic of him, honestly πŸ’–


and that's the whole page, bestie! you now understand vm_page_insert and vm_page_remove better than like 90% of people who claim they do. go forth and be careful with the busy flag πŸ™ˆ

this was the Debian flavor of the page, dated July 17, 2001 β€” yeah she's vintage, but vintage is a vibe and she still ate πŸ’…βœ¨ mwah, bye!! πŸ¦‹

πŸ“¦ where this page comes from