Re: [PATCH 02/10] mm/ksm: skip subpages of compound pages

Matthew Wilcox
2024-06-05T03:52:18Z

On Tue, Jun 04, 2024 at 12:24:44PM +0800, alexs@kernel.org wrote:
> From: "Alex Shi (tencent)" <alexs@kernel.org>
>
> When a folio isn't fit for KSM, the subpages are unlikely to be good,
> So let's skip the rest page checking to save some actions.

Why would you say that is true? We have plenty of evidence that
userspace allocators can allocate large folios, then use only the first
few bytes, leaving many tail pages full of zeroes.

> @@ -2660,6 +2662,9 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page)
> cond_resched();
> continue;
> }
> +
> + VM_WARN_ON(PageTail(*page));
> + nr = compound_nr(*page);

And this is simply wrong. *page can obviously be a tail page.