randomize_page(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 randomize_page(9) 🌸

ok so this is a kernel API manual page for randomize_page, section 9, bestie β€” the one that hands you back a random address that's page aligned. it's giving "little function, big responsibility" energy and i'm obsessed πŸ’…


✨ NAME ✨

randomize_page β€” generate a random, page aligned address πŸŽ€


✨ SYNOPSIS ✨

unsigned long randomize_page (unsigned long start , unsigned long range );

like literally that's the whole signature. two unsigned longs in, one unsigned long out. no cap. 🫢


✨ ARGUMENTS ✨

  • start β€” the smallest acceptable address the caller will take. it's the floor, the bare minimum, the "i will not go below this" of addresses. πŸ™ˆ
  • range β€” the size of the area, starting at start, within which the random address must fall. so the whole playground is start onward for range bytes, and your random address has to land somewhere in there. 🌈

✨ DESCRIPTION ✨

ok so here's the vibe: if start + range would overflow, then range gets capped. that's it, that's the whole description β€” the function does its thing, but it's not about to let an overflow situation ruin everyone's day. ⭐


✨ NOTE ✨

ngl this one's a little historical tea β˜• β€” the old randomize_range, which this here function replaces, just presumed that start was already page aligned. like, assumed. didn't check. iconic behavior tbh.

we now align it regardless πŸ’– so no matter what you hand it, alignment is handled. you're welcome.


✨ RETURN ✨

a page aligned address within [start, start + range). πŸ”₯

and on error? you just get start back. that's it. not a fancy error code, not a NULL β€” literally start. so heads up πŸ‘‘, check before you assume success, iykyk.


✨ SEE ALSO ✨

kernel file ./mm/util.c and honestly a whole friend group of friends:

kfree_const(9), __kmemdup_nul(9), kstrdup(9), kstrdup_const(9), kstrndup(9), kmemdup(9), kmemdup_array(9), kvmemdup(9), kmemdup_nul(9), memdup_user(9), vmemdup_user(9), strndup_user(9), memdup_user_nul(9), __account_locked_vm(9), account_locked_vm(9), __vmalloc_array(9), vmalloc_array(9), __vcalloc(9), vcalloc(9), folio_mapping(9), folio_copy(9), get_cmdline(9), mem_dump_obj(9), compat_set_desc_from_vma(9), __compat_vma_mmap(9), compat_vma_mmap(9), snapshot_page(9), mmap_action_prepare(9), mmap_action_complete(9), folio_pte_batch(9), page_range_contiguous(9)

like. that's a lot of besties. go say hi πŸ’œ


and that's the page!! πŸ¦‹ it lives in ./mm, and this edition is dated October 2026 β€” so mark your calendar, screenshot it, send it to the group chat, whatever you gotta do. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from