On 28 Feb 2025, at 11:35, Matthew Wilcox wrote: > 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? Yes and it gets rid of the new include. Let me send v2. > > 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? > >> + entries = 1; >> + else >> + entries = nr; >> } else { >> VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio); >> entries = 1; >> -- >> 2.47.2 >> Best Regards, Yan, Zi