diff options
author | XenHat | 2023-03-27 21:33:21 -0400 |
---|---|---|
committer | XenHat | 2023-03-27 21:33:21 -0400 |
commit | a0f769a34bd55cb766b9033926e1b6ac81294ebe (patch) | |
tree | a656339b8a7120fddd02342d4421f3a69550c9f3 | |
parent | 015af61cf8d6fe80e933d8416dd9f3eb8d0e1d1d (diff) | |
download | aur-a0f769a34bd55cb766b9033926e1b6ac81294ebe.tar.gz |
Tentative re-write of the linker memory usage workaround
-rwxr-xr-x | PKGBUILD | 2 | ||||
-rwxr-xr-x | compile.bash | 73 |
2 files changed, 49 insertions, 26 deletions
@@ -31,7 +31,7 @@ install=alchemy.install source=("${pkgname}"::'git+https://git.alchemyviewer.org/alchemy/alchemy-next.git#branch='"${AL_BRANCH_OVERRIDE:-main}" 'compile.bash') sha256sums=('SKIP' - '7c841143956b312b2abb47d89151be9522e6fb0391450e311a3f4696aa05f792') + 'b1804aa12f4ae454db93436b58a5cf2dfc8dfee191959e4209abfa2c6788980f') pkgver() { cd "${pkgname}" || exit 1 diff --git a/compile.bash b/compile.bash index 9a20852afa30..510983f5482d 100755 --- a/compile.bash +++ b/compile.bash @@ -32,32 +32,55 @@ build() { fi ulimit -n 20000 build_jobs=$(nproc) - if [[ ${build_jobs} -gt 1 ]]; then - mempercorekb=$((4 * 1048576)) - # The viewer requires an average of 4GB of memory per core to link - requiredmemorykb=$(($(nproc) * mempercorekb)) - # Source: Total Used Free - free_output="$(free --kilo --total | tail -n+2| tr -s ' ')" - totalmemorykb=$(grep Total <<< "$free_output" | cut -d ' ' -f 2) - availablememorykb=$(cut -d ' ' -f 7 <<< "$free_output") - echo "Total memory: $totalmemorykb (includes swap)" - echo "Available memory: $availablememorykb" - echo "Required memory: $requiredmemorykb" - if [[ ${requiredmemorykb} -gt ${totalmemorykb} ]]; then + if [[ -z "$NO_SMART_JOB_COUNT" ]]; then + if [[ ${build_jobs} -gt 1 ]]; then + jobs=1 + # The viewer requires an average of 4GB of memory per core to link + # Note: Behaviour change compared to the previous versions: + # This script will no longer try to allocate build memory into swap + # This is bad practice, and swap should be reserved to evict process + # memory from physical ram to make place for the current workset. + # This script will now try to check if swap is present and sufficent + # for the current used memory to be stored in swap before allocating, + # and will fallback to conservative allocation if swap is not available + gigperlinkprocess=4 + mempercorekb=$((gigperlinkprocess * 1048576)) + requiredmemorykb=$(($(nproc) * mempercorekb)) + free_output="$(free --kilo --total | tail -n+2| tr -s ' ')" + physical_output=$(grep "Mem:" <<< "$free_output") + #total_output=$(grep Total: <<< "$free_output") + usedmemorykbphysical=$(cut -d ' ' -f 3 <<< "$physical_output") + totalmemorykbphysical=$(cut -d ' ' -f 2 <<< "$physical_output") + swap_output=$(grep Swap: <<< "$free_output") + # Determine available swap space + availableswapkb=0 + if [[ -n "$swap_output" ]]; then + availableswapkb=$(cut -d ' ' -f 4 <<< "$swap_output") + fi + availablememorykbphysical=$(cut -d ' ' -f 7 <<< "$free_output") + echo "Total memory: $totalmemorykbphysical (includes swap)" + echo "Available memory: $availablememorykbphysical" + echo "Required memory: $requiredmemorykb" + echo "Available physical memory on this system: $((availablememorykbphysical/1024/1024)) GB" echo "Estimated required memory to build with all cores: $((requiredmemorykb/1024/1024)) GB" - echo "Available memory on this system: $((availablememorykb/1024/1024)) GB" - echo "Warning: Not enough physical memory to build with all cores, adjusting" - if [[ ${requiredmemorykb} -gt ${availablememorykb} ]]; then - jobs=1 - echo "Allocating build jobs according to available memory (including swap) (${availablememorykb}/${requiredmemorykb})..." - # FIXME: Goes one iteration beyond what it should - while [[ $((jobs * mempercorekb)) -lt ${availablememorykb} ]]; do - jobs=$((jobs+1)) - echo -e "${jobs} jobs would consume $(((jobs * mempercorekb)/1024/1024))GB" - done - # Back off one job count. Not sure why I have to do this but - # the loop is doing one extra iteration. - jobs=$((jobs-1)) + if [[ ${requiredmemorykb} -gt ${availablememorykbphysical} ]]; then + echo "Warning: Not enough available physical memory to build with all cores" + if [[ ${usedmemorykbphysical} -lt ${availableswapkb} ]]; then + # use all physical ram as swap will do its job + echo "There is enough free swap to store the currently used memory" + jobs=$(((totalmemorykbphysical/1024/1024)/gigperlinkprocess)) + else + # Not enough swap to hold ram contents, calculate manually + echo "Allocating build jobs according to available physical memory ("$((availablememorykbphysical/1024/1024))"/"$((requiredmemorykb/1024/1024))"GB)..." + # FIXME: Goes one iteration beyond what it should + while [[ $((jobs * mempercorekb)) -lt ${availablememorykbphysical} ]]; do + jobs=$((jobs+1)) + echo -e "${jobs} jobs would consume $(((jobs * mempercorekb)/1024/1024))GB" + done + # Back off one job count. Not sure why I have to do this but + # the loop is doing one extra iteration. + jobs=$((jobs-1)) + fi build_jobs=${jobs} echo "Computed job count: ${build_jobs}" fi |