summaryrefslogtreecommitdiffstats
path: root/remote/modules/vmchooser/data/opt
diff options
context:
space:
mode:
authorSimon Rettberg2013-07-12 19:51:21 +0200
committerSimon Rettberg2013-07-12 19:51:21 +0200
commit64bdaa5ae643b44733d821feb8ae349f2920c4c1 (patch)
tree4efc4c3165703938c02ea33d46ce8f2427856a3e /remote/modules/vmchooser/data/opt
parent[vmplayer] More updates to hw-config setup (diff)
downloadtm-scripts-64bdaa5ae643b44733d821feb8ae349f2920c4c1.tar.gz
tm-scripts-64bdaa5ae643b44733d821feb8ae349f2920c4c1.tar.xz
tm-scripts-64bdaa5ae643b44733d821feb8ae349f2920c4c1.zip
[vmchooser] Try to refine calculation of amount of memory to assign to VM
Diffstat (limited to 'remote/modules/vmchooser/data/opt')
-rwxr-xr-xremote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh33
1 files changed, 22 insertions, 11 deletions
diff --git a/remote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh b/remote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh
index b0672e5b..5dd5d4a4 100755
--- a/remote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh
+++ b/remote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh
@@ -317,19 +317,30 @@ VM_ID=$(expr substr $$ $(expr ${#$} - 1) 2)
# Make sure cpu_cores is not empty
cpu_cores=${cpu_cores:-"1"}
-# Total amount of memory defined in stage 3
-# TODO: Should be dependent on the setup (if diff is written to RAM ...)
-permem=60
-if [ "x${VMCHOOSER_FORCE_HALF_MEM}" == "x1" ]; then
- permem=30
+# Amount of memory for the VM. Be generous if diff is written to HDD
+if mount | grep -q '^/dev/sd.*on.*/tmp'; then
+ reserve=16
+ min=512
+ max=1024
+else
+ reserve=65
+ min=768
+ max=8192
fi
-# Get a result which can be divided through 4
-mem=$(expr ${totalmem} / 100 \* ${permem} / 4 \* 4)
-if [ -n "${mainvirtmem}" ]; then
- forcemem=$(expr ${mainvirtmem} / 4 \* 4)
- mem=${forcemem}
+
+# Calculate absulute amount of RAM that should stay available to the host
+reserve="$[ ( $totalmem * $reserve ) / 100 ]"
+# Respect some upper and lower bounds for the host amount
+[ "$reserve" -lt "$min" ] && reserve="$min"
+[ "$reserve" -gt "$max" ] && reserve="$max"
+
+# Get a result which can be divided by 4
+mem="$[ ( ( $totalmem - $reserve ) / 4 ) * 4 ]"
+if [ -n "$mainvirtmem" ]; then
+ forcemem="$[ "$mainvirtmem" / 4 * 4 ]"
+ mem="$forcemem"
fi
-hostmem=$(expr ${totalmem} - ${mem})
+hostmem="$[ $totalmem - $mem ]"
# Configuring ethernet mac address: first 3 bytes are fixed (00:50:56)
# 4th byte is the VM-ID (0D)