[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250307052919.34542-4-kprateek.nayak@amd.com>
Date: Fri, 7 Mar 2025 05:29:18 +0000
From: K Prateek Nayak <kprateek.nayak@....com>
To: Linus Torvalds <torvalds@...ux-foundation.org>, Oleg Nesterov
<oleg@...hat.com>, Alexander Viro <viro@...iv.linux.org.uk>, "Christian
Brauner" <brauner@...nel.org>, <linux-fsdevel@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
CC: Jan Kara <jack@...e.cz>, "Matthew Wilcox (Oracle)" <willy@...radead.org>,
Mateusz Guzik <mjguzik@...il.com>, Rasmus Villemoes <ravi@...vas.dk>,
"Gautham R. Shenoy" <gautham.shenoy@....com>, <Neeraj.Upadhyay@....com>,
<Ananth.narayan@....com>, Swapnil Sapkal <swapnil.sapkal@....com>, "K Prateek
Nayak" <kprateek.nayak@....com>
Subject: [PATCH v2 3/4] fs/pipe: Use pipe_buf() helper to retrieve pipe buffer
Use pipe_buf() helper to retrieve the pipe buffer throughout the file
replacing the open-coded the logic.
Suggested-by: Oleg Nesterov <oleg@...hat.com>
Signed-off-by: K Prateek Nayak <kprateek.nayak@....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
Powered by blists - more mailing lists