在linux中,当物理内存mem不足时,就会使用虚拟内存(swap分区)
例如增加2G虚拟内存,操作如下:
1.查看内存大小
root@localhost \~\]# free -m  2.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs\*count=文件大小) \[root@localhost \~\]# dd if=/dev/zero of=h bs=1M count=1024 3.目录空间大小 \[root@localhost \~\]# du -sh h 4.格式化为交换分区文件 \[root@localhost \~\]# mkswap h #建立swap的文件系统 5.启用交换分区文件: \[root@localhost \~\]# swapon h #启用swap文件 6.查看下扩充后的内存 \[root@localhost \~\]# free -m #查看swap添加了1G内存  7.使系统开机时自启用,在文件/etc/fstab中添加一行: /root/swapfile swap swap defaults 0 0 8.关闭某个分区 \[root@localhost \~\]# swapoff h 