Linux filesystem development
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Breno Leitao <leitao@debian.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	mjguzik@gmail.com, josh@joshtriplett.org, Jan Kara <jack@suse.cz>,
	jlayton@kernel.org, axboe@kernel.dk, shakeel.butt@linux.dev,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH v4] fs/pipe: unify the page pools into a single per-pipe pool
Date: Fri, 17 Jul 2026 18:19:45 +0200	[thread overview]
Message-ID: <alpWISUKMvqrp5ET@redhat.com> (raw)
In-Reply-To: <20260710-b4-pipe-unification-v4-1-ff31c39f1c16@debian.org>

On 07/10, Breno Leitao wrote:
>
> Pipes keep two separate page caches:
>  a) The per-pipe, lock-protected tmp_page[2]
>  b) An on-stack anon_pipe_prealloc burst pool of up to eight pages
>     filled before the lock
>
> Converge them into a single per-pipe pool (struct anon_pipe_prealloc
> embedded in pipe_inode_info) with the same budget as before: up to
> PIPE_PREALLOC_MAX (8) pages, trimmed back to PIPE_PREALLOC_KEEP (2)
> after each operation. tmp_page[2] is removed.
>
> Pages are still allocated and freed outside pipe->mutex; only the
> assignment into the pool is done under it.
>
> anon_pipe_prefill_and_lock() tops the pool up to the write's page count
> -- and returns with pipe->mutex held, so a write acquires the lock only
> once.
>
> anon_pipe_trim_and_unlock() trims the pool under that same lock before
> dropping it, then frees the excess.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> Reviewed-by: Mateusz Guzik <mjguzik@gmail.com>

I personally like this change. To me it really makes this logic more
simple/clear.

Reviewed-by: Oleg Nesterov <oleg@redhat.com>


One comment below...

> +static void anon_pipe_prefill_and_lock(struct pipe_inode_info *pipe, size_t total_len)
>  {
> -	unsigned int want, i;
> -	struct page *page;
> -
> -	prealloc->count = 0;
> -	if (total_len <= PAGE_SIZE)
> -		return;
> +	struct page *pages[PIPE_PREALLOC_MAX];
> +	unsigned int want, have, need, n = 0;
>
>  	want = min_t(unsigned int, DIV_ROUND_UP(total_len, PAGE_SIZE),
>  		     PIPE_PREALLOC_MAX);
> +	/* Unlocked read; the pool is refilled under the lock below. */
> +	have = min_t(unsigned int, READ_ONCE(pipe->prealloc.count), want);

And READ_ONCE() is enough correctness wise.

But AFAIK it is not enough to make KCSAN happy. anon_pipe_prealloc_pop/push
which modify ->count under pipe->mutex need WRITE_ONCE() to please KCSAN.

Or anon_pipe_prefill_and_lock() can use data_race(READ_ONCE()).

Oleg.


      reply	other threads:[~2026-07-17 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 10:31 [PATCH v4] fs/pipe: unify the page pools into a single per-pipe pool Breno Leitao
2026-07-17 16:19 ` 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=alpWISUKMvqrp5ET@redhat.com \
    --to=oleg@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=josh@joshtriplett.org \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=shakeel.butt@linux.dev \
    --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