skwq_has_sleeper(9)
πΈ skwq_has_sleeper β a kernel API manual, bestie edition πΈ
okay so this is from the Kernel API Manual, page skwq_has_sleeper(9), and honestly? it's a little baddie. let's get into it π
β¨ NAME β¨
skwq_has_sleeper β check if there are any waiting processes π
like... is anybody in the queue? hello?? π«Ά
π¦ SYNOPSIS π¦
bool skwq_has_sleeper (struct socket_wq *wq );
that's it. that's the whole thing. short and iconic π
π ARGUMENTS π
wqβ astruct socket_wq. that's the whole description, she's mysterious like that π
β RETURN β
returns true if the socket_wq has waiting processes. no cap, that's the vibe check π₯
π DESCRIPTION π
okay so here's the tea, bestie. the whole point of skwq_has_sleeper and sock_poll_wait is to wrap the memory barrier call. they exist because of a race that got found hanging out in the tcp code π like, actual bug energy.
consider the following tcp code paths:
CPU1 CPU2
sys_select receive packet
... ...
__add_wait_queue update tp->rcv_nxt
... ...
tp->rcv_nxt check sock_def_readable
... {
schedule rcu_read_lock;
wq = rcu_dereference(sk->sk_wq);
if (wq && waitqueue_active(wq->wait))
wake_up_interruptible(wq->wait)
...
}
so the race for tcp fires when the __add_wait_queue changes that CPU1 did just... stay chilling in its cache. and the same goes for the tp->rcv_nxt update on the CPU2 side. π so then CPU1 could end up calling schedule and sleep forever if there's no more data on the socket. forever!! not me having a whole existential crisis about a sleep that never wakes up π
like genuinely, that's the danger here β a process stuck sleeping with no wakeup coming. that's why the memory barrier wrapping exists. slay for correctness, not for vibes π«Ά
π SEE ALSO π
all the siblings and cousins, in the kernel file ./include/net/sock.h:
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)lock_sock_fast(9)unlock_sock_fast(9)sk_wmem_alloc_get(9)sk_rmem_alloc_get(9)sk_has_allocations(9)sock_poll_wait(9)sk_page_frag(9)_sock_tx_timestamp(9)sk_eat_skb(9)
π and that's the page!! it lives in ./include/net and the date on this one is October 2026 β so yeah, future-coded manual page, we love to see it. go read sock_poll_wait(9) next, iykyk ππβ¨
π¦ 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