Update vm-rctl

Add 'limit_' prefix to option in config file
Set no limit by default
Error supporting RCTL writen to the log file
Some limits checked by FreeBSD version
This commit is contained in:
ramdaron
2016-02-16 19:27:55 +06:00
parent 16eb399429
commit cc53a655b9

View File

@@ -10,45 +10,51 @@ __vm_set_rctl_limits(){
local _conf="${vm_dir}/${_name}/${_name}.conf"
__config_load "${_conf}"
__config_get "_pcpu" "pcpu"
__config_get "_pcpu" "limit_pcpu"
__config_get "_rbps" "limit_rbps"
__config_get "_wbps" "limit_wbps"
__config_get "_riops" "limit_riops"
__config_get "_wiops" "limit_wiops"
# it be available in FreeBSD 11.0
# __config_get "_rbps" "readbps"
# __config_get "_wbps" "writebps"
# __config_get "_riops" "readiops"
# __config_get "_wiops" "writeiops"
# set defaults: no limits
: ${_pcpu:=-1}
: ${_rbps:=-1}
: ${_wbps:=-1}
: ${_riops:=-1}
: ${_wiops:=-1}
# wait a few seconds until the bhyve starts
sleep 1;
_pid=$(pgrep -fx "bhyve: ${_name}")
if [ -n "${_pid}" ]; then
if [ ! -z "${_pcpu}" -o ! -z "${_ior}" -o ! -z "${_iow}" ]; then
if [ "${_pcpu}" -ne -1 -o ${_rbps} -ne -1 -o ${_wbps} -ne -1 -o ${_riops} -ne -1 -o ${_wiops} -ne -1 ]; then
/usr/bin/rctl > /dev/null 2>&1
_exit=$?
[ ${_exit} -ne 0 ] && __err "RCTL support requested but RCTL not available"
[ ${_exit} -ne 0 ] && __log "guest" "${_name}" "RCTL support requested but RCTL not available"
if [ ! -z "${_pcpu}" ]; then
/usr/bin/rctl -a process:${_pid}:pcpu:deny=${_pcpu}
__log "guest" "${_name}" "limit rctl pcpu resource to ${_pcpu}"
fi
# it be available in FreeBSD 11.0
if [ ! -z ${_rbps} ]; then
/usr/bin/rctl -a process:${_pid}:readbps:throttle=${_rbps}
__log "guest" "limit rctl readbps resource to ${_rbps}"
fi
if [ ! -z ${_wbps} ]; then
/usr/bin/rctl -a process:${_pid}:writebps:throttle=${_wbps}
__log "guest" "limit rctl writebps resource to ${_wbps}"
fi
if [ ! -z ${_riops} ]; then
/usr/bin/rctl -a process:${_pid}:readiops:throttle=${_riops}
__log "guest" "limit rctl readiops resource to ${_riops}"
fi
if [ ! -z ${_wiops} ]; then
/usr/bin/rctl -a process:${_pid}:writeiops:throttle=${_wiops}
__log "guest" "limit rctl writeiops resource to ${_wiops}"
if [ ${BSD_VERSION} -ge 1100000 ]; then
if [ ! -z ${_rbps} ]; then
/usr/bin/rctl -a process:${_pid}:readbps:throttle=${_rbps}
__log "guest" "limit rctl readbps resource to ${_rbps}"
fi
if [ ! -z ${_wbps} ]; then
/usr/bin/rctl -a process:${_pid}:writebps:throttle=${_wbps}
__log "guest" "limit rctl writebps resource to ${_wbps}"
fi
if [ ! -z ${_riops} ]; then
/usr/bin/rctl -a process:${_pid}:readiops:throttle=${_riops}
__log "guest" "limit rctl readiops resource to ${_riops}"
fi
if [ ! -z ${_wiops} ]; then
/usr/bin/rctl -a process:${_pid}:writeiops:throttle=${_wiops}
__log "guest" "limit rctl writeiops resource to ${_wiops}"
fi
fi
fi
fi