diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2011-10-26 12:01:59 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2011-10-26 13:23:46 +0000 |
commit | ea514130cd49220ccc77a91eb5a9604bf5d846e7 (patch) | |
tree | 9adf35f4449ea31285323bfae5ece7d30ccd4087 /setup-disk.in | |
parent | 6b1a0368417832a81a17025cf78188cf2a55a447 (diff) | |
download | alpine-conf-ea514130cd49220ccc77a91eb5a9604bf5d846e7.zip |
setup-disk: fix swap size calculation
use 2 * total ram or maximum 1/4 of the smallest disk.
don't use more than 4G swap
if swap is smaller than 64MB then don't bother create swap at all.
ref #732
Diffstat (limited to 'setup-disk.in')
-rw-r--r-- | setup-disk.in | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/setup-disk.in b/setup-disk.in index 0e9cd17..33ab925 100644 --- a/setup-disk.in +++ b/setup-disk.in @@ -287,12 +287,27 @@ unmount_partitions() { # figure out decent default swap size in mega bytes find_swap_size() { - if [ -n "$SWAP_SIZE" ]; then - return - fi local memtotal_kb=$(awk '$1 == "MemTotal:" {print $2}' /proc/meminfo) - # use 2 * avaiable ram - echo $(( $memtotal_kb * 2 / 1024 )) + # use 2 * avaiable ram or no more than 1/3 of smallest disk space + local size=$(( $memtotal_kb * 2 / 1024 )) + local disk= disksize= + for disk in $@; do + local sysfspath=/sys/block/${disk#/dev/}/size + # disksize = x * 512 / (1024 * 1024) = x / 2048 + # maxsize = $disksize / 4 = x / (2048 * 4) = x / 8192 + maxsize=$(awk '{ printf "%i", $0 / 8192 }' $sysfspath ) + if [ $size -gt $maxsize ]; then + size=$maxsize + fi + done + if [ $size -gt 4096 ]; then + # dont ever use more than 4G + size=4096 + elif [ $size -lt 64 ]; then + # dont bother create swap smaller than 64MB + size=0 + fi + echo $size } has_mounted_part() { @@ -824,7 +839,6 @@ esac DISK_MODE= USE_LVM= -SWAP_SIZE=$(find_swap_size) # Parse args while getopts "hk:Lm:o:qrs:v" opt; do case $opt in @@ -912,6 +926,10 @@ if [ -n "$diskdevs" ] && [ -z "$DISK_MODE" ]; then DISK_MODE="$answer" fi +if [ -z "$SWAP_SIZE" ]; then + SWAP_SIZE=$(find_swap_size $diskdevs) +fi + set -- $diskdevs if [ $# -gt 1 ]; then USE_RAID=1 |