Re: [PATCH] tmpfs: fix regressions from wider use of ZERO_PAGE
From: Hugh Dickins
Date: Sat Apr 09 2022 - 02:08:56 EST
On Sat, 9 Apr 2022, Christoph Hellwig wrote:
> On Fri, Apr 08, 2022 at 01:38:41PM -0700, Hugh Dickins wrote:
> > + } else if (iter_is_iovec(to)) {
> > + /*
> > + * Copy to user tends to be so well optimized, but
> > + * clear_user() not so much, that it is noticeably
> > + * faster to copy the zero page instead of clearing.
> > + */
> > + ret = copy_page_to_iter(ZERO_PAGE(0), offset, nr, to);
>
> Is the offset and length guaranteed to be less than PAGE_SIZE here?
Almost :) The offset is guaranteed to be less than PAGE_SIZE here, and
the length is guaranteed to be less than or equal to PAGE_SIZE - offset.
>
> Either way I'd rather do this optimization in iov_iter_zero rather
> than hiding it in tmpfs.
Let's see what others say. I think we would all prefer clear_user() to be
enhanced, and hack around it neither here in tmpfs nor in iov_iter_zero().
But that careful work won't get done by magic, nor by me.
And iov_iter_zero() has to deal with a wider range of possibilities,
when pulling in cache lines of ZERO_PAGE(0) will be less advantageous,
than in tmpfs doing a large dd - the case I'm aiming not to regress here
(tmpfs has been copying ZERO_PAGE(0) like this for years).
Hugh