androidubuntu

Is it possible to build AOSP on 32GB RAM?


I am well aware the minimal requirements explicitly state 64GB RAM, but in another how-to article I read 32GB and also comments under that article confirmed that.

But when I try "m -j28" I end up with this: (and now also tested with -j8)

[100% 1/1] analyzing Android.bp files and generating ninja file at out/soong/build.aosp_cf_x86_64_phone.ninja
FAILED: out/soong/build.aosp_cf_x86_64_phone.ninja
cd "$(dirname "out/host/linux-x86/bin/soong_build")" && BUILDER="$PWD/$(basename "out/host/linux-x86/bin/soong_build")" && cd / && env -i  "$BUILDER"     --top "$TOP"     --soong_out "out/soong"     --out "out"     --soong_variables out/soong/soong.aosp_
cf_x86_64_phone.variables -o out/soong/build.aosp_cf_x86_64_phone.ninja -l out/.module_paths/Android.bp.list --available_env out/soong/soong.environment.available --used_env out/soong/soong.environment.used.aosp_cf_x86_64_phone.build Android.bp
Warning: Module 'androidx.wear_wear' depends on non-existing optional_uses_libs 'wear-sdk'
Warning: Module 'androidx.wear.compose_compose-foundation' depends on non-existing optional_uses_libs 'wear-sdk'
Killed
20:55:51 soong bootstrap failed with: exit status 1
ninja: build stopped: subcommand failed.

#### failed to build some targets (54 seconds) ####

I see no further useful info in the out/verbose.log file.
Also I don't assume the missing optional library 'wear-sdk' is the reason why the build was killed.
So is it the RAM after all?



Solution

  • Try configuring ZRAM. ZRAM is form of memory swapping that compresses swapped memory pages in RAM rather than swapping them to disk. Disk swap is the default configuration utilized by Ubuntu and tends to be a meager 2 GiB; it is slower than ZRAM and that is not nearly enough.

    I'd suggest make the ZRAM 3/4 the size of total RAM. This should allow you get close to 64 GiB usable RAM on a machine with 32 GiB physical RAM.

    If absolutely necessary use both ZRAM and a disk swap (larger than 2 GiB), but try with just ZRAM and using fewer threads first since disk swap is usually very slow. In theory a large enough disk swap should guarantee success.

    Here is an example article explaining how to configure ZRAM: https://fosspost.org/enable-zram-on-linux-better-system-performance

    Finally use -j 24 option or so when initiating the build to prevent too many concurrent processes from executing at the same time and consuming excessive RAM.

    I notice during AOSP builds there are two phases that require a lot of RAM:

    1. The initial startup phase of the build where build files (Soong and makefiles) are evaluated and the build plan is created. This is pretty much a single-threaded operation based my observations. I don't know why this uses so much RAM but I've seen RAM use go over 40 GiB on Android 13 builds during this phase. Since I don't know the root cause and it is single threaded I don't know of any ways to reduce the RAM requirements for this phase.
    2. During the build there is a phase when many instances of the kotlin compiler and/or java compiler are being executed in parallel based on the the number of threads allocated to the build. I have observed that each instance of those compilers can use 1.5 GiB or more of RAM so if you have 32 threads running these compilers you can consume more than 48 GiB of RAM easily. This phase is where it might help to limit the number of concurrent threads. Using above ZRAM/swap techniques you might get away with 24 threads in your situation but probably not the full 32 threads your CPU is capable of.