Next Previous Contents

8. Kernel Daemons

Unfortunately, this section contains more conjectures and questions than facts. Perhaps you can help?

If you issue the ps aux command, you will see something like the following:

USER       PID %CPU %MEM  SIZE   RSS TTY STAT START   TIME COMMAND
root         1  0.1  8.0  1284   536   ? S    07:37   0:04 init [2] 
root         2  0.0  0.0     0     0   ? SW   07:37   0:00 (kflushd)
root         3  0.0  0.0     0     0   ? SW   07:37   0:00 (kupdate)
root         4  0.0  0.0     0     0   ? SW   07:37   0:00 (kpiod)
root         5  0.0  0.0     0     0   ? SW   07:37   0:00 (kswapd)
root        52  0.0 10.7  1552   716   ? S    07:38   0:01 syslogd -m 0 
root        54  0.0  7.1  1276   480   ? S    07:38   0:00 klogd 
root        56  0.3 17.3  2232  1156   1 S    07:38   0:13 -bash 
root        57  0.0  7.1  1272   480   2 S    07:38   0:01 /sbin/agetty 38400 tt
root        64  0.1  7.2  1272   484  S1 S    08:16   0:01 /sbin/agetty -L ttyS1
root        70  0.0 10.6  1472   708   1 R   Sep 11   0:01 ps aux 

This is a list of the processes running on the system. Note that init is process number one. Processes 2, 3, 4 and 5 are kflushd, kupdate, kpiod and kswapd. There is something strange here though: notice that in both the virtual storage size (SIZE) and the Real Storage Size (RSS) columns, these processes have zeroes. How can a process use no memory? These processes are really part of the kernel. The kernel does not show up on process lists at all, and you can only work out what memory it is using by subtracting the memory available from the amount on your system. The brackets around the command name could signify that these are kernel processes(?)

kswapd moves parts of programs that are not currently being used from real storage (ie RAM) to the swap space (ie hard disk). kflushd writes data from buffers to disk. This allows things to run faster. What programs write can be kept in memory, in a buffer, then written to disk in larger more efficient chunks. I don't know what kupdate and kpiod are for.

This is where my knowledge ends. What do these last two daemons do? Why do kernel daemons get explicit process numbers rather than just being anonymous bits of kernel code? Does init actually start them, or are they already running when init arrives on the scene?

I put a script to mount /proc and do a ps aux in /sbin/init. Process 1 was the script itself, and processess 2, 3, 4 and 5 were the kernel daemons just as under the real init. The kernel must put these processes there, because my script certainly didn't!

The following ramblings were contributed by David Leadbeater:

These processes seem to take care of disk reads and writes, they seem to be started by the kernel but after it runs the init process, it seems that being run as kernel processes rather than seperate processess they are protected from being killed (kill -9 dosen't stop them), I am not sure why they are run as seperate threads (it seems to be something with disk access)

kflushd and kupdate These two processes are started to flush dirty (changed) buffers back to disk. kflushd is run when the buffers are full and kupdate runs periodically (5 seconds?) to sync the disk and the buffers in memory.

kpiod and kswapd These deal with paging out pages (sections) of memory into the swap file so main memory never gets exhausted, these are similar to kflushd and kupdate in that one is run when needed kpiod and the other kswapd is run peridically (1 second intervals)

Other Kernel Daemons On a default install of RH6 kupdate is missing but update is running as a user space daemon so it seems it needs to be run! Also another daemon mdrecoveryd is there, this seems to be dealing with software RAID, looking at the kernel source it seems that some SCSI drivers also start seperate processes.

I am still unsure of the meaning of the brackets but it seems that they appear when the RSS of a process is 0 meaning it isn't using any memory?

(end of ramble, thanks David)

8.1 Configuration

I don't know of any configuration for these kernel daemons.

8.2 Exercises

Find out what these processes are for, how they work, and write a new ``Kernel Daemons'' section for this document and send it to me!

8.3 More Information

The Linux Documentation Project's ``The Linux Kernel'' (see section The Linux Kernel for a url), and the kernel source code are all I can think of.


Next Previous Contents