VM_PAGE_ALLOC(9)

okay so bestie, welcome to vm_page_alloc(9) from the Kernel Developer's Manual πŸ’–. this page is literally about allocating a page for a vm_object, and it's giving main character energy in the VM subsystem. no cap, every flag matters, so let's get into it. ✨


✨ NAME ✨

vm_page_alloc β€” allocate a page for a vm_object


πŸ¦‹ SYNOPSIS πŸ¦‹

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

vm_page_t
vm_page_alloc(vm_object_t object, vm_pindex_t pindex, int req);

🌸 DESCRIPTION 🌸

so the vm_page_alloc() function allocates a page at pindex within object. it's assumed that a page has not already been allocated at pindex. the page that comes back is inserted into the object, unless VM_ALLOC_NOOBJ is specified in the req. periodt. πŸ’…

also, huge vibe check: vm_page_alloc() will not sleep. like, it's not gonna catch feelings or block, it just does its thing. iconic. πŸ‘‘

its arguments are:

  • object β€” the VM object to allocate the page for. bestie, the object must be locked if VM_ALLOC_NOOBJ is not specified. no lock, no talk. πŸ”’
  • pindex β€” the index into the object at which the page should be inserted. it's literally the spot in the lineup. πŸ“
  • req β€” the bitwise-inclusive OR of a class and any optional flags indicating how the page should be allocated. so you're mixing and matching, but there are rules.

exactly one of the following classes must be specified:

  • VM_ALLOC_NORMAL β€” the page should be allocated with no special treatment. just a regular degular page, no drama. ✨
  • VM_ALLOC_SYSTEM β€” the page can be allocated if the cache is empty and the free page count is above the interrupt reserved water mark. this flag should be used only when the system really needs the page. like, emergency-level need, not just a want. 🚨
  • VM_ALLOC_INTERRUPT β€” vm_page_alloc() is being called during an interrupt. a page will be returned successfully if the free page count is greater than zero. interrupt mode activated, no cap. ⚑

the optional flags are:

  • VM_ALLOC_NOBUSY β€” the returned page will not be exclusive busy.
  • VM_ALLOC_NODUMP β€” the returned page will not be included in any kernel core dumps regardless of whether or not it is mapped in to KVA. so it's lowkey invisible to dumps. πŸ™ˆ
  • VM_ALLOC_NOOBJ β€” do not associate the allocated page with a vm object. the object argument is ignored. it's giving independent page energy. πŸ¦‹
  • VM_ALLOC_SBUSY β€” the returned page will be shared busy.
  • VM_ALLOC_WIRED β€” the returned page will be wired. it's locked in, literally. πŸ”—
  • VM_ALLOC_ZERO β€” indicate a preference for a pre-zeroed page. there is no guarantee that the returned page will be zeroed, but it will have the PG_ZERO flag set if it is zeroed. so like, manifesting a zeroed page, but the universe might say no. πŸ•―οΈ

πŸ’– RETURN VALUES πŸ’–

the vm_page_t that was allocated is returned if successful; otherwise, NULL is returned. so either you get your page or you get nothing, and honestly that's the risk you take. 😭


πŸ‘‘ NOTES πŸ‘‘

the pager process is always upgraded to VM_ALLOC_SYSTEM unless VM_ALLOC_INTERRUPT is set. so yeah, pager stays getting promoted, iykyk. πŸ’…


🌈 AUTHORS 🌈

this manual page was written by Chad David <davidc@acns.ab.ca>. iconic of him, fr fr. 🫢


and that's the whole vibe. this page came from Debian, dated November 16, 2016 β€” so it's a classic, but still slaying. bye bestie! πŸŽ€πŸ’œ

πŸ“¦ where this page comes from