* [PATCH] pipe: remove needless spin_lock in pipe_read/pipe_write
@ 2021-11-22 4:11 yangerkun
2021-11-29 6:22 ` yangerkun
0 siblings, 1 reply; 3+ messages in thread
From: yangerkun @ 2021-11-22 4:11 UTC (permalink / raw)
To: dhowells, viro; +Cc: linux-fsdevel
Once enable CONFIG_WATCH_QUEUE, we should protect pipe with
pipe->rd_wait.lock since post_one_notification may write pipe from
contexts where pipe->mutex cannot be token. But nowdays we will try
take it for anycase, it seems needless. Besides, pipe_write will break
once it's pipe with O_NOTIFICATION_PIPE, pipe->rd_wait.lock seems no
need at all. We make some change base on that, and it can help improve
performance for some case like pipe_pst1 in libMicro.
ARMv7 for our scene, before this patch:
5483 nsecs/call
After this patch:
4854 nsecs/call
Signed-off-by: yangerkun <yangerkun@huawei.com>
---
fs/pipe.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/fs/pipe.c b/fs/pipe.c
index 6d4342bad9f1..e8ced0c50824 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -320,14 +320,18 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
if (!buf->len) {
pipe_buf_release(pipe, buf);
- spin_lock_irq(&pipe->rd_wait.lock);
#ifdef CONFIG_WATCH_QUEUE
+ if (pipe->watch_queue)
+ spin_lock_irq(&pipe->rd_wait.lock);
if (buf->flags & PIPE_BUF_FLAG_LOSS)
pipe->note_loss = true;
#endif
tail++;
pipe->tail = tail;
- spin_unlock_irq(&pipe->rd_wait.lock);
+#ifdef CONFIG_WATCH_QUEUE
+ if (pipe->watch_queue)
+ spin_unlock_irq(&pipe->rd_wait.lock);
+#endif
}
total_len -= chars;
if (!total_len)
@@ -504,16 +508,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
* it, either the reader will consume it or it'll still
* be there for the next write.
*/
- spin_lock_irq(&pipe->rd_wait.lock);
-
head = pipe->head;
- if (pipe_full(head, pipe->tail, pipe->max_usage)) {
- spin_unlock_irq(&pipe->rd_wait.lock);
+ if (pipe_full(head, pipe->tail, pipe->max_usage))
continue;
- }
pipe->head = head + 1;
- spin_unlock_irq(&pipe->rd_wait.lock);
/* Insert it into the buffer array */
buf = &pipe->bufs[head & mask];
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] pipe: remove needless spin_lock in pipe_read/pipe_write
2021-11-22 4:11 [PATCH] pipe: remove needless spin_lock in pipe_read/pipe_write yangerkun
@ 2021-11-29 6:22 ` yangerkun
2021-12-16 8:31 ` yangerkun
0 siblings, 1 reply; 3+ messages in thread
From: yangerkun @ 2021-11-29 6:22 UTC (permalink / raw)
To: dhowells, viro; +Cc: linux-fsdevel
ping
On 2021/11/22 12:11, yangerkun wrote:
> Once enable CONFIG_WATCH_QUEUE, we should protect pipe with
> pipe->rd_wait.lock since post_one_notification may write pipe from
> contexts where pipe->mutex cannot be token. But nowdays we will try
> take it for anycase, it seems needless. Besides, pipe_write will break
> once it's pipe with O_NOTIFICATION_PIPE, pipe->rd_wait.lock seems no
> need at all. We make some change base on that, and it can help improve
> performance for some case like pipe_pst1 in libMicro.
>
> ARMv7 for our scene, before this patch:
> 5483 nsecs/call
> After this patch:
> 4854 nsecs/call
>
> Signed-off-by: yangerkun <yangerkun@huawei.com>
> ---
> fs/pipe.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 6d4342bad9f1..e8ced0c50824 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -320,14 +320,18 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
>
> if (!buf->len) {
> pipe_buf_release(pipe, buf);
> - spin_lock_irq(&pipe->rd_wait.lock);
> #ifdef CONFIG_WATCH_QUEUE
> + if (pipe->watch_queue)
> + spin_lock_irq(&pipe->rd_wait.lock);
> if (buf->flags & PIPE_BUF_FLAG_LOSS)
> pipe->note_loss = true;
> #endif
> tail++;
> pipe->tail = tail;
> - spin_unlock_irq(&pipe->rd_wait.lock);
> +#ifdef CONFIG_WATCH_QUEUE
> + if (pipe->watch_queue)
> + spin_unlock_irq(&pipe->rd_wait.lock);
> +#endif
> }
> total_len -= chars;
> if (!total_len)
> @@ -504,16 +508,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
> * it, either the reader will consume it or it'll still
> * be there for the next write.
> */
> - spin_lock_irq(&pipe->rd_wait.lock);
> -
> head = pipe->head;
> - if (pipe_full(head, pipe->tail, pipe->max_usage)) {
> - spin_unlock_irq(&pipe->rd_wait.lock);
> + if (pipe_full(head, pipe->tail, pipe->max_usage))
> continue;
> - }
>
> pipe->head = head + 1;
> - spin_unlock_irq(&pipe->rd_wait.lock);
>
> /* Insert it into the buffer array */
> buf = &pipe->bufs[head & mask];
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pipe: remove needless spin_lock in pipe_read/pipe_write
2021-11-29 6:22 ` yangerkun
@ 2021-12-16 8:31 ` yangerkun
0 siblings, 0 replies; 3+ messages in thread
From: yangerkun @ 2021-12-16 8:31 UTC (permalink / raw)
To: dhowells, viro; +Cc: linux-fsdevel
ping...
On 2021/11/29 14:22, yangerkun wrote:
> ping
>
> On 2021/11/22 12:11, yangerkun wrote:
>> Once enable CONFIG_WATCH_QUEUE, we should protect pipe with
>> pipe->rd_wait.lock since post_one_notification may write pipe from
>> contexts where pipe->mutex cannot be token. But nowdays we will try
>> take it for anycase, it seems needless. Besides, pipe_write will break
>> once it's pipe with O_NOTIFICATION_PIPE, pipe->rd_wait.lock seems no
>> need at all. We make some change base on that, and it can help improve
>> performance for some case like pipe_pst1 in libMicro.
>>
>> ARMv7 for our scene, before this patch:
>> 5483 nsecs/call
>> After this patch:
>> 4854 nsecs/call
>>
>> Signed-off-by: yangerkun <yangerkun@huawei.com>
>> ---
>> fs/pipe.c | 15 +++++++--------
>> 1 file changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/pipe.c b/fs/pipe.c
>> index 6d4342bad9f1..e8ced0c50824 100644
>> --- a/fs/pipe.c
>> +++ b/fs/pipe.c
>> @@ -320,14 +320,18 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
>> if (!buf->len) {
>> pipe_buf_release(pipe, buf);
>> - spin_lock_irq(&pipe->rd_wait.lock);
>> #ifdef CONFIG_WATCH_QUEUE
>> + if (pipe->watch_queue)
>> + spin_lock_irq(&pipe->rd_wait.lock);
>> if (buf->flags & PIPE_BUF_FLAG_LOSS)
>> pipe->note_loss = true;
>> #endif
>> tail++;
>> pipe->tail = tail;
>> - spin_unlock_irq(&pipe->rd_wait.lock);
>> +#ifdef CONFIG_WATCH_QUEUE
>> + if (pipe->watch_queue)
>> + spin_unlock_irq(&pipe->rd_wait.lock);
>> +#endif
>> }
>> total_len -= chars;
>> if (!total_len)
>> @@ -504,16 +508,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter
>> *from)
>> * it, either the reader will consume it or it'll still
>> * be there for the next write.
>> */
>> - spin_lock_irq(&pipe->rd_wait.lock);
>> -
>> head = pipe->head;
>> - if (pipe_full(head, pipe->tail, pipe->max_usage)) {
>> - spin_unlock_irq(&pipe->rd_wait.lock);
>> + if (pipe_full(head, pipe->tail, pipe->max_usage))
>> continue;
>> - }
>> pipe->head = head + 1;
>> - spin_unlock_irq(&pipe->rd_wait.lock);
>> /* Insert it into the buffer array */
>> buf = &pipe->bufs[head & mask];
>>
> .
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-16 8:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-22 4:11 [PATCH] pipe: remove needless spin_lock in pipe_read/pipe_write yangerkun
2021-11-29 6:22 ` yangerkun
2021-12-16 8:31 ` yangerkun
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).