Skip to content

Commit f714f4f

Browse files
Mel Gormantorvalds
authored andcommitted
mm: numa: call MMU notifiers on THP migration
MMU notifiers must be called on THP page migration or secondary MMUs will get very confused. Signed-off-by: Mel Gorman <mgorman@suse.de> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Alex Thorlton <athorlton@sgi.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2b4847e commit f714f4f

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎mm/migrate.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/hugetlb_cgroup.h>
3737
#include <linux/gfp.h>
3838
#include <linux/balloon_compaction.h>
39+
#include <linux/mmu_notifier.h>
3940

4041
#include <asm/tlbflush.h>
4142

@@ -1716,12 +1717,13 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
17161717
struct page *page, int node)
17171718
{
17181719
spinlock_t *ptl;
1719-
unsigned long haddr = address & HPAGE_PMD_MASK;
17201720
pg_data_t *pgdat = NODE_DATA(node);
17211721
int isolated = 0;
17221722
struct page *new_page = NULL;
17231723
struct mem_cgroup *memcg = NULL;
17241724
int page_lru = page_is_file_cache(page);
1725+
unsigned long mmun_start = address & HPAGE_PMD_MASK;
1726+
unsigned long mmun_end = mmun_start + HPAGE_PMD_SIZE;
17251727
pmd_t orig_entry;
17261728

17271729
/*
@@ -1756,10 +1758,12 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
17561758
WARN_ON(PageLRU(new_page));
17571759

17581760
/* Recheck the target PMD */
1761+
mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
17591762
ptl = pmd_lock(mm, pmd);
17601763
if (unlikely(!pmd_same(*pmd, entry) || page_count(page) != 2)) {
17611764
fail_putback:
17621765
spin_unlock(ptl);
1766+
mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
17631767

17641768
/* Reverse changes made by migrate_page_copy() */
17651769
if (TestClearPageActive(new_page))
@@ -1800,15 +1804,16 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
18001804
* The SetPageUptodate on the new page and page_add_new_anon_rmap
18011805
* guarantee the copy is visible before the pagetable update.
18021806
*/
1803-
flush_cache_range(vma, haddr, haddr + HPAGE_PMD_SIZE);
1804-
page_add_new_anon_rmap(new_page, vma, haddr);
1805-
pmdp_clear_flush(vma, haddr, pmd);
1806-
set_pmd_at(mm, haddr, pmd, entry);
1807+
flush_cache_range(vma, mmun_start, mmun_end);
1808+
page_add_new_anon_rmap(new_page, vma, mmun_start);
1809+
pmdp_clear_flush(vma, mmun_start, pmd);
1810+
set_pmd_at(mm, mmun_start, pmd, entry);
1811+
flush_tlb_range(vma, mmun_start, mmun_end);
18071812
update_mmu_cache_pmd(vma, address, &entry);
18081813

18091814
if (page_count(page) != 2) {
1810-
set_pmd_at(mm, haddr, pmd, orig_entry);
1811-
flush_tlb_range(vma, haddr, haddr + HPAGE_PMD_SIZE);
1815+
set_pmd_at(mm, mmun_start, pmd, orig_entry);
1816+
flush_tlb_range(vma, mmun_start, mmun_end);
18121817
update_mmu_cache_pmd(vma, address, &entry);
18131818
page_remove_rmap(new_page);
18141819
goto fail_putback;
@@ -1823,6 +1828,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
18231828
*/
18241829
mem_cgroup_end_migration(memcg, page, new_page, true);
18251830
spin_unlock(ptl);
1831+
mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
18261832

18271833
unlock_page(new_page);
18281834
unlock_page(page);
@@ -1843,7 +1849,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
18431849
ptl = pmd_lock(mm, pmd);
18441850
if (pmd_same(*pmd, entry)) {
18451851
entry = pmd_mknonnuma(entry);
1846-
set_pmd_at(mm, haddr, pmd, entry);
1852+
set_pmd_at(mm, mmun_start, pmd, entry);
18471853
update_mmu_cache_pmd(vma, address, &entry);
18481854
}
18491855
spin_unlock(ptl);

0 commit comments

Comments
 (0)