Re: [RFC PATCH 1/3] mm/migrate: Add folio_migrate_mapping

From: Matthew Wilcox
Date: Tue May 11 2021 - 18:33:08 EST


On Tue, May 11, 2021 at 06:04:21PM -0400, Zi Yan wrote:
> On 10 May 2021, at 19:23, Matthew Wilcox (Oracle) wrote:
> > +++ b/mm/migrate.c
> > @@ -355,7 +355,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page)
> > */
> > expected_count += is_device_private_page(page);
> > if (mapping)
> > - expected_count += thp_nr_pages(page) + page_has_private(page);
> > + expected_count += compound_nr(page) + page_has_private(page);
>
> Why this change? Is it because you are passing folio->page to expected_page_refs() below
> and the nr_pages for the folio should be checked with folio_nr_pages() which just returns
> compound_nr()?
>
> The change seems to imply that folio can be compound page and migrated even when THP is
> disabled. Is it the case or something else?

That's exactly right.

In general, I don't like to pass &folio->page to functions, but this one
might be handling device private pages (apparently), and they have bogus
refcounts, so devmap pages are explicitly disallowed from being folios
until the refcount problem gets fixed.