This is a note to let you know that I've just added the patch titled

    mm: Wait for THP migrations to complete during NUMA hinting faults

to the 3.11-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     mm-wait-for-thp-migrations-to-complete-during-numa-hinting-faults.patch
and it can be found in the queue-3.11 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <[email protected]> know about it.


>From 42836f5f8baa33085f547098b74aa98991ee9216 Mon Sep 17 00:00:00 2001
From: Mel Gorman <[email protected]>
Date: Mon, 7 Oct 2013 11:28:43 +0100
Subject: mm: Wait for THP migrations to complete during NUMA hinting faults

From: Mel Gorman <[email protected]>

commit 42836f5f8baa33085f547098b74aa98991ee9216 upstream.

The locking for migrating THP is unusual. While normal page migration
prevents parallel accesses using a migration PTE, THP migration relies on
a combination of the page_table_lock, the page lock and the existance of
the NUMA hinting PTE to guarantee safety but there is a bug in the scheme.

If a THP page is currently being migrated and another thread traps a
fault on the same page it checks if the page is misplaced. If it is not,
then pmd_numa is cleared. The problem is that it checks if the page is
misplaced without holding the page lock meaning that the racing thread
can be migrating the THP when the second thread clears the NUMA bit
and faults a stale page.

This patch checks if the page is potentially being migrated and stalls
using the lock_page if it is potentially being migrated before checking
if the page is misplaced or not.

Signed-off-by: Mel Gorman <[email protected]>
Reviewed-by: Rik van Riel <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

---
 mm/huge_memory.c |   23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1307,13 +1307,14 @@ int do_huge_pmd_numa_page(struct mm_stru
        if (current_nid == numa_node_id())
                count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
 
-       target_nid = mpol_misplaced(page, vma, haddr);
-       if (target_nid == -1) {
-               put_page(page);
-               goto clear_pmdnuma;
-       }
+       /*
+        * Acquire the page lock to serialise THP migrations but avoid dropping
+        * page_table_lock if at all possible
+        */
+       if (trylock_page(page))
+               goto got_lock;
 
-       /* Acquire the page lock to serialise THP migrations */
+       /* Serialise against migrationa and check placement check placement */
        spin_unlock(&mm->page_table_lock);
        lock_page(page);
 
@@ -1324,9 +1325,17 @@ int do_huge_pmd_numa_page(struct mm_stru
                put_page(page);
                goto out_unlock;
        }
-       spin_unlock(&mm->page_table_lock);
+
+got_lock:
+       target_nid = mpol_misplaced(page, vma, haddr);
+       if (target_nid == -1) {
+               unlock_page(page);
+               put_page(page);
+               goto clear_pmdnuma;
+       }
 
        /* Migrate the THP to the requested node */
+       spin_unlock(&mm->page_table_lock);
        migrated = migrate_misplaced_transhuge_page(mm, vma,
                                pmdp, pmd, addr, page, target_nid);
        if (!migrated)


Patches currently in stable-queue which might be from [email protected] are

queue-3.11/mm-wait-for-thp-migrations-to-complete-during-numa-hinting-faults.patch
queue-3.11/mm-account-for-a-thp-numa-hinting-update-as-one-pte-update.patch
queue-3.11/mm-prevent-parallel-splits-during-thp-migration.patch
queue-3.11/mm-close-races-between-thp-migration-and-pmd-numa-clearing.patch
queue-3.11/mm-numa-do-not-account-for-a-hinting-fault-if-we-raced.patch
queue-3.11/mm-numa-sanitize-task_numa_fault-callsites.patch
--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to