kthread_worker_fn(9)
π 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 initializedkthread_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:
kthread_should_stop(9)kthread_should_park(9)kthread_freezable_should_stop(9)kthread_func(9)kthread_data(9)kthread_probe_data(9)kthread_complete_and_exit(9)kthread_create_on_node(9)kthread_bind(9)kthread_create_on_cpu(9)kthread_unpark(9)kthread_park(9)kthread_stop(9)kthread_stop_put(9)kthread_affine_preferred(9)kthreads_update_housekeeping(9)kthread_create_worker_on_node(9)kthread_create_worker_on_cpu(9)kthread_queue_work(9)kthread_delayed_work_timer_fn(9)kthread_queue_delayed_work(9)kthread_flush_work(9)kthread_mod_delayed_work(9)kthread_cancel_work_sync(9)kthread_cancel_delayed_work_sync(9)kthread_flush_worker(9)kthread_destroy_worker(9)kthread_use_mm(9)kthread_unuse_mm(9)kthread_associate_blkcg(9)kthread_blkcg(9)
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
- 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