Re: [PATCH 3/3] io_uring: follow **iovec idiom in io_import_iovec

Pavel Begunkov
2020-07-13T21:20:06Z

On 14/07/2020 00:16, Jens Axboe wrote:
> On 7/13/20 3:12 PM, Pavel Begunkov wrote:
>> On 14/07/2020 00:09, Jens Axboe wrote:
>>> On 7/13/20 1:59 PM, Pavel Begunkov wrote:
>>>> @@ -3040,8 +3040,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock,
>>>> }
>>>> }
>>>> out_free:
>>>> - if (!(req->flags & REQ_F_NEED_CLEANUP))
>>>> - kfree(iovec);
>>>> + kfree(iovec);
>>>> return ret;
>>>> }
>>>
>>> Faster to do:
>>>
>>> if (iovec)
>>> kfree(iovec)
>>>
>>> to avoid a stupid call. Kind of crazy, but I just verified with this one
>>> as well that it's worth about 1.3% CPU in my stress test.
>>
>> That looks crazy indeed
>
> I suspect what needs to happen is that kfree should be something ala:
>
> static inline void kfree(void *ptr)
> {
> if (ptr)
> __kfree(ptr);
> }
>
> to avoid silly games like this. Needs to touch all three slab
> allocators, though definitely in the trivial category.

Just thought the same, but not sure it's too common to have kfree(NULL).

The drop is probably because of extra call + cold jumps with unlikely().

void kfree() {
trace_kfree(_RET_IP_, objp);

if (unlikely(ZERO_OR_NULL_PTR(objp)))
return;
}

--
Pavel Begunkov