From: Andrei Vagin <avagin@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Sasha Levin <sashal@kernel.org>, stable <stable@vger.kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH AUTOSEL 5.5 542/542] pipe: use exclusive waits when reading or writing
Date: Tue, 18 Feb 2020 14:33:25 -0800 [thread overview]
Message-ID: <20200218223325.GA143300@gmail.com> (raw)
In-Reply-To: <CAHk-=wi8Q8xtZt1iKcqSaV1demDnyixXT+GyDZi-Lk61K3+9rw@mail.gmail.com>
On Tue, Feb 18, 2020 at 10:28:23AM -0800, Linus Torvalds wrote:
> On Tue, Feb 18, 2020 at 10:20 AM Matthew Wilcox <willy@infradead.org> wrote:
> >
> > You don't want to move wake_up_partner() up and call it from pipe_release()?
>
> I was actually thinking of going the other way - two of three users of
> wake_up_partner() are redundantly waking up the wrong side, and the
> third user is pointlessly written too.
>
> So I was _thinking_ of a patch like the appended (which is on top of
> the previous patch), but ended up not doing it. Until you brought it
> up.
>
> But I won't bother committing this, since it shouldn't really matter.
I run CRIU tests on the kernel with both these patches. Everything work
as expected. Thank you for the fix.
>
> Linus
> fs/pipe.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 2144507447c5..79ba61430f9c 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -1025,12 +1025,6 @@ static int wait_for_partner(struct pipe_inode_info *pipe, unsigned int *cnt)
> return cur == *cnt ? -ERESTARTSYS : 0;
> }
>
> -static void wake_up_partner(struct pipe_inode_info *pipe)
> -{
> - wake_up_interruptible_all(&pipe->rd_wait);
> - wake_up_interruptible_all(&pipe->wr_wait);
> -}
> -
> static int fifo_open(struct inode *inode, struct file *filp)
> {
> struct pipe_inode_info *pipe;
> @@ -1078,7 +1072,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
> */
> pipe->r_counter++;
> if (pipe->readers++ == 0)
> - wake_up_partner(pipe);
> + wake_up_interruptible_all(&pipe->wr_wait);
>
> if (!is_pipe && !pipe->writers) {
> if ((filp->f_flags & O_NONBLOCK)) {
> @@ -1104,7 +1098,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
>
> pipe->w_counter++;
> if (!pipe->writers++)
> - wake_up_partner(pipe);
> + wake_up_interruptible_all(&pipe->rd_wait);
>
> if (!is_pipe && !pipe->readers) {
> if (wait_for_partner(pipe, &pipe->r_counter))
> @@ -1120,12 +1114,12 @@ static int fifo_open(struct inode *inode, struct file *filp)
> * the process can at least talk to itself.
> */
>
> - pipe->readers++;
> - pipe->writers++;
> + if (pipe->readers++ == 0)
> + wake_up_interruptible_all(&pipe->wr_wait);
> + if (pipe->writers++ == 0)
> + wake_up_interruptible_all(&pipe->rd_wait);
> pipe->r_counter++;
> pipe->w_counter++;
> - if (pipe->readers == 1 || pipe->writers == 1)
> - wake_up_partner(pipe);
> break;
>
> default:
next prev parent reply other threads:[~2020-02-18 22:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200214154854.6746-1-sashal@kernel.org>
2020-02-14 15:48 ` [PATCH AUTOSEL 5.5 539/542] fuse: don't overflow LLONG_MAX with end offset Sasha Levin
2020-02-14 15:48 ` [PATCH AUTOSEL 5.5 542/542] pipe: use exclusive waits when reading or writing Sasha Levin
2020-02-18 9:51 ` Andrei Vagin
2020-02-18 17:36 ` Linus Torvalds
2020-02-18 17:54 ` Linus Torvalds
2020-02-18 18:17 ` Linus Torvalds
2020-02-18 18:20 ` Matthew Wilcox
2020-02-18 18:28 ` Linus Torvalds
2020-02-18 22:33 ` Andrei Vagin [this message]
2020-02-18 23:03 ` Linus Torvalds
2020-03-05 18:19 ` Andrei Vagin
2020-03-05 18:40 ` Linus Torvalds
2020-03-05 19:54 ` Andrei Vagin
2020-02-18 18:53 ` Linus Torvalds
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=20200218223325.GA143300@gmail.com \
--to=avagin@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.org \
/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).