From owner-freebsd-rc@FreeBSD.ORG Tue Jun 14 22:28:49 2011 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 636971065687 for ; Tue, 14 Jun 2011 22:28:49 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) by mx1.freebsd.org (Postfix) with ESMTP id 2F79E8FC15 for ; Tue, 14 Jun 2011 22:28:49 +0000 (UTC) Received: from turtle.stack.nl (turtle.stack.nl [IPv6:2001:610:1108:5010::132]) by mx1.stack.nl (Postfix) with ESMTP id 93CD13593AE for ; Wed, 15 Jun 2011 00:28:48 +0200 (CEST) Received: by turtle.stack.nl (Postfix, from userid 1677) id 88D1E17496; Wed, 15 Jun 2011 00:28:48 +0200 (CEST) Date: Wed, 15 Jun 2011 00:28:48 +0200 From: Jilles Tjoelker To: freebsd-rc@freebsd.org Message-ID: <20110614222848.GA25563@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [PATCH] Reducing forks in the boot sequence X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jun 2011 22:28:49 -0000 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