virtual memory exhausted: Cannot allocate memory

http://blog.csdn.net/taiyang1987912/article/details/41695895

1. Problems

       When installing a virtual machine, the system does not set the swap size or set the memory to be too small, and the compiler will have the problem of virtual memory exhausted: Cannot allocate memory. You can use swap to expand the memory.

Second, the solution

When executing free -m, it prompts Cannot allocate memory:

(The swap file can be placed in your favorite location such as /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=1024count=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  

The memory is too small, increasing the memory can solve it.

 

You can turn off swap after use:

 

[html]  view plain copy View code snippets on CODE Derive to my code slice
 
  1. [root@hz mnt]# swapoff swap  
  2. [root@hz mnt]# rm -f /opt/images/swap  

The swap file can also not be deleted and kept for future use. The key is that your virtual machine hard disk is sufficient.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326933141&siteId=291194637