0345-0347.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 352 行

HTML
352
字号




<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Advanced System Administration</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!-- ISBN=0672311739 //-->

<!-- TITLE=RED HAT LINUX 2ND EDITION //-->

<!-- AUTHOR=DAVID PITTS ET AL //-->

<!-- PUBLISHER=MACMILLAN //-->

<!-- IMPRINT=SAMS PUBLISHING //-->

<!-- PUBLICATION DATE=1998 //-->

<!-- CHAPTER=16 //-->

<!-- PAGES=0341-0350 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0341-0344.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0348-0350.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-345"><P>Page 345</P></A>









<P>The following table explains what each field means.

</P>





<TABLE WIDTH="360">

<TR><TD>

<B>Field</B>

</TD><TD>

<B>Description</B>

</TD></TR>

<TR><TD>

up

</TD><TD>

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.

</TD></TR>

<TR><TD>

processes

</TD><TD>

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.

</TD></TR>

<TR><TD>

CPU states

</TD><TD>

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.

</TD></TR>

<TR><TD>

Mem

</TD><TD>

Statistics on memory usage, including total available

memory, free memory, used memory, shared memory, and memory

used for buffers.

</TD></TR>

<TR><TD>

Swap

</TD><TD>

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.

</TD></TR>

<TR><TD>

PID

</TD><TD>

The process ID of each task.

</TD></TR>

<TR><TD>

USER

</TD><TD>

The username of the task's owner.

</TD></TR>

<TR><TD>

PRI

</TD><TD>

The priority of the task.

</TD></TR>

<TR><TD>

NI

</TD><TD>

The nice value of the task. Negative

nice values are lower priority.

</TD></TR>

<TR><TD>

SIZE

</TD><TD>

The size of the task's code plus data plus stack space, in kilobytes.

</TD></TR>

<TR><TD>

RSS

</TD><TD>

The total amount of physical memory used by the task,

in kilobytes.

</TD></TR>

<TR><TD>

SHARE

</TD><TD>

The amount of shared memory used by the task.

</TD></TR>

<TR><TD>

STATE

</TD><TD>

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.

</TD></TR>

<TR><TD>

TIME

</TD><TD>

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.

</TD></TR>

<TR><TD>

%CPU

</TD><TD>

The task's share of the CPU time since the last screen

update, expressed as a percentage of total CPU time.

</TABLE>





<!-- CODE SNIP //-->

<PRE>

                                   Continues                                                                 continues

</PRE>

<!-- END CODE SNIP //-->



<A NAME="PAGENUM-346"><P>Page 346</P></A>



<TABLE WIDTH="360">

<TR><TD>

<B>Field</B>

</TD><TD>

<B>Description</B>

</TD></TR>

<TR><TD>

%MEM

</TD><TD>

The task's share of the physical memory.

</TD></TR>

<TR><TD>

COMMAND

</TD><TD>

The task's command name, which will be truncated if tasks

have only the name of the program in parentheses (for

example, &quot;(getty)&quot;).

</TD></TR>

</TABLE>









<P>As you can probably tell from the server used to obtain the data, there are no current

bottlenecks in the system.

</P>









<P>free is another good command for showing the amount of memory that is used and is, as

you can imagine, free:

</P>





<!-- CODE //-->

<PRE>

shell:/home/dpitts$ free

             total       used       free     shared    buffers     cached

Mem:         63420      61668       1752      23676      13360      32084

-/+ buffers:            16224      47196

Swap:        33228       1096      32132

</PRE>

<!-- END CODE //-->











<P>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.

</P>









<P>The last line (Swap:) shows similar information for the swapped spaces. If this line is all

zeroes, your swap space is not activated.

</P>









<P>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:

</P>





<!-- CODE SNIP //-->

<PRE>

$ swapon /temporary_swap

</PRE>

<!-- END CODE SNIP //-->











<P>To automatically use swap spaces, list them in the

/etc/fstab file. The following example lists two swap files for the

/etc/fstab:

</P>





<!-- CODE SNIP //-->

<PRE>

/dev/hda8 none swap sw 0 0

/swapfile none swap sw 0 0

</PRE>

<!-- END CODE SNIP //-->











<P>To remove a swap space, use the swapoff command. Usually, this is necessary only when

using a temporary swap space.

</P>



<A NAME="PAGENUM-347"><P>Page 347</P></A>



<CENTER>

<TABLE BGCOLOR="#FFFF99">

<TR><TD>

<B>WARNING</B>

</TD></TR>

<TR><TD>

<BLOCKQUOTE>

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.

</BLOCKQUOTE></TD></TR>

</TABLE></CENTER>

<BR>



<H3>

How Much Swap Is Enough?

</H3>









<P>A common question asked by people who are designing a system for the first time is,

&quot;How much swap space is enough?&quot; 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.

</P>









<P>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:

</P>









<OL>

<LI>    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.



<LI>   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.



<LI>     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.



<LI>     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.

</OL>









<P>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

</P>



<P><CENTER>

<a href="0341-0344.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0348-0350.html">Next</A>

</CENTER></P>









</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?