-->
Page 345
The following table explains what each field means.
Field | Description |
up | The time the system has been up and the three load averages for the system. The load averages are the average number of processes ready to run during the last 1, 5, and 15 minutes. This line is just like the output of uptime. |
processes | The total number of processes running at the time of the last update. This is also broken down into the number of tasks that are running, sleeping, stopped, and zombied. |
CPU states | The percentage of CPU time in user mode, system mode, niced tasks, and idle. (Niced tasks are only those whose nice value is negative.) Time spent in niced tasks will also be counted in system and user time, so the total will be more than 100 percent. |
Mem | Statistics on memory usage, including total available memory, free memory, used memory, shared memory, and memory used for buffers. |
Swap | Statistics on swap space, including total swap space, available swap space, and used swap space. This and Mem are just like the output of free. |
PID | The process ID of each task. |
USER | The username of the task's owner. |
PRI | The priority of the task. |
NI | The nice value of the task. Negative nice values are lower priority. |
SIZE | The size of the task's code plus data plus stack space, in kilobytes. |
RSS | The total amount of physical memory used by the task, in kilobytes. |
SHARE | The amount of shared memory used by the task. |
STATE | The state of the task, either S for sleeping, D for uninterrupted sleep, R for running, Z for zombies, or T for stopped or traced. |
TIME | Total CPU time the task has used since it started. If cumulative mode is on, this also includes the CPU time used by the process's children that have died. You can set cumulative mode with the S command-line option or toggle it with the interactive com mand S. |
%CPU | The task's share of the CPU time since the last screen update, expressed as a percentage of total CPU time. |
Continues continues
Page 346
Field | Description |
%MEM | The task's share of the physical memory. |
COMMAND | The task's command name, which will be truncated if tasks have only the name of the program in parentheses (for example, "(getty)"). |
As you can probably tell from the server used to obtain the data, there are no current bottlenecks in the system.
free is another good command for showing the amount of memory that is used and is, as you can imagine, free:
shell:/home/dpitts$ free total used free shared buffers cached Mem: 63420 61668 1752 23676 13360 32084 -/+ buffers: 16224 47196 Swap: 33228 1096 32132
The first line of output (Mem:) shows the physical memory. The total column does not show the physical memory used by the kernel, which is usually about a megabyte. The used column shows the amount of memory used. The free column shows the amount of free memory. The shared column shows the amount of memory shared by several processes. The buffers column shows the current size of the disk buffer cache. The cached column shows how much memory has been cached off to disk.
The last line (Swap:) shows similar information for the swapped spaces. If this line is all zeroes, your swap space is not activated.
To activate a swap space, use the swapon command. The swapon command tells the kernel that the swap space can be used. The location of the swap space is given as the argument passed to the command. The following example shows starting a temporary swap file:
$ swapon /temporary_swap
To automatically use swap spaces, list them in the /etc/fstab file. The following example lists two swap files for the /etc/fstab:
/dev/hda8 none swap sw 0 0 /swapfile none swap sw 0 0
To remove a swap space, use the swapoff command. Usually, this is necessary only when using a temporary swap space.
Page 347
WARNING |
If swap space is removed, the system will attempt to move any swapped pages into other swap space or to physical memory. Should there not be enough space, the system will freak out but will eventually come back. During the time that it is trying to figure out what to do with these extra pages, the system will be unavailable. |
A common question asked by people who are designing a system for the first time is, "How much swap space is enough?" Some people just estimate that you should have twice as much swap space as you have physical memory. Following this method, if you have a system with 16MB of memory, you will set up 32MB of swap space. Depending on how much physical memory you have, this number can be way out of line. For example, my system has 64MB of physical memory, so I should configure 124MB of paging space. I would say that this is unnecessary. I prefer to use a slightly more complex strategy for determining the amount of swap space needed.
Determining the amount of swap space you need is a simple four-step program. First, admit that you have a memory problem. No, sorry, that is a different program. The four steps are as follows:
Sometimes these calculations show that you don't need any swap space; my system with 64MB of RAM is an example. It is a good policy to create some space anyway. Linux uses the swap space so that as much physical memory as possible is kept free. It swaps out memory pages that