public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Stefan Roesch <[email protected]>,
	[email protected], [email protected]
Cc: [email protected],
	Olivier Langlois <[email protected]>,
	Jakub Kicinski <[email protected]>
Subject: Re: [PATCH v11 2/5] io-uring: add napi busy poll support
Date: Fri, 28 Apr 2023 12:32:13 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

This looks much better now! One question and a minor comment:

> @@ -2619,9 +2622,13 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
>  
>  		if (get_timespec64(&ts, uts))
>  			return -EFAULT;
> +
>  		iowq.timeout = ktime_add_ns(timespec64_to_ktime(ts), ktime_get_ns());

Probably want to kill that extra added line, not worth respinning for
obviously.

> diff --git a/io_uring/napi.c b/io_uring/napi.c
> new file mode 100644
> index 000000000000..a085122cae8b
> --- /dev/null
> +++ b/io_uring/napi.c
> +void __io_napi_add(struct io_ring_ctx *ctx, struct file *file)
> +{
> +	unsigned int napi_id;
> +	struct socket *sock;
> +	struct sock *sk;
> +	struct io_napi_ht_entry *he;
> +
> +	sock = sock_from_file(file);
> +	if (!sock)
> +		return;
> +
> +	sk = sock->sk;
> +	if (!sk)
> +		return;
> +
> +	napi_id = READ_ONCE(sk->sk_napi_id);
> +
> +	/* Non-NAPI IDs can be rejected. */
> +	if (napi_id < MIN_NAPI_ID)
> +		return;
> +
> +	spin_lock(&ctx->napi_lock);
> +	hash_for_each_possible(ctx->napi_ht, he, node, napi_id) {
> +		if (he->napi_id == napi_id) {
> +			he->timeout = jiffies + NAPI_TIMEOUT;
> +			goto out;
> +		}
> +	}
> +
> +	he = kmalloc(sizeof(*he), GFP_NOWAIT);
> +	if (!he)
> +		goto out;
> +
> +	he->napi_id = napi_id;
> +	he->timeout = jiffies + NAPI_TIMEOUT;
> +	hash_add(ctx->napi_ht, &he->node, napi_id);
> +
> +	list_add_tail(&he->list, &ctx->napi_list);
> +
> +out:
> +	spin_unlock(&ctx->napi_lock);
> +}

Didn't look into the details here just yet, but one thing occurred to me
- would it be possible to rcu_read_lock() protect the hash for lookup? I
would imagine that the ratio of successful lookups to "nope nothing
found, need to alloc and insert" is quite high, and we could avoid the
napi_lock for that case when just iterating the hash.

Would obviously need rcu freeing of 'he' as well, and so forth. And some
way to detect if 'he' is going away or not. But seems like it'd be
doable without too much trouble?

-- 
Jens Axboe


  reply	other threads:[~2023-04-28 18:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 18:12 [PATCH v11 0/5] io_uring: add napi busy polling support Stefan Roesch
2023-04-28 18:12 ` [PATCH v11 1/5] io-uring: move io_wait_queue definition to header file Stefan Roesch
2023-04-28 18:12 ` [PATCH v11 2/5] io-uring: add napi busy poll support Stefan Roesch
2023-04-28 18:32   ` Jens Axboe [this message]
2023-04-28 18:12 ` [PATCH v11 3/5] io-uring: add sqpoll support for napi busy poll Stefan Roesch
2023-04-28 18:12 ` [PATCH v11 4/5] io_uring: add register/unregister napi function Stefan Roesch
2023-04-28 18:12 ` [PATCH v11 5/5] io_uring: add prefer busy poll to register and unregister napi api Stefan Roesch

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] \
    [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