io-uring.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
To: "axboe@kernel.dk" <axboe@kernel.dk>
Cc: joseph qi <joseph.qi@linux.alibaba.com>,
	io-uring <io-uring@vger.kernel.org>
Subject: Re: Question about fileset unregister and update codes
Date: Mon, 11 May 2020 19:09:27 +0800	[thread overview]
Message-ID: <6466a229-033d-3eac-5517-d83fd0553384@linux.alibaba.com> (raw)
In-Reply-To: <64638b5f-401e-5cf4-23d9-0a31119d1b9c@linux.alibaba.com>

hi,

Could you please have a look at this mail? Thanks.

Regards,
Xiaoguang Wang

> hi,
> 
> Look at below function:
> static bool io_register_op_must_quiesce(int op)
> {
>      switch (op) {
>      case IORING_UNREGISTER_FILES:
>      case IORING_REGISTER_FILES_UPDATE:
>      case IORING_REGISTER_PROBE:
>      case IORING_REGISTER_PERSONALITY:
>      case IORING_UNREGISTER_PERSONALITY:
>          return false;
>      default:
>          return true;
>      }
> }
> 
> IORING_REGISTER_FILES will quiesces the ctx, but IORING_UNREGISTER_FILES
> and IORING_REGISTER_FILES_UPDATE won't, so I wonder how userspace applications
> can sure when they can unregister or update the registered fileset.
> Imagine below application behaviour:
>       ThreadA                     |      ThreadB
>                                   |
>      1, register a file           |     while (1) {
>      2, prepare a batch of sqes   |         wait a cqe and handle this cqe.
>      3, submit prepared sqes      |     }
>      4, unregister or update file |
>                                   |
> 
> If IORING_SETUP_SQPOLL is not enabled, I think step4 is safe, because step3
> will ensure that all sqes will be prepared by io_req_set_file(), then corresponding
> struct file will be resolved and ctx->file_data->refs will be increased, we know
> unless requst is completed, struct file will not be put, finally we know step4
> is safe.
> 
> But if IORING_SETUP_SQPOLL is enabled, step3 will complete quickly, if kernel
> thread io_sq_thread submit sqes before step4, everything is ok, but if step4
> starts to run, holding uring_lock, later io_sq_thread starts to handle sqes and
> all previously submitted sqes will be returned with EBADF.
> 
> I'm not sure whether should make application ensure that all sqes against registered
> file to complete, then app can unregister or update fileset, if so, I think it'll
> introduce extra programming overhead to programmer.
> 
> Or if IORING_SETUP_SQPOLL is enabled, we call io_submit_sqes in unregister/update codes,
> then applications will not need to worry about above race.
> 
> Regards,
> Xiaoguang Wang

      reply	other threads:[~2020-05-11 11:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 13:55 Question about fileset unregister and update codes Xiaoguang Wang
2020-05-11 11:09 ` Xiaoguang Wang [this message]

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 \
    --in-reply-to=6466a229-033d-3eac-5517-d83fd0553384@linux.alibaba.com \
    --to=xiaoguang.wang@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=joseph.qi@linux.alibaba.com \
    /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;
as well as URLs for NNTP newsgroup(s).