Linux 如何调整虚拟内存大小

我用的CentOS, 直接贴操作步骤,供参考:

[root@1pad ~]# free -m

             total       used       free     shared    buffers     cached
Mem:          3702        722       2979          0        149        230
-/+ buffers/cache:        342       3359
Swap:         3839          0       3839
[root@1pad ~]# cd /home
[root@1pad home]# pwd

/home
[root@1pad home]# dd if=/dev/zero of=swapfile bs=4096 count=15728640                              #(新的虚拟内存大小 = bs * count bytes)
15728640+0 records in
15728640+0 records out
64424509440 bytes (64 GB) copied, 478.958 s, 135 MB/s
[root@1pad home]# ls
alex  swapfile
[root@1pad home]# /sbin/mkswap swapfile
mkswap: swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 62914556 KiB
no label, UUID=a029accb-6676-48cb-ba7d-d31b9e84be37
[root@1pad home]# /sbin/swapon swapfile
[root@1pad home]# /sbin/swapon -s

Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       3932152 236     -1
/home/swapfile                          file            62914552        0       -2
[root@1pad home]# free -m
             total       used       free     shared    buffers     cached
Mem:          3702       3565        137          0        138       2972
-/+ buffers/cache:        453       3248
Swap:        65279          0      65279
[root@1pad home]# vim /etc/fstab                             #在fstab结尾加入如下两行,目的是为了让新创建的swap分区在电脑重启后能够自动挂载
#Expand the swap space---Alex Tian, Jan. 27th, 2015
/home/swapfile swap swap defaults 0 0

最后检查/etc/rc.d/rc.local脚本中是否将所有fstab中要求挂载的swap分区都给关闭。
如果是的话,将其中的swapoff -a注释或者删掉。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值