Skip to content

Commit

Permalink
api: refactor nproc wrapper to use available memory instead of free
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theofficialgman committed Jan 10, 2024
1 parent fed6a8d commit 2f9870c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f9870c

Please sign in to comment.