1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<!--Converted with LaTeX2HTML 96.1-h (September 30, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->
<HTML>
<HEAD>
<TITLE>Using a swap space</TITLE>
<META NAME="description" CONTENT="Using a swap space">
<META NAME="keywords" CONTENT="sag">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<LINK REL=STYLESHEET HREF="sag.css">
</HEAD>
<BODY LANG="EN" >
<A NAME="tex2html1094" HREF="node63.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html1092" HREF="node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html1086" HREF="node61.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html1096" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html1097" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1095" HREF="node63.html">Sharing swap spaces with </A>
<B>Up:</B> <A NAME="tex2html1093" HREF="node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1087" HREF="node61.html">Creating a swap space</A>
<BR> <P>
<H1><A NAME="SECTION00630000000000000000">Using a swap space</A></H1>
<P>
An initialized swap space is taken into use with <tt>swapon</tt><A NAME="1904"> </A>.
This command tells the kernel that the swap
space can be used. The path to the swap space is given as
the argument, so to start swapping on a temporary swap
file one might use the following command.
<BLOCKQUOTE> <TT>
<code>$</code> <I>swapon /extra-swap</I> <BR>
<code>$</code>
</TT></BLOCKQUOTE>
Swap spaces can be used automatically by listing them in
the <tt>/etc/fstab</tt><A NAME="1906"> </A> file.
<BLOCKQUOTE> <TT>
<code>/dev/hda8 none swap sw 0 0</code> <BR>
<code>/swapfile none swap sw 0 0</code>
</TT></BLOCKQUOTE>
The startup scripts will run
the command <tt>swapon -a</tt>, which will start swapping on
all the swap spaces listed in <tt>/etc/fstab</tt><A NAME="1908"> </A>. Therefore,
the <tt>swapon</tt><A NAME="1910"> </A> command is usually used only when extra swap
is needed.
<P>
You can monitor the use of swap spaces with <tt>free</tt><A NAME="1912"> </A>.
It will tell the total amount of swap space used.
<BLOCKQUOTE> <TT>
<code>$</code> <I>free</I> <BR>
<code> total used free shared buffers</code> <BR>
<code>Mem: 15152 14896 256 12404 2528</code> <BR>
<code>-/+ buffers: 12368 2784</code> <BR>
<code>Swap: 32452 6684 25768</code> <BR>
<code>$</code>
</TT></BLOCKQUOTE>
The first line of output (<code>Mem:</code>) 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 second line does not count buffers).
The free column shows completely unused memory. The shared column shows
the amount of memory shared by several processes; the more, the merrier.
The buffers column shows the current size of the disk buffer cache.
<P>
That last line (<code>Swap:</code>) shows similar information for the swap
spaces. If this line is all zeroes, your swap space is not activated.
<P>
The same information is available via <tt>top</tt><A NAME="1914"> </A>,
or using the <tt>proc</tt> filesystem in file <tt>/proc/meminfo</tt><A NAME="1916"> </A>.
It is
currently difficult to get information on the use of a specific
swap space.
<P>
A swap space can be removed from use with <tt>swapoff</tt><A NAME="1918"> </A>.
It is usually not necessary to do it, except for temporary
swap spaces.
Any pages in use in the swap space are swapped in first; if
there is not sufficient physical memory to hold them, they will
then be swapped out (to some other swap space).
If there is not enough virtual memory to hold all of the pages
Linux will start to thrash; after a long while it should
recover, but meanwhile the system is unusable. You should
check (e.g., with <tt>free</tt><A NAME="1920"> </A>) that there is enough free
memory before removing a swap space from use.
<P>
All the swap spaces that are used automatically with
<tt>swapon -a</tt> can be removed from use with <tt>swapoff -a</tt>;
it looks at the file <tt>/etc/fstab</tt><A NAME="1922"> </A> to find what to remove.
Any manually used swap spaces will remain in use.
<P>
Sometimes a lot of swap space can be in use even though there
is a lot of free physical memory. This can happen for instance
if at one point there is need to swap, but later a big process
that occupied much of the physical memory terminates and
frees the memory. The swapped-out data is not
automatically swapped in until it is needed, so the physical
memory may remain free for a long time. There is no need to
worry about this, but it can be comforting to know what is
happening.
<P>
<HR><A NAME="tex2html1094" HREF="node63.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html1092" HREF="node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html1086" HREF="node61.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html1096" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html1097" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1095" HREF="node63.html">Sharing swap spaces with </A>
<B>Up:</B> <A NAME="tex2html1093" HREF="node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1087" HREF="node61.html">Creating a swap space</A>
<P><ADDRESS>
<I>Lars Wirzenius <BR>
Sat Nov 15 02:32:11 EET 1997</I>
</ADDRESS>
</BODY>
</HTML>
|