Compile: virtual memory exhausted: Cannot allocate memory, exhaustedallocate
I. Problems
When the system does not set the swap size or the memory size is too small when installing the virtual machine, the Compilation Program will encounter the virtual memory exhausted: Cannot allocate memory problem. You can use swap to expand the memory.
Ii. Solution
The prompt "Cannot allocate memory" is displayed when free-m is executed:
(Swap files can be stored in your favorite location, such as/var/swap)
[Html]View plain copy
- [Root @ Byrd byrd] # free-m
- Total used free shared buffers cached
- Mem: 512 108 403 0 0 28
- -/+ Buffers/cache: 79 432
- Swap: 0 0 0
- [Root @ Byrd ~] # Mkdir/opt/images/
- [Root @ Byrd ~] # Rm-rf/opt/images/swap
- [Root @ Byrd ~] # Dd if =/dev/zero of =/opt/images/swap bs = 1024 count = 2048000
- 2048000 + 0 records in
- 2048000 + 0 records out
- 2097152000 bytes (2.1 GB) copied, 82.7509 s, 25.3 MB/s
- [Root @ Byrd ~] # Mkswap/opt/images/swap
- Mkswap:/opt/images/swap: warning: don't erase bootbits sectors
- On whole disk. Use-f to force.
- Setting up swapspace version 1, size = 2047996 KiB
- No label, UUID = 59daeabb-d0c5-46b6-bf52-108e6b05eb0b
- [Root @ hz mnt] # swapon/opt/images/swap
- [Root @ hz mnt] # free-m
- Total used free shared buffers cached
- Mem: 488 481 7 0 6 417
- -/+ Buffers/cache: 57 431
- Swap: 999 0 999
The memory size is too small. Increasing the memory size can solve this problem.
After use, you can turn off the swap:
[Html]View plain copy
- [Root @ hz mnt] # swapoff swap
- [Root @ hz mnt] # rm-f/opt/images/swap
Swap files can also be deleted without being deleted and used later. The key is that your VM hard disk is sufficient.