From: Gabriel Krisman Bertazi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 17/17] io_uring/alloc_cache: switch to array based caching
Date: Thu, 21 Mar 2024 13:20:16 -0400 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]> (Jens Axboe's message of "Thu, 21 Mar 2024 10:38:37 -0600")
Jens Axboe <[email protected]> writes:
> On 3/21/24 9:59 AM, Gabriel Krisman Bertazi wrote:
>> Jens Axboe <[email protected]> writes:
>>
>>> Currently lists are being used to manage this, but lists isn't a very
>>> good choice for as extracting the current entry necessitates touching
>>> the next entry as well, to update the list head.
>>>
>>> Outside of that detail, games are also played with KASAN as the list
>>> is inside the cached entry itself.
>>>
>>> Finally, all users of this need a struct io_cache_entry embedded in
>>> their struct, which is union'ized with something else in there that
>>> isn't used across the free -> realloc cycle.
>>>
>>> Get rid of all of that, and simply have it be an array. This will not
>>> change the memory used, as we're just trading an 8-byte member entry
>>> for the per-elem array size.
>>>
>>> This reduces the overhead of the recycled allocations, and it reduces
>>> the code we have to support recycling.
>>
>> Hi Jens,
>>
>> I tried applying the entire to your for-6.10/io_uring branch to test it
>> and only this last patch failed to apply. The tip of the branch I have
>> is 22261e73e8d2 ("io_uring/alloc_cache: shrink default max entries from
>> 512 to 128").
>
> Yeah it has some dependencies that need unraveling. The easiest is if
> you just pull:
>
> git://git.kernel.dk/linux io_uring-recvsend-bundle
>
> into current -git master, and then just test that. That gets you pretty
> much everything that's being tested and played with.
>
> Top of tree is d5653d2fcf1383c0fbe8b64545664aea36c7aca2 right now.
thanks, I'll test with that.
>
>>> -static inline struct io_cache_entry *io_alloc_cache_get(struct io_alloc_cache *cache)
>>> +static inline void *io_alloc_cache_get(struct io_alloc_cache *cache)
>>> {
>>> - if (cache->list.next) {
>>> - struct io_cache_entry *entry;
>>> + if (cache->nr_cached) {
>>> + void *entry = cache->entries[--cache->nr_cached];
>>>
>>> - entry = container_of(cache->list.next, struct io_cache_entry, node);
>>> kasan_mempool_unpoison_object(entry, cache->elem_size);
>>> - cache->list.next = cache->list.next->next;
>>> - cache->nr_cached--;
>>> return entry;
>>> }
>>>
>>> return NULL;
>>> }
>>>
>>> -static inline void io_alloc_cache_init(struct io_alloc_cache *cache,
>>> - unsigned max_nr, size_t size)
>>> +static inline int io_alloc_cache_init(struct io_alloc_cache *cache,
>>> + unsigned max_nr, size_t size)
>>> {
>>> - cache->list.next = NULL;
>>> + cache->entries = kvmalloc_array(max_nr, sizeof(void *), GFP_KERNEL);
>>> + if (!cache->entries)
>>> + return -ENOMEM;
>>> cache->nr_cached = 0;
>>> cache->max_cached = max_nr;
>>> cache->elem_size = size;
>>> + return 0;
>>> }
>>>
>>> static inline void io_alloc_cache_free(struct io_alloc_cache *cache,
>>> - void (*free)(struct io_cache_entry *))
>>> + void (*free)(const void *))
>>
>> Minor, but since free is supposed to free the entry, const doesn't
>> make sense here. Also, you actually just cast it away immediately in
>> every usage.
>
> It's because then I can use kfree() directly for most cases, only two of
> them have special freeing functions. And kfree takes a const void *. I
> should add a comment about that.
TIL. For the record, I was very puzzled on why kfree receives a const
pointer just to cast it away immediately too. Then I found Linus
discussing it at https://yarchive.net/comp/const.html
Anyway, in this case, we are actually modifying it in io_rw_cache_free,
and we don't need to explicitly cast from non-const to const , so I still
think you can avoid the comment and drop the const. But that is just
a nitpick that i won't insist.
Thanks!
--
Gabriel Krisman Bertazi
next prev parent reply other threads:[~2024-03-21 17:20 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 22:55 [PATCHSET v2 0/17] Improve async state handling Jens Axboe
2024-03-20 22:55 ` [PATCH 01/17] io_uring/net: switch io_send() and io_send_zc() to using io_async_msghdr Jens Axboe
2024-04-06 20:58 ` Pavel Begunkov
2024-04-07 21:47 ` Jens Axboe
2024-03-20 22:55 ` [PATCH 02/17] io_uring/net: switch io_recv() " Jens Axboe
2024-03-20 22:55 ` [PATCH 03/17] io_uring/net: unify cleanup handling Jens Axboe
2024-03-20 22:55 ` [PATCH 04/17] io_uring/net: always setup an io_async_msghdr Jens Axboe
2024-03-20 22:55 ` [PATCH 05/17] io_uring/net: get rid of ->prep_async() for receive side Jens Axboe
2024-03-20 22:55 ` [PATCH 06/17] io_uring/net: get rid of ->prep_async() for send side Jens Axboe
2024-03-20 22:55 ` [PATCH 07/17] io_uring: kill io_msg_alloc_async_prep() Jens Axboe
2024-03-20 22:55 ` [PATCH 08/17] io_uring/net: add iovec recycling Jens Axboe
2024-03-20 22:55 ` [PATCH 09/17] io_uring/net: drop 'kmsg' parameter from io_req_msg_cleanup() Jens Axboe
2024-03-20 22:55 ` [PATCH 10/17] io_uring/rw: always setup io_async_rw for read/write requests Jens Axboe
2024-03-25 12:03 ` Anuj gupta
2024-03-25 14:54 ` Jens Axboe
2024-03-20 22:55 ` [PATCH 11/17] io_uring: get rid of struct io_rw_state Jens Axboe
2024-03-20 22:55 ` [PATCH 12/17] io_uring/rw: add iovec recycling Jens Axboe
2024-03-20 22:55 ` [PATCH 13/17] io_uring/net: move connect to always using async data Jens Axboe
2024-03-20 22:55 ` [PATCH 14/17] io_uring/uring_cmd: switch to always allocating " Jens Axboe
2024-03-20 22:55 ` [PATCH 15/17] io_uring/uring_cmd: defer SQE copying until we need it Jens Axboe
2024-03-25 12:41 ` Anuj gupta
2024-03-25 14:55 ` Jens Axboe
2024-03-20 22:55 ` [PATCH 16/17] io_uring: drop ->prep_async() Jens Axboe
2024-04-06 20:54 ` Pavel Begunkov
2024-04-07 21:46 ` Jens Axboe
2024-03-20 22:55 ` [PATCH 17/17] io_uring/alloc_cache: switch to array based caching Jens Axboe
2024-03-21 15:59 ` Gabriel Krisman Bertazi
2024-03-21 16:38 ` Jens Axboe
2024-03-21 17:20 ` Gabriel Krisman Bertazi [this message]
2024-03-21 17:22 ` 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