try_get_locked_pte(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ try_get_locked_pte(9) β€” Kernel API Manual πŸ¦‹

okay bestie, so this one is in section 9 of the kernel API manual, and it's genuinely such a vibe once you get it. it's try_get_locked_pte, and it's basically get_locked_pte()'s chill, non-blocking little sibling. let's get into it πŸ’…

✨ NAME ✨

try_get_locked_pte β€” literally just like get_locked_pte(), except it's atomic and it does a trylock instead of committing to the wait 🫢

🌸 SYNOPSIS 🌸

pte_t * try_get_locked_pte (struct mm_struct *mm , unsigned long vmaddr
, spinlock_t **ptl );

πŸŽ€ ARGUMENTS πŸŽ€

  • mm β€” the mm. that's it, that's the whole description, she's mysterious like that ✨
  • vmaddr β€” the userspace virtual address whose pte we're trying to find πŸ‘€
  • ptl β€” this gets set to the pointer to the lock that's used to lock the pte, but only in case of success. if it doesn't work out, don't count on it πŸ’€

πŸ’– DESCRIPTION πŸ’–

so this function returns the pointer to the pte corresponding to addr in mm, super similarly to get_locked_pte. but here's where they differ, and it's kind of a big deal: unlike get_locked_pte, no attempt is made to allocate missing page tables. none. zero. not today πŸ™ˆ

so if a missing or large entry is found, the function just returns NULL. no drama, no allocation, just nope. and if the ptl lock is contended? you get -EAGAIN back, because she's not about to sit around waiting πŸ”₯

in case of success, *ptl will point to the locked pte lock for the returned pte β€” same behavior as get_locked_pte does, icon behavior honestly πŸ‘‘

πŸ”’ CONTEXT πŸ”’

you gotta hold mmap_lock or the vma lock, and it needs to be held for read or for write. non-negotiable bestie, don't skip this one 🫢

⭐ RETURN ⭐

  • NULL if the pte cannot be reached.
  • -EAGAIN if the pte can be reached, but it just cannot be locked 😭
  • the pointer to the pte corresponding to addr in mm, if it can be reached and locked. slay πŸ’…

🌈 SEE ALSO 🌈

kernel file ./arch/s390/mm/gmap_helpers.c, plus these absolute legends:


and that's the whole page, bestie πŸŽ€ brought to you by the fine folks over at ./arch/s390/mm, dated October 2026, from the try_get_locked_pte(9) files β€” go forth and trylock responsibly πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from