Linux 6.8 Landing A Tantalizing Optimization For Common $PATH-Based Searches

Written by Michael Larabel in Linux Kernel on 8 January 2024 at 02:41 PM EST. 8 Comments
LINUX KERNEL
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:
"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.

Josh Tripllett's patch


Nothing beats a small patch for a nice performance win.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week