[aarch64] Absurdly high memory usage when compiling on arm64
Attempting to build serve-d with aarch64 results in 4GB+ of memory consumption. Of interest, I also recently compiled serve-d with ldc on 32-bit arm, debian stretch, and did not have a memory problem. The version of ldc was the same, but different versions of gcc and llvm were used.
The command which results in memory exhaustion acquired from dub -v.
[venix@pbpro serve-d]$ /usr/bin/ldc2 -c -of.dub/build/executable-debug-linux.posix-aarch64.arm_hardfloat-ldc_2089-2F728021E9F19F90CC6C6BB94D4BF4E6/serve-d.o -d-debug -g -w -oq -od=.dub/obj -d-version=Have_serve_d -d-version=Have_rm_rf -d-version=Have_diet_complete -d-version=Have_emsi_containers -d-version=Have_eventsystem -d-version=Have_libddoc -d-version=Have_painlessjson -d-version=Have_serve_d_http -d-version=Have_workspace_d -d-version=built_with_dub -d-version=StdLoggerDisableWarning -d-version=Have_stdx_allocator -d-version=LIBDDOC_CONFIG_LIB -d-version=Have_libdparse -d-version=Have_dunit -d-version=Have_painlesstraits -d-version=Have_requests -d-version=Have_cachetools -d-version=Have_dfmt -d-version=Have_dscanner -d-version=Have_dub -d-version=Have_inifiled -d-version=Have_standardpaths -d-version=Have_dsymbol -d-version=DubUseCurl -d-version=Have_xdgpaths -d-version=xdgpathsFileTest -d-version=Have_isfreedesktop -Isource/ -I../../.dub/packages/rm-rf-0.1.0/rm-rf/source/ -I../../.dub/packages/diet-complete-0.0.3/diet-complete/source/ -I../../.dub/packages/emsi_containers-0.8.0-alpha.19/emsi_containers/src/ -I../../.dub/packages/stdx-allocator-2.77.5/stdx-allocator/source/ -I../../.dub/packages/eventsystem-1.2.0/eventsystem/source/ -I../../.dub/packages/libddoc-0.7.0/libddoc/src/ -I../../.dub/packages/libdparse-0.13.1/libdparse/src/ -I../../.dub/packages/painlessjson-1.4.0/painlessjson/source/ -I../../.dub/packages/dunit-1.0.15/dunit/source/ -I../../.dub/packages/painlesstraits-0.3.0/painlesstraits/source/ -I../../.dub/packages/painlesstraits-0.3.0/painlesstraits/source -I../../.dub/packages/painlesstraits-0.3.0/painlesstraits/test -Ihttp/source/ -I../../.dub/packages/requests-1.0.12/requests/source -I../../.dub/packages/cachetools-0.3.1/cachetools/source -I../../.dub/packages/workspace-d-3.5.0/workspace-d/source/ -I../../.dub/packages/dfmt-0.11.0/dfmt/src/ -I../../.dub/packages/dscanner-0.8.0/dscanner/src/ -I../../.dub/packages/dsymbol-0.9.0/dsymbol/src/ -I../../.dub/packages/inifiled-1.3.1/inifiled/source -I../../.dub/packages/dub-1.18.0/dub/source/ -I../../.dub/packages/standardpaths-0.8.1/standardpaths/source/ -I../../.dub/packages/xdgpaths-0.2.5/xdgpaths/source/ -I../../.dub/packages/isfreedesktop-0.1.1/isfreedesktop/source/ -Jviews -J../../.dub/packages/diet-complete-0.0.3/diet-complete/views -J../../.dub/packages/workspace-d-3.5.0/workspace-d/views -J../../.dub/packages/dfmt-0.11.0/dfmt/bin -J../../.dub/packages/dscanner-0.8.0/dscanner/bin source/app.d source/crash_handler.d source/served/commands/calltips.d source/served/commands/code_actions.d source/served/commands/code_lens.d source/served/commands/complete.d source/served/commands/dcd_update.d source/served/commands/definition.d source/served/commands/dub.d source/served/commands/file_search.d source/served/commands/format.d source/served/commands/symbol_search.d source/served/extension.d source/served/info.d source/served/io/git_build.d source/served/io/http_wrap.d source/served/io/memory.d source/served/io/nothrow_fs.d source/served/linters/diagnosticmanager.d source/served/linters/dscanner.d source/served/linters/dub.d source/served/lsp/filereader.d source/served/lsp/jsonrpc.d source/served/lsp/protocol.d source/served/lsp/protoext.d source/served/lsp/textdocumentmanager.d source/served/types.d source/served/utils/async.d source/served/utils/ddoc.d source/served/utils/diet.d source/served/utils/fibermanager.d source/served/utils/progress.d source/served/utils/translate.d source/served/workers/rename_listener.d ../../.dub/packages/rm-rf-0.1.0/rm-rf/source/rm/rf.d -vv
Targeting 'aarch64-unknown-linux-gnu' (CPU 'generic' with features '')
Building type: real
Building type: int
Building type: dchar
Building type: char
Building type: ulong
Building type: byte
Building type: long
Building type: bool
Building type: uint
Building type: ubyte
Building type: short
Building type: wchar
Building type: ushort
Building type: double
^Z
At this point Building type: double memory reaches 22% up next comes Building type: float after which no further output is given and memory continues to increase until all exhausted. with a sufficiently large swapfile, it can complete.
This should be the configure command used to build ldc
cmake \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SKIP_RPATH=ON \
-DINCLUDE_INSTALL_DIR=/usr/include/dlang/ldc \
-DBUILD_SHARED_LIBS=BOTH \
-DBUILD_LTO_LIBS=OFF \
-DLDC_WITH_LLD=OFF \
-DD_COMPILER_FLAGS="-link-defaultlib-shared=false" \
-DADDITIONAL_DEFAULT_LDC_SWITCHES="\"-link-defaultlib-shared\"" \
..
make
The device runs Manjaro, so it may be a perfect storm of newness given the fact Debian didn't have the same problem and I couldn't find any prior reference to this.
[venix@pbpro serve-d]$ cat /etc/os-release
NAME="Manjaro-ARM"
ID=manjaro-arm
PRETTY_NAME="Manjaro ARM"
ANSI_COLOR="1;32"
HOME_URL="https://www.manjaro.org/"
SUPPORT_URL="https://forum.manjaro.org/c/manjaro-arm/"
[venix@pbpro serve-d]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-unknown-linux-gnu/9.2.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://github.com/archlinuxarm/PKGBUILDs/issues --enable-languages=c,c++,fortran,go,lto,objc,obj-c++,d --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --host=aarch64-unknown-linux-gnu --build=aarch64-unknown-linux-gnu --with-arch=armv8-a --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)
[venix@pbpro build-ldc]$ ldc2 --version
LDC - the LLVM D compiler (1.19.0):
based on DMD v2.089.1 and LLVM 9.0.1
built with LDC - the LLVM D compiler (1.18.0)
Default target: aarch64-unknown-linux-gnu
Host CPU: cortex-a53
http://dlang.org - http://wiki.dlang.org/LDC
This memory issue does not manifest on Debian stretch running 32-bit arm, with a custom compiled ldc2,and all the versions are much older. LLVM was 3.9.
Reproduce:
- Install Manjaro for arm64(Pinebook Pro or Rock64) and update
- Install ldc2 and dub
pacman -Syu ldc dub - Checkout serve-d
- Compile server-d using dub
dub -v - Watch memory and wait for crash.
4 GB aren't that unusual (at least without -lowmem), depending on CTFE usage and number of template instantiations. According to your -v output, it's all in the front-end stage, so LLVM version etc. don't play a role. Can you check the memory requirements when compiling for x64 (or 32-bit ARM), e.g., by prepending /usr/bin/time -v to the ldc2 cmdline, for comparison?
Here is the output from /usr/bin/time -v for aarch64, x64, and armhf (32bit). I also tried adding -lowmem in ldc2.conf but it seemed like dub ignored it. Running the ldc2 command with it, resulted in lower memory usage
x86-64 - dub - ldc
Command being timed: "dub build --force"
User time (seconds): 131.64
System time (seconds): 14.19
Percent of CPU this job got: 94%
Elapsed (wall clock) time (h:mm:ss or m:ss): 2:34.53
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3774800
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 48946
Minor (reclaiming a frame) page faults: 4927176
Voluntary context switches: 50414
Involuntary context switches: 41433
Swaps: 0
File system inputs: 1022872
File system outputs: 549112
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
aarch64 - dub - ldc
Command being timed: "dub build -v --force"
User time (seconds): 282.06
System time (seconds): 23.38
Percent of CPU this job got: 78%
Elapsed (wall clock) time (h:mm:ss or m:ss): 6:29.21
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3683360
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 28488
Minor (reclaiming a frame) page faults: 5190698
Voluntary context switches: 46224
Involuntary context switches: 22576
Swaps: 0
File system inputs: 1025944
File system outputs: 599816
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
32-bit armhf - dub - ldc
Command being timed: "dub -v build --force"
User time (seconds): 297.88
System time (seconds): 13.71
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 5:12.01
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2881728
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 223
Minor (reclaiming a frame) page faults: 2905871
Voluntary context switches: 270
Involuntary context switches: 4327
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
aarch64 - ldc
User time (seconds): 67.66
System time (seconds): 7.55
Percent of CPU this job got: 46%
Elapsed (wall clock) time (h:mm:ss or m:ss): 2:40.92
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3639244
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 29060
Minor (reclaiming a frame) page faults: 1384633
Voluntary context switches: 46351
Involuntary context switches: 20797
Swaps: 0
File system inputs: 763600
File system outputs: 44152
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
aarch64 - ldc with -lowmem
User time (seconds): 87.40
System time (seconds): 2.80
Percent of CPU this job got: 96%
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:33.17
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2640032
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 318
Minor (reclaiming a frame) page faults: 673674
Voluntary context switches: 1024
Involuntary context switches: 840
Swaps: 0
File system inputs: 133208
File system outputs: 44144
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Okay thx, so everything's looking as expected, the general memory requirements (maximum resident set size) are pretty high for serve-d, nothing AArch64 specific. I'm sure you'll see similar numbers with DMD/any other compiler based on the DMD frontend.
Edit: Oh sry, I haven't realized you already posted non-LDC results (gdc?).
I also tried adding -lowmem in ldc2.conf but it seemed like dub ignored it.
Heh yeah, -lowmem is the only option (well, besides -conf) which is ignored in the config file, because that'd be too late to switch between GC and bump-pointer mode.
Thanks for the help. There's a record of it now, since serve-d is used with visual studio code, any other unfortunate souls with 4GB of RAM will now have some guidance.
Edit: Oh sry, I haven't realized you already posted non-LDC results (gdc?).
All the output is from ldc, I'll try to get some others for comparison.
It's too bad I can't use -lowmem in the config. It would make this much easier to deal with.
You're welcome.
All the output is from ldc
I got confused by aarch64 and aarch64 - ldc.
It's too bad I can't use -lowmem in the config.
There's a way - setting the env var DFLAGS=-lowmem and using ldmd2 instead of ldc2 with dub. Well now that I've typed that out, I think DFLAGS should work with ldc2 too, because dub uses it too and converts it to regular cmdline flags IIRC.
Not compiling all modules at once might help with memory requirements too (dub --build-mode=singleFile).
DFLAGS=-lowmem works perfectly, singleFile must have -lowmem set or it will still use about 3GB. With -lowmem it's around 1.2GB but has the nasty affect of increasing build time 5x. Build time was verified on x64 and it still took about 5x longer.
Are there any side effects to -lowmem to be concerned about? Might make a good default for low memory systems <= 4GB at minimum, maybe even <8GB.
DFLAGS=-lowmem
Command being timed: "dub build -v --force"
User time (seconds): 272.87
System time (seconds): 11.73
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 4:47.03
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2306240
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 101
Minor (reclaiming a frame) page faults: 2839348
Voluntary context switches: 192
Involuntary context switches: 5013
Swaps: 0
File system inputs: 16
File system outputs: 545248
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
dub --build-mode=singleFile
Command being timed: "dub build --build-mode=singleFile -v --force"
User time (seconds): 1626.01
System time (seconds): 185.96
Percent of CPU this job got: 87%
Elapsed (wall clock) time (h:mm:ss or m:ss): 34:21.66
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 3670880
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 47360
Minor (reclaiming a frame) page faults: 47962565
Voluntary context switches: 75068
Involuntary context switches: 61168
Swaps: 0
File system inputs: 4554752
File system outputs: 1885056
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
dub --build-mode=singleFile with -lowmem
Command being timed: "dub build --build-mode=singleFile -v --force"
User time (seconds): 1631.50
System time (seconds): 84.78
Percent of CPU this job got: 99%
Elapsed (wall clock) time (h:mm:ss or m:ss): 28:44.15
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1271972
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 102
Minor (reclaiming a frame) page faults: 21931806
Voluntary context switches: 4404
Involuntary context switches: 18647
Swaps: 0
File system inputs: 816
File system outputs: 660544
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Are there any side effects to -lowmem to be concerned about?
It's usually slower, not terribly, but definitely noticeable, due to the additional garbage collections. See https://github.com/ldc-developers/ldc/pull/2916#issuecomment-443433594 for some numbers at the time the feature was introduced (without parallel GC marking etc.).
Might make a good default for low memory systems <= 4GB at minimum, maybe even <8GB.
I don't think so; it really seems to mostly depend on how extensively CTFE and template instantiations are used. IIRC, compiling the tiny ldc-build-runtime tool (a few hundred lines, but importing Phobos stuff) at one stage took about ~~4x~~ 2x as much memory as compiling the entire DMD frontend at once.
Edit: Also, on Linux x64, 2.4 GB of memory suffice to build LDC all-at-once and compile each Phobos unittest (separately) - with a single serial build job and without resorting to -lowmem (SemaphoreCI).
I think this is good to be closed then before this becomes too much of a debate, that suggestion falls in the user experience category more than anything.
To re-iterate what lead to this.
- Installed vsCodium (Visual Studio Code)
- Installed code-d extension
- System crash due to memory exhaustion
It's not a good experience when the dev tool being installed crashes your system. If I had been trying D for the first time, I'd move along and never look back.
Edit: Sadly, being able to set it in /etc/ldc2.conf would be the perfect solution, and easily undone for those who don't need/want it.
Let's close it then, as LDC is the wrong addressee for the issue anyway. There are multiple solutions to this, among which:
- refactoring serve-d or its dependencies
- tweaking the DMD frontend for lower memory usage
- adding
-lowmemin serve-d's dub config, - providing prebuilt AArch64 serve-d binaries (there are free AArch64 CI services for native compilations, cross-compilation would be another option...)