一、 查看内存和swap 大小,发现swap 是内存大小的一半

  [root@gamedb ~]# free -m

             total       used       free     shared    buffers     cached

Mem:      1001        338        662          0          8        307

-/+ buffers/cache:    22        978

Swap:       509          0        509

===========================================================================================  

二、 决定修改swap大小,首先在空间合适处创建用于分区的 swap 文件

[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000

读入了 2000000+0 个块

输出了 2000000+0 个块

(注意:if 表示 infile,of 表示outfile,bs=1024 表示写入的每个块的大小为1024B=1KB(1024B字节=1024*8bit位)

  ===========================================================================================

三、查看创建的文件大小是否符合要求:

[root@gamedb tmp]# du -sh big_swap

2.0G     big_swap

[root@gamedb tmp]# ls -al big_swap

-rw-r--r--  1 root root 2048000000  6 18 11:55 big_swap

  ===========================================================================================

四、将目的文件设置为swap分区文件

[root@gamedb tmp]# mkswap big_swap

Setting up swapspace version 1, size = 2047995 kB

  ===========================================================================================

五、激活swap,立即启用交换分区文件:

[root@gamedb tmp]# swapon big_swap

  ===========================================================================================

六、再次查看内存和虚拟内存,发现已经被正常修改:

[root@gamedb tmp]# free -m

             total       used       free     shared    buffers     cached

Mem:      1001        984         16          0          2        931

-/+ buffers/cache:    50        950

Swap:     2462          0       2462

  ===========================================================================================

七、若要想使开机时自启用 则需修改文件 /etc/fstab 中的 swap

[root@gamedb tmp]# vi /etc/fstab

# LABEL=SWAP-hda2         swap                    swap    defaults        0 0

  /tmp/big_swap               swap                    swap    defaults        0 0