The close_range system call for closing all file descriptors “FDs” in a given range should enjoy a nice speed boost with the in-development Linux 7.0 kernel.
Last week saw all the feature-heavy VFS pull requests that brought nullfs and open_tree_namespace, standardized generic I/O error reporting, non-blocking timestamps, and other improvements. Sent out on Monday were some lingering VFS patches mailed out by Christian Brauner.
Notable with the vfs misc 2 pull is optimizing the close_range system call. The close_range usage drops from O(range size) to O(active FDs) with now being more efficient to provide a “significant improvement” for large range close operations on sparse file descriptor tables. Brauner summed it up as:
“Optimize close_range() from O(range size) to O(active FDs) by using find_next_bit() on the open_fds bitmap instead of linearly scanning the entire requested range. This is a significant improvement for large-range close operations on sparse file descriptor tables.”
The close_range system call is used to close all file descriptors in a given range on the system.
Qiliang Yuan of China Telecom who authored this patch had similarly wrote:
“In close_range(), the kernel traditionally performs a linear scan over the [fd, max_fd] range, resulting in O(N) complexity where N is the range size. For processes with sparse FD tables, this is inefficient as it checks many unallocated slots.
This patch optimizes __range_close() by using find_next_bit() on the open_fds bitmap to skip holes. This shifts the algorithmic complexity from O(Range Size) to O(Active FDs), providing a significant performance boost for large-range close operations on sparse file descriptor tables.”
The code was merged today to Linux Git. A lot of nice work building up for Linux 7.0.
