public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Pavel Begunkov <[email protected]>, [email protected]
Subject: Re: [PATCH 3/3] io_uring: follow **iovec idiom in io_import_iovec
Date: Mon, 13 Jul 2020 15:26:10 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 7/13/20 3:18 PM, Pavel Begunkov wrote:
> 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).

Right, except the io_read/io_write path it'll be 100% common unless you
have more than the inline number of segments.

I see the same thing for eg the slab should_failslab() call, which isn't
inlined even if the kconfig isn't enabled. And for should_fail_bio()
as well. Those two add up to another ~1% or so of pointless overhead.

> 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;
> }

Must be, since the kfree() one adds up to more than the two above ones
that are just the call itself.

-- 
Jens Axboe


  reply	other threads:[~2020-07-13 21:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 19:59 [PATCH for-5.9 0/3] rw iovec copy cleanup Pavel Begunkov
2020-07-13 19:59 ` [PATCH 1/3] io_uring: simplify io_req_map_rw() Pavel Begunkov
2020-07-13 19:59 ` [PATCH 2/3] io_uring: add a helper for async rw iovec prep Pavel Begunkov
2020-07-13 19:59 ` [PATCH 3/3] io_uring: follow **iovec idiom in io_import_iovec Pavel Begunkov
2020-07-13 21:09   ` Jens Axboe
2020-07-13 21:12     ` Pavel Begunkov
2020-07-13 21:16       ` Jens Axboe
2020-07-13 21:18         ` Pavel Begunkov
2020-07-13 21:26           ` Jens Axboe [this message]
2020-07-13 21:09 ` [PATCH for-5.9 0/3] rw iovec copy cleanup Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox