ptep_try_set(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… ptep_try_set(9) β€” the Kernel API Manual tea 🫢

okay bestie, buckle up, because we're diving into ptep_try_set(9) from the Kernel API Manual and honestly? it's giving ✨atomic vibes✨


πŸŽ€ NAME πŸŽ€

ptep_try_set β€” atomically set an empty kernel PTE, no cap πŸ’…


🌸 SYNOPSIS 🌸

bool ptep_try_set (pte_t *ptep , pte_t new_pte );

literally that's the whole signature, slay πŸ¦‹


✨ ARGUMENTS ✨

  • ptep β€” the page table entry, bestie. the slot we're eyeing πŸ‘€
  • new_pte β€” the value we wanna install in there πŸ’–

πŸ”₯ DESCRIPTION πŸ”₯

okay so here's the whole vibe: ptep_try_set atomically sets *ptep to new_pte iff *ptep is pte_none. it returns true on success β€” and returns false if the slot was already populated or if the arch has no implementation. it's giving "you had one shot" energy πŸ’…

⚠️ this is for special kernel page tables only β€” never user page tables. not me being dramatic, that's just the rule πŸ™ˆ

the caller must prevent concurrent teardown of ptep and must accept that other writers may race. yes, bestie, accept it β€” other writers are gonna race, that's just the situation 🫢

and listen: concurrent clearers must use ptep_get_and_clear so that racing accesses agree on the outcome. teamwork makes the dream work, fr fr 🌈

architectures opt in by providing a cmpxchg-based override and defining ptep_try_set as an identity macro β€” iconic behavior, honestly πŸ‘‘

the generic stub returns false, which is correct for callers that fall through to oops on failure. yes that's on purpose. no that's not a bug. it's correct πŸ˜­πŸ’€


πŸ¦‹ SEE ALSO πŸ¦‹

Kernel file ./include/linux/pgtable.h and also this whole squad of legends:


that's the whole page, bestie, go forth and set those PTEs atomically πŸ’œ

mwah πŸ’‹ β€” this little number lives in ./include/linux, dated October 2026, and that's the tea πŸ“

πŸ“¦ where this page comes from