mm/migrate: fix shmem xarray update during migration
Subsystems (2)
Zi Yan
reviewerPATCH 1/1 mm/migrate: fix shmem xarray update during migration
Pagecache uses multi-index entries for large folio, so does shmem. Only swap cache still stores multiple entries for a single large folio. Commit fc346d0a70a1 ("mm: migrate high-order folios in swap cache correctly") fixed swap cache but got shmem wrong by storing multiple entries for a large shmem folio. Fix it by storing a single entry for a shmem folio.
--- mm/migrate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/migrate.c +6 -1
@@ -44,6 +44,7 @@#include <linux/sched/sysctl.h> #include <linux/memory-tiers.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <asm/tlbflush.h>
@@ -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)) + entries =1 ; +else + entries = nr; }else {VM_BUG_ON_FOLIO (folio_test_swapcache (folio), folio); entries =1 ;
Signature · 1 line
2.47.2
mm/migrate.c static int __folio_migrate_mapping(struct address_space *mapping, · line 529
Quoted 7 lines · Zi Yan
mm/migrate.c +2
-1@@ -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 ;-(
Quoted 9 lines
mm/migrate.c +3
-0+ entries =1 ; + else + entries = nr; }else {VM_BUG_ON_FOLIO (folio_test_swapcache (folio), folio); entries =1 ;Signature · 1 line
2.47.2
Zi Yan
reviewerQuoted 10 lines · Matthew Wilcox
mm/migrate.c static int __folio_migrate_mapping(struct address_space *mapping, · line 529
Quoted 7 lines · Zi Yan
mm/migrate.c +2
-1@@ -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?
Yes and it gets rid of the new include. Let me send v2.
Quoted 3 lines
Also, how did this bug remain unnoticed for almost 4 years? Our testing is terrible ;-(
Probably not 4 years. Before fc346d0a70a1 (2023), shmem was right, swap cache was wrong. After fc346d0a70a1, shmem is wrong, swap cache is right. And before Baolin’s patch, shmem only has PMD size folio to use multi-index entries. Maybe getting PMD size folio is really impossible when compaction runs a lot?
Quoted 10 lines
Quoted 10 lines
mm/migrate.c +3
-0+ entries =1 ; + else + entries = nr; }else {VM_BUG_ON_FOLIO (folio_test_swapcache (folio), folio); entries =1 ;Signature · 1 line
2.47.2
Best Regards,
Yan, Zi
Quoted 28 lines · Zi Yan
Pagecache uses multi-index entries for large folio, so does shmem. Only swap cache still stores multiple entries for a single large folio. Commit
fc346d0a70a1("mm: migrate high-order folios in swap cache correctly") fixed swap cache but got shmem wrong by storing multiple entries for a large shmem folio. Fix it by storing a single entry for a shmem folio.Fixes fc346d0a70a1 ("mm: migrate high-order folios in swap cache correctly")Reported-by Liu Shixin <[email protected]>Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/migrate.c +1
-0@@ -44,6 +44,7 @@#include <linux/sched/sysctl.h> #include <linux/memory-tiers.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <asm/tlbflush.h>
mm/migrate.c static int __folio_migrate_mapping(struct address_space *mapping, · line 532
Quoted 9 lines
mm/migrate.c +5
-1@@ -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)) + entries =1 ; +else + entries = nr;
LGTM functionally.
As a minor style suggestion, can we consider using a ternary operator:
entries = shmem_mapping(mapping) ? 1 : nr; /* shmem uses high-order entry */
This looks cleaner to me.
Quoted 3 lines
mm/migrate.c +0
-0}else {VM_BUG_ON_FOLIO (folio_test_swapcache (folio), folio); entries =1 ;
Zi Yan
reviewerQuoted 42 lines · Shivank Garg
Quoted 28 lines · Zi Yan
Pagecache uses multi-index entries for large folio, so does shmem. Only swap cache still stores multiple entries for a single large folio. Commit
fc346d0a70a1("mm: migrate high-order folios in swap cache correctly") fixed swap cache but got shmem wrong by storing multiple entries for a large shmem folio. Fix it by storing a single entry for a shmem folio.Fixes fc346d0a70a1 ("mm: migrate high-order folios in swap cache correctly")Reported-by Liu Shixin <[email protected]>Signed-off-by Zi Yan <[email protected]>--- mm/migrate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/migrate.c +1
-0@@ -44,6 +44,7 @@#include <linux/sched/sysctl.h> #include <linux/memory-tiers.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <asm/tlbflush.h> mm/migrate.c static int __folio_migrate_mapping(struct address_space *mapping, · line 532
Quoted 9 lines
mm/migrate.c +5
-1@@ -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)) + entries =1 ; +else + entries = nr;LGTM functionally.
As a minor style suggestion, can we consider using a ternary operator:
Quoted 5 lines
entries =
shmem_mapping(mapping)? 1 : nr; /* shmem uses high-order entry */This looks cleaner to me.
Reviewed-by Shivank Garg <[email protected]>
Thanks.
Best Regards,
Yan, Zi