Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Ubuntu RPi freeze during C++ compilation

📅 2021-Feb-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ raspberry pi ⬩ 📚 Archive

I was compiling the Veracrypt C++ source code when the system froze up completely. This was on my Raspberry Pi 3 Model B+ board which was running Ubuntu 20.04. The system was unfrozen only after about 30 minutes and I saw this error at the shell:

$ make
...
g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[1]: *** [/home/ashwin/VeraCrypt-VeraCrypt_1.24-Update7/src/Build/Include/Makefile.inc:28: CommandLineInterface.o] Error 1
make[1]: *** Waiting for unfinished jobs....
g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[1]: *** [/home/ashwin/VeraCrypt-VeraCrypt_1.24-Update7/src/Build/Include/Makefile.inc:28: FavoriteVolume.o] Error 1
make: *** [Makefile:424: all] Error 2

Looking up /var/log/syslog I noticed that the kernel had detected that the system was hung. It would wait for 120 seconds, the time specified in /proc/sys/kernel/hung_task_timeout_secs, and then try again. It did this for about 20 minutes and about 10 minutes after that the C++ compiler invoked the OOM killer: cc1plus invoked oom-killer. The killer killed the C++ compiler and the system was unfrozen.

Solution

It looked like the C++ compiler was running out of RAM. I had seen this problem earlier on Raspbian, where the solution had been to increase the size of its swap file.

But Ubuntu seemed to neither use a swap file nor a swap partition on the Raspberry Pi. So I looked for other solutions.

On my computers, I set MAKEFLAGS to use all the available CPU cores for faster builds. Since the BCM2837B0 chip used in my RPi has a quad-core ARM CPU, I had set the flag to --jobs=4. This meant that 4 instances of the C++ compiler were running in parallel when the system ran out of memory.

I reduced the 4 to 1 and I was able to compile without any further hiccups.