Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-19 Thread Mel Gorman
On Tue, Dec 17, 2013 at 05:53:45PM -0500, Sasha Levin wrote:
> Hi Mel,
> 
> On 12/10/2013 10:51 AM, Mel Gorman wrote:
> >+
> >+/* mmap_sem prevents this happening but warn if that changes */
> >+WARN_ON(pmd_trans_migrating(pmd));
> >+
> 
> I seem to be hitting this warning with latest -next kernel:
> 

Patch will follow shortly. I appreciate these trinity bug reports but in
the future is there any chance you could include the trinity command line
and the config file you used? Details on the machine would also be nice. In
this case, knowing if the machine was NUMA or not would have been helpful.

Thanks!

-- 
Mel Gorman
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-19 Thread Mel Gorman
On Tue, Dec 17, 2013 at 05:53:45PM -0500, Sasha Levin wrote:
 Hi Mel,
 
 On 12/10/2013 10:51 AM, Mel Gorman wrote:
 +
 +/* mmap_sem prevents this happening but warn if that changes */
 +WARN_ON(pmd_trans_migrating(pmd));
 +
 
 I seem to be hitting this warning with latest -next kernel:
 

Patch will follow shortly. I appreciate these trinity bug reports but in
the future is there any chance you could include the trinity command line
and the config file you used? Details on the machine would also be nice. In
this case, knowing if the machine was NUMA or not would have been helpful.

Thanks!

-- 
Mel Gorman
SUSE Labs
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-17 Thread Sasha Levin

Hi Mel,

On 12/10/2013 10:51 AM, Mel Gorman wrote:

+
+   /* mmap_sem prevents this happening but warn if that changes */
+   WARN_ON(pmd_trans_migrating(pmd));
+


I seem to be hitting this warning with latest -next kernel:

[ 1704.594807] WARNING: CPU: 28 PID: 35287 at mm/huge_memory.c:887 
copy_huge_pmd+0x145/
0x3a0()
[ 1704.597258] Modules linked in:
[ 1704.597844] CPU: 28 PID: 35287 Comm: trinity-main Tainted: GW
3.13.0-rc4-
next-20131217-sasha-00013-ga878504-dirty #4149
[ 1704.599924]  0377e delta! pid slot 27 [36258]: old:2 
now:537927697 diff:
537927695 8803593ddb90 8439501c 854722c1
[ 1704.604846]   8803593ddbd0 8112f8ac 
8803593ddbe0
[ 1704.606391]  88034bc137f0 880e41677000 800b47c009e4 
88034a638000
[ 1704.608008] Call Trace:
[ 1704.608511]  [] dump_stack+0x52/0x7f
[ 1704.609699]  [] warn_slowpath_common+0x8c/0xc0
[ 1704.612617]  [] warn_slowpath_null+0x1a/0x20
[ 1704.614043]  [] copy_huge_pmd+0x145/0x3a0
[ 1704.615587]  [] copy_page_range+0x3f2/0x560
[ 1704.616869]  [] ? rwsem_wake+0x51/0x70
[ 1704.617942]  [] dup_mmap+0x2c9/0x3d0
[ 1704.619146]  [] dup_mm+0xad/0x150
[ 1704.620051]  [] copy_process+0xa68/0x12e0
[ 1704.622976]  [] ? __lock_release+0x1da/0x1f0
[ 1704.624234]  [] do_fork+0x96/0x270
[ 1704.624975]  [] ? context_tracking_user_exit+0x195/0x1d0
[ 1704.626427]  [] ? trace_hardirqs_on+0xd/0x10
[ 1704.627681]  [] SyS_clone+0x16/0x20
[ 1704.628833]  [] stub_clone+0x69/0x90
[ 1704.629672]  [] ? tracesys+0xdd/0xe2


Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-17 Thread Sasha Levin

Hi Mel,

On 12/10/2013 10:51 AM, Mel Gorman wrote:

+
+   /* mmap_sem prevents this happening but warn if that changes */
+   WARN_ON(pmd_trans_migrating(pmd));
+


I seem to be hitting this warning with latest -next kernel:

[ 1704.594807] WARNING: CPU: 28 PID: 35287 at mm/huge_memory.c:887 
copy_huge_pmd+0x145/
0x3a0()
[ 1704.597258] Modules linked in:
[ 1704.597844] CPU: 28 PID: 35287 Comm: trinity-main Tainted: GW
3.13.0-rc4-
next-20131217-sasha-00013-ga878504-dirty #4149
[ 1704.599924]  0377e delta! pid slot 27 [36258]: old:2 
now:537927697 diff:
537927695 8803593ddb90 8439501c 854722c1
[ 1704.604846]   8803593ddbd0 8112f8ac 
8803593ddbe0
[ 1704.606391]  88034bc137f0 880e41677000 800b47c009e4 
88034a638000
[ 1704.608008] Call Trace:
[ 1704.608511]  [8439501c] dump_stack+0x52/0x7f
[ 1704.609699]  [8112f8ac] warn_slowpath_common+0x8c/0xc0
[ 1704.612617]  [8112f8fa] warn_slowpath_null+0x1a/0x20
[ 1704.614043]  [812b91c5] copy_huge_pmd+0x145/0x3a0
[ 1704.615587]  [8127e032] copy_page_range+0x3f2/0x560
[ 1704.616869]  [81199ef1] ? rwsem_wake+0x51/0x70
[ 1704.617942]  [8112cf59] dup_mmap+0x2c9/0x3d0
[ 1704.619146]  [8112d54d] dup_mm+0xad/0x150
[ 1704.620051]  [8112e178] copy_process+0xa68/0x12e0
[ 1704.622976]  [81194eda] ? __lock_release+0x1da/0x1f0
[ 1704.624234]  [8112eee6] do_fork+0x96/0x270
[ 1704.624975]  [81249465] ? context_tracking_user_exit+0x195/0x1d0
[ 1704.626427]  [811930ed] ? trace_hardirqs_on+0xd/0x10
[ 1704.627681]  [8112f0d6] SyS_clone+0x16/0x20
[ 1704.628833]  [843a6309] stub_clone+0x69/0x90
[ 1704.629672]  [843a6150] ? tracesys+0xdd/0xe2


Thanks,
Sasha
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-10 Thread 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.

Cc: sta...@vger.kernel.org
Signed-off-by: Mel Gorman 
Reviewed-by: Rik van Riel 
---
 include/linux/migrate.h |  9 +
 mm/huge_memory.c| 22 --
 mm/migrate.c| 12 
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index f5096b5..b7717d7 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -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)
 {
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0ecaba2..e3b6a75 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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);
diff --git a/mm/migrate.c b/mm/migrate.c
index a987525..cfb4190 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -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
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-10 Thread 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.

Cc: sta...@vger.kernel.org
Signed-off-by: Mel Gorman mgor...@suse.de
Reviewed-by: Rik van Riel r...@redhat.com
---
 include/linux/migrate.h |  9 +
 mm/huge_memory.c| 22 --
 mm/migrate.c| 12 
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index f5096b5..b7717d7 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -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)
 {
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0ecaba2..e3b6a75 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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);
diff --git a/mm/migrate.c b/mm/migrate.c
index a987525..cfb4190 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -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
-- 
1.8.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-09 Thread Rik van Riel
On 12/09/2013 02:09 AM, Mel Gorman wrote:
> 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.
> 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Mel Gorman 

Reviewed-by: Rik van Riel 


-- 
All rights reversed
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-09 Thread Rik van Riel
On 12/09/2013 02:09 AM, Mel Gorman wrote:
 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.
 
 Cc: sta...@vger.kernel.org
 Signed-off-by: Mel Gorman mgor...@suse.de

Reviewed-by: Rik van Riel r...@redhat.com


-- 
All rights reversed
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-08 Thread 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.

Cc: sta...@vger.kernel.org
Signed-off-by: Mel Gorman 
---
 include/linux/migrate.h |  9 +
 mm/huge_memory.c| 22 --
 mm/migrate.c| 12 
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index f5096b5..b7717d7 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -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)
 {
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0ecaba2..e3b6a75 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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);
diff --git a/mm/migrate.c b/mm/migrate.c
index a987525..cfb4190 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -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
-- 
1.8.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 10/18] mm: numa: Avoid unnecessary disruption of NUMA hinting during migration

2013-12-08 Thread 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.

Cc: sta...@vger.kernel.org
Signed-off-by: Mel Gorman mgor...@suse.de
---
 include/linux/migrate.h |  9 +
 mm/huge_memory.c| 22 --
 mm/migrate.c| 12 
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index f5096b5..b7717d7 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -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)
 {
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0ecaba2..e3b6a75 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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);
diff --git a/mm/migrate.c b/mm/migrate.c
index a987525..cfb4190 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -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
-- 
1.8.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/