Commit fc94368
fs/file: optimize close_range() complexity from O(N) to O(Sparse)
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.
Signed-off-by: Qiliang Yuan <realwujing@gmail.com>
Signed-off-by: Qiliang Yuan <yuanql9@chinatelecom.cn>
Link: https://patch.msgid.link/20260123081221.659125-1-realwujing@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>1 parent 6cbfdf8 commit fc94368
1 file changed
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
777 | 777 | | |
778 | 778 | | |
779 | 779 | | |
| 780 | + | |
780 | 781 | | |
781 | 782 | | |
782 | 783 | | |
783 | | - | |
| 784 | + | |
| 785 | + | |
784 | 786 | | |
785 | 787 | | |
786 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
787 | 791 | | |
788 | 792 | | |
789 | 793 | | |
790 | 794 | | |
791 | 795 | | |
792 | 796 | | |
| 797 | + | |
793 | 798 | | |
794 | 799 | | |
795 | 800 | | |
796 | 801 | | |
| 802 | + | |
797 | 803 | | |
798 | 804 | | |
799 | 805 | | |
| |||
0 commit comments