Out of memory on rebuild with 4GB swap?

Also check that you have enabled overcommit.