From 2f9870caf4804a483b7d19d6d791daf6d26b9091 Mon Sep 17 00:00:00 2001 From: theofficialgman <28281419+theofficialgman@users.noreply.github.com> Date: Tue, 9 Jan 2024 19:41:31 -0500 Subject: [PATCH] api: refactor `nproc` wrapper to use available memory instead of free Available memory is an estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use. --- api | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/api b/api index a9df07b5ff..fd48ca443b 100755 --- a/api +++ b/api @@ -3285,15 +3285,20 @@ sudo_popup() { #just like sudo on passwordless systems like PiOS, but displays a nproc() { #Reduce the number of compile threads on low-RAM systems #The Pi02 and Pi3A+ have 4 cores but 500MB of RAM. This function reduces the number of threads to use if RAM is low. - local free="$(free | grep 'Mem:' | awk '{print $4}')" + #Estimation of how much memory is available for starting new applications, without swapping. + local available="$(free | grep 'Mem:' | awk '{print $7}')" - if [ "$free" -gt $((500*1024)) ] || [ "$GITHUB_ACTIONS" == "true" ];then - #Free memory >500MB, use normal number of threads + if [ "$available" -gt $((1000*1024)) ] || [ "$GITHUB_ACTIONS" == "true" ];then + #available memory > 1000MB, use normal number of threads command nproc + elif [ "$available" -gt $((500*1024)) ];then + #500MB < available memory <= 1000MB, use 2 threads + echo 2 + warning "Your system has less than 1000MB of available RAM, so this will compile with only 2 threads." else - #Free memory <500MB, use 1 thread + #available memory <= 500MB, use 1 thread echo 1 - warning "Your system has less than 500MB of free RAM, so this will compile with only 1 thread." + warning "Your system has less than 500MB of available RAM, so this will compile with only 1 thread." fi } #end of command interceptors