public inbox for [email protected]
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <[email protected]>
To: Jens Axboe <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/3] io_uring: get rid of alloc cache init_once handling
Date: Thu, 23 Jan 2025 14:47:24 -0500	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]> (Jens Axboe's message of "Thu, 23 Jan 2025 11:45:26 -0700")

Jens Axboe <[email protected]> writes:

> init_once is called when an object doesn't come from the cache, and
> hence needs initial clearing of certain members. While the whole
> struct could get cleared by memset() in that case, a few of the cache
> members are large enough that this may cause unnecessary overhead if
> the caches used aren't large enough to satisfy the workload. For those
> cases, some churn of kmalloc+kfree is to be expected.
>
> Ensure that the 3 users that need clearing put the members they need
> cleared at the start of the struct, and wrap the rest of the struct in
> a struct group so the offset is known.
>
> While at it, improve the interaction with KASAN such that when/if
> KASAN writes to members inside the struct that should be retained over
> caching, it won't trip over itself. For rw and net, the retaining of
> the iovec over caching is disabled if KASAN is enabled. A helper will
> free and clear those members in that case.
>
> @@ -1813,11 +1798,10 @@ void io_netmsg_cache_free(const void *entry)
>  {
>  	struct io_async_msghdr *kmsg = (struct io_async_msghdr *) entry;
>  
> -	if (kmsg->free_iov) {
> -		kasan_mempool_unpoison_object(kmsg->free_iov,
> -				kmsg->free_iov_nr * sizeof(struct iovec));
> +#if !defined(CONFIG_KASAN)
> +	if (kmsg->free_iov)
>  		io_netmsg_iovec_free(kmsg);
> -	}
> +#endif

Among mostly ugly choices, this is an improvement over the init_once
callback.  I'd just fold the above codeguard into the code:

  if (IS_DEFINED(CONFIG_KASAN) && kmsg->free_iov)

Other than that,

Reviewed-by: Gabriel Krisman Bertazi <[email protected]>


>  	kfree(kmsg);
>  }
>  #endif
> diff --git a/io_uring/net.h b/io_uring/net.h
> index 52bfee05f06a..b804c2b36e60 100644
> --- a/io_uring/net.h
> +++ b/io_uring/net.h
> @@ -5,16 +5,20 @@
>  
>  struct io_async_msghdr {
>  #if defined(CONFIG_NET)
> -	struct iovec			fast_iov;
> -	/* points to an allocated iov, if NULL we use fast_iov instead */
>  	struct iovec			*free_iov;
> +	/* points to an allocated iov, if NULL we use fast_iov instead */
>  	int				free_iov_nr;
> -	int				namelen;
> -	__kernel_size_t			controllen;
> -	__kernel_size_t			payloadlen;
> -	struct sockaddr __user		*uaddr;
> -	struct msghdr			msg;
> -	struct sockaddr_storage		addr;
> +	struct_group(clear,

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2025-01-23 19:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-23 18:45 [PATCHSET v2 0/3] Cleanup alloc cache init_once handling Jens Axboe
2025-01-23 18:45 ` [PATCH 1/3] io_uring/uring_cmd: cleanup struct io_uring_cmd_data layout Jens Axboe
2025-01-23 18:45 ` [PATCH 2/3] io_uring: get rid of alloc cache init_once handling Jens Axboe
2025-01-23 19:47   ` Gabriel Krisman Bertazi [this message]
2025-01-23 18:45 ` [PATCH 3/3] io_uring/alloc_cache: get rid of _nocache() helper 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