summaryrefslogtreecommitdiffstats
path: root/remote
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
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')
-rwxr-xr-xremote/modules/vmchooser/data/etc/openslx/vmchooser/vmchooser-env11
-rwxr-xr-xremote/modules/vmchooser/data/opt/openslx/bin/run-virt.sh33
-rw-r--r--remote/modules/vmplayer/data/etc/openslx/vmware/run-virt.include4
3 files changed, 32 insertions, 16 deletions
diff --git a/remote/modules/vmchooser/data/etc/openslx/vmchooser/vmchooser-env b/remote/modules/vmchooser/data/etc/openslx/vmchooser/vmchooser-env
index 4bdf63c3..e2a3e063 100755
--- a/remote/modules/vmchooser/data/etc/openslx/vmchooser/vmchooser-env
+++ b/remote/modules/vmchooser/data/etc/openslx/vmchooser/vmchooser-env
@@ -59,12 +59,17 @@ mkdir -p /var/log/samba
#from plugins/vmchooser/80-after-plugins/virtualization.sh
# change free mem
-totalmem=$(expr $(grep -i "memtotal" /proc/meminfo \
- | awk '{print $2}') / 1024)
+mem_free=$(grep -i "^memfree:" /proc/meminfo | awk '{print $2}')
+mem_cached=$(grep -i "^cached:" /proc/meminfo | awk '{print $2}')
+mem_swapcached=$(grep -i "^swapcached:" /proc/meminfo | awk '{print $2}')
+[ -z "$mem_free" ] && mem_free="2048000"
+[ -z "$mem_cached" ] && mem_cached="0"
+[ -z "$mem_swapcached" ] && mem_swapcached="0"
+totalmem="$[ ( $mem_free + $mem_cached + $mem_swapcached ) / 1024 ]"
echo "totalmem=${totalmem}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf
# cpu cores
-CPU_CORES=$(grep 'processor.*:' /proc/cpuinfo | wc -l)
+CPU_CORES=$(grep '^processor.*:' /proc/cpuinfo | wc -l)
if [ "${CPU_CORES}" -gt "1" 2>/dev/null ]; then
echo "cpu_cores=${CPU_CORES}" >> ${VMCHOOSER_CONF_DIR}/virtualization.conf
else
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)
diff --git a/remote/modules/vmplayer/data/etc/openslx/vmware/run-virt.include b/remote/modules/vmplayer/data/etc/openslx/vmware/run-virt.include
index 1178ca2f..5ac0454a 100644
--- a/remote/modules/vmplayer/data/etc/openslx/vmware/run-virt.include
+++ b/remote/modules/vmplayer/data/etc/openslx/vmware/run-virt.include
@@ -21,9 +21,9 @@
function clean_string ()
{
if [ "$#" -ge 1 ]; then
- echo "$@" | tr '[:upper:]' '[:lower:]' | tr -d '\t _./'
+ echo "$@" | tr '[A-Z]' '[a-z]' | tr -d '\t _./'
else
- cat - | tr '[:upper:]' '[:lower:]' | tr -d '\t _./'
+ cat - | tr '[A-Z]' '[a-z]' | tr -d '\t _./'
fi
}