Re: [PATCH v3 3/3] fs/file.c: add fast path in find_next_fd()

Ma, Yu
2024-07-04T14:51:07Z

On 7/4/2024 6:03 PM, Jan Kara wrote:
> On Wed 03-07-24 10:33:11, Yu Ma wrote:
>> There is available fd in the lower 64 bits of open_fds bitmap for most cases
>> when we look for an available fd slot. Skip 2-levels searching via
>> find_next_zero_bit() for this common fast path.
>>
>> Look directly for an open bit in the lower 64 bits of open_fds bitmap when a
>> free slot is available there, as:
>> (1) The fd allocation algorithm would always allocate fd from small to large.
>> Lower bits in open_fds bitmap would be used much more frequently than higher
>> bits.
>> (2) 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.
>> (3) There is fast path inside of find_next_zero_bit() when size<=64 to speed up
>> searching.
>>
>> As suggested by Mateusz Guzik <mjguzik gmail.com> and Jan Kara <jack@suse.cz>,
>> update the fast path from alloc_fd() to find_next_fd(). With which, on top of
>> patch 1 and 2, pts/blogbench-1.1.0 read is improved by 13% and write by 7% on
>> Intel ICX 160 cores configuration with v6.10-rc6.
>>
>> Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
>> Signed-off-by: Yu Ma <yu.ma@intel.com>
> Nice! The patch looks good to me. Feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> One style nit below:
>
>> diff --git a/fs/file.c b/fs/file.c
>> index a15317db3119..f25eca311f51 100644
>> --- a/fs/file.c
>> +++ b/fs/file.c
>> @@ -488,6 +488,11 @@ struct files_struct init_files = {
>>
>> static unsigned int find_next_fd(struct fdtable *fdt, unsigned int start)
>> {
>> + unsigned int bit;
> Empty line here please to separate variable declaration and code...

Thanks Honza, copy that :)

>
>> + bit = find_next_zero_bit(fdt->open_fds, BITS_PER_LONG, start);
>> + if (bit < BITS_PER_LONG)
>> + return bit;
>> +
>> unsigned int maxfd = fdt->max_fds; /* always multiple of BITS_PER_LONG */
>> unsigned int maxbit = maxfd / BITS_PER_LONG;
>> unsigned int bitbit = start / BITS_PER_LONG;
> Honza