Re: [PATCH] mm/migrate: fix shmem xarray update during migration

From: Matthew Wilcox
Date: Fri Feb 28 2025 - 11:36:44 EST


On Fri, Feb 28, 2025 at 10:42:19AM -0500, Zi Yan wrote:
> @@ -524,7 +525,11 @@ static int __folio_migrate_mapping(struct address_space *mapping,
> folio_set_swapcache(newfolio);
> newfolio->private = folio_get_private(folio);
> }
> - entries = nr;
> + /* shmem uses high-order entry */
> + if (shmem_mapping(mapping))

It's be cheaper to check folio_test_anon() here, right?

Also, how did this bug remain unnoticed for almost 4 years?
Our testing is terrible ;-(

> + entries = 1;
> + else
> + entries = nr;
> } else {
> VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio);
> entries = 1;
> --
> 2.47.2
>