diff options
author | jilles <jilles@FreeBSD.org> | 2012-02-04 23:12:14 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-02-04 23:12:14 +0000 |
commit | c9a60ad55a7cdcf983430853a4bdb15d31340f0b (patch) | |
tree | cdf2aa0b0a8655054be3d8275658129bb9b75c99 /bin/sh/eval.c | |
parent | a3ada8a47cbcc2eecf9773251384c95d920c9cab (diff) | |
download | FreeBSD-src-c9a60ad55a7cdcf983430853a4bdb15d31340f0b.zip FreeBSD-src-c9a60ad55a7cdcf983430853a4bdb15d31340f0b.tar.gz |
sh: Use vfork in a few common cases.
This uses vfork() for simple commands and command substitutions containing a
single simple command, invoking an external program under certain conditions
(no redirections or variable assignments, non-interactive shell, no job
control). These restrictions limit the amount of code executed in a vforked
child.
There is a large speedup (for example 35%) in microbenchmarks. The
difference in buildkernel is smaller (for example 0.5%) but still
statistically significant. See
http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html
for some numbers.
The use of vfork() can be disabled by setting a variable named
SH_DISABLE_VFORK.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index a5f0aff..2d90921 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -921,6 +921,15 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) if (pipe(pip) < 0) error("Pipe call failed: %s", strerror(errno)); } + if (cmdentry.cmdtype == CMDNORMAL && + cmd->ncmd.redirect == NULL && + varlist.list == NULL && + (mode == FORK_FG || mode == FORK_NOJOB) && + !disvforkset() && !iflag && !mflag) { + vforkexecshell(jp, argv, environment(), path, + cmdentry.u.index, flags & EV_BACKCMD ? pip : NULL); + goto parent; + } if (forkshell(jp, cmd, mode) != 0) goto parent; /* at end of routine */ if (flags & EV_BACKCMD) { |