-->

Previous | Table of Contents | Next

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.

How Much Swap Is Enough?

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:

  1. Estimate your total memory needs. Consider the largest amount of space you will need at any given time. Consider what programs you will be running simultaneously. A common way of determining this is to set up a bogus swap space (quite large) and load as many programs as you estimate will be run at the same time. Then, check how much memory you have used. There are a few things that typically don't show up when a memory check is performed. The kernel, for example, will use about a megabyte of space.
  2. Add a couple megabytes as a buffer for those programs that you did not think you would be using but found out later that, in fact, you will.
  3. Subtract the amount of physical memory you have from this total. The amount left is the amount of swap space needed to run your system with all the memory in use.
  4. If the total from step 3 is more than approximately three times the amount of physical memory you have, there will probably be problems. If the amount is greater than three times the cost, then it is worthwhile to add more physical memory.

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

Previous | Table of Contents | Next