Linux 6.8 Landing A Tantalizing Optimization For Common $PATH-Based Searches
For the execve() system call to execute a program by pathname, the Linux 6.8 kernel is set to land a new optimization to "dramatically" speed-up PATH searches.
The execve updates for Linux 6.8 bring a new fail-fast check to speed-up execve-based PATH searches.
Linux developer Josh Triplett authored the optimization and commented on the patch:
Quite a nice win at 26% faster for execve-based PATH searches, especially for this being a common operation. It was brought up on that patch that shell scripts tend to use stat() for checking the files in the PATH while the GNU C Library (glibc) and the likes of Musl libc, Python, Perl, and others tend to use the execve-based approach and thus benefit from this kernel optimization.
Nothing beats a small patch for a nice performance win.
The execve updates for Linux 6.8 bring a new fail-fast check to speed-up execve-based PATH searches.
Linux developer Josh Triplett authored the optimization and commented on the patch:
"Currently, execve allocates an mm and parses argv and envp before checking if the path exists. However, the common case of a $PATH search may have several failed calls to exec before a single success. Do a filename lookup for the purposes of returning ENOENT before doing more expensive operations.
...
To measure performance, I ran 2000 fork and execvpe calls with a seven-element PATH in which the file was found in the seventh directory (representative of the common case as /usr/bin is the seventh directory on my $PATH), as well as 2000 fork and execve calls with an absolute path to an existing binary. I recorded the minimum time for each, to eliminate noise from context switches and similar.
Without fast-path:
fork/execvpe: 49876ns
fork/execve: 32773ns
With fast-path:
fork/execvpe: 36890ns
fork/execve: 32069ns
The cost of the additional lookup seems to be in the noise for a successful exec, but it provides a 26% improvement for the path search
case by speeding up the six failed execs."
Quite a nice win at 26% faster for execve-based PATH searches, especially for this being a common operation. It was brought up on that patch that shell scripts tend to use stat() for checking the files in the PATH while the GNU C Library (glibc) and the likes of Musl libc, Python, Perl, and others tend to use the execve-based approach and thus benefit from this kernel optimization.
Nothing beats a small patch for a nice performance win.
8 Comments