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註釋或者刪掉。
發佈了55 篇原創文章 · 獲贊 5 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章