The compiler works great, there are 4 cores available, but if I use all 4 of them, invariably the memory runs out. Aside from uninstalling as many services as possible, compiling with a cross-compiler and skipping on the GUI/IDE, what can one do?

  • 1
    Adding swap space. – Janka Oct 9 '18 at 12:53
  • @Janka zram? Have you actually done it? – user1095108 Oct 9 '18 at 13:20
  • 1
    Huh? Swap space means nothing more than reserving a few gigabytes on your sd card (partition or file), then swapon it. It won't do any good for speed, but you won't run out of memory either. – Janka Oct 9 '18 at 13:31
  • If it is OK to ask - what OS and compiler are you using to compile multi-core? I will need such approach in near future. I am pretty happy cross-compiling, single CPU so far. – Jan Hus Oct 9 '18 at 14:04
  • rpi3b+ with gcc from the testing repository, I have zram setup, but I am plagued with device resets. Could be my device though, it seems to work ok on another RPi. Actually, I'd advise to use zram. – user1095108 Oct 9 '18 at 14:57

It appears my problems were power-supply related. A 5V/3A power supply solved the reset problem when the cores started burning too much power. ZRAM solved the lockup problem when memory ran out (but you need to be sure to supply enough, that is, around 100M, /tmp space). I am actually impressed with the compilation speed now. The zram approach is the way to go, but also mount /tmp as tmpfs with at least 100M space and disable/uninstall as many services as you can. Doing this allows me to use all 4 cores for compilation without crashes and resets. It also saves my SD card, since the temporary files will not be written to SD, but into memory. I'd also advise to add some cooling to the Pi. I have placed some heat sinks on the Pi chips, but it does not appear to be enough at times. Also, you should hack around the ext4 a little (like turn on writeback and discard options).



free -h:

              total        used        free      shared  buff/cache   available
Mem:           976M         25M        896M        6.4M         54M        897M
Swap:          976M          0B        976M


Startup finished in 2.754s (kernel) + 3.853s (userspace) = 6.607s

tune2fs -l

tune2fs 1.43.4 (31-Jan-2017)
Filesystem volume name:   rootfs
Last mounted on:          /
Filesystem UUID:          fd695ef5-f047-44bd-b159-2a78c53af20a
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
**Default mount options:    journal_data_writeback discard**
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              1889056
Block count:              7802880
Reserved block count:     315875
Free blocks:              7406202
Free inodes:              1849110
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      106
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         7904
Inode blocks per group:   494
Flex block group size:    16
Filesystem created:       Wed Jun 27 03:08:02 2018
Last mount time:          Thu Nov  3 18:16:43 2016
Last write time:          Thu Nov  3 18:16:42 2016
Mount count:              261
Maximum mount count:      -1
Last checked:             Thu Nov  3 18:16:44 2016
Check interval:           0 (<none>)
Lifetime writes:          12 GB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      7c83a135-91d4-411c-9e7e-0c08c37476d1
Journal backup:           inode blocks


proc            /proc           proc    defaults          0       0
PARTUUID=9cde2d98-01  /boot           vfat    defaults,noatime  0       2
PARTUUID=9cde2d98-02  /               ext4    defaults,noatime,commit=60 0       1
tmpfs   /tmp    tmpfs    defaults,noatime,nosuid,size=100m    0 0
  • But wouldn’t cross compiling be faster and less problematic? – John Keates Oct 9 '18 at 19:40
  • yeah, but why bother with setting up the toolchain and libs for just an occasional compile? I use my Pi as a WiFi router and some occasional compiling for the arm. Zram does no harm for any setup, I think, even if you're into GUI. – user1095108 Oct 9 '18 at 20:57
  • In that case it makes less sense indeed. I didn’t see any usage context. – John Keates Oct 9 '18 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.