Re: [PATCH] mm/huge_memory: fix swap entry values of tail pages of THP

From: Charan Teja Kalla
Date: Wed Feb 28 2024 - 10:37:02 EST


Thanks David/Zi Yan,

On 2/27/2024 9:45 PM, Zi Yan wrote:
> So likely we'd have to fix the stable kernels:
>
> 4.19
> 5.4
> 5.10
> 5.15
> 6.1
>
> That's a lot of pre-folio code. A backport of my series likely won't really make any sense.

So, I assume this is a consensus to have stable-only fix for this issue.

>
> For v6.1, the fix would like below?
>
> diff --git a/mm/migrate.c b/mm/migrate.c
> index c93dd6a31c31..c5968021fde0 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -423,8 +423,12 @@ int folio_migrate_mapping(struct address_space *mapping,
> if (folio_test_swapbacked(folio)) {
> __folio_set_swapbacked(newfolio);
> if (folio_test_swapcache(folio)) {
> + int i;
> +
> folio_set_swapcache(newfolio);
> - newfolio->private = folio_get_private(folio);
> + for (i = 0; i < nr; i++)
> + set_page_private(folio_page(newfolio, i),
> + page_private(folio_page(folio, i)));
> }
> entries = nr;
> } else {

Similar to this is what we had tested[1] internally and observed no issues.

Can this be taken to 6.1, please?

[1]https://lore.kernel.org/linux-mm/8620c1a0-e091-46e9-418a-db66e621b9c4@xxxxxxxxxxx/

Thanks,
Charan