购买了一个1G内存云主机,装了docker,发现在里面执行make报如下错误,怀疑是内存不够所致,几乎把所有程序都停了,编译还是报一样的错误,于是打算加点内存,发现加1G内存至少需要1K多的money,太贵了。
c++: fatal error: Killed signal terminated program cc1plus
于是想是否可以增加虚拟内存,在网上找了增加虚拟内存的方法,试了还真的ok。
top - 23:09:20 up 77 days, 12:45, 3 users, load average: 2.74, 4.44, 2.94
Tasks: 104 total, 1 running, 90 sleeping, 13 stopped, 0 zombie
%Cpu(s): 3.3 us, 3.7 sy, 0.0 ni, 0.0 id, 93.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016516 total, 75984 free, 875676 used, 64856 buff/cache
KiB Swap: 2047996 total, 1068336 free, 979660 used. 27880 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
27620 root 20 0 1407044 770932 556 D 6.0 75.8 0:27.00 cc1plus
27743 root 20 0 756312 7288 1308 S 0.7 0.7 0:01.11 barad_agent
25 root 20 0 0 0 0 S 0.3 0.0 1:12.64 kswapd0
1 root 20 0 191032 1688 1060 S 0.0 0.2 5:38.47 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.11 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 1:18.39 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/
操作步骤如下:
[root@VM_0_5_centos var]# dd if=/dev/zero of=/var/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 24.6811 s, 85.0 MB/s
[root@VM_0_5_centos var]# mkswap /var/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=cce4d9e5-8b2b-4ac3-8256-68b5611c5c7e
[root@VM_0_5_centos var]# mkswap -f /var/swap
mkswap: /var/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=f70bfb56-c582-4515-a912-e23b5c9f3b40
[root@VM_0_5_centos var]# swapon /var/swap
swapon: /var/swap: insecure permissions 0644, 0600 suggested.
[root@VM_0_5_centos var]# free
total used free shared buff/cache available
Mem: 1016516 198496 76060 780 741960 650356
Swap: 2047996 0 2047996
[root@VM_0_5_centos var]#
虚拟内存取消办法:
-
[root@VM_0_5_centos var]# swapoff /var/swap [root@VM_0_5_centos var]# free total used free shared buff/cache available Mem: 1016516 196760 190860 780 628896 659524 Swap: 0 0 0