lkml.org 
[lkml]   [2013]   [Oct]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 05/63] mm: Wait for THP migrations to complete during NUMA hinting faults
    Date
    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.

    Cc: stable <stable@vger.kernel.org>
    Signed-off-by: Peter Zijlstra <peterz@infradead.org>
    Signed-off-by: Mel Gorman <mgorman@suse.de>
    ---
    mm/huge_memory.c | 23 ++++++++++++++++-------
    1 file changed, 16 insertions(+), 7 deletions(-)

    diff --git a/mm/huge_memory.c b/mm/huge_memory.c
    index dab2bab..f362363 100644
    --- a/mm/huge_memory.c
    +++ b/mm/huge_memory.c
    @@ -1295,13 +1295,14 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
    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);

    @@ -1312,9 +1313,17 @@ int do_huge_pmd_numa_page(struct mm_struct *mm, struct vm_area_struct *vma,
    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)
    --
    1.8.4


    \
     
     \ /
      Last update: 2013-10-07 13:21    [W:4.180 / U:0.096 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site