diff options
author | Xenhat Hex | 2022-09-30 23:20:40 -0400 |
---|---|---|
committer | Xenhat Hex | 2022-09-30 23:20:40 -0400 |
commit | 3624d16a80c83f528cbb9aa250ed2a6d09bbe11e (patch) | |
tree | 890fb85f48f842feb229a301752f51f8bdc84582 | |
parent | f7a088713152b73c1329dd8709bb42f2480271d0 (diff) | |
download | aur-3624d16a80c83f528cbb9aa250ed2a6d09bbe11e.tar.gz |
make compile script take swap memory into account
-rwxr-xr-x | compile.bash | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/compile.bash b/compile.bash index f998b9cd8543..a0bcac208228 100755 --- a/compile.bash +++ b/compile.bash @@ -12,29 +12,34 @@ pip3 install --no-cache --upgrade autobuild --quiet # we have a lot of files, relax ulimit to help performance ulimit -n 20000 -AUTOBUILD_CPU_COUNT=$(nproc) -if [[ ${AUTOBUILD_CPU_COUNT} -gt 1 ]]; then - #if false; then - # The viewer requires an average of 4GB of memory per core to link - mempercorekb=$((4 * 1048576)) - requiredmemorykb=$(($(nproc) * mempercorekb)) - availablememorykb=$(grep MemTotal /proc/meminfo|tr -s ' '|cut -d ' ' -f 2) - #freememkb="$(grep MemFree /proc/meminfo | tr -s ' ' | cut -d ' ' -f 2)" - if [[ ${requiredmemorykb} -gt ${availablememorykb} ]]; then - jobs=0 - until [[ $(((jobs + 1) * mempercorekb)) -gt ${availablememorykb} ]]; do +build_jobs=$(nproc) +if [[ ${build_jobs} -gt 1 ]]; then + # The viewer requires an average of 4GB of memory per core to link + mempercorekb=$((4 * 1048576)) + requiredmemorykb=$(($(nproc) * mempercorekb)) + # Source: Total Used Free + free_output="$(free --kilo --total | tr -s ' ')" + totalmemorykb=$(grep Total <<< "$free_output" | cut -d ' ' -f 2) + freememorykb=$(grep Total <<< "$free_output" | cut -d ' ' -f 4) + echo "Total memory: $totalmemorykb (includes swap)" + echo "Free memory: $freememorykb" + echo "Required memory: $requiredmemorykb" + if [[ ${requiredmemorykb} -gt ${totalmemorykb} ]]; then + echo "Not enough physical memory to build with all cores, adjusting" + echo "Estimated required memory to build with all cores: $((requiredmemorykb/1024/1024)) GB" + if [[ ${requiredmemorykb} -gt ${freememorykb} ]]; then + jobs=1 + echo "Allocating build jobs according to available memory (${freememorykb}/${requiredmemorykb})..." + while [[ $((jobs * mempercorekb)) -lt ${freememorykb} ]]; do jobs=$((jobs+1)) - done - #((jobs--)) - AUTOBUILD_CPU_COUNT=${jobs} - #fi - elif [[ ${AUTOBUILD_CPU_COUNT} -le 8 ]]; then - AUTOBUILD_CPU_COUNT=$((AUTOBUILD_CPU_COUNT - 1)) - else - AUTOBUILD_CPU_COUNT=$((AUTOBUILD_CPU_COUNT - 2)) + echo -e "${jobs}...$(((jobs * mempercorekb)/1024/1024))GB" + done + echo "" + build_jobs=${jobs} fi + fi fi -export AUTOBUILD_CPU_COUNT +export AUTOBUILD_CPU_COUNT=$build_jobs autobuild configure -A 64 -c ReleaseOS -- \ -DLL_TESTS:BOOL=OFF \ -DDISABLE_FATAL_WARNINGS=ON \ |