Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Worker threads in linux

Why is it sometimes necessary to create new worker threads, that execute deferrable work functions, instead of just scheduling it on the default "events/n" kernel worker thread ?

like image 208
Bandicoot Avatar asked Oct 20 '25 13:10

Bandicoot


1 Answers

The events worker thread need to multiplex many tasks, so it's not allowed to block it (call schedule() inside single task). However there are many tasks that need to block (wait for disk, network, some device etc.) and there are many functions in kernel that block internally (like semaphores or even memory allocation). Such functions may only be run on behalf of userland inside a syscall or in a dedicated kernel thread.

While it would be theoretically possible to rewrite such code to a long chain of events, it would make it complex and unmaintainable and the overhead of kernel thread is quite small.

like image 179
Jan Hudec Avatar answered Oct 23 '25 04:10

Jan Hudec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!