Skip to content

Commit

Permalink
Rework: get_free_swap_perc
Browse files Browse the repository at this point in the history
Signed-off-by: Timofey Titovets <[email protected]>
  • Loading branch information
nefelim4ag committed Mar 12, 2017
1 parent 5cd8bc7 commit 92e77dd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions systemd-swap
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ case "$1" in
swapfu_path=${swapfu_path:-"/var/lib/systemd-swap/swapfu"}
swapfu_prio=${swapfu_prio:-"-1024"}
INFO "swapFU: create empty file"
mkdir -p $(dirname $swapfu_path)
mkdir -p "$(dirname $swapfu_path)"
touch $swapfu_path
swapfu_nocow=${swapfu_nocow:-1}
if YN $swapfu_nocow; then
Expand Down Expand Up @@ -176,12 +176,12 @@ case "$1" in
swapfc_enabled=${swapfc_enabled:-0}
if YN $swapfc_enabled; then
get_free_swap_perc(){
calc(){
# +1 prevent devide by zero
total="${2}" free="${4}"
echo $(( (${4}*100)/(${2}+1) ));
}
calc $(free -b | grep Swap:)
total="$(grep SwapTotal: /proc/meminfo | grep -o -e '[0-9]*')"
free="$(grep SwapFree: /proc/meminfo | grep -o -e '[0-9]*')"
total=$((total*1024))
free=$((free*1024))
echo $(( (${free}*100)/(${total}+1) ));
}
mkswap_w(){
chunk_size="$1" file="$2"
Expand Down

0 comments on commit 92e77dd

Please sign in to comment.