From: Bernd Schubert <bernd.schubert@fastmail.fm>
To: Miklos Szeredi <miklos@szeredi.hu>, Amir Goldstein <amir73il@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, Bernd Schubert <bschubert@ddn.com>
Subject: Re: [PATCH v3 9/9] fuse: allow parallel dio writes with FUSE_DIRECT_IO_ALLOW_MMAP
Date: Fri, 9 Feb 2024 12:48:03 +0100 [thread overview]
Message-ID: <f44c0101-0016-4f82-a02d-0dcfefbf4e96@fastmail.fm> (raw)
In-Reply-To: <1be6f498-2d56-4c19-9f93-0678ad76e775@fastmail.fm>
On 2/9/24 12:21, Bernd Schubert wrote:
>
>
> On 2/9/24 11:50, Miklos Szeredi wrote:
>> On Thu, 8 Feb 2024 at 18:09, Amir Goldstein <amir73il@gmail.com> wrote:
>>
>>> static int fuse_inode_get_io_cache(struct fuse_inode *fi)
>>> {
>>> + int err = 0;
>>> +
>>> assert_spin_locked(&fi->lock);
>>> - if (fi->iocachectr < 0)
>>> - return -ETXTBSY;
>>> - if (fi->iocachectr++ == 0)
>>> - set_bit(FUSE_I_CACHE_IO_MODE, &fi->state);
>>> - return 0;
>>> + /*
>>> + * Setting the bit advises new direct-io writes to use an exclusive
>>> + * lock - without it the wait below might be forever.
>>> + */
>>> + set_bit(FUSE_I_CACHE_IO_MODE, &fi->state);
>>> + while (!err && fuse_is_io_cache_wait(fi)) {
>>> + spin_unlock(&fi->lock);
>>> + err = wait_event_killable(fi->direct_io_waitq,
>>> + !fuse_is_io_cache_wait(fi));
>>> + spin_lock(&fi->lock);
>>> + }
>>> + /*
>>> + * Enter caching mode or clear the FUSE_I_CACHE_IO_MODE bit if we
>>> + * failed to enter caching mode and no other caching open exists.
>>> + */
>>> + if (!err)
>>> + fi->iocachectr++;
>>> + else if (fi->iocachectr <= 0)
>>> + clear_bit(FUSE_I_CACHE_IO_MODE, &fi->state);
>>
>> This seems wrong: if the current task is killed, and there's anther
>> task trying to get cached open mode, then clearing
>> FUSE_I_CACHE_IO_MODE will allow new parallel writes, breaking this
>> logic.
>
> This is called holding a spin lock, another task cannot enter here?
> Neither can direct-IO, because it is also locked out. The bit helps DIO
> code to avoid trying to do parallel DIO without the need to take a spin
> lock. When DIO decides it wants to do parallel IO, it first has to get
> past fi->iocachectr < 0 - if there is another task trying to do cache
> IO, either DIO gets < 0 first and the other cache task has to wait, or
> cache tasks gets > 0 and dio will continue with the exclusive lock. Or
> do I miss something?
Now I see what you mean, there is an unlock and another task might have also already set the bit
I think this should do
diff --git a/fs/fuse/iomode.c b/fs/fuse/iomode.c
index acd0833ae873..7c22edd674cb 100644
--- a/fs/fuse/iomode.c
+++ b/fs/fuse/iomode.c
@@ -41,6 +41,8 @@ static int fuse_inode_get_io_cache(struct fuse_inode *fi)
err = wait_event_killable(fi->direct_io_waitq,
!fuse_is_io_cache_wait(fi));
spin_lock(&fi->lock);
+ if (!err)
+ /* Another interrupted task might have unset it */
+ set_bit(FUSE_I_CACHE_IO_MODE, &fi->state);
}
/*
* Enter caching mode or clear the FUSE_I_CACHE_IO_MODE bit if we
next prev parent reply other threads:[~2024-02-09 11:48 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 17:05 [PATCH v3 0/9] fuse: inode IO modes and mmap + parallel dio Amir Goldstein
2024-02-08 17:05 ` [PATCH v3 1/9] fuse: Fix VM_MAYSHARE and direct_io_allow_mmap Amir Goldstein
2024-02-08 17:05 ` [PATCH v3 2/9] fuse: Create helper function if DIO write needs exclusive lock Amir Goldstein
2024-02-09 9:50 ` Miklos Szeredi
2024-02-08 17:05 ` [PATCH v3 3/9] fuse: Add fuse_dio_lock/unlock helper functions Amir Goldstein
2024-02-08 17:05 ` [PATCH v3 4/9] fuse: factor out helper fuse_truncate_update_attr() Amir Goldstein
2024-02-08 17:05 ` [PATCH v3 5/9] fuse: allocate ff->release_args only if release is needed Amir Goldstein
2024-02-09 9:57 ` Miklos Szeredi
2024-02-09 11:26 ` Bernd Schubert
2024-02-08 17:06 ` [PATCH v3 6/9] fuse: break up fuse_open_common() Amir Goldstein
2024-02-09 9:59 ` Miklos Szeredi
2024-02-08 17:06 ` [PATCH v3 7/9] fuse: prepare for failing open response Amir Goldstein
2024-02-08 17:06 ` [PATCH v3 8/9] fuse: introduce inode io modes Amir Goldstein
2024-02-09 10:21 ` Miklos Szeredi
2024-02-09 10:35 ` Amir Goldstein
2024-02-09 10:56 ` Miklos Szeredi
2024-02-09 11:50 ` Amir Goldstein
2024-02-08 17:06 ` [PATCH v3 9/9] fuse: allow parallel dio writes with FUSE_DIRECT_IO_ALLOW_MMAP Amir Goldstein
2024-02-09 10:50 ` Miklos Szeredi
2024-02-09 11:21 ` Bernd Schubert
2024-02-09 11:48 ` Bernd Schubert [this message]
2024-02-09 12:12 ` Amir Goldstein
2024-02-09 12:19 ` Amir Goldstein
2024-02-09 12:19 ` Bernd Schubert
2024-02-09 13:26 ` Miklos Szeredi
2024-02-09 15:28 ` Amir Goldstein
2024-03-17 13:54 ` Amir Goldstein
2024-03-17 19:31 ` Miklos Szeredi
2024-03-17 20:00 ` Amir Goldstein
2024-03-17 20:02 ` Miklos Szeredi
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=f44c0101-0016-4f82-a02d-0dcfefbf4e96@fastmail.fm \
--to=bernd.schubert@fastmail.fm \
--cc=amir73il@gmail.com \
--cc=bschubert@ddn.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 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).