Skip to content

Commit 0c40bf4

Browse files
intelmyAl Viro
authored andcommitted
fs/file.c: add fast path in find_next_fd()
Skip 2-levels searching via find_next_zero_bit() when there is free slot in the word contains next_fd, as: (1) next_fd indicates the lower bound for the first free fd. (2) There is fast path inside of find_next_zero_bit() when size<=64 to speed up searching. (3) After fdt is expanded (the bitmap size doubled for each time of expansion), it would never be shrunk. The search size increases but there are few open fds available here. This fast path is proposed by Mateusz Guzik <[email protected]>, and agreed by Jan Kara <[email protected]>, which is more generic and scalable than previous versions. And on top of patch 1 and 2, it improves pts/blogbench-1.1.0 read by 8% and write by 4% on Intel ICX 160 cores configuration with v6.10-rc7. Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Tim Chen <[email protected]> Signed-off-by: Yu Ma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent c9a3019 commit 0c40bf4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,15 @@ static unsigned int find_next_fd(struct fdtable *fdt, unsigned int start)
472472
unsigned int maxfd = fdt->max_fds; /* always multiple of BITS_PER_LONG */
473473
unsigned int maxbit = maxfd / BITS_PER_LONG;
474474
unsigned int bitbit = start / BITS_PER_LONG;
475+
unsigned int bit;
476+
477+
/*
478+
* Try to avoid looking at the second level bitmap
479+
*/
480+
bit = find_next_zero_bit(&fdt->open_fds[bitbit], BITS_PER_LONG,
481+
start & (BITS_PER_LONG - 1));
482+
if (bit < BITS_PER_LONG)
483+
return bit + bitbit * BITS_PER_LONG;
475484

476485
bitbit = find_next_zero_bit(fdt->full_fds_bits, maxbit, bitbit) * BITS_PER_LONG;
477486
if (bitbit >= maxfd)

0 commit comments

Comments
 (0)