diff options
author | John Sonnenschein <johns@joyent.com> | 2012-01-12 21:43:07 +0000 |
---|---|---|
committer | John Sonnenschein <johns@joyent.com> | 2012-01-12 21:43:07 +0000 |
commit | ffd3d51cda0d52ac103aaa51865ea8b99ce2bc39 (patch) | |
tree | caccc892b2859e382f40b29bf961281341b6e99c /usr/src/lib | |
parent | 1636e739ebc2ac80c49a1e69f71fda812db48850 (diff) | |
parent | 9aac36a25d67d80901ad3284d1c2045d3d1a6d64 (diff) | |
download | illumos-joyent-ffd3d51cda0d52ac103aaa51865ea8b99ce2bc39.tar.gz |
Merge branch 'master' into gcc4
Diffstat (limited to 'usr/src/lib')
-rw-r--r-- | usr/src/lib/brand/joyent/zone/statechange.ksh | 81 | ||||
-rwxr-xr-x | usr/src/lib/brand/kvm/zone/statechange.ksh | 67 | ||||
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_pool.c | 2 |
3 files changed, 143 insertions, 7 deletions
diff --git a/usr/src/lib/brand/joyent/zone/statechange.ksh b/usr/src/lib/brand/joyent/zone/statechange.ksh index ba4df02b99..70be7819b4 100644 --- a/usr/src/lib/brand/joyent/zone/statechange.ksh +++ b/usr/src/lib/brand/joyent/zone/statechange.ksh @@ -19,7 +19,7 @@ # # CDDL HEADER END # -# Copyright 2010, 2011 Joyent, Inc. All rights reserved. +# Copyright 2010, 2012 Joyent, Inc. All rights reserved. # Use is subject to license terms. # @@ -385,6 +385,69 @@ setup_snapshots() done } +# +# If the zone has a CPU cap, calculate the CPU baseline and set it so we can +# track when we're bursting. There are many ways that the baseline can be +# calculated based on the other settings in the zones (e.g. a simple way would +# be as a precentage of the cap). +# +# For SmartMachines, our CPU baseline is calculated off of the system's +# provisionable memory and the memory cap of the zone. We assume that 83% of +# the system's memory is usable by zones (the rest is for the OS) and we assume +# that the zone memory cap is set so that we're proportional to how many zones +# we can provision on the system (i.e. we don't overprovision memory). Using +# these assumptions, we calculate the proportion of CPU for the zone based on +# its proportion of memory. Thus, the zone's CPU baseline is calculated using: +# ((zone capped memsize in MB) * 100) / (MB/core). +# Uncapped zones have no baseline (i.e. infrastructure zones). +# +# Remember that the cpu-cap rctl and the baseline are expressed in units of +# a percent of a CPU, so 100 is 1 full CPU. +# +setup_cpu_baseline() +{ + # If there is already a baseline, don't set one heuristically + curr_base=`prctl -P -n zone.cpu-baseline -i zone $ZONENAME | nawk '{ + if ($2 == "privileged") print $3 + }'` + [ -n "$curr_base" ] && return + + # Get current cap and convert from zonecfg format into rctl format + cap=`zonecfg -z $ZONENAME info capped-cpu | nawk '{ + if ($1 == "[ncpus:") print (substr($2, 1, length($2) - 1) * 100) + }'` + [ -z "$cap" ] && return + + # Get zone's memory cap in MB times 100 + zmem=`zonecfg -z $ZONENAME info capped-memory | nawk '{ + if ($1 == "[physical:") { + val = substr($2, 1, length($2) - 2) + units = substr($2, length($2) - 1, 1) + + # convert GB to MB + if (units == "G") + val *= 1024 + print (val * 100) + } + }'` + [ -z "$zmem" ] && return + + # Get system's total memory in MB + smem=`prtconf -m` + # provisionable memory is 83% of total memory (bash can't do floats) + prov_mem=$((($smem * 83) / 100)) + nprocs=`psrinfo -v | \ + nawk '/virtual processor/ {cnt++} END {print cnt}'` + + mb_per_core=$(($prov_mem / $nprocs)) + + baseline=$(($zmem / $mb_per_core)) + [[ $baseline == 0 ]] && baseline=1 + [[ $baseline -gt $cap ]] && baseline=$cap + + prctl -n zone.cpu-baseline -v $baseline -t priv -i zone $ZONENAME +} + cleanup_snapshots() { # @@ -431,10 +494,18 @@ load_sdc_sysinfo load_sdc_config [[ "$subcommand" == "pre" && $cmd == 0 ]] && setup_fs -[[ "$subcommand" == "post" && $cmd == 0 ]] && setup_snapshots -[[ "$subcommand" == "pre" && $cmd == 4 ]] && cleanup_snapshots -[[ "$subcommand" == "post" && $cmd == 0 ]] && setup_net -[[ "$subcommand" == "pre" && $cmd == 4 ]] && cleanup_net +if [[ "$subcommand" == "post" && $cmd == 0 ]]; then + setup_snapshots + setup_net +fi + +# We can't set a rctl until we have a process in the zone to grab +[[ "$subcommand" == "post" && $cmd == 1 ]] && setup_cpu_baseline + +if [[ "$subcommand" == "pre" && $cmd == 4 ]]; then + cleanup_snapshots + cleanup_net +fi exit 0 diff --git a/usr/src/lib/brand/kvm/zone/statechange.ksh b/usr/src/lib/brand/kvm/zone/statechange.ksh index 7c08ce6ea9..22f647775a 100755 --- a/usr/src/lib/brand/kvm/zone/statechange.ksh +++ b/usr/src/lib/brand/kvm/zone/statechange.ksh @@ -19,7 +19,7 @@ # # CDDL HEADER END # -# Copyright 2010, 2011 Joyent, Inc. All rights reserved. +# Copyright 2010, 2012 Joyent, Inc. All rights reserved. # Use is subject to license terms. # @@ -318,6 +318,69 @@ setup_fs() } # +# If the zone has a CPU cap, calculate the CPU baseline and set it so we can +# track when we're bursting. There are many ways that the baseline can be +# calculated based on the other settings in the zones (e.g. a simple way would +# be as a precentage of the cap). +# +# For SmartMachines, our CPU baseline is calculated off of the system's +# provisionable memory and the memory cap of the zone. We assume that 83% of +# the system's memory is usable by zones (the rest is for the OS) and we assume +# that the zone memory cap is set so that we're proportional to how many zones +# we can provision on the system (i.e. we don't overprovision memory). Using +# these assumptions, we calculate the proportion of CPU for the zone based on +# its proportion of memory. Thus, the zone's CPU baseline is calculated using: +# ((zone capped memsize in MB) * 100) / (MB/core). +# Uncapped zones have no baseline (i.e. infrastructure zones). +# +# Remember that the cpu-cap rctl and the baseline are expressed in units of +# a percent of a CPU, so 100 is 1 full CPU. +# +setup_cpu_baseline() +{ + # If there is already a baseline, don't set one heuristically + curr_base=`prctl -P -n zone.cpu-baseline -i zone $ZONENAME | nawk '{ + if ($2 == "privileged") print $3 + }'` + [ -n "$curr_base" ] && return + + # Get current cap and convert from zonecfg format into rctl format + cap=`zonecfg -z $ZONENAME info capped-cpu | nawk '{ + if ($1 == "[ncpus:") print (substr($2, 1, length($2) - 1) * 100) + }'` + [ -z "$cap" ] && return + + # Get zone's memory cap in MB times 100 + zmem=`zonecfg -z $ZONENAME info capped-memory | nawk '{ + if ($1 == "[physical:") { + val = substr($2, 1, length($2) - 2) + units = substr($2, length($2) - 1, 1) + + # convert GB to MB + if (units == "G") + val *= 1024 + print (val * 100) + } + }'` + [ -z "$zmem" ] && return + + # Get system's total memory in MB + smem=`prtconf -m` + # provisionable memory is 83% of total memory (bash can't do floats) + prov_mem=$((($smem * 83) / 100)) + nprocs=`psrinfo -v | \ + nawk '/virtual processor/ {cnt++} END {print cnt}'` + + mb_per_core=$(($prov_mem / $nprocs)) + + baseline=$(($zmem / $mb_per_core)) + [[ $baseline == 0 ]] && baseline=1 + [[ $baseline -gt $cap ]] && baseline=$cap + + prctl -n zone.cpu-baseline -v $baseline -t priv -i zone $ZONENAME +} + +# # We're halting the zone, perform network cleanup. # cleanup_net() @@ -351,5 +414,7 @@ echo "statechange $subcommand $cmd" >>/tmp/kvm.log [[ "$subcommand" == "pre" && $cmd == 0 ]] && setup_fs [[ "$subcommand" == "pre" && $cmd == 4 ]] && cleanup_net [[ "$subcommand" == "post" && $cmd == 0 ]] && setup_net +# We can't set a rctl until we have a process in the zone to grab +[[ "$subcommand" == "post" && $cmd == 1 ]] && setup_cpu_baseline exit 0 diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c index 8eb7e2ca15..bf833d1bdd 100644 --- a/usr/src/lib/libzfs/common/libzfs_pool.c +++ b/usr/src/lib/libzfs/common/libzfs_pool.c @@ -270,7 +270,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len, case PROP_TYPE_NUMBER: intval = zpool_get_prop_int(zhp, prop, &src); - if (literal) { + if (literal && prop != ZPOOL_PROP_HEALTH) { (void) snprintf(buf, len, "%llu", (u_longlong_t)intval); break; |