📄 node61.html
字号:
<!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>产生对换空间</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" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/sag.css">
</HEAD>
<BODY LANG="EN" >
<A NAME="tex2html1062" HREF="node62.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node62.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/next_motif.gif"></A> <A NAME="tex2html1060" HREF="node59.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/up_motif.gif"></A> <A NAME="tex2html1054" HREF="node60.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node60.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/previous_motif.gif"></A> <A NAME="tex2html1064" HREF="node1.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/contents_motif.gif"></A> <A NAME="tex2html1065" HREF="node108.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node108.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1063" HREF="node62.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node62.html">Using a swap space</A>
<B>Up:</B> <A NAME="tex2html1061" HREF="node59.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1055" HREF="node60.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node60.html">What is virtual memory?</A>
<BR> <P>
<H1><A NAME="SECTION00620000000000000000">产生对换空间</A></H1>
<P>
对换文件是普通文件,对核心没有什么特别的。唯一不同是它没有孔,用
<tt>mkswap</tt><A NAME="1890"> </A>准备。必须在本地盘上,不能
在通过NFS mount的文件系统中。
<P>
关于孔,是重要的。对换文件保留了磁盘空间,使核心能快速对换出一页,而不必经过如文件的定位磁盘扇区的全部事情。
核心只用分配给这个文件的所有扇区。由于文件中的孔意味着没有为文件中这个位置分配磁盘扇区,这对核心使用不利。
<P>
产生没有孔的对换文件的一个好办法是通过如下命令:
<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>
<tt>/extra-swap</tt><A NAME="1892"> </A>是对换文件名,大小由<tt>count=</tt>给出.
大小最好是4的倍数,因为核心写出的<b>内存页</b>是4KB。如果不是4的倍数,最后那几KB将不可用。
<P>
对换分区也没什么特别。就象产生其他分区一样产生;唯一的不同是它作为原始分区使用,即没有任何
文件系统,最好将对换分区标记为类型82(Linux swap),虽然这对核心没有影响,但这使分区列表更清晰。
<P>
产生对换文件或对换分区后,需要写个标记起用它,这包括核心要用的一些管理信息。命令是
<tt>mkswap</tt><A NAME="1895"> </A>, 用法如下:
<BLOCKQUOTE> <TT>
<code>$</code> <I>mkswap /extra-swap 1024</I> <BR>
<code>Setting up swapspace, size = 1044480 bytes</code> <BR>
<code>$</code>
</TT></BLOCKQUOTE>
注意对换空间现在还没用,它存在,但核心还没用它提供虚拟内存。
<P>
请一定小心使用<tt>mkswap</tt><A NAME="1897"> </A>, 因为它不检查文件或分区是否被其他东西使用。
<em>你可能用<tt>mkswap</tt><A NAME="1899"> </A>很容易地覆盖了重要文件和分区!</em>
幸好,你只需在你安装系统时使用<tt>mkswap</tt><A NAME="1901"> </A>。
<P>
Linux内存管理限制了每个对换空间约为127MB(由于技术原因,实际限制是
<IMG WIDTH=251 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline3833" SRC="img11.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/img11.gif">字节,
或127.6875MB)。 可以同时使用最多16个对换空间,总计差不多2GB。
<A NAME="tex2html26" HREF="footnode.html#1835" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/footnode.html#1835">
<IMG ALIGN=BOTTOM ALT="gif" SRC="foot_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/foot_motif.gif"></A>
<P>
<HR><A NAME="tex2html1062" HREF="node62.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node62.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/next_motif.gif"></A> <A NAME="tex2html1060" HREF="node59.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node59.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/up_motif.gif"></A> <A NAME="tex2html1054" HREF="node60.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node60.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/previous_motif.gif"></A> <A NAME="tex2html1064" HREF="node1.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node1.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/contents_motif.gif"></A> <A NAME="tex2html1065" HREF="node108.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node108.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME="tex2html1063" HREF="node62.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node62.html">Using a swap space</A>
<B>Up:</B> <A NAME="tex2html1061" HREF="node59.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node59.html">Memory Management</A>
<B> Previous:</B> <A NAME="tex2html1055" HREF="node60.html" tppabs="http://linux.ccpi.gov.cn/Linux/linuxadmin/node60.html">What is virtual memory?</A>
<P><ADDRESS>
<I>Lars Wirzenius <BR>
Sun Jun 29 13:31:22 EEST 1997</I>
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -