Re: [PATCH v2 3/5] mm/shmem: introduce copy_zero_to_iter() for large zeroing
From: Chi Zhiling
Date: Mon Jun 01 2026 - 10:58:01 EST
On 6/1/26 9:22 PM, Matthew Wilcox wrote:
On Mon, Jun 01, 2026 at 01:57:02PM +0800, Chi Zhiling wrote:
Currently, holes larger than PAGE_SIZE cannot be handled because
ZERO_PAGE is limited to a single page. Add copy_zero_to_iter() as a
wrapper to support copying larger zero ranges to the iterator.
I think Hugh put this optimisation in the wrong place, and you're
perpetuating that ;-)
So perhaps we can start by moving this optimisation to lib/iov_iter.c?
And then you can redo your optimisation on top of that.
Sure, it's good to see this optimization moved into another place :)
In that case, I'll assume iov_iter_zero() is already well optimized and drop copy_page_to_iter() in v3.
By the way, I assume the benefit of this optimization depends on the CPU architecture, right? If so, I wonder whether lib/iov_iter.c is the most appropriate place for it.
diff --git a/mm/shmem.c b/mm/shmem.c
index 3b5dc21b323c..112cae9f9e4f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3427,19 +3427,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
else
ret = copy_page_to_iter(page, offset, nr, to);
folio_put(folio);
- } else if (user_backed_iter(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);
} else {
- /*
- * But submitting the same page twice in a row to
- * splice() - or others? - can result in confusion:
- * so don't attempt that optimization on pipes etc.
- */
ret = iov_iter_zero(nr, to);
}
I'll include this change to v3.
Thanks,