summaryrefslogtreecommitdiff
path: root/sag-0.6.1-www/Invisible/sag-0.6/node61.html
blob: 5385417e08be7d95313fade13687b53797d53948 (plain)
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
<!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>Creating a swap space</TITLE>
<META NAME="description" CONTENT="Creating 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="tex2html1082" HREF="node62.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html1080" HREF="node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html1074" HREF="node60.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html1084" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html1085" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1083" HREF="node62.html">Using a swap space</A>
<B>Up:</B> <A NAME="tex2html1081" HREF="node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1075" HREF="node60.html">What is virtual memory?</A>
<BR> <P>
<H1><A NAME="SECTION00620000000000000000">Creating a swap space</A></H1>
<P>
	A swap file is an ordinary file; it is in no way special to
	the kernel.  The only thing that matters to the kernel is that
	it has no holes, and that it is prepared for use with
	<tt>mkswap</tt><A NAME="1891">&#160;</A>.  It must reside on a local disk, however; it
	can't reside in a filesystem that has been mounted over NFS
	due to implementation reasons.
<P>
	The bit about holes is important. The swap file 
	reserves the disk space so that the kernel can quickly swap out
	a page without having to go through all the things
	that are necessary when allocating a disk sector to a file.
	The kernel merely uses any sectors that have already been
	allocated to the file.  Because a hole in a file means that
	there are no disk sectors allocated (for that place in the
	file), it is not good for the kernel to try to use them.
<P>
	One good way to create the swap file without holes is through
	the following command:
		<BLOCKQUOTE> <TT>
<code>$</code> <I>dd if=/dev/zero of=/extra-swap bs=1024 count=1024</I><BR> 
<code>1024+0 records in</code> <BR> 
<code>1024+0 records out</code> <BR> 
<code>$</code>
		</TT></BLOCKQUOTE>
	where <tt>/extra-swap</tt><A NAME="1893">&#160;</A> is the name of the swap file and 
	the size of is given after the <tt>count=</tt>.  It is best for
	the size to be a multiple of 4, because the kernel writes out
	<b>memory pages</b>, which are 4 kilobytes in size.  If the
	size is not a multiple of 4, the last couple of kilobytes may
	be unused.
<P>
	A swap partition is also not special in any way.  You create it
	just like any other partition; the only difference is that it is
	used as a raw partition, that is, it will not contain any
	filesystem at all.  It is a good idea to mark swap partitions as
	type 82 (Linux swap); this will the make partition listings
	clearer, even though it is not strictly necessary to the kernel.
<P>
	After you have created a swap file or a swap partition, you
	need to write a signature to its beginning; this contains some
	administrative information and is used by the kernel.  The
	command to do this is <tt>mkswap</tt><A NAME="1896">&#160;</A>, used like this:
		<BLOCKQUOTE> <TT>
<code>$</code> <I>mkswap /extra-swap 1024</I> <BR> 
<code>Setting up swapspace, size = 1044480 bytes</code> <BR> 
<code>$</code>
		</TT></BLOCKQUOTE>
	Note that the swap space is still not in use yet: it
	exists, but the kernel does not use it to provide virtual
	memory.
<P>
	You should be very careful when using <tt>mkswap</tt><A NAME="1898">&#160;</A>, since it
	does not check that the file or partition isn't used for anything
	else.  <em>You can easily overwrite important files and
	partitions with <tt>mkswap</tt><A NAME="1900">&#160;</A>!</em>  Fortunately, you should only
	need to use <tt>mkswap</tt><A NAME="1902">&#160;</A> when you install your system.
<P>
	The Linux memory manager limits the size of each swap space to
	about 127&nbsp;MB (for various technical reasons, the actual limit
	is <IMG WIDTH=78 HEIGHT=12 ALIGN=MIDDLE ALT="tex2html_wrap_inline4269" SRC="img11.gif"> bytes, or
	127.6875 megabytes).  You can, however, use up to
	16 swap spaces simultaneously, for a total of almost
	2&nbsp;GB.<A NAME="tex2html27" HREF="footnode.html#1836"><IMG  ALIGN=BOTTOM ALT="gif" SRC="./foot_motif.gif"></A>
<P>
<HR><A NAME="tex2html1082" HREF="node62.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="./next_motif.gif"></A> <A NAME="tex2html1080" HREF="node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="./up_motif.gif"></A> <A NAME="tex2html1074" HREF="node60.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="./previous_motif.gif"></A> <A NAME="tex2html1084" HREF="node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="./contents_motif.gif"></A> <A NAME="tex2html1085" HREF="node114.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="./index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1083" HREF="node62.html">Using a swap space</A>
<B>Up:</B> <A NAME="tex2html1081" HREF="node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1075" HREF="node60.html">What is virtual memory?</A>
<P><ADDRESS>
<I>Lars Wirzenius <BR>
Sat Nov 15 02:32:11 EET 1997</I>
</ADDRESS>
</BODY>
</HTML>