kthread_worker_fn(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– kthread_worker_fn(9) πŸ’–

okay so you found a page from the Kernel API Manual and it's literally called kthread_worker_fn β€” bestie, this is the function that keeps a kthread worker alive and processing, and honestly it's kind of the main character of the whole worker situation. let's get into it 🫢


✨ NAME ✨

kthread_worker_fn β€” the kthread function that processes a kthread_worker. that's it, that's the vibe.


🌸 SYNOPSIS 🌸

int kthread_worker_fn (void *worker_ptr );

πŸŽ€ ARGUMENTS πŸŽ€

  • worker_ptr β€” pointer to an initialized kthread_worker. like, it has to be initialized already, no showing up unready to this function πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: this function implements the main cycle of the kthread worker. it processes work_list until it gets stopped with kthread_stop. and when the queue is empty? it sleeps. iconic behavior, honestly β€” it just naps until there's something to do 😴✨

now the rules, because there are rules and you will respect them:

  • the works are not allowed to keep any locks when they finish.
  • the works are not allowed to disable preemption when they finish.
  • the works are not allowed to disable interrupts when they finish.

there's a defined safe point for freezing when one work finishes and before a new one is started β€” so like, the freezer knows exactly where to catch it. 🧊

also, and this one matters: the works must not be handled by more than one worker at the same time. see also kthread_queue_work for that whole situation. no cap, one work = one worker, don't be messy πŸ™ˆ

fr fr, those "not allowed" lines are hard requirements, not suggestions. locks held across the finish, or preemption/interrupts left disabled β€” that's a problem, and the kernel will not be cute about it πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./kernel/kthread.c β€” and like, the entire extended universe of kthread functions, all in one place:


okay that's the whole page!! πŸ’œ this one came out of ./kernel and the date on it is October 2026 β€” so like, future-core of the kernel docs, slay. go forth and queue your works responsibly, bestie πŸŽ€πŸ”₯⭐

πŸ“¦ where this page comes from