Sitemap

The Linux Process Journey — kworker

2 min readAug 18, 2022

--

A kworker is a kernel thread that performs processing as part of the kernel, especially if case of interrupts, timers, I/O, etc. It is based on workqueues which are async execution mechanisms, that execute in “process context” (I will post on workqueus in more details separately, for now it is all that you need to know).

Overall, there are a couple of kworkers running on a Linux machine. The naming pattern of kworkers includes: the number of the core on which it is executed, the id of the thread and can contain also string that hints what the kworker does (check the output of ‘ps -ef | grep kworker’ — see the screenshot below).

Press enter or click to view image in full size
‘ps -ef | grep kworker’ output

The big question is — “How do we know what each kwoker is doing?”. It’s a great question, the way in which we are going to answer it is by using ftrace (function tracing inside the kernel — I suggest reading more about that — https://www.kernel.org/doc/Documentation/trace/ftrace.txt). The command we are going to use are:

echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event

cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log

The first one enables the tracing regarding workqueus. The second reads the tracing data and saves it to a file. We can also run “cat /sys/kernel/debug/tracing/trace_pipe | grep kworker” and change the grep filter to a specific kworker process. In the trace we will see the function name that each kworker thread is going to execute.

See you in my next writeup ;-) You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru). Also, you can read my other writeups on medium — https://medium.com/@boutnaru. You can find my free eBooks at https://TheLearningJourneyEbooks.com.

Press enter or click to view image in full size
ftrace output (tracing kworker)

--

--

Responses (1)