public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	David Howells <dhowells@redhat.com>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs/pipe.c: simplify tmp_page handling
Date: Fri, 7 Mar 2025 23:51:35 +0100	[thread overview]
Message-ID: <20250307225135.GB28762@redhat.com> (raw)
In-Reply-To: <20250307221004.1115255-1-linux@rasmusvillemoes.dk>

On 03/07, Rasmus Villemoes wrote:
>
> Assigning the newly allocated page to pipe->tmp_page, only to
> unconditionally clear ->tmp_page a little later, seems somewhat odd.

Oh yes, but could you look at

	[PATCH v2 1/1] pipe: change pipe_write() to never add a zero-sized buffer
	https://lore.kernel.org/all/20250210114039.GA3588@redhat.com/

already in Christian's tree although I will probably need to rebase
this patch on top of the recent changes.

Oleg.

> It made sense prior to commit a194dfe6e6f6 ("pipe: Rearrange sequence
> in pipe_write() to preallocate slot"), when a user copy was done
> between the allocation and the buf->page = page assignment, and a
> failure there would then just leave the pipe's one-element page cache
> populated. Now, the same purpose is served by the page being inserted
> as a size-0 buffer, and the next write attempting to merge with that
> buffer.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  fs/pipe.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 4d0799e4e719..097400cce241 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -508,13 +508,14 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
>  			struct page *page = pipe->tmp_page;
>  			int copied;
>  
> -			if (!page) {
> +			if (page) {
> +				pipe->tmp_page = NULL;
> +			} else {
>  				page = alloc_page(GFP_HIGHUSER | __GFP_ACCOUNT);
>  				if (unlikely(!page)) {
>  					ret = ret ? : -ENOMEM;
>  					break;
>  				}
> -				pipe->tmp_page = page;
>  			}
>  
>  			/* Allocate a slot in the ring in advance and attach an
> @@ -534,7 +535,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
>  				buf->flags = PIPE_BUF_FLAG_PACKET;
>  			else
>  				buf->flags = PIPE_BUF_FLAG_CAN_MERGE;
> -			pipe->tmp_page = NULL;
>  
>  			copied = copy_page_from_iter(page, 0, PAGE_SIZE, from);
>  			if (unlikely(copied < PAGE_SIZE && iov_iter_count(from))) {
> -- 
> 2.48.1
> 


      parent reply	other threads:[~2025-03-07 22:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07 22:10 [PATCH] fs/pipe.c: simplify tmp_page handling Rasmus Villemoes
2025-03-07 22:43 ` Mateusz Guzik
2025-03-07 22:51 ` Oleg Nesterov [this message]

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=20250307225135.GB28762@redhat.com \
    --to=oleg@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=torvalds@linux-foundation.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