public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Ammar Faizi <[email protected]>, Stefan Roesch <[email protected]>
Cc: io-uring Mailing List <[email protected]>,
	Facebook Kernel Team <[email protected]>,
	Olivier Langlois <[email protected]>,
	Jakub Kicinski <[email protected]>
Subject: Re: [PATCH v10 2/5] io-uring: add napi busy poll support
Date: Thu, 27 Apr 2023 05:16:18 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <ZEnkUMF/[email protected]>

On 4/26/23 8:56?PM, Ammar Faizi wrote:
> On Tue, Apr 25, 2023 at 11:18:42AM -0700, Stefan Roesch wrote:
>> +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);
>> +}
> 
> What about using GFP_KERNEL to allocate 'he' outside the spin lock, then
> kfree() it in the (he->napi_id == napi_id) path after unlock?

We actually discussed this in previous versions of this, it kind of
optimizes for the wrong thing. Only the first trip through here should
allocate a 'he' unit, the rest will find it on the hash. That means that
now the common case will alloc+free an extra one, pointlessly.

> That would make the critical section shorter. Also, GFP_NOWAIT is likely
> to fail under memory pressure.

If a ~48 byte allocation fails, then I suspect we have more serious
issues at hand rather than ignoring NAPI for this socket!

-- 
Jens Axboe


  reply	other threads:[~2023-04-27 11:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 18:18 [PATCH v10 0/5] io_uring: add napi busy polling support Stefan Roesch
2023-04-25 18:18 ` [PATCH v10 1/5] io-uring: move io_wait_queue definition to header file Stefan Roesch
2023-04-25 18:18 ` [PATCH v10 2/5] io-uring: add napi busy poll support Stefan Roesch
2023-04-27  1:41   ` Jens Axboe
2023-04-27  1:46     ` Jens Axboe
2023-04-27 17:34       ` Stefan Roesch
2023-04-27  1:50     ` Jens Axboe
2023-04-27  1:59       ` Jens Axboe
2023-04-27 18:21         ` Stefan Roesch
2023-04-27 17:44       ` Stefan Roesch
2023-04-27 16:27     ` Stefan Roesch
2023-04-28  1:09       ` Jens Axboe
2023-04-27  2:56   ` Ammar Faizi
2023-04-27 11:16     ` Jens Axboe [this message]
2023-04-25 18:18 ` [PATCH v10 3/5] io-uring: add sqpoll support for napi busy poll Stefan Roesch
2023-04-25 18:18 ` [PATCH v10 4/5] io_uring: add register/unregister napi function Stefan Roesch
2023-04-25 18:18 ` [PATCH v10 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