lock_sock_fast(9)
π
lock_sock_fast(9) β like, the fast version of lock_sock, bestie
okay so this page lives in the Kernel API Manual (section 9, kernel developer vibes only π§) and it's about one lil function that's gonna save you so much time if you respect its rules. let's get into it β¨
πΈ NAME πΈ
lock_sock_fast β the fast version of lock_sock. that's it, that's the whole name. short, sweet, iconic π
π¦ SYNOPSIS π¦
bool lock_sock_fast (struct sock *sk );
literally one argument, returns a bool, no cap. π«Ά
π ARGUMENTS π
skβ the socket. that's the whole description, she's lowkey mysterious like that π
β¨ DESCRIPTION β¨
okay bestie, listen carefully because this one has rules π
you should only use this version for a very small section, where the process won't block. like, in-and-out, blink-and-you-miss-it energy. if it's a big sprawling critical section, this is not the function for you, go use the regular one, i'm begging π
it returns false if the fast path is taken, and here's exactly what the world looks like in that case:
sk_lock.slockis lockedowned = 0- BH disabled
it returns true if the slow path is taken, and then the state flips to:
sk_lock.slockis unlockedowned = 1- BH enabled
so yeah β false = fast path, true = slow path. yes, it's a little upside-down from what your brain wants, no i don't make the rules π
write it down. put it on a sticky note. put it on your forehead, idc, just don't get it backwards.
β οΈ fr fr: small section only, and only where the process won't block. that's the whole deal you're making with this function.
π₯ SEE ALSO π₯
all the related lore lives in the kernel file ./include/net/sock.h, and these are the siblings/cousins/friends-of-friends you might wanna check out:
struct sock_common(9)struct sock(9)sk_user_data_is_nocopy(9)__locked_read_sk_user_data_with_flags(9)__rcu_dereference_sk_user_data_with_flags(9)sk_for_each_entry_offset_rcu(9)SOCK_CONNECT_BIND(9)unlock_sock_fast(9)sk_wmem_alloc_get(9)sk_rmem_alloc_get(9)sk_has_allocations(9)skwq_has_sleeper(9)sock_poll_wait(9)sk_page_frag(9)_sock_tx_timestamp(9)sk_eat_skb(9)
(and yes, unlock_sock_fast(9) is right there β she's the other half of the duo, don't leave her hanging π«Ά)
π sign-off π
bestie this page comes to you from the ./include/net directory, dated October 2026, and it's literally titled lock_sock_fast(9) under the Kernel API Manual. go forth, lock fast, stay tiny, and remember: small section, no blocking, and always check your return value πβ¨π
π¦ 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