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
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms