From: Kemeng Shi <shikemeng@huaweicloud.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, dhowells@redhat.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] pipe: avoid repeat check of pipe->readers with pipe lock held
Date: Fri, 29 Sep 2023 00:17:52 +0800 [thread overview]
Message-ID: <20230928161752.142268-3-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230928161752.142268-1-shikemeng@huaweicloud.com>
Change to pipe->readers is protected by pipe_lock. Only recheck
pipe->reader after relock to avoid repeat check of pipe->readers with
pipe lock held.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/pipe.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index b19875720ff1..e9c63f66d1c7 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -479,13 +479,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
}
for (;;) {
- if (!pipe->readers) {
- send_sig(SIGPIPE, current, 0);
- if (!ret)
- ret = -EPIPE;
- break;
- }
-
head = pipe->head;
if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
unsigned int mask = pipe->ring_size - 1;
@@ -573,6 +566,12 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
__pipe_lock(pipe);
was_empty = pipe_empty(pipe->head, pipe->tail);
wake_next_writer = true;
+ if (!pipe->readers) {
+ send_sig(SIGPIPE, current, 0);
+ if (!ret)
+ ret = -EPIPE;
+ break;
+ }
}
out:
if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))
--
2.30.0
next prev parent reply other threads:[~2023-09-28 8:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 16:17 [PATCH 0/2] Two cleanups to pipe Kemeng Shi
2023-09-28 16:17 ` [PATCH 1/2] pipe: remove pipe_full check with wrong head in pipe_write Kemeng Shi
2023-09-28 16:17 ` Kemeng Shi [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-10-08 9:47 [PATCH 0/2] Two cleanups to pipe Kemeng Shi
2023-10-08 9:48 ` [PATCH 2/2] pipe: avoid repeat check of pipe->readers with pipe lock held Kemeng Shi
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=20230928161752.142268-3-shikemeng@huaweicloud.com \
--to=shikemeng@huaweicloud.com \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).