From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: Joanne Koong <joannelkoong@gmail.com>,
miklos@szeredi.hu, linux-fsdevel@vger.kernel.org
Cc: josef@toxicpanda.com, bernd.schubert@fastmail.fm,
laoar.shao@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH v4 1/2] fuse: add optional kernel-enforced timeout for requests
Date: Wed, 21 Aug 2024 15:55:59 +0800 [thread overview]
Message-ID: <b6850802-1440-4e38-af90-756b656a5f78@linux.alibaba.com> (raw)
In-Reply-To: <20240813232241.2369855-2-joannelkoong@gmail.com>
Hi, Joanne,
On 8/14/24 7:22 AM, Joanne Koong wrote:
> There are situations where fuse servers can become unresponsive or take
> too long to reply to a request. Currently there is no upper bound on
> how long a request may take, which may be frustrating to users who get
> stuck waiting for a request to complete.
>
> This commit adds a timeout option (in seconds) for requests. If the
> timeout elapses before the server replies to the request, the request
> will fail with -ETIME.
>
> There are 3 possibilities for a request that times out:
> a) The request times out before the request has been sent to userspace
> b) The request times out after the request has been sent to userspace
> and before it receives a reply from the server
> c) The request times out after the request has been sent to userspace
> and the server replies while the kernel is timing out the request
>
> While a request timeout is being handled, there may be other handlers
> running at the same time if:
> a) the kernel is forwarding the request to the server
> b) the kernel is processing the server's reply to the request
> c) the request is being re-sent
> d) the connection is aborting
> e) the device is getting released
>
> Proper synchronization must be added to ensure that the request is
> handled correctly in all of these cases. To this effect, there is a new
> FR_FINISHING bit added to the request flags, which is set atomically by
> either the timeout handler (see fuse_request_timeout()) which is invoked
> after the request timeout elapses or set by the request reply handler
> (see dev_do_write()), whichever gets there first. If the reply handler
> and the timeout handler are executing simultaneously and the reply handler
> sets FR_FINISHING before the timeout handler, then the request will be
> handled as if the timeout did not elapse. If the timeout handler sets
> FR_FINISHING before the reply handler, then the request will fail with
> -ETIME and the request will be cleaned up.
>
> Currently, this is the refcount lifecycle of a request:
>
> Synchronous request is created:
> fuse_simple_request -> allocates request, sets refcount to 1
> __fuse_request_send -> acquires refcount
> queues request and waits for reply...
> fuse_simple_request -> drops refcount
>
> Background request is created:
> fuse_simple_background -> allocates request, sets refcount to 1
>
> Request is replied to:
> fuse_dev_do_write
> fuse_request_end -> drops refcount on request
>
> Proper acquires on the request reference must be added to ensure that the
> timeout handler does not drop the last refcount on the request while
> other handlers may be operating on the request. Please note that the
> timeout handler may get invoked at any phase of the request's
> lifetime (eg before the request has been forwarded to userspace, etc).
>
> It is always guaranteed that there is a refcount on the request when the
> timeout handler is executing. The timeout handler will be either
> deactivated by the reply/abort/release handlers, or if the timeout
> handler is concurrently executing on another CPU, the reply/abort/release
> handlers will wait for the timeout handler to finish executing first before
> it drops the final refcount on the request.
>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
> fs/fuse/dev.c | 192 +++++++++++++++++++++++++++++++++++++++++++++--
> fs/fuse/fuse_i.h | 14 ++++
> fs/fuse/inode.c | 7 ++
> 3 files changed, 205 insertions(+), 8 deletions(-)
> @@ -1951,9 +2105,10 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
> goto copy_finish;
> }
>
> + __fuse_get_request(req);
> +
While re-inspecting the patch, I doubt if acquiring an extra req->count
here is really needed here.
There are three conditions for concurrency between reply receiving and
timeout handler:
1. timeout handler acquires fpq->lock first and delets the request from
processing[] table. In this case, fuse_dev_write() has no chance of
accessing this request since it has previously already been removed from
the processing[] table. No concurrency and no extra refcount needed here.
2. fuse_dev_write() acquires fpq->lock first and sets FR_FINISHING. In
this case the timeout handler will be disactivated when seeing
FR_FINISHING. Also No concurrency and no extra refcount needed here.
2. fuse_dev_write() acquires fpq->lock first but timeout handler sets
FR_FINISHING first. In this case, fuse_dev_write() handler will return,
leaving the request to the timeout hadler. The access to fuse_req from
fuse_dev_write() is safe as long as fuse_dev_write() still holds
fpq->lock, as the timeout handler may free the request only after
acquiring and releasing fpq->lock. Besides, as for fuse_dev_write(),
the only operation after releasing fpq->lock is fuse_copy_finish(cs),
which shall be safe even when the fuse_req may have been freed by the
timeout handler (not seriously confirmed though)?
Please correct me if I missed something.
> /* Is it an interrupt reply ID? */
> if (oh.unique & FUSE_INT_REQ_BIT) {
> - __fuse_get_request(req);
> spin_unlock(&fpq->lock);
>
> err = 0;
> @@ -1969,6 +2124,18 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
> goto copy_finish;
> }
>
> + if (test_and_set_bit(FR_FINISHING, &req->flags)) {
> + /* timeout handler is already finishing the request */
> + spin_unlock(&fpq->lock);
> + fuse_put_request(req);
> + goto copy_finish;
> + }
> +
> + /*
> + * FR_FINISHING ensures the timeout handler will be a no-op if it runs,
> + * but unset req->fpq here as an extra safeguard
> + */
> + req->fpq = NULL;
> clear_bit(FR_SENT, &req->flags);
> list_move(&req->list, &fpq->io);
> req->out.h = oh;
> @@ -1995,6 +2162,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
> spin_unlock(&fpq->lock);
>
> fuse_request_end(req);
> + fuse_put_request(req);
> out:
> return err ? err : nbytes;
>
--
Thanks,
Jingbo
next prev parent reply other threads:[~2024-08-21 7:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 23:22 [PATCH v4 0/2] fuse: add timeout option for requests Joanne Koong
2024-08-13 23:22 ` [PATCH v4 1/2] fuse: add optional kernel-enforced timeout " Joanne Koong
2024-08-21 7:55 ` Jingbo Xu [this message]
2024-08-21 17:38 ` Joanne Koong
2024-08-13 23:22 ` [PATCH v4 2/2] fuse: add default_request_timeout and max_request_timeout sysctls Joanne Koong
2024-08-20 6:39 ` Yafang Shao
2024-08-20 18:31 ` Joanne Koong
2024-08-21 2:00 ` Yafang Shao
2024-08-22 7:06 ` Jingbo Xu
2024-08-22 21:19 ` Joanne Koong
2024-08-23 2:17 ` Jingbo Xu
2024-08-23 22:54 ` Joanne Koong
2024-08-27 8:12 ` Jingbo Xu
2024-08-27 18:13 ` Joanne Koong
2024-08-28 2:27 ` Jingbo Xu
2024-08-21 2:01 ` [PATCH v4 0/2] fuse: add timeout option for requests Yafang Shao
2024-08-26 20:30 ` Joanne Koong
2024-08-21 13:47 ` Miklos Szeredi
2024-08-21 14:15 ` Bernd Schubert
2024-08-21 14:25 ` Miklos Szeredi
2024-08-21 18:11 ` Josef Bacik
2024-08-21 18:54 ` Miklos Szeredi
2024-08-21 21:22 ` Joanne Koong
2024-08-22 10:52 ` Miklos Szeredi
2024-08-22 17:31 ` Joanne Koong
2024-08-22 17:43 ` Miklos Szeredi
2024-08-22 22:38 ` Joanne Koong
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=b6850802-1440-4e38-af90-756b656a5f78@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=bernd.schubert@fastmail.fm \
--cc=joannelkoong@gmail.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=laoar.shao@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.