NUMA balancing segmentation fault fixes and misc followups v3
Subsystems (13)
Mel Gorman
reviewercover NUMA balancing segmentation fault fixes and misc followups v3
Alex Thorlton reported segementation faults when NUMA balancing is enabled on large machines. There is no obvious explanation from the console what the problem but similar problems have been observed by Rik van Riel and myself if migration was aggressive enough. Alex, this series is against 3.13-rc2, a verification that the fix addresses your problem would be appreciated.
This series starts with a range of patches aimed at addressing the segmentation fault problem while offsetting some of the cost to avoid badly regressing performance in -stable. Those that are cc'd to stable (patches 1-12) should be merged ASAP. The rest of the series is relatively minor stuff that fell out during the course of development that is ok to wait for the next merge window but should help with the continued development of NUMA balancing.
arch/sparc/include/asm/pgtable_64.h | 4 +- arch/x86/include/asm/pgtable.h | 11 +++- arch/x86/mm/gup.c | 13 +++++ include/asm-generic/pgtable.h | 2 +- include/linux/migrate.h | 9 ++++ include/linux/mm_types.h | 44 +++++++++++++++ include/linux/mmzone.h | 5 +- include/trace/events/migrate.h | 26 +++++++++ include/trace/events/sched.h | 93 ++++++++++++++++++++++++++++++++ kernel/fork.c | 1 + kernel/sched/core.c | 2 + kernel/sched/fair.c | 15 +++++- mm/huge_memory.c | 45 ++++++++++++---- mm/migrate.c | 103 ++++++++++++++++++++++++++++-------- mm/mprotect.c | 15 ++++-- mm/pgtable-generic.c | 8 ++- 16 files changed, 348 insertions(+), 48 deletions(-)
Signature · 1 line
1.8.4
Mel Gorman
reviewerPATCH 1/18 mm: numa: Serialise parallel get_user_page against THP migration
Base pages are unmapped and flushed from cache and TLB during normal page migration and replaced with a migration entry that causes any parallel or gup to block until migration completes. THP does not unmap pages due to a lack of support for migration entries at a PMD level. This allows races with get_user_pages and get_user_pages_fast which commit 3f926ab94 ("mm:
Close races between THP migration and PMD numa clearing") made worse by introducing a pmd_clear_flush().
This patch forces get_user_page (fast and normal) on a pmd_numa page to go through the slow get_user_page path where it will serialise against THP migration and properly account for the NUMA hinting fault. On the migration side the page table lock is taken for each PTE update.
--- arch/x86/mm/gup.c | 13 +++++++++++++ mm/huge_memory.c | 24 ++++++++++++++++-------- mm/migrate.c | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 15 deletions(-)
arch/x86/mm/gup.c +13 -0
@@ -83,6 +83,12 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr,pte_t pte =gup_get_pte (ptep);struct page *page; +/* Similar to the PMD case, NUMA hinting must take slow path */ +if (pte_numa (pte)) { +pte_unmap (ptep); +return 0 ; + } +if ((pte_flags (pte) & (mask | _PAGE_SPECIAL)) != mask) {pte_unmap (ptep);return 0 ;
@@ -167,6 +173,13 @@ static int gup_pmd_range(pud_t pud, unsigned long addr, unsigned long end,if (pmd_none (pmd) ||pmd_trans_splitting (pmd))return 0 ;if (unlikely (pmd_large (pmd))) { +/* +* NUMA hinting faults need to be handled in the GUP +* slowpath for accounting purposes and so that they +* can be serialised against THP migration. +*/ +if (pmd_numa (pmd)) +return 0 ;if (!gup_huge_pmd (pmd, addr, next, write, pages, nr))return 0 ; }else {
mm/huge_memory.c +16 -8
@@ -1243,6 +1243,10 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,if ((flags &FOLL_DUMP ) &&is_huge_zero_pmd (*pmd))return ERR_PTR (-EFAULT ); +/* Full NUMA hinting faults to serialise migration in fault paths */ +if ((flags &FOLL_NUMA ) &&pmd_numa (*pmd)) + goto out; + page =pmd_page (*pmd);VM_BUG_ON (!PageHead (page));if (flags &FOLL_TOUCH ) {
@@ -1323,23 +1327,27 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,/* If the page was locked, there are no parallel migrations */ if (page_locked) goto clear_pmdnuma; + } -/* -* Otherwise wait for potential migrations and retry. We do -* relock and check_same as the page may no longer be mapped. -* As the fault is being retried, do not account for it. -*/ +/* +* If there are potential migrations, wait for completion and retry. We +* do not relock and check_same as the page may no longer be mapped. +* Furtermore, even if the page is currently misplaced, there is no +* guarantee it is still misplaced after the migration completes. +*/ +if (!page_locked) {spin_unlock (ptl);wait_on_page_locked (page); page_nid =-1 ; goto out; } -/* Page is misplaced, serialise migrations and parallel THP splits */ +/* +* Page is misplaced. Page lock serialises migrations. Acquire anon_vma +* to serialises splits +*/ get_page (page);spin_unlock (ptl); -if (!page_locked) -lock_page (page); anon_vma =page_lock_anon_vma_read (page);/* Confirm the PMD did not change while page_table_lock was released */
mm/migrate.c +31 -7
@@ -1722,6 +1722,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,struct page *new_page =NULL ;struct mem_cgroup *memcg =NULL ;int page_lru =page_is_file_cache (page); +pmd_t orig_entry;/* * Rate-limit the amount of data that is being migrated to a node.
@@ -1756,7 +1757,8 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,/* Recheck the target PMD */ ptl =pmd_lock (mm, pmd); -if (unlikely (!pmd_same (*pmd, entry))) { +if (unlikely (!pmd_same (*pmd, entry) ||page_count (page) !=2 )) { +fail_putback:spin_unlock (ptl);/* Reverse changes made by migrate_page_copy() */
@@ -1786,16 +1788,34 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,*/ mem_cgroup_prepare_migration (page, new_page, &memcg); + orig_entry = *pmd; entry =mk_pmd (new_page, vma->vm_page_prot); - entry =pmd_mknonnuma (entry); - entry =maybe_pmd_mkwrite (pmd_mkdirty (entry), vma); entry =pmd_mkhuge (entry); + entry =maybe_pmd_mkwrite (pmd_mkdirty (entry), vma); +/* +* Clear the old entry under pagetable lock and establish the new PTE. +* Any parallel GUP will either observe the old page blocking on the +* page lock, block on the page table lock or observe the new page. +* The SetPageUptodate on the new page and page_add_new_anon_rmap +* guarantee the copy is visible before the pagetable update. +*/ +flush_cache_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); +page_add_new_anon_rmap (new_page, vma, haddr);pmdp_clear_flush (vma, haddr, pmd);set_pmd_at (mm, haddr, pmd, entry); -page_add_new_anon_rmap (new_page, vma, haddr);update_mmu_cache_pmd (vma, address, &entry); + +if (page_count (page) !=2 ) { +set_pmd_at (mm, haddr, pmd, orig_entry); +flush_tlb_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); +update_mmu_cache_pmd (vma, address, &entry); +page_remove_rmap (new_page); + goto fail_putback; + } +page_remove_rmap (page); +/* * Finish the charge transaction under the page table lock to * prevent split_huge_page() from dividing up the charge
@@ -1820,9 +1840,13 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, out_fail:count_vm_events (PGMIGRATE_FAIL ,HPAGE_PMD_NR ); out_dropref: - entry =pmd_mknonnuma (entry); -set_pmd_at (mm, haddr, pmd, entry); -update_mmu_cache_pmd (vma, address, &entry); + ptl =pmd_lock (mm, pmd); +if (pmd_same (*pmd, entry)) { + entry =pmd_mknonnuma (entry); +set_pmd_at (mm, haddr, pmd, entry); +update_mmu_cache_pmd (vma, address, &entry); + } +spin_unlock (ptl);unlock_page (page);put_page (page);
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 01/18] mm: numa: Serialise parallel get_user_page against THP migration
Quoted 8 lines · Mel Gorman
Base pages are unmapped and flushed from cache and TLB during normal page migration and replaced with a migration entry that causes any parallel or gup to block until migration completes. THP does not unmap pages due to a lack of support for migration entries at a PMD level. This allows races with
get_user_pagesandget_user_pages_fastwhich commit3f926ab94("mm:
Close races between THP migration and PMD numa clearing") made worse by introducing apmd_clear_flush().
Quoted 7 lines
This patch forces
get_user_page(fast and normal) on apmd_numapage to go through the slowget_user_pagepath where it will serialise against THP migration and properly account for the NUMA hinting fault. On the migration side the page table lock is taken for each PTE update.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 2/18 mm: numa: Call MMU notifiers on THP migration
In reply to Mel GormanMMU notifiers must be called on THP page migration or secondary MMUs will get very confused.
--- mm/migrate.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
mm/migrate.c +14 -8
@@ -36,6 +36,7 @@#include <linux/hugetlb_cgroup.h> #include <linux/gfp.h> #include <linux/balloon_compaction.h> +#include <linux/mmu_notifier.h> #include <asm/tlbflush.h>
@@ -1716,12 +1717,13 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, struct page *page, int node) {spinlock_t *ptl; -unsigned long haddr = address &HPAGE_PMD_MASK ;pg_data_t *pgdat =NODE_DATA (node);int isolated =0 ;struct page *new_page =NULL ;struct mem_cgroup *memcg =NULL ;int page_lru =page_is_file_cache (page); +unsigned long mmun_start = address &HPAGE_PMD_MASK ; +unsigned long mmun_end = mmun_start +HPAGE_PMD_SIZE ;pmd_t orig_entry;/*
@@ -1756,10 +1758,12 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,WARN_ON (PageLRU (new_page));/* Recheck the target PMD */ +mmu_notifier_invalidate_range_start (mm, mmun_start, mmun_end); ptl =pmd_lock (mm, pmd);if (unlikely (!pmd_same (*pmd, entry) ||page_count (page) !=2 )) { fail_putback:spin_unlock (ptl); +mmu_notifier_invalidate_range_end (mm, mmun_start, mmun_end);/* Reverse changes made by migrate_page_copy() */ if (TestClearPageActive (new_page))
@@ -1800,15 +1804,16 @@ fail_putback:* The SetPageUptodate on the new page and page_add_new_anon_rmap * guarantee the copy is visible before the pagetable update. */ -flush_cache_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); -page_add_new_anon_rmap (new_page, vma, haddr); -pmdp_clear_flush (vma, haddr, pmd); -set_pmd_at (mm, haddr, pmd, entry); +flush_cache_range (vma, mmun_start, mmun_end); +page_add_new_anon_rmap (new_page, vma, mmun_start); +pmdp_clear_flush (vma, mmun_start, pmd); +set_pmd_at (mm, mmun_start, pmd, entry); +flush_tlb_range (vma, mmun_start, mmun_end);update_mmu_cache_pmd (vma, address, &entry);if (page_count (page) !=2 ) { -set_pmd_at (mm, haddr, pmd, orig_entry); -flush_tlb_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); +set_pmd_at (mm, mmun_start, pmd, orig_entry); +flush_tlb_range (vma, mmun_start, mmun_end);update_mmu_cache_pmd (vma, address, &entry);page_remove_rmap (new_page); goto fail_putback;
@@ -1823,6 +1828,7 @@ fail_putback:*/ mem_cgroup_end_migration (memcg, page, new_page, true);spin_unlock (ptl); +mmu_notifier_invalidate_range_end (mm, mmun_start, mmun_end);unlock_page (new_page);unlock_page (page);
@@ -1843,7 +1849,7 @@ out_dropref: ptl =pmd_lock (mm, pmd);if (pmd_same (*pmd, entry)) { entry =pmd_mknonnuma (entry); -set_pmd_at (mm, haddr, pmd, entry); +set_pmd_at (mm, mmun_start, pmd, entry);update_mmu_cache_pmd (vma, address, &entry); }spin_unlock (ptl);
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/18] mm: numa: Call MMU notifiers on THP migration
Quoted 5 lines · Mel Gorman
MMU notifiers must be called on THP page migration or secondary MMUs will get very confused.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 3/18 mm: Clear pmd_numa before invalidating
In reply to Mel Gormanpmdp_invalidate clears the present bit without taking into account that it might be in the _PAGE_NUMA bit leaving the PMD in an unexpected state. Clear pmd_numa before invalidating.
--- mm/pgtable-generic.c | 3 +++ 1 file changed, 3 insertions(+)
mm/pgtable-generic.c +3 -0
@@ -191,6 +191,9 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)void pmdp_invalidate (struct vm_area_struct *vma,unsigned long address,pmd_t *pmdp) { +pmd_t entry = *pmdp; +if (pmd_numa (entry)) + entry =pmd_mknonnuma (entry);set_pmd_at (vma->vm_mm, address, pmdp,pmd_mknotpresent (*pmdp));flush_tlb_range (vma, address, address +HPAGE_PMD_SIZE ); }
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 03/18] mm: Clear pmd_numa before invalidating
Quoted 6 lines · Mel Gorman
pmdp_invalidateclears the present bit without taking into account that it might be in the_PAGE_NUMAbit leaving the PMD in an unexpected state. Clearpmd_numabefore invalidating.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 4/18 mm: numa: Do not clear PMD during PTE update scan
In reply to Mel GormanIf the PMD is flushed then a parallel fault in handle_mm_fault() will enter the pmd_none and do_huge_pmd_anonymous_page() path where it'll attempt to insert a huge zero page. This is wasteful so the patch avoids clearing the PMD when setting pmd_numa.
--- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
@@ -1529,7 +1529,7 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,*/ if (!is_huge_zero_page (page) && !pmd_numa (*pmd)) { - entry =pmdp_get_and_clear (mm, addr, pmd); + entry = *pmd; entry =pmd_mknuma (entry); ret =HPAGE_PMD_NR ; }
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/18] mm: numa: Do not clear PMD during PTE update scan
Quoted 7 lines · Mel Gorman
If the PMD is flushed then a parallel fault in
handle_mm_fault()will enter thepmd_noneanddo_huge_pmd_anonymous_page()path where it'll attempt to insert a huge zero page. This is wasteful so the patch avoids clearing the PMD when settingpmd_numa.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 5/18 mm: numa: Do not clear PTE for pte_numa update
In reply to Mel GormanThe TLB must be flushed if the PTE is updated but change_pte_range is clearing the PTE while marking PTEs pte_numa without necessarily flushing the TLB if it reinserts the same entry. Without the flush, it's conceivable that two processors have different TLBs for the same virtual address and at the very least it would generate spurious faults. This patch only unmaps the pages in change_pte_range for a full protection change.
--- mm/mprotect.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/mprotect.c +6 -2
@@ -52,13 +52,14 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,pte_t ptent;bool updated = false; - ptent =ptep_modify_prot_start (mm, addr, pte);if (!prot_numa) { + ptent =ptep_modify_prot_start (mm, addr, pte); ptent =pte_modify (ptent, newprot); updated = true; }else {struct page *page; + ptent = *pte; page =vm_normal_page (vma, addr, oldpte);if (page) {if (!pte_numa (oldpte)) {
@@ -79,7 +80,10 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,if (updated) pages++; -ptep_modify_prot_commit (mm, addr, pte, ptent); + +/* Only !prot_numa always clears the pte */ +if (!prot_numa) +ptep_modify_prot_commit (mm, addr, pte, ptent); }else if (IS_ENABLED (CONFIG_MIGRATION ) && !pte_file (oldpte)) {swp_entry_t entry =pte_to_swp_entry (oldpte);
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/18] mm: numa: Do not clear PTE for pte_numa update
Quoted 9 lines · Mel Gorman
The TLB must be flushed if the PTE is updated but
change_pte_rangeis clearing the PTE while marking PTEspte_numawithout necessarily flushing the TLB if it reinserts the same entry. Without the flush, it's conceivable that two processors have different TLBs for the same virtual address and at the very least it would generate spurious faults. This patch only unmaps the pages inchange_pte_rangefor a full protection change.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 6/18 mm: numa: Ensure anon_vma is locked to prevent parallel THP splits
In reply to Mel GormanThe anon_vma lock prevents parallel THP splits and any associated complexity that arises when handling splits during THP migration. This patch checks if the lock was successfully acquired and bails from THP migration if it failed for any reason.
--- mm/huge_memory.c | 7 +++++++ 1 file changed, 7 insertions(+)
mm/huge_memory.c +7 -0
@@ -1359,6 +1359,13 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, goto out_unlock; } +/* Bail if we fail to protect against THP splits for any reason */ +if (unlikely (!anon_vma)) { +put_page (page); + page_nid =-1 ; + goto clear_pmdnuma; + } +/* * Migrate the THP to the requested node, returns with page unlocked * and pmd_numa cleared.
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 06/18] mm: numa: Ensure anon_vma is locked to prevent parallel THP splits
Quoted 7 lines · Mel Gorman
The
anon_vmalock prevents parallel THP splits and any associated complexity that arises when handling splits during THP migration. This patch checks if the lock was successfully acquired and bails from THP migration if it failed for any reason.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 7/18 mm: numa: Avoid unnecessary work on the failure path
In reply to Mel GormanIf a PMD changes during a THP migration then migration aborts but the failure path is doing more work than is necessary.
--- mm/migrate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +3 -1
@@ -1780,7 +1780,8 @@ fail_putback:putback_lru_page (page);mod_zone_page_state (page_zone (page),NR_ISOLATED_ANON + page_lru, -HPAGE_PMD_NR ); - goto out_fail; + + goto out_unlock; }/*
@@ -1854,6 +1855,7 @@ out_dropref: }spin_unlock (ptl); +out_unlock:unlock_page (page);put_page (page);return 0 ;
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 07/18] mm: numa: Avoid unnecessary work on the failure path
Quoted 5 lines · Mel Gorman
If a PMD changes during a THP migration then migration aborts but the failure path is doing more work than is necessary.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 8/18 sched: numa: Skip inaccessible VMAs
In reply to Mel GormanInaccessible VMA should not be trapping NUMA hint faults. Skip them.
--- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/sched/fair.c +7 -0
@@ -1752,6 +1752,13 @@ void task_numa_work(struct callback_head *work) (vma->vm_file && (vma->vm_flags & (VM_READ|VM_WRITE)) == (VM_READ))) continue; +/* +* Skip inaccessible VMAs to avoid any confusion between +* PROT_NONE and NUMA hinting ptes +*/ +if (!(vma->vm_flags & (VM_READ |VM_EXEC |VM_WRITE ))) +continue ; + do { start = max(start, vma->vm_start); end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE);
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 08/18] sched: numa: Skip inaccessible VMAs
Quoted 4 lines · Mel Gorman
Inaccessible VMA should not be trapping NUMA hint faults. Skip them.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 9/18 mm: numa: Clear numa hinting information on mprotect
In reply to Mel GormanOn a protection change it is no longer clear if the page should be still accessible. This patch clears the NUMA hinting fault bits on a protection change.
--- mm/huge_memory.c | 2 ++ mm/mprotect.c | 2 ++ 2 files changed, 4 insertions(+)
mm/huge_memory.c +2 -0
@@ -1522,6 +1522,8 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, ret =1 ;if (!prot_numa) { entry =pmdp_get_and_clear (mm, addr, pmd); +if (pmd_numa (entry)) + entry =pmd_mknonnuma (entry); entry =pmd_modify (entry, newprot); ret =HPAGE_PMD_NR ;BUG_ON (pmd_write (entry));
mm/mprotect.c +2 -0
@@ -54,6 +54,8 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,if (!prot_numa) { ptent =ptep_modify_prot_start (mm, addr, pte); +if (pte_numa (ptent)) + ptent =pte_mknonnuma (ptent); ptent =pte_modify (ptent, newprot); updated = true; }else {
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/18] mm: numa: Clear numa hinting information on mprotect
Quoted 3 lines · Mel Gorman
On a protection change it is no longer clear if the page should be still accessible. This patch clears the NUMA hinting fault bits on a protection change.
I had to think about this one, because my first thought was "wait, aren't NUMA ptes inaccessible already?".
Then I thought about doing things like adding read or write permission in the mprotect, eg. changing from PROT_NONE to PROT_READ ... and it became unclear what to do with the NUMA bit in that case...
This patch clears up some confusing situations :)
Quoted 2 lines
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 10/18 mm: numa: Avoid unnecessary disruption of NUMA hinting during migration
In reply to Mel Gormando_huge_pmd_numa_page() handles the case where there is parallel THP migration. However, by the time it is checked the NUMA hinting information has already been disrupted. This patch adds an earlier check with some helpers.
--- include/linux/migrate.h | 9 +++++++++ mm/huge_memory.c | 22 ++++++++++++++++------ mm/migrate.c | 12 ++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-)
include/linux/migrate.h +9 -0
@@ -90,10 +90,19 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,#endif /* CONFIG_MIGRATION */ #ifdef CONFIG_NUMA_BALANCING +extern bool pmd_trans_migrating (pmd_t pmd); +extern void wait_migrate_huge_page (struct anon_vma *anon_vma,pmd_t *pmd);extern int migrate_misplaced_page (struct page *page,struct vm_area_struct *vma,int node);extern bool migrate_ratelimited (int node);#else +static inline bool pmd_trans_migrating (pmd_t pmd) +{ +return false; +} +static inline void wait_migrate_huge_page (struct anon_vma *anon_vma,pmd_t *pmd) +{ +}static inline int migrate_misplaced_page (struct page *page,struct vm_area_struct *vma,int node) {
mm/huge_memory.c +16 -6
@@ -882,6 +882,10 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, ret =0 ; goto out_unlock; } + +/* mmap_sem prevents this happening but warn if that changes */ +WARN_ON (pmd_trans_migrating (pmd)); +if (unlikely (pmd_trans_splitting (pmd))) {/* split huge page running from under us */ spin_unlock (src_ptl);
@@ -1299,6 +1303,17 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,if (unlikely (!pmd_same (pmd, *pmdp))) goto out_unlock; +/* +* If there are potential migrations, wait for completion and retry +* without disrupting NUMA hinting information. Do not relock and +* check_same as the page may no longer be mapped. +*/ +if (unlikely (pmd_trans_migrating (*pmdp))) { +spin_unlock (ptl); +wait_migrate_huge_page (vma->anon_vma, pmdp); + goto out; + } + page =pmd_page (pmd);BUG_ON (is_huge_zero_page (page)); page_nid =page_to_nid (page);
@@ -1329,12 +1344,7 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, goto clear_pmdnuma; } -/* -* If there are potential migrations, wait for completion and retry. We -* do not relock and check_same as the page may no longer be mapped. -* Furtermore, even if the page is currently misplaced, there is no -* guarantee it is still misplaced after the migration completes. -*/ +/* Migration could have started since the pmd_trans_migrating check */ if (!page_locked) {spin_unlock (ptl);wait_on_page_locked (page);
mm/migrate.c +12 -0
@@ -1655,6 +1655,18 @@ int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 1 ; } +bool pmd_trans_migrating (pmd_t pmd) +{ +struct page *page =pmd_page (pmd); +return PageLocked (page); +} + +void wait_migrate_huge_page (struct anon_vma *anon_vma,pmd_t *pmd) +{ +struct page *page =pmd_page (*pmd); +wait_on_page_locked (page); +} +/* * Attempt to migrate a misplaced page to the specified destination * node. Caller is expected to have an elevated reference count on
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration
Quoted 6 lines · Mel Gorman
do_huge_pmd_numa_page()handles the case where there is parallel THP migration. However, by the time it is checked the NUMA hinting information has already been disrupted. This patch adds an earlier check with some helpers.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 11/18 mm: fix TLB flush race between migration, and change_protection_range
In reply to Mel GormanFrom: Rik van Riel <[email protected]>
There are a few subtle races, between change_protection_range (used by mprotect and change_prot_numa) on one side, and NUMA page migration and compaction on the other side.
The basic race is that there is a time window between when the PTE gets made non-present (PROT_NONE or NUMA), and the TLB is flushed.
During that time, a CPU may continue writing to the page.
This is fine most of the time, however compaction or the NUMA migration code may come in, and migrate the page away.
When that happens, the CPU may continue writing, through the cached translation, to what is no longer the current memory location of the process.
This only affects x86, which has a somewhat optimistic pte_accessible. All other architectures appear to be safe, and will either always flush, or flush whenever there is a valid mapping, even with no permissions (SPARC).
The basic race looks like this:
CPU A CPU B CPU C
load TLB entry
make entry PTE/PMD_NUMA
fault on entry
read/write old page
start migrating page
change PTE/PMD to new page
read/write old page [*]
flush TLB
reload TLB from new entry read/write new page lose data
[*] the old page may belong to a new user at this point!
The obvious fix is to flush remote TLB entries, by making sure that pte_accessible aware of the fact that PROT_NONE and PROT_NUMA memory may still be accessible if there is a TLB flush pending for the mm.
This should fix both NUMA migration and compaction.
--- arch/sparc/include/asm/pgtable_64.h | 4 ++-- arch/x86/include/asm/pgtable.h | 11 ++++++++-- include/asm-generic/pgtable.h | 2 +- include/linux/mm_types.h | 44 +++++++++++++++++++++++++++++++++++++ kernel/fork.c | 1 + mm/huge_memory.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/pgtable-generic.c | 5 +++-- 8 files changed, 69 insertions(+), 7 deletions(-)
arch/sparc/include/asm/pgtable_64.h +2 -2
@@ -619,7 +619,7 @@ static inline unsigned long pte_present(pte_t pte) }#define pte_accessible pte_accessible -static inline unsigned long pte_accessible (pte_t a) +static inline unsigned long pte_accessible (struct mm_struct *mm,pte_t a) {return pte_val (a) & _PAGE_VALID; }
@@ -847,7 +847,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,* SUN4V NOTE: _PAGE_VALID is the same value in both the SUN4U * and SUN4V pte layout, so this inline test is fine. */ -if (likely (mm != &init_mm) &&pte_accessible (orig)) +if (likely (mm != &init_mm) &&pte_accessible (mm, orig))tlb_batch_add (mm, addr, ptep, orig, fullmm); }
arch/x86/include/asm/pgtable.h +9 -2
@@ -452,9 +452,16 @@ static inline int pte_present(pte_t a) }#define pte_accessible pte_accessible -static inline int pte_accessible (pte_t a) +static inline bool pte_accessible (struct mm_struct *mm,pte_t a) { -return pte_flags (a) & _PAGE_PRESENT; +if (pte_flags (a) & _PAGE_PRESENT) +return true; + +if ((pte_flags (a) & (_PAGE_PROTNONE | _PAGE_NUMA)) && +tlb_flush_pending (mm)) +return true; + +return false; }static inline int pte_hidden (pte_t pte)
include/asm-generic/pgtable.h +1 -1
@@ -217,7 +217,7 @@ static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)#endif #ifndef pte_accessible -# define pte_accessible (pte) ((void)(pte),1) +# define pte_accessible (mm, pte) ((void)(pte), 1)#endif #ifndef flush_tlb_fix_spurious_fault
include/linux/mm_types.h +44 -0
54 lines not on this page · raw message
kernel/fork.c +1 -0
@@ -537,6 +537,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p)spin_lock_init (&mm->page_table_lock);mm_init_aio (mm);mm_init_owner (mm, p); +clear_tlb_flush_pending (mm);if (likely (!mm_alloc_pgd (mm))) { mm->def_flags =0 ;
mm/huge_memory.c +7 -0
@@ -1377,6 +1377,13 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, }/* +* The page_table_lock above provides a memory barrier +* with change_protection_range. +*/ +if (tlb_flush_pending (mm)) +flush_tlb_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); + +/* * Migrate the THP to the requested node, returns with page unlocked * and pmd_numa cleared. */
mm/mprotect.c +2 -0
@@ -187,6 +187,7 @@ static unsigned long change_protection_range(struct vm_area_struct *vma,BUG_ON (addr >= end); pgd =pgd_offset (mm, addr);flush_cache_range (vma, addr, end); +set_tlb_flush_pending (mm); do { next = pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd))
@@ -198,6 +199,7 @@ static unsigned long change_protection_range(struct vm_area_struct *vma,/* Only flush the TLB if we actually modified any entries: */ if (pages)flush_tlb_range (vma, start, end); +clear_tlb_flush_pending (mm);return pages; }
mm/pgtable-generic.c +3 -2
@@ -110,9 +110,10 @@ int pmdp_clear_flush_young(struct vm_area_struct *vma,pte_t ptep_clear_flush (struct vm_area_struct *vma,unsigned long address,pte_t *ptep) { +struct mm_struct *mm = (vma)->vm_mm;pte_t pte; - pte =ptep_get_and_clear ((vma)->vm_mm, address, ptep); -if (pte_accessible (pte)) + pte =ptep_get_and_clear (mm, address, ptep); +if (pte_accessible (mm, pte))flush_tlb_page (vma, address);return pte; }
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 11/18] mm: fix TLB flush race between migration, and change_protection_range
On 12/09/2013 02:09 AM, Mel Gorman wrote:
After reading the locking thread that Paul McKenney started, I wonder if I got the barriers wrong in these functions...
include/linux/mm_types.h static inline cpumask_t *mm_cpumask(struct mm_struct *mm) · line 479
Quoted 10 lines
include/linux/mm_types.h +10
-0+#if defined(CONFIG_NUMA_BALANCING ) || defined(CONFIG_COMPACTION ) +/* +* Memory barriers to keep this state in sync are graciously provided by +* the page table locks, outside of which no page table modifications happen. +* The barriers below prevent the compiler from re-ordering the instructions +* around the memory barriers that are already present in the code. +*/ +static inline bool tlb_flush_pending (struct mm_struct *mm) +{ +barrier ();
Should this be smp_mb__after_unlock_lock(); ?
include/linux/mm_types.h static inline cpumask_t *mm_cpumask(struct mm_struct *mm) · line 492
Quoted 13 lines
include/linux/mm_types.h +13
-0+return mm->tlb_flush_pending; +} +static inline void set_tlb_flush_pending (struct mm_struct *mm) +{ + mm->tlb_flush_pending = true; +barrier (); +} +/* Clearing is done after a TLB flush, which also provides a barrier. */ +static inline void clear_tlb_flush_pending (struct mm_struct *mm) +{ +barrier (); + mm->tlb_flush_pending = false; +}
And these smp_mb__before_spinlock() ?
Paul? Peter?
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerRe: [PATCH 11/18] mm: fix TLB flush race between migration, and change_protection_range
Quoted 5 lines · Rik van Riel
On 12/09/2013 02:09 AM, Mel Gorman wrote:
After reading the locking thread that Paul McKenney started, I wonder if I got the barriers wrong in these functions...
If Documentation/memory-barriers.txt could not be used to frighten small children before, it certainly can now.
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION) +/* + * Memory barriers to keep this state in sync are graciously provided by + * the page table locks, outside of which no page table modifications happen.
Quoted 9 lines
Review
Quoted 6 lines
+ * The barriers below prevent the compiler from re-ordering the instructions
+ * around the memory barriers that are already present in the code.
+ */(quoted diff) +3
-0+static inline bool tlb_flush_pending(struct mm_struct *mm) +{ + barrier();Should this be
smp_mb__after_unlock_lock(); ?
I think this is still ok. Minimally, it's missing the unlock/lock pair that would cause smp_mb__after_unlock_lock() to be treated as a full barrier on architectures that care. The CPU executing this code as already seen the pmd_numa update if it's in the fault handler so it just needs to be sure to not reorder the check with respect to the page copy.
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ return mm->tlb_flush_pending; +} +static inline void set_tlb_flush_pending(struct mm_struct *mm) +{ + mm->tlb_flush_pending = true; + barrier(); +}
That now needs an smp_mb_before_spinlock to guarantee that the store mm->tlb_flush_pending does not leak into the section updating the page tables and get re-ordered. The result would pair with tlb_flush_pending to guarantee that a pagetable update that starts in parallel will be visible to flush the TLB before the cop
Quoted 7 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+/* Clearing is done after a TLB flush, which also provides a barrier. */ +static inline void clear_tlb_flush_pending(struct mm_struct *mm) +{ + barrier(); + mm->tlb_flush_pending = false; +}
This should be ok. Stores updating page tables complete before the ptl unlock in addition to the TLB flush itself being a barrier that guarantees the this update takes place afterwards.
Peter/Paul?
include/linux/mm_types.h +6 -1
@@ -482,7 +482,12 @@ static inline bool tlb_flush_pending(struct mm_struct *mm)static inline void set_tlb_flush_pending (struct mm_struct *mm) { mm->tlb_flush_pending = true; -barrier (); + +/* +* Guarantee that the tlb_flush_pending store does not leak into the +* critical section updating the page tables +*/ +smp_mb_before_spinlock (); }/* Clearing is done after a TLB flush, which also provides a barrier. */ static inline void clear_tlb_flush_pending (struct mm_struct *mm)
Re: [PATCH 11/18] mm: fix TLB flush race between migration, and change_protection_range
Quoted 8 lines · Mel Gorman
Quoted 4 lines · Rik van Riel
On 12/09/2013 02:09 AM, Mel Gorman wrote:
After reading the locking thread that Paul McKenney started, I wonder if I got the barriers wrong in these functions...
If
Documentation/memory-barriers.txtcould not be used to frighten small children before, it certainly can now.
Depends on the children. Some might find it quite attractive, sort of like running while carrying a knife.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+#if defined(CONFIG_NUMA_BALANCING) || defined(CONFIG_COMPACTION) +/* + * Memory barriers to keep this state in sync are graciously provided by + * the page table locks, outside of which no page table modifications happen.Quoted 8 lines
Review
Quoted 6 lines
+ * The barriers below prevent the compiler from re-ordering the instructions
+ * around the memory barriers that are already present in the code.
+ */(quoted diff) +3
-0+static inline bool tlb_flush_pending(struct mm_struct *mm) +{ + barrier();Should this be
smp_mb__after_unlock_lock(); ?
Quoted 5 lines
I think this is still ok. Minimally, it's missing the unlock/lock pair that would cause
smp_mb__after_unlock_lock()to be treated as a full barrier on architectures that care. The CPU executing this code as already seen thepmd_numaupdate if it's in the fault handler so it just needs to be sure to not reorder the check with respect to the page copy.
You really do need a lock operation somewhere shortly before the smp_mb__after_unlock_lock().
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+ return mm->tlb_flush_pending; +} +static inline void set_tlb_flush_pending(struct mm_struct *mm) +{ + mm->tlb_flush_pending = true;
Quoted 8 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ barrier(); +}That now needs an
smp_mb_before_spinlockto guarantee that the storemm->tlb_flush_pendingdoes not leak into the section updating the page tables and get re-ordered. The result would pair withtlb_flush_pendingto guarantee that a pagetable update that starts in parallel will be visible to flush the TLB before the cop
That would be required even if UNLOCK+LOCK continued being a full barrier. A lock acquisition by itself never was guaranteed to be a full barrier.
Thanx, Paul
Quoted 23 lines
Quoted 7 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+/* Clearing is done after a TLB flush, which also provides a barrier. */ +static inline void clear_tlb_flush_pending(struct mm_struct *mm) +{ + barrier(); + mm->tlb_flush_pending = false; +}This should be ok. Stores updating page tables complete before the ptl unlock in addition to the TLB flush itself being a barrier that guarantees the this update takes place afterwards.
Peter/Paul?
include/linux/mm_types.h +0
-0@@ -482,7 +482,12 @@ static inline bool tlb_flush_pending(struct mm_struct *mm)static inline void set_tlb_flush_pending (struct mm_struct *mm) { mm->tlb_flush_pending = true;
include/linux/mm_types.h static inline bool tlb_flush_pending(struct mm_struct *mm) · line 493
Quoted 10 lines
include/linux/mm_types.h +6
-1-barrier (); + +/* +* Guarantee that the tlb_flush_pending store does not leak into the +* critical section updating the page tables +*/ +smp_mb_before_spinlock (); }/* Clearing is done after a TLB flush, which also provides a barrier. */ static inline void clear_tlb_flush_pending (struct mm_struct *mm)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerRe: [PATCH 11/18] mm: fix TLB flush race between migration, and change_protection_range
Quoted 11 lines · Paul E. McKenney
Quoted 7 lines
Quoted 1 line
Should this be
smp_mb__after_unlock_lock(); ?I think this is still ok. Minimally, it's missing the unlock/lock pair that would cause
smp_mb__after_unlock_lock()to be treated as a full barrier on architectures that care. The CPU executing this code as already seen thepmd_numaupdate if it's in the fault handler so it just needs to be sure to not reorder the check with respect to the page copy.You really do need a lock operation somewhere shortly before the
smp_mb__after_unlock_lock().
My badly phrased point was that there was no unlock/lock operation nearby that needs to be ordered with respect to the tlb_flush_pending check. I do not see a need for smp_mb__after_unlock_lock() here and just this hunk is required.
Quoted 10 lines
Quoted 10 lines
index c122bb1..33e5519 100644
include/linux/mm_types.h +2
-1@@ -482,7 +482,12 @@ static inline bool tlb_flush_pending(struct mm_struct *mm)static inline void set_tlb_flush_pending (struct mm_struct *mm) { mm->tlb_flush_pending = true; -barrier (); + +/*
Quoted 8 lines
include/linux/mm_types.h static inline bool tlb_flush_pending(struct mm_struct *mm) · line 493
Quoted 8 lines
include/linux/mm_types.h +4
-0+* Guarantee that the tlb_flush_pending store does not leak into the +* critical section updating the page tables +*/ +smp_mb_before_spinlock (); }/* Clearing is done after a TLB flush, which also provides a barrier. */ static inline void clear_tlb_flush_pending (struct mm_struct *mm)
A double check would be nice please.
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 12/18 mm: numa: Defer TLB flush for THP migration as long as possible
In reply to Mel GormanTHP migration can fail for a variety of reasons. Avoid flushing the TLB to deal with THP migration races until the copy is ready to start.
--- mm/huge_memory.c | 7 ------- mm/migrate.c | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-)
mm/huge_memory.c +0 -7
@@ -1377,13 +1377,6 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma, }/* -* The page_table_lock above provides a memory barrier -* with change_protection_range. -*/ -if (tlb_flush_pending (mm)) -flush_tlb_range (vma, haddr, haddr +HPAGE_PMD_SIZE ); - -/* * Migrate the THP to the requested node, returns with page unlocked * and pmd_numa cleared. */
mm/migrate.c +6 -0
@@ -1759,6 +1759,12 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, goto out_fail; } +/* PTL provides a memory barrier with change_protection_range */ + ptl =pmd_lock (mm, pmd); +if (tlb_flush_pending (mm)) +flush_tlb_range (vma, mmun_start, mmun_end); +spin_unlock (ptl); +/* Prepare a page as a migration target */ __set_page_locked (new_page);SetPageSwapBacked (new_page);
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/18] mm: numa: Defer TLB flush for THP migration as long as possible
Quoted 7 lines · Mel Gorman
mm/migrate.c +0
-0@@ -1759,6 +1759,12 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, goto out_fail; }
mm/migrate.c int migrate_misplaced_transhuge_page(struct mm_struct *mm, · line 1770
Quoted 10 lines
mm/migrate.c +6
-0+/* PTL provides a memory barrier with change_protection_range */ + ptl =pmd_lock (mm, pmd); +if (tlb_flush_pending (mm)) +flush_tlb_range (vma, mmun_start, mmun_end); +spin_unlock (ptl); +/* Prepare a page as a migration target */ __set_page_locked (new_page);SetPageSwapBacked (new_page);
I don't think there is a need for that extra memory barrier.
On the "set_tlb_flush_pending, turn ptes into NUMA ones" side, we have a barrier in the form of the page table lock.
We only end up in this code path if the pte/pmd already is a NUMA one, and we take several spinlocks along the way to doing this test. That provides for the memory barrier in this code path.
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 13/18 mm: numa: Make NUMA-migrate related functions static
In reply to Mel Gormannumamigrate_update_ratelimit and numamigrate_isolate_page only have callers in mm/migrate.c. This patch makes them static.
--- mm/migrate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/migrate.c +3 -2
@@ -1593,7 +1593,8 @@ bool migrate_ratelimited(int node) }/* Returns true if the node is migrate rate-limited after the update */ -bool numamigrate_update_ratelimit (pg_data_t *pgdat,unsigned long nr_pages) +static bool numamigrate_update_ratelimit (pg_data_t *pgdat, +unsigned long nr_pages) {bool rate_limited = false;
@@ -1617,7 +1618,7 @@ bool numamigrate_update_ratelimit(pg_data_t *pgdat, unsigned long nr_pages)return rate_limited; } -int numamigrate_isolate_page (pg_data_t *pgdat,struct page *page) +static int numamigrate_isolate_page (pg_data_t *pgdat,struct page *page) {int page_lru;
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
Hi Mel,
Quoted 3 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.
I have already send out patches to fix this issue yesterday. ;-)
http://marc.info/?l=linux-mm&m=138648332222847&w=2
http://marc.info/?l=linux-mm&m=138648332422848&w=2
Regards,
Wanpeng Li
Quoted 36 lines
Signed-off-by Mel Gorman <[email protected]>---
mm/migrate.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)mm/migrate.c +3
-2@@ -1593,7 +1593,8 @@ bool migrate_ratelimited(int node) }/* Returns true if the node is migrate rate-limited after the update */ -bool numamigrate_update_ratelimit (pg_data_t *pgdat,unsigned long nr_pages) +static bool numamigrate_update_ratelimit (pg_data_t *pgdat, +unsigned long nr_pages) {bool rate_limited = false;@@ -1617,7 +1618,7 @@ bool numamigrate_update_ratelimit(pg_data_t *pgdat, unsigned long nr_pages)return rate_limited; } -int numamigrate_isolate_page (pg_data_t *pgdat,struct page *page) +static int numamigrate_isolate_page (pg_data_t *pgdat,struct page *page) {int page_lru;Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): 20131209072010.GA3716@hacker.(null)
Mel Gorman
reviewerRe: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
Quoted 11 lines · Wanpeng Li
Hi Mel,
Quoted 3 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.I have already send out patches to fix this issue yesterday. ;-)
http://marc.info/?l=linux-mm&m=138648332222847&w=2
http://marc.info/?l=linux-mm&m=138648332422848&w=2
I know. I had written the patch some time ago waiting to go out with the TLB flush fix and just didn't bother dropping it in response to your series.
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
Quoted 9 lines · Mel Gorman
Quoted 8 lines · Wanpeng Li
Hi Mel,
Quoted 3 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.I have already send out patches to fix this issue yesterday. ;-)
Quoted 7 lines
Quoted 3 lines
http://marc.info/?l=linux-mm&m=138648332222847&w=2
http://marc.info/?l=linux-mm&m=138648332422848&w=2I know. I had written the patch some time ago waiting to go out with the TLB flush fix and just didn't bother dropping it in response to your series.
Ok, could you review my patchset v3? Thanks in advance. ;-)
Regards,
Wanpeng Li
Quoted 4 lines
Signature · 3 lines
-- Mel Gorman SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
A message that is not in the archive (sent off-list or not yet received): 20131209085720.GA16251@hacker.(null)
Mel Gorman
reviewerRe: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
Quoted 14 lines · Wanpeng Li
Quoted 13 lines · Mel Gorman
Quoted 11 lines · Wanpeng Li
Hi Mel,
Quoted 3 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.I have already send out patches to fix this issue yesterday. ;-)
http://marc.info/?l=linux-mm&m=138648332222847&w=2
http://marc.info/?l=linux-mm&m=138648332422848&w=2
Quoted 6 lines
Quoted 3 lines
I know. I had written the patch some time ago waiting to go out with the TLB flush fix and just didn't bother dropping it in response to your series.
Ok, could you review my patchset v3? Thanks in advance. ;-)
Glanced through it this morning and saw nothing wrong. I expect it'll get picked up in due course.
Thanks
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
Quoted 19 lines · Mel Gorman
Quoted 18 lines · Wanpeng Li
Quoted 16 lines · Mel Gorman
Quoted 11 lines · Wanpeng Li
Hi Mel,
Quoted 3 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.I have already send out patches to fix this issue yesterday. ;-)
http://marc.info/?l=linux-mm&m=138648332222847&w=2
http://marc.info/?l=linux-mm&m=138648332422848&w=2I know. I had written the patch some time ago waiting to go out with the TLB flush fix and just didn't bother dropping it in response to your series.
Quoted 5 lines
Quoted 2 lines
Ok, could you review my patchset v3? Thanks in advance. ;-)
Glanced through it this morning and saw nothing wrong. I expect it'll get picked up in due course.
Thanks Mel. ;-)
Regards,
Wanpeng Li
Quoted 6 lines
Thanks
Signature · 2 lines
Mel Gorman SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 13/18] mm: numa: Make NUMA-migrate related functions static
In reply to Mel GormanQuoted 4 lines · Mel Gorman
numamigrate_update_ratelimitandnumamigrate_isolate_pageonly have callers inmm/migrate.c. This patch makes them static.Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 14/18 mm: numa: Limit scope of lock for NUMA migrate rate limiting
In reply to Mel GormanNUMA migrate rate limiting protects a migration counter and window using a lock but in some cases this can be a contended lock. It is not critical that the number of pages be perfect, lost updates are acceptable. Reduce the importance of this lock.
--- include/linux/mmzone.h | 5 +---- mm/migrate.c | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-)
include/linux/mmzone.h +1 -4
@@ -758,10 +758,7 @@ typedef struct pglist_data {int kswapd_max_order;enum zone_type classzone_idx;#ifdef CONFIG_NUMA_BALANCING -/* -* Lock serializing the per destination node AutoNUMA memory -* migration rate limiting data. -*/ +/* Lock serializing the migrate rate limiting window */ spinlock_t numabalancing_migrate_lock;/* Rate limiting time interval */
mm/migrate.c +12 -9
@@ -1596,26 +1596,29 @@ bool migrate_ratelimited(int node)static bool numamigrate_update_ratelimit (pg_data_t *pgdat,unsigned long nr_pages) { -bool rate_limited = false; -/* * Rate-limit the amount of data that is being migrated to a node. * Optimal placement is no good if the memory bus is saturated and * all the time is being spent migrating! */ -spin_lock (&pgdat->numabalancing_migrate_lock);if (time_after (jiffies, pgdat->numabalancing_migrate_next_window)) { +spin_lock (&pgdat->numabalancing_migrate_lock); pgdat->numabalancing_migrate_nr_pages =0 ; pgdat->numabalancing_migrate_next_window = jiffies +msecs_to_jiffies (migrate_interval_millisecs); +spin_unlock (&pgdat->numabalancing_migrate_lock); }if (pgdat->numabalancing_migrate_nr_pages > ratelimit_pages) - rate_limited = true; -else - pgdat->numabalancing_migrate_nr_pages += nr_pages; -spin_unlock (&pgdat->numabalancing_migrate_lock); - -return rate_limited; +return true; + +/* +* This is an unlocked non-atomic update so errors are possible. +* The consequences are failing to migrate when we potentiall should +* have which is not severe enough to warrant locking. If it is ever +* a problem, it can be converted to a per-cpu counter. +*/ + pgdat->numabalancing_migrate_nr_pages += nr_pages; +return false; }static int numamigrate_isolate_page (pg_data_t *pgdat,struct page *page)
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 14/18] mm: numa: Limit scope of lock for NUMA migrate rate limiting
Quoted 6 lines · Mel Gorman
NUMA migrate rate limiting protects a migration counter and window using a lock but in some cases this can be a contended lock. It is not critical that the number of pages be perfect, lost updates are acceptable. Reduce the importance of this lock.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 15/18 mm: numa: Trace tasks that fail migration due to rate limiting
In reply to Mel GormanA low local/remote numa hinting fault ratio is potentially explained by failed migrations. This patch adds a tracepoint that fires when migration fails due to migration rate limitation.
--- include/trace/events/migrate.h | 26 ++++++++++++++++++++++++++ mm/migrate.c | 5 ++++- 2 files changed, 30 insertions(+), 1 deletion(-)
include/trace/events/migrate.h +26 -0
@@ -45,6 +45,32 @@ TRACE_EVENT(mm_migrate_pages, __print_symbolic(__entry->reason, MIGRATE_REASON)) ); +TRACE_EVENT (mm_numa_migrate_ratelimit, + + TP_PROTO(struct task_struct *p, int dst_nid, unsigned long nr_pages), + +TP_ARGS (p, dst_nid, nr_pages), + +TP_STRUCT__entry ( + __array( char, comm, TASK_COMM_LEN) + __field( pid_t, pid) + __field( int, dst_nid) + __field( unsigned long, nr_pages) + ), + +TP_fast_assign ( + memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __entry->pid = p->pid; + __entry->dst_nid = dst_nid; + __entry->nr_pages = nr_pages; + ), + +TP_printk ("comm=%s pid=%d dst_nid=%d nr_pages=%lu" , + __entry->comm, + __entry->pid, + __entry->dst_nid, + __entry->nr_pages) +);#endif /* _TRACE_MIGRATE_H */ /* This part must be outside protection */
mm/migrate.c +4 -1
@@ -1608,8 +1608,11 @@ static bool numamigrate_update_ratelimit(pg_data_t *pgdat,msecs_to_jiffies (migrate_interval_millisecs);spin_unlock (&pgdat->numabalancing_migrate_lock); } -if (pgdat->numabalancing_migrate_nr_pages > ratelimit_pages) +if (pgdat->numabalancing_migrate_nr_pages > ratelimit_pages) { +trace_mm_numa_migrate_ratelimit (current, pgdat->node_id, + nr_pages);return true; + }/* * This is an unlocked non-atomic update so errors are possible.
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 15/18] mm: numa: Trace tasks that fail migration due to rate limiting
Quoted 5 lines · Mel Gorman
A low local/remote numa hinting fault ratio is potentially explained by failed migrations. This patch adds a tracepoint that fires when migration fails due to migration rate limitation.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 16/18 mm: numa: Do not automatically migrate KSM pages
In reply to Mel GormanKSM pages can be shared between tasks that are not necessarily related to each other from a NUMA perspective. This patch causes those pages to be ignored by automatic NUMA balancing so they do not migrate and do not cause unrelated tasks to be grouped together.
--- mm/mprotect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/mprotect.c +2 -1
@@ -23,6 +23,7 @@#include <linux/mmu_notifier.h> #include <linux/migrate.h> #include <linux/perf_event.h> +#include <linux/ksm.h> #include <asm/uaccess.h> #include <asm/pgtable.h> #include <asm/cacheflush.h>
@@ -63,7 +64,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ptent = *pte; page =vm_normal_page (vma, addr, oldpte); -if (page) { +if (page && !PageKsm (page)) {if (!pte_numa (oldpte)) { ptent =pte_mknuma (ptent); updated = true;
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 16/18] mm: numa: Do not automatically migrate KSM pages
Quoted 6 lines · Mel Gorman
KSM pages can be shared between tasks that are not necessarily related to each other from a NUMA perspective. This patch causes those pages to be ignored by automatic NUMA balancing so they do not migrate and do not cause unrelated tasks to be grouped together.
Signed-off-by Mel Gorman <[email protected]>
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 17/18 sched: Tracepoint task movement
In reply to Mel Gormanmove_task() is called from move_one_task and move_tasks and is an approximation of load balancer activity. We should be able to track tasks that move between CPUs frequently. If the tracepoint included node information then we could distinguish between in-node and between-node traffic for load balancer decisions. The tracepoint allows us to track local migrations, remote migrations and average task migrations.
--- include/trace/events/sched.h | 35 +++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 2 ++ 2 files changed, 37 insertions(+)
include/trace/events/sched.h +35 -0
@@ -443,6 +443,41 @@ TRACE_EVENT(sched_process_hang, );#endif /* CONFIG_DETECT_HUNG_TASK */ +/* +* Tracks migration of tasks from one runqueue to another. Can be used to +* detect if automatic NUMA balancing is bouncing between nodes +*/ +TRACE_EVENT (sched_move_task, + + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu), + +TP_STRUCT__entry ( + __field( pid_t, pid ) + __field( pid_t, tgid ) + __field( pid_t, ngid ) + __field( int, src_cpu ) + __field( int, src_nid ) + __field( int, dst_cpu ) +__field ( int, dst_nid ) + ), + +TP_fast_assign ( + __entry->pid = task_pid_nr(tsk); + __entry->tgid = task_tgid_nr(tsk); + __entry->ngid = task_numa_group_id(tsk); + __entry->src_cpu = src_cpu; + __entry->src_nid = cpu_to_node(src_cpu); + __entry->dst_cpu = dst_cpu; + __entry->dst_nid = cpu_to_node(dst_cpu); + ), + +TP_printk ("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d" , + __entry->pid, __entry->tgid, __entry->ngid, + __entry->src_cpu, __entry->src_nid, + __entry->dst_cpu, __entry->dst_nid) +);#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
kernel/sched/fair.c +2 -0
@@ -4770,6 +4770,8 @@ static void move_task(struct task_struct *p, struct lb_env *env)set_task_cpu (p, env->dst_cpu);activate_task (env->dst_rq, p,0 );check_preempt_curr (env->dst_rq, p,0 ); + +trace_sched_move_task (p, env->src_cpu, env->dst_cpu); }/*
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 17/18] sched: Tracepoint task movement
Quoted 8 lines · Mel Gorman
move_task()is called frommove_one_taskandmove_tasksand is an approximation of load balancer activity. We should be able to track tasks that move between CPUs frequently. If the tracepoint included node information then we could distinguish between in-node and between-node traffic for load balancer decisions. The tracepoint allows us to track local migrations, remote migrations and average task migrations.Signed-off-by Mel Gorman <[email protected]>
Does this replicate the task_sched_migrate_task tracepoint in set_task_cpu() ?
I know Drew has been using that tracepoint in his (still experimental) numatop script. Drew, does this tracepoint look better than the trace point that you are currently using, or is it similar enough that we do not really benefit from this addition?
Quoted 60 lines
include/trace/events/sched.h +35
-0@@ -443,6 +443,41 @@ TRACE_EVENT(sched_process_hang, );#endif /* CONFIG_DETECT_HUNG_TASK */ +/* +* Tracks migration of tasks from one runqueue to another. Can be used to +* detect if automatic NUMA balancing is bouncing between nodes +*/ +TRACE_EVENT (sched_move_task, + + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu), + +TP_STRUCT__entry ( + __field( pid_t, pid ) + __field( pid_t, tgid ) + __field( pid_t, ngid ) + __field( int, src_cpu ) + __field( int, src_nid ) + __field( int, dst_cpu ) +__field ( int, dst_nid ) + ), + +TP_fast_assign ( + __entry->pid = task_pid_nr(tsk); + __entry->tgid = task_tgid_nr(tsk); + __entry->ngid = task_numa_group_id(tsk); + __entry->src_cpu = src_cpu; + __entry->src_nid = cpu_to_node(src_cpu); + __entry->dst_cpu = dst_cpu; + __entry->dst_nid = cpu_to_node(dst_cpu); + ), + +TP_printk ("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d" , + __entry->pid, __entry->tgid, __entry->ngid, + __entry->src_cpu, __entry->src_nid, + __entry->dst_cpu, __entry->dst_nid) +);#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */ kernel/sched/fair.c +2
-0@@ -4770,6 +4770,8 @@ static void move_task(struct task_struct *p, struct lb_env *env)set_task_cpu (p, env->dst_cpu);activate_task (env->dst_rq, p,0 );check_preempt_curr (env->dst_rq, p,0 ); + +trace_sched_move_task (p, env->src_cpu, env->dst_cpu); }/*
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerRe: [PATCH 17/18] sched: Tracepoint task movement
Quoted 8 lines · Rik van Riel
Quoted 7 lines · Mel Gorman
move_task()is called frommove_one_taskandmove_tasksand is an approximation of load balancer activity. We should be able to track tasks that move between CPUs frequently. If the tracepoint included node information then we could distinguish between in-node and between-node traffic for load balancer decisions. The tracepoint allows us to track local migrations, remote migrations and average task migrations.
Quoted 5 lines
Quoted 1 line
Signed-off-by Mel Gorman <[email protected]>Does this replicate the
task_sched_migrate_tasktracepoint inset_task_cpu()?
There is significant overlap but bits missing. We do not necessarily know where the task was previously running and whether this is a local->remote migration. We also cannot tell the difference between load balancer activity, numa balancing and try_to_wake_up. Still, you're right, this patch is not painting a full picture either. I'll drop it for now and look at improving the existing task_sched_migrate_task tracepoint.
Signature · 8 lines
Mel Gorman SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 17/18] sched: Tracepoint task movement
In reply to Rik van RielQuoted 10 lines · Rik van Riel
Quoted 8 lines · Mel Gorman
move_task()is called frommove_one_taskandmove_tasksand is an approximation of load balancer activity. We should be able to track tasks that move between CPUs frequently. If the tracepoint included node information then we could distinguish between in-node and between-node traffic for load balancer decisions. The tracepoint allows us to track local migrations, remote migrations and average task migrations.Signed-off-by Mel Gorman <[email protected]>
Quoted 7 lines
Does this replicate the
task_sched_migrate_tasktracepoint inset_task_cpu()?I know Drew has been using that tracepoint in his (still experimental) numatop script. Drew, does this tracepoint look better than the trace point that you are currently using, or is it similar enough that we do not really benefit from this addition?
Right, sched::sched_migrate_task only gives us pid, orig_cpu, and dest_cpu, but all the fields below are important. The numamigtop script has been extracting/using all that information as well, but by using the pid and /proc, plus a cpu-node map built from /sys info. I agree with Mel that enhancing the tracepoint is a good idea. Doing so, would allow trace data of this sort to be analyzed without a tool, or at least with a much simpler tool.
drew
Quoted 59 lines
Quoted 59 lines
include/trace/events/sched.h +35
-0@@ -443,6 +443,41 @@ TRACE_EVENT(sched_process_hang, );#endif /* CONFIG_DETECT_HUNG_TASK */ +/* +* Tracks migration of tasks from one runqueue to another. Can be used to +* detect if automatic NUMA balancing is bouncing between nodes +*/ +TRACE_EVENT (sched_move_task, + + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu), + +TP_STRUCT__entry ( + __field( pid_t, pid ) + __field( pid_t, tgid ) + __field( pid_t, ngid ) + __field( int, src_cpu ) + __field( int, src_nid ) + __field( int, dst_cpu ) +__field ( int, dst_nid ) + ), + +TP_fast_assign ( + __entry->pid = task_pid_nr(tsk); + __entry->tgid = task_tgid_nr(tsk); + __entry->ngid = task_numa_group_id(tsk); + __entry->src_cpu = src_cpu; + __entry->src_nid = cpu_to_node(src_cpu); + __entry->dst_cpu = dst_cpu; + __entry->dst_nid = cpu_to_node(dst_cpu); + ), + +TP_printk ("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d" , + __entry->pid, __entry->tgid, __entry->ngid, + __entry->src_cpu, __entry->src_nid, + __entry->dst_cpu, __entry->dst_nid) +);#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */ kernel/sched/fair.c +2
-0@@ -4770,6 +4770,8 @@ static void move_task(struct task_struct *p, struct lb_env *env)set_task_cpu (p, env->dst_cpu);activate_task (env->dst_rq, p,0 );check_preempt_curr (env->dst_rq, p,0 ); + +trace_sched_move_task (p, env->src_cpu, env->dst_cpu); }
Quoted 6 lines
Quoted 2 lines
kernel/sched/fair.c +0
-0/* Signature · 1 line
All rights reversed
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Mel Gorman
reviewerPATCH 18/18 sched: Add tracepoints related to NUMA task migration
In reply to Mel GormanThis patch adds three tracepoints
o trace_sched_move_numa when a task is moved to a node
o trace_sched_swap_numa when a task is swapped with another task
o trace_sched_stick_numa when a numa-related migration fails
The tracepoints allow the NUMA scheduler activity to be monitored and the following high-level metrics can be calculated
o NUMA migrated stuck nr trace_sched_stick_numa
o NUMA migrated idle nr trace_sched_move_numa
o NUMA migrated swapped nr trace_sched_swap_numa
o NUMA local swapped trace_sched_swap_numa src_nid == dst_nid (should never happen)
o NUMA remote swapped trace_sched_swap_numa src_nid != dst_nid (should == NUMA migrated swapped)
o NUMA group swapped trace_sched_swap_numa src_ngid == dst_ngid
Maybe a small number of these are acceptable but a high number would be a major surprise. It would be even worse if bounces are frequent.
o NUMA avg task migs. Average number of migrations for tasks
o NUMA stddev task mig Self-explanatory
o NUMA max task migs. Maximum number of migrations for a single task
In general the intent of the tracepoints is to help diagnose problems where automatic NUMA balancing appears to be doing an excessive amount of useless work.
--- include/trace/events/sched.h | 68 ++++++++++++++++++++++++++++++++++++++++---- kernel/sched/core.c | 2 ++ kernel/sched/fair.c | 6 ++-- 3 files changed, 69 insertions(+), 7 deletions(-)
include/trace/events/sched.h +63 -5
@@ -443,11 +443,7 @@ TRACE_EVENT(sched_process_hang, );#endif /* CONFIG_DETECT_HUNG_TASK */ -/* -* Tracks migration of tasks from one runqueue to another. Can be used to -* detect if automatic NUMA balancing is bouncing between nodes -*/ -TRACE_EVENT(sched_move_task, +DECLARE_EVENT_CLASS(sched_move_task_template, TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
@@ -478,6 +474,68 @@ TRACE_EVENT(sched_move_task, __entry->src_cpu, __entry->src_nid, __entry->dst_cpu, __entry->dst_nid) ); + +/* +* Tracks migration of tasks from one runqueue to another. Can be used to +* detect if automatic NUMA balancing is bouncing between nodes +*/ +DEFINE_EVENT (sched_move_task_template, sched_move_task, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +DEFINE_EVENT (sched_move_task_template, sched_move_numa, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +DEFINE_EVENT (sched_move_task_template, sched_stick_numa, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +TRACE_EVENT (sched_swap_numa, + + TP_PROTO(struct task_struct *src_tsk, int src_cpu, + struct task_struct *dst_tsk, int dst_cpu), + +TP_ARGS (src_tsk, src_cpu, dst_tsk, dst_cpu), + +TP_STRUCT__entry ( + __field( pid_t, src_pid ) + __field( pid_t, src_tgid ) + __field( pid_t, src_ngid ) + __field( int, src_cpu ) + __field( int, src_nid ) + __field( pid_t, dst_pid ) + __field( pid_t, dst_tgid ) + __field( pid_t, dst_ngid ) + __field( int, dst_cpu ) +__field ( int, dst_nid ) + ), + +TP_fast_assign ( + __entry->src_pid = task_pid_nr(src_tsk); + __entry->src_tgid = task_tgid_nr(src_tsk); + __entry->src_ngid = task_numa_group_id(src_tsk); + __entry->src_cpu = src_cpu; + __entry->src_nid = cpu_to_node(src_cpu); + __entry->dst_pid = task_pid_nr(dst_tsk); + __entry->dst_tgid = task_tgid_nr(dst_tsk); + __entry->dst_ngid = task_numa_group_id(dst_tsk); + __entry->dst_cpu = dst_cpu; + __entry->dst_nid = cpu_to_node(dst_cpu); + ), + +TP_printk ("src_pid=%d src_tgid=%d src_ngid=%d src_cpu=%d src_nid=%d dst_pid=%d dst_tgid=%d dst_ngid=%d dst_cpu=%d dst_nid=%d" , + __entry->src_pid, __entry->src_tgid, __entry->src_ngid, + __entry->src_cpu, __entry->src_nid, + __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid, + __entry->dst_cpu, __entry->dst_nid) +);#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
kernel/sched/core.c +2 -0
@@ -1108,6 +1108,7 @@ int migrate_swap(struct task_struct *cur, struct task_struct *p)if (!cpumask_test_cpu (arg.src_cpu,tsk_cpus_allowed (arg.dst_task))) goto out; +trace_sched_swap_numa (cur, arg.src_cpu, p, arg.dst_cpu); ret =stop_two_cpus (arg.dst_cpu, arg.src_cpu, migrate_swap_stop, &arg); out:
@@ -4091,6 +4092,7 @@ int migrate_task_to(struct task_struct *p, int target_cpu)/* TODO: This is not properly updating schedstats */ +trace_sched_move_numa (p, curr_cpu, target_cpu);return stop_one_cpu (curr_cpu, migration_cpu_stop, &arg); }
kernel/sched/fair.c +4 -2
@@ -1272,11 +1272,13 @@ static int task_numa_migrate(struct task_struct *p) p->numa_scan_period =task_scan_min (p);if (env.best_task ==NULL ) { -int ret =migrate_task_to (p, env.best_cpu); +if ((ret =migrate_task_to (p, env.best_cpu)) !=0 ) +trace_sched_stick_numa (p, env.src_cpu, env.best_cpu);return ret; } - ret =migrate_swap (p, env.best_task); +if ((ret =migrate_swap (p, env.best_task)) !=0 ); +trace_sched_stick_numa (p, env.src_cpu,task_cpu (env.best_task));put_task_struct (env.best_task);return ret; }
Signature · 7 lines
1.8.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 18/18] sched: Add tracepoints related to NUMA task migration
Quoted 21 lines · Mel Gorman
This patch adds three tracepoints
otrace_sched_move_numawhen a task is moved to a node
otrace_sched_swap_numawhen a task is swapped with another task
otrace_sched_stick_numawhen a numa-related migration failsThe tracepoints allow the NUMA scheduler activity to be monitored and the following high-level metrics can be calculated
o NUMA migrated stuck nr
trace_sched_stick_numa
o NUMA migrated idle nrtrace_sched_move_numa
o NUMA migrated swapped nrtrace_sched_swap_numa
o NUMA local swappedtrace_sched_swap_numasrc_nid==dst_nid(should never happen)
o NUMA remote swappedtrace_sched_swap_numasrc_nid!=dst_nid(should == NUMA migrated swapped)
o NUMA group swappedtrace_sched_swap_numasrc_ngid==dst_ngid
Maybe a small number of these are acceptable but a high number would be a major surprise. It would be even worse if bounces are frequent.
o NUMA avg task migs. Average number of migrations for tasks
o NUMA stddev task mig Self-explanatory
o NUMA max task migs. Maximum number of migrations for a single task
Quoted 5 lines
In general the intent of the tracepoints is to help diagnose problems where automatic NUMA balancing appears to be doing an excessive amount of useless work.
Signed-off-by Mel Gorman <[email protected]>
Quoted 127 lines
include/trace/events/sched.h +63
-5@@ -443,11 +443,7 @@ TRACE_EVENT(sched_process_hang, );#endif /* CONFIG_DETECT_HUNG_TASK */ -/* -* Tracks migration of tasks from one runqueue to another. Can be used to -* detect if automatic NUMA balancing is bouncing between nodes -*/ -TRACE_EVENT(sched_move_task, +DECLARE_EVENT_CLASS(sched_move_task_template, TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),@@ -478,6 +474,68 @@ TRACE_EVENT(sched_move_task, __entry->src_cpu, __entry->src_nid, __entry->dst_cpu, __entry->dst_nid) ); + +/* +* Tracks migration of tasks from one runqueue to another. Can be used to +* detect if automatic NUMA balancing is bouncing between nodes +*/ +DEFINE_EVENT (sched_move_task_template, sched_move_task, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +DEFINE_EVENT (sched_move_task_template, sched_move_numa, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +DEFINE_EVENT (sched_move_task_template, sched_stick_numa, + TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu), + +TP_ARGS (tsk, src_cpu, dst_cpu) +); + +TRACE_EVENT (sched_swap_numa, + + TP_PROTO(struct task_struct *src_tsk, int src_cpu, + struct task_struct *dst_tsk, int dst_cpu), + +TP_ARGS (src_tsk, src_cpu, dst_tsk, dst_cpu), + +TP_STRUCT__entry ( + __field( pid_t, src_pid ) + __field( pid_t, src_tgid ) + __field( pid_t, src_ngid ) + __field( int, src_cpu ) + __field( int, src_nid ) + __field( pid_t, dst_pid ) + __field( pid_t, dst_tgid ) + __field( pid_t, dst_ngid ) + __field( int, dst_cpu ) +__field ( int, dst_nid ) + ), + +TP_fast_assign ( + __entry->src_pid = task_pid_nr(src_tsk); + __entry->src_tgid = task_tgid_nr(src_tsk); + __entry->src_ngid = task_numa_group_id(src_tsk); + __entry->src_cpu = src_cpu; + __entry->src_nid = cpu_to_node(src_cpu); + __entry->dst_pid = task_pid_nr(dst_tsk); + __entry->dst_tgid = task_tgid_nr(dst_tsk); + __entry->dst_ngid = task_numa_group_id(dst_tsk); + __entry->dst_cpu = dst_cpu; + __entry->dst_nid = cpu_to_node(dst_cpu); + ), + +TP_printk ("src_pid=%d src_tgid=%d src_ngid=%d src_cpu=%d src_nid=%d dst_pid=%d dst_tgid=%d dst_ngid=%d dst_cpu=%d dst_nid=%d" , + __entry->src_pid, __entry->src_tgid, __entry->src_ngid, + __entry->src_cpu, __entry->src_nid, + __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid, + __entry->dst_cpu, __entry->dst_nid) +);#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */ kernel/sched/core.c +2
-0@@ -1108,6 +1108,7 @@ int migrate_swap(struct task_struct *cur, struct task_struct *p)if (!cpumask_test_cpu (arg.src_cpu,tsk_cpus_allowed (arg.dst_task))) goto out; +trace_sched_swap_numa (cur, arg.src_cpu, p, arg.dst_cpu); ret =stop_two_cpus (arg.dst_cpu, arg.src_cpu, migrate_swap_stop, &arg); out:@@ -4091,6 +4092,7 @@ int migrate_task_to(struct task_struct *p, int target_cpu)/* TODO: This is not properly updating schedstats */ +trace_sched_move_numa (p, curr_cpu, target_cpu);return stop_one_cpu (curr_cpu, migration_cpu_stop, &arg); }kernel/sched/fair.c +4
-2@@ -1272,11 +1272,13 @@ static int task_numa_migrate(struct task_struct *p) p->numa_scan_period =task_scan_min (p);if (env.best_task ==NULL ) { -int ret =migrate_task_to (p, env.best_cpu); +if ((ret =migrate_task_to (p, env.best_cpu)) !=0 ) +trace_sched_stick_numa (p, env.src_cpu, env.best_cpu);return ret; } - ret =migrate_swap (p, env.best_task); +if ((ret =migrate_swap (p, env.best_task)) !=0 ); +trace_sched_stick_numa (p, env.src_cpu,task_cpu (env.best_task));put_task_struct (env.best_task);return ret; }
Signature · 7 lines
All rights reversed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>