mm/migrate: set swap entry values of THP tail pages properly.
Subsystems (2)
PATCH 1/1 mm/migrate: set swap entry values of THP tail pages properly.
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/migrate.c +5 -1
@@ -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 {
Signature · 1 line
2.43.0
Quoted 5 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Corresponding swapcache entries need to be updated as well. e71769ae5260 ("mm: enable thp migration for shmem thp") fixed it already.
Quoted 26 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/migrate.c +5
-1@@ -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 {Signature · 1 line
2.43.0
--
Best Regards,
Yan, Zi
Thanks David for various inputs on this patch!!.
Quoted 4 lines · Zi Yan
Quoted 2 lines · Zi Yan
From: Zi Yan <[email protected]>
Quoted 9 lines
Quoted 3 lines
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Corresponding swapcache entries need to be updated as well.
e71769ae5260("mm: enable thp migration for shmem thp") fixed it already.Fixes 616b8371539a ("mm: thp: enable thp migration in generic path")
Thanks Zi Yan, for posting this patch. I think below tag too applicable?
Closes:
https://lore.kernel.org/linux-mm/[email protected]/
Quoted 32 lines
Quoted 27 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/migrate.c +5
-1@@ -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 {Signature · 1 line
2.43.0--
Best Regards,
Yan, Zi
Quoted 14 lines · Charan Teja Kalla
Thanks David for various inputs on this patch!!.
Quoted 11 lines · Zi Yan
Quoted 5 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Corresponding swapcache entries need to be updated as well.
e71769ae5260("mm: enable thp migration for shmem thp") fixed it already.
Quoted 7 lines
Quoted 2 lines
Fixes 616b8371539a ("mm: thp: enable thp migration in generic path")Thanks Zi Yan, for posting this patch. I think below tag too applicable?
Right. Let me add it to other stable fixes I am going to send.
Hi Greg,
Could you add the information above (text, Fixes, and Closes) to this patch? Or do you want me to resend?
Thanks.
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/migrate.c +5
-1@@ -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;
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
mm/migrate.c +0
-0}else {Signature · 1 line
2.43.0--
Best Regards,
Yan, Zi
--
Best Regards,
Yan, Zi
Quoted 19 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)mm/migrate.c +0
-0@@ -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)) {
mm/migrate.c int folio_migrate_mapping(struct address_space *mapping, · line 434
Quoted 10 lines
mm/migrate.c +5
-1+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 {
Hopefully Charan can run the reproducer against this.
Signature · 3 lines
Cheers, David / dhildenb
Greg KH
maintainerQuoted 10 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
What is the git commit id of this change in Linus's tree?
thanks,
greg k-h
Quoted 7 lines · Greg KH
Quoted 6 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)What is the git commit id of this change in Linus's tree?
Unfortunately, we had to do stable-only versions, because the backport
of the "accidental" fix that removes the per-subpage "private" information would be non-trivial, especially for pre-folio-converison times.
The accidental fix is
07e09c483cbef2a252f75d95670755a0607288f5
Signature · 3 lines
Cheers, David / dhildenb
Greg KH
maintainerQuoted 15 lines · David Hildenbrand
Quoted 7 lines · Greg KH
Quoted 6 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)What is the git commit id of this change in Linus's tree?
Quoted 7 lines
Unfortunately, we had to do stable-only versions, because the backport of the "accidental" fix that removes the per-subpage "private" information would be non-trivial, especially for pre-folio-converison times.
The accidental fix is
07e09c483cbef2a252f75d95670755a0607288f5
None of that is obvious at all here, we need loads of documentation in the changelog text that says all of that please.
thanks,
greg k-h
Quoted 20 lines · Greg KH
Quoted 19 lines · David Hildenbrand
Quoted 7 lines · Greg KH
Quoted 6 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)What is the git commit id of this change in Linus's tree?
Unfortunately, we had to do stable-only versions, because the backport of the "accidental" fix that removes the per-subpage "private" information would be non-trivial, especially for pre-folio-converison times.
Quoted 6 lines
Quoted 3 lines
The accidental fix is
07e09c483cbef2a252f75d95670755a0607288f5None of that is obvious at all here, we need loads of documentation in the changelog text that says all of that please.
How about?
Before 07e09c483cbe ("mm/huge_memory: work on folio->swap instead ofpage->private when splitting folio"), when a THP is added into swapcache,
each of its subpages has its own swapcache entry and need ->private pointing
to the right swapcache entry. THP added to swapcache function is added in38d8b4e6bdc87 ("mm, THP, swap: delay splitting THP during swap out").
When THP migration was added in 616b8371539a6 ("mm: thp: enable thp migration in generic path"), it did not take care of swapcached THP's subpages, neither updated subpage's ->private nor replaced subpage pointer in
the swapcache. Later, e71769ae5260 ("mm: enable thp migration for shmem thp")
fixed swapcache update part. Now this patch fixes the subpage ->private
update part.
--
Best Regards,
Yan, Zi
Greg KH
maintainerQuoted 31 lines · Zi Yan
Quoted 20 lines · Greg KH
Quoted 19 lines · David Hildenbrand
Quoted 7 lines · Greg KH
Quoted 6 lines · Zi Yan
From: Zi Yan <[email protected]>
The tail pages in a THP can have swap entry information stored in their private field. When migrating to a new page, all tail pages of the new page need to update ->private to avoid future data corruption.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)What is the git commit id of this change in Linus's tree?
Unfortunately, we had to do stable-only versions, because the backport of the "accidental" fix that removes the per-subpage "private" information would be non-trivial, especially for pre-folio-converison times.
Quoted 6 lines
Quoted 3 lines
The accidental fix is
07e09c483cbef2a252f75d95670755a0607288f5None of that is obvious at all here, we need loads of documentation in the changelog text that says all of that please.
How about?
Quoted 10 lines
Before
07e09c483cbe("mm/huge_memory: work onfolio->swapinstead ofpage->privatewhen splitting folio"), when a THP is added into swapcache,
each of its subpages has its own swapcache entry and need ->private pointing
to the right swapcache entry. THP added to swapcache function is added in38d8b4e6bdc87("mm, THP, swap: delay splitting THP during swap out").
When THP migration was added in616b8371539a6("mm: thp: enable thp migration in generic path"), it did not take care of swapcached THP's subpages, neither updated subpage's ->private nor replaced subpage pointer in
the swapcache. Later,e71769ae5260("mm: enable thp migration for shmem thp")
fixed swapcache update part. Now this patch fixes the subpage ->private
update part.
That's better than what is there now :)
So yes, please resend all of these with the new text and then we can queue them up.
thanks,
greg k-h