randomize_page(9)
πΈ 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 atstart, within which the random address must fall. so the whole playground isstartonward forrangebytes, 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms