From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
<linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Jan Kara <jack@suse.cz>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Mateusz Guzik <mjguzik@gmail.com>,
Rasmus Villemoes <ravi@prevas.dk>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
<Neeraj.Upadhyay@amd.com>, <Ananth.narayan@amd.com>,
Swapnil Sapkal <swapnil.sapkal@amd.com>,
"K Prateek Nayak" <kprateek.nayak@amd.com>
Subject: [PATCH v2 3/4] fs/pipe: Use pipe_buf() helper to retrieve pipe buffer
Date: Fri, 7 Mar 2025 05:29:18 +0000 [thread overview]
Message-ID: <20250307052919.34542-4-kprateek.nayak@amd.com> (raw)
In-Reply-To: <20250307052919.34542-1-kprateek.nayak@amd.com>
Use pipe_buf() helper to retrieve the pipe buffer throughout the file
replacing the open-coded the logic.
Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
Changelog:
RFC v1..v2:
o New patch.
---
fs/pipe.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index 88e81f84e3ea..4d6ca0f892b1 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -274,7 +274,6 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
/* Read ->head with a barrier vs post_one_notification() */
unsigned int head = smp_load_acquire(&pipe->head);
unsigned int tail = pipe->tail;
- unsigned int mask = pipe->ring_size - 1;
#ifdef CONFIG_WATCH_QUEUE
if (pipe->note_loss) {
@@ -301,7 +300,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
#endif
if (!pipe_empty(head, tail)) {
- struct pipe_buffer *buf = &pipe->bufs[tail & mask];
+ struct pipe_buffer *buf = pipe_buf(pipe, tail);
size_t chars = buf->len;
size_t written;
int error;
@@ -471,8 +470,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
was_empty = pipe_empty(head, pipe->tail);
chars = total_len & (PAGE_SIZE-1);
if (chars && !was_empty) {
- unsigned int mask = pipe->ring_size - 1;
- struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask];
+ struct pipe_buffer *buf = pipe_buf(pipe, head - 1);
int offset = buf->offset + buf->len;
if ((buf->flags & PIPE_BUF_FLAG_CAN_MERGE) &&
@@ -503,7 +501,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
head = pipe->head;
if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
- unsigned int mask = pipe->ring_size - 1;
struct pipe_buffer *buf;
struct page *page = pipe->tmp_page;
int copied;
@@ -525,7 +522,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
pipe->head = head + 1;
/* Insert it into the buffer array */
- buf = &pipe->bufs[head & mask];
+ buf = pipe_buf(pipe, head);
buf->page = page;
buf->ops = &anon_pipe_buf_ops;
buf->offset = 0;
--
2.43.0
next prev parent reply other threads:[~2025-03-07 5:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 5:29 [PATCH v2 0/4] pipe: Trivial cleanups K Prateek Nayak
2025-03-07 5:29 ` [PATCH v2 1/4] fs/pipe: Limit the slots in pipe_resize_ring() K Prateek Nayak
2025-03-07 14:51 ` Oleg Nesterov
2025-03-07 16:16 ` K Prateek Nayak
2025-03-07 22:30 ` Oleg Nesterov
2025-03-07 5:29 ` [PATCH v2 2/4] kernel/watch_queue: Use pipe_buf() to retrieve the pipe buffer K Prateek Nayak
2025-03-07 5:29 ` K Prateek Nayak [this message]
2025-03-07 5:29 ` [PATCH v2 4/4] fs/splice: Use pipe_buf() helper to retrieve " K Prateek Nayak
2025-03-10 7:59 ` [PATCH v2 0/4] pipe: Trivial cleanups Christian Brauner
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=20250307052919.34542-4-kprateek.nayak@amd.com \
--to=kprateek.nayak@amd.com \
--cc=Ananth.narayan@amd.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=brauner@kernel.org \
--cc=gautham.shenoy@amd.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=oleg@redhat.com \
--cc=ravi@prevas.dk \
--cc=swapnil.sapkal@amd.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--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
all inboxes | Powered by JetHome®