20

When I try to compile Phalcon, I get an error:

virtual memory exhausted: Cannot allocate memory

I am running the following commands

git clone --depth=1 git://github.com/phalcon/cphalcon.git 
cd cphalcon/build 
sudo ./install

I have a VPS with 1GB RAM

Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67

3 Answers3

35

Add more swapfile may help. I met this problem when tried to compile YouCompleteMe for vim, solved it by adding swapfile.

https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-14-04

Hunger
  • 5,186
  • 5
  • 23
  • 29
  • 3
    I faced this problem trying to install Python Pandas inside a virtualenv in a Amazon t1.micro instance. And adding temporary swap solved the issue :) – Javier de la Rosa Jun 01 '14 at 18:23
14

It seems GCC is allocating a lot of memory, check this

https://web.archive.org/web/20141202015428/http://hostingfu.com/article/compiling-with-gcc-on-low-memory-vps

Stopping as many services as possible (Apache, MySQL etc.) will free up more memory, and Phalcon will compile. Worst case scenario you will need to increase the memory of your virtual box.

Thanks to @AndrewD for providing the link that works.

Nikolaos Dimopoulos
  • 11,495
  • 6
  • 39
  • 67
  • Am I correct in assuming that any sizable codebase you compile with GCC risks hitting this limit and its not a fault with phalcon? – CodeMonkey Apr 09 '14 at 15:05
  • @CodeMonkey That is correct. I posted this because Phalcon uses significantly lower resources than other frameworks and people tend to use lower end resources. This makes the problem more evident :) – Nikolaos Dimopoulos Apr 10 '14 at 17:02
  • 1
    Looks like hostingfu is no more so you can now find this here: https://web.archive.org/web/20141202015428/http://hostingfu.com/article/compiling-with-gcc-on-low-memory-vps – AndrewD Jul 14 '15 at 16:42
  • 1
    Link-only answers are discouraged on StackOverflow for this reason. The important points from the article should be posted as an answer. – David Grayson Aug 16 '15 at 21:07
  • Tried `CFLAGS="$CFLAGS --param ggc-min-expand=0 --param ggc-min-heapsize=8192"` on an aws micro instance via ssh. Didn't work and ran into `virtual memory exhausted: Cannot allocate memory` when running make `make: *** [phalcon.lo] Error 1`. Tried the swapfile approach mentioned in the other answer and it worked on the first try. – Ultimater May 06 '18 at 09:38
2

Another option that Andres suggested is to build from a different folder:

https://forum.phalconphp.com/discussion/7891/upgrading-from-201-to-205-getting-virtual-memory-exhausted-canno

The steps would be...

git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/ext
sudo ./install

As he explained it, this approach uses less memory but takes more time and for newer version of GCC >4.7 the end result is the same.

Jim
  • 404
  • 2
  • 14