歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> 編譯時:virtual memory exhausted: Cannot allocate memory,exhaustedallocate

編譯時:virtual memory exhausted: Cannot allocate memory,exhaustedallocate

日期:2017/3/6 9:31:28   编辑:學習Linux

編譯時:virtual memory exhausted: Cannot allocate memory,exhaustedallocate


編譯時:virtual memory exhausted: Cannot allocate memory,exhaustedallocate


一、問題

當安裝虛擬機時系統時沒有設置swap大小或設置內存太小,編譯程序會出現virtual memory exhausted: Cannot allocate memory的問題,可以用swap擴展內存的方法。

二、解決方法

在執行free -m的是時候提示Cannot allocate memory:

(swap文件可以放在自己喜歡的位置如/var/swap)

[html] view plain copy
  1. [root@Byrd byrd]# free -m
  2. total used free shared buffers cached
  3. Mem: 512 108 403 0 0 28
  4. -/+ buffers/cache: 79 432
  5. Swap: 0 0 0
  6. [root@Byrd ~]# mkdir /opt/images/
  7. [root@Byrd ~]# rm -rf /opt/images/swap
  8. [root@Byrd ~]# dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
  9. 2048000+0 records in
  10. 2048000+0 records out
  11. 2097152000 bytes (2.1 GB) copied, 82.7509 s, 25.3 MB/s
  12. [root@Byrd ~]# mkswap /opt/images/swap
  13. mkswap: /opt/images/swap: warning: don't erase bootbits sectors
  14. on whole disk. Use -f to force.
  15. Setting up swapspace version 1, size = 2047996 KiB
  16. no label, UUID=59daeabb-d0c5-46b6-bf52-465e6b05eb0b
  17. [root@hz mnt]# swapon /opt/images/swap
  18. [root@hz mnt]# free -m
  19. total used free shared buffers cached
  20. Mem: 488 481 7 0 6 417
  21. -/+ buffers/cache: 57 431
  22. Swap: 999 0 999

內存太小,增加內存可以解決。

使用完畢後可以關掉swap:

[html] view plain copy 在CODE上查看代碼片派生到我的代碼片
  1. [root@hz mnt]# swapoff swap
  2. [root@hz mnt]# rm -f /opt/images/swap

swap文件也可以不刪除,留著以後使用,關鍵是你的虛擬機硬盤夠用。

http://xxxxxx/Linuxjc/1141595.html TechArticle

Copyright © Linux教程網 All Rights Reserved