clear_pages(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… clear_pages β€” the kernel API manual, bestie edition ✨

okay so this is a page from the Kernel API Manual (that's the manual name, we're just folding it in here πŸŽ€) and it's about clear_pages. Get comfy, this one's short but there are rules.


🌸 NAME 🌸

clear_pages β€” clears a page range for kernel-internal use. That's it, that's the whole job. πŸ’–


✨ SYNOPSIS ✨

void clear_pages (void *addr , unsigned int npages );

like. look at her. no return value, she just does it. πŸ’…


🫢 ARGUMENTS 🫢

  • addr β€” start address. where the clearing begins, bestie πŸ“
  • npages β€” number of pages. how many of them we're clearing ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

lowkey let me say the most important thing first: if you're clearing a page range that's gonna get mapped to user space, use clear_user_pages instead. not this one. this one is not for that. iykyk 🌈

second thing, and this is the one people forget: it does absolutely no exception handling. none. zero. not a single one. πŸ’€

and here's the vibe check on scheduling β€” this is the part that gets people, so listen up πŸ‘‘

even though the clearing operation is preemptible, clear_pages does not call cond_resched to check whether rescheduling is required. and on architectures where it reduces to a few long-running instructions, it might not even be able to. 🫠

so what does that mean for you?

  • Under preemptible models? literally not a problem, you're fine, go off πŸ’–
  • Under cooperatively scheduled models? different story. the caller is expected to limit npages to no more than PROCESS_PAGES_NON_PREEMPT_BATCH. that's on you, not on her. πŸŽ€
fr fr do not skip the PROCESS_PAGES_NON_PREEMPT_BATCH limit in cooperatively scheduled models. it's not a suggestion, it's the whole contract ✨

πŸ’œ SEE ALSO πŸ’œ

the absolute iconic lineup of friends, all of them, in order, no skips πŸ‘‘βœ¨:


okay and that's the page!! πŸ’– this one lives over in ./include/linux and the date on it is October 2026 β€” so like, mark your calendar bestie, that's the version you're reading πŸŽ€βœ¨ slay, go clear some pages (kernel-internal ones only, please) πŸ¦‹πŸ’…

πŸ“¦ where this page comes from