Re: [PATCH v4 08/13] mm/collapse: call collapse_file() from collapse_single_pmd()

From: Kiryl Shutsemau

Date: Fri Oct 02 2026 - 07:04:23 EST


On Mon, Sep 28, 2026 at 09:41:18PM -0400, Zi Yan wrote:
> On Mon Sep 28, 2026 at 6:06 AM EDT, Kiryl Shutsemau wrote:
> > From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
> >
> > collapse_scan_file() reads the page cache to decide whether a table is
> > worth collapsing and, when it is, calls collapse_file() itself. The
> > caller cannot get between the decision and the collapse.
> >
> > Move the collapse_file() call up into collapse_single_pmd(), so the scan
> > stops at the decision.
> >
> > Two things change with it. The writeback retry re-runs collapse_file()
> > alone instead of rescanning first; collapse_file() repeats the scan's
> > checks under the page cache lock anyway. And mm_khugepaged_scan_file
>
> So the new version is a little faster by saving a file scan?

On the writeback retry, yes: one page cache walk less per retry.

But that path is MADV_COLLAPSE only, after a dirty page sent the first
collapse_file() back and the writeback has run, so it is rare and the
saving is small. Not measured.

The scan rate change is in the next patch, where a refused file table
no longer costs khugepaged a relock.

Not measured on the file side either, but it is the same shape as the
anonymous scan, where the relock per refused table was most of the cost
of a pass over memory that is already huge.

--
Kiryl Shutsemau / Kirill A. Shutemov