125 lines
5.5 KiB
HTML
125 lines
5.5 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE>From Power Up To Bash Prompt: Kernel Daemons</TITLE>
|
|
<LINK HREF="From-PowerUp-To-Bash-Prompt-HOWTO-9.html" REL=next>
|
|
<LINK HREF="From-PowerUp-To-Bash-Prompt-HOWTO-7.html" REL=previous>
|
|
<LINK HREF="From-PowerUp-To-Bash-Prompt-HOWTO.html#toc8" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO-9.html">Next</A>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO-7.html">Previous</A>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO.html#toc8">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s8">8. Kernel Daemons</A></H2>
|
|
|
|
<P>If you issue the <CODE>ps aux</CODE> command, you will see something like the following:
|
|
<P>
|
|
<P>
|
|
<PRE>
|
|
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
|
|
</PRE>
|
|
<P>
|
|
<P>This is a list of the processes running on the system. The information comes
|
|
from the <CODE>/proc</CODE> filesystem that I mentioned in the previous section.
|
|
Note that <CODE>init</CODE>
|
|
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?
|
|
<P>
|
|
<P>These processes are the kernel daemons. Most of 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 kernel daemons are started after init,
|
|
so they get process numbers like normal processes do. But their code and
|
|
data lives in the kernel's part of the memory.
|
|
<P>
|
|
<P>There are brackets around the entries in the command column
|
|
because the <CODE>/proc</CODE> filesystem does not contain command line information
|
|
for these processes.
|
|
<P>
|
|
<P>So what are these kernel daemons for?
|
|
Previous versions of this document had a plea for help,
|
|
as I didn't know much about the kernel daemons.
|
|
The following partial story has been patched together
|
|
from various replies to that plea, for which I am most grateful.
|
|
Further clues, references and corrections are most welcome!
|
|
<P>
|
|
<P>Input and output is done via <EM>buffers</EM> in memory.
|
|
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. The daemons <CODE>kflushd</CODE> and <CODE>kupdate</CODE>
|
|
handle this work:
|
|
<CODE>kupdate</CODE> runs periodically (5 seconds?)
|
|
to check whether there are any dirty buffers. If there are, it gets
|
|
<CODE>kflushd</CODE> to flush them to disk.
|
|
<P>
|
|
<P>Processes often have nothing to do, and ones that are running often
|
|
don't need all of their code and data in memory. This means we can
|
|
make better use of our memory, by shifting unused parts of running programs
|
|
out to the swap partition(s) of the hard disk.
|
|
Moving this data in and out of memory as needed is done by
|
|
<CODE>kpiod</CODE> and <CODE>kswapd</CODE>. Every second or so, <CODE>kswapd</CODE>
|
|
wakes up to check out the memory situation, and if something out on
|
|
the disk is needed in memory, or there is not enough free memory,
|
|
<CODE>kpiod</CODE> is called in.
|
|
<P>
|
|
<P>There might also be a <CODE>kapmd</CODE> daemon running on your system if you
|
|
have configured automatic power management into your kernel.
|
|
<P>
|
|
<P>
|
|
<H2><A NAME="ss8.1">8.1 Configuration</A>
|
|
</H2>
|
|
|
|
<P>The program <CODE>update</CODE> allows you to configure <CODE>kflushd</CODE> and <CODE>kswapd</CODE>.
|
|
Try <CODE>update -h</CODE> for some information.
|
|
<P>
|
|
<P>Swap space is turned on by <CODE>swapon</CODE> and off by <CODE>swapoff</CODE>.
|
|
The init script (<CODE>/etc/rc.sysinit</CODE> or <CODE>/etc/rc.d/rc.sysinit</CODE>)
|
|
usually calls <CODE>swapon</CODE> as the system is coming up.
|
|
I'm told that <CODE>swapoff</CODE> is handy for saving power on laptops.
|
|
<P>
|
|
<H2><A NAME="ss8.2">8.2 Exercises</A>
|
|
</H2>
|
|
|
|
<P>Do an <CODE>update -d</CODE>, note the blatherings on the
|
|
last line about ``threshold for buffer fratricide''.
|
|
Now there's an intriguing concept, go investigate!
|
|
<P>
|
|
<P>Change directory to <CODE>/proc/sys/vm</CODE> and <CODE>cat</CODE> the
|
|
files there. See what you can work out.
|
|
<P>
|
|
<H2><A NAME="ss8.3">8.3 More Information</A>
|
|
</H2>
|
|
|
|
<P>The Linux Documentation Project's ``The Linux Kernel''
|
|
(see section
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO-4.html#Kernel">The Linux Kernel</A> for a url)
|
|
<P>
|
|
<P>The Linux kernel source code, if you are brave enough!
|
|
The <CODE>kswapd</CODE> code is in <CODE>linux/mm/vmscan.c</CODE>,
|
|
and <CODE>kflushd</CODE> and <CODE>kupdate</CODE>
|
|
are in <CODE>linux/fs/buffer.c</CODE>.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<HR>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO-9.html">Next</A>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO-7.html">Previous</A>
|
|
<A HREF="From-PowerUp-To-Bash-Prompt-HOWTO.html#toc8">Contents</A>
|
|
</BODY>
|
|
</HTML>
|