[PATCH] Reducing forks in the boot sequence
Jilles Tjoelker
jilles at stack.nl
Tue Jun 14 22:28:49 UTC 2011
The below patch reduces vm.stats.vm.v_forks at REQUIRE: LOGIN time
of a simple 9-current VM by 105 (which is a bit more than 10%).
A side effect is that values starting with a hyphen and all whitespace
are preserved.
All versions of FreeBSD sh fork for a command substitution containing a
'.' or 'eval' command because these utilities may cause anything to be
invoked; the same thing applies to a command substitution that calls a
function. If people want to keep doing this (rather than returning
values via variables), I could look into an extension of the
optimization for command substitution (and possibly regular subshells)
that tries to avoid forking until the script does something that makes
it unavoidable (such as setting new traps, changing the current
directory, changing shell options).
The function _find_processes is pretty slow also for internal reasons.
Index: etc/rc.subr
===================================================================
--- etc/rc.subr (revision 222648)
+++ etc/rc.subr (working copy)
@@ -1062,7 +1062,7 @@
# Set defaults if defined.
for _var in $rcvar $rcvars; do
- _defval=`eval echo "\\\$${_var}_defval"`
+ eval _defval=\$${_var}_defval
if [ -n "$_defval" ]; then
eval : \${$_var:=\$${_var}_defval}
fi
@@ -1070,9 +1070,9 @@
# check obsolete rc.conf variables
for _var in $rcvars_obsolete; do
- _v=`eval echo \\$$_var`
- _msg=`eval echo \\$${_var}_obsolete_msg`
- _new=`eval echo \\$${_var}_newvar`
+ eval _v=\$$_var
+ eval _msg=\$${_var}_obsolete_msg
+ eval _new=\$${_var}_newvar
case $_v in
"")
;;
@@ -1743,7 +1743,7 @@
_echoonce()
{
local _var _msg _mode
- _var=`eval echo \\$$1`
+ eval _var=\$$1
_msg=$2
_mode=$3
--
Jilles Tjoelker
More information about the freebsd-rc
mailing list