summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2018-04-10 14:13:35 +0000
committerkevans <kevans@FreeBSD.org>2018-04-10 14:13:35 +0000
commitc5a12e8a9915f9affb92e5bec902dc2ef30b64db (patch)
treef37589476261755df7316e440f800eb6cc14bdfd
parent193da2bbca26b8a13dced49df5ea63881945da55 (diff)
downloadFreeBSD-src-c5a12e8a9915f9affb92e5bec902dc2ef30b64db.zip
FreeBSD-src-c5a12e8a9915f9affb92e5bec902dc2ef30b64db.tar.gz
MFC r319828, r324625
r319828: rc.subr: Optimize repeated sourcing. When /etc/rc runs all /etc/rc.d scripts, it has already loaded /etc/rc.subr but each /etc/rc.d script sources it again (since /etc/rc.d scripts must also work when started stand-alone). Therefore, if rc.subr is already loaded, return so sh need not parse the rest of the file. A second effect is that there is no longer a compound command around most of rc.subr. This reduces memory usage while sh is loading rc.subr for the first time (but this memory is free()d once rc.subr is loaded). For purposes of porting this to other systems, I do not recommend porting this to systems with shells that do not have the change to the return special builtin like in r255215 (before FreeBSD 10.0-RELEASE). This change ensures that return in the top level of a dot script returns from the dot script, even if the dot script was sourced from a function. A comparison of CPU time on an amd64 bhyve virtual machine from a times command added near the end of /etc/rc, all four values summed: x orig1 + quickreturn +--------------------------------------------------------------------------+ | + + + x x x| ||______M__A_________| |______M___A__________| | +--------------------------------------------------------------------------+ N Min Max Median Avg Stddev x 3 1.704 1.802 1.726 1.744 0.051419841 + 3 1.467 1.559 1.487 1.5043333 0.048387326 Difference at 95.0% confidence -0.239667 +/- 0.113163 -13.7424% +/- 6.48873% (Student's t, pooled s = 0.0499266) r324625: rc.subr: Remove test that is always true. The code above always sets _pidcmd to a non-empty value.
-rw-r--r--etc/rc.subr12
1 files changed, 4 insertions, 8 deletions
diff --git a/etc/rc.subr b/etc/rc.subr
index 1ec0b3e..cc7d893 100644
--- a/etc/rc.subr
+++ b/etc/rc.subr
@@ -38,7 +38,9 @@
# Operating System dependent/independent variables
#
-if [ -z "${_rc_subr_loaded}" ]; then
+if [ -n "${_rc_subr_loaded}" ]; then
+ return
+fi
_rc_subr_loaded="YES"
@@ -928,9 +930,7 @@ run_rc_command()
else
_pidcmd='rc_pid=$(check_process '"$_procname $command_interpreter"')'
fi
- if [ -n "$_pidcmd" ]; then
- _keywords="${_keywords} status poll"
- fi
+ _keywords="${_keywords} status poll"
fi
if [ -z "$rc_arg" ]; then
@@ -2172,7 +2172,3 @@ _echoonce()
if kenv -q rc.debug > /dev/null ; then
rc_debug=YES
fi
-
-fi # [ -z "${_rc_subr_loaded}" ]
-
-_rc_subr_loaded=:
OpenPOWER on IntegriCloud