Skip to contentSkip to conversation

mm: migrate: fix an incorrect call of prep_transhuge_page()

PATCH Applied Zi Yan 5 participants 16 messages Nov 21, 2017 – Nov 22, 2017

Subsystems (3)
lore
Share & tools
lore

Zi Yan

author
#0 lore raw

PATCH 1/1 mm: migrate: fix an incorrect call of prep_transhuge_page()

From: Zi Yan <[email protected]>

In [1], Andrea reported that during memory hotplug/hot remove prep_transhuge_page() is called incorrectly on non-THP pages for migration, when THP is on but THP migration is not enabled. This leads to a bad state of target pages for migration.

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

[1] https://lkml.org/lkml/2017/11/20/411

Fixes 8135d8926c08 ("mm: memory_hotplug: memory hotremove supports thp migration")
Cc Naoya Horiguchi <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
---
 include/linux/migrate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/migrate.h +1 -1
index 895ec0c4942e..a2246cf670ba 100644
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);
 
 	return new_page;
Signature · 7 lines
2.14.2

--
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>
maintainer
#1 lore raw
Quoted 7 lines · On Mon, 20 Nov 2017 21:18:55 -0500 Zi Yan <[email protected]> wrote:

In [1], Andrea reported that during memory hotplug/hot remove prep_transhuge_page() is called incorrectly on non-THP pages for migration, when THP is on but THP migration is not enabled. This leads to a bad state of target pages for migration.

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

What are the user-visible effects of the bug?

--
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>

#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 7 lines · On Mon, 20 Nov 2017 21:18:55 -0500 Zi Yan <[email protected]> wrote:

In [1], Andrea reported that during memory hotplug/hot remove prep_transhuge_page() is called incorrectly on non-THP pages for migration, when THP is on but THP migration is not enabled. This leads to a bad state of target pages for migration.

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

What are the user-visible effects of the bug?

By inspecting the code, if called on a non-THP, prep_transhuge_page() will
1) change the value of the mapping of (page + 2), since it is used for THP deferred list;
2) change the lru value of (page + 1), since it is used for THP’s dtor.

Both can lead to data corruption of these two pages.

—
Best Regards,
Yan Zi

#3 lore raw
Quoted 7 lines · Zi Yan
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Mon, 20 Nov 2017 21:18:55 -0500 Zi Yan <[email protected]> wrote:

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

Quoted 7 lines
Quoted 1 line

What are the user-visible effects of the bug?

By inspecting the code, if called on a non-THP, prep_transhuge_page() will
1) change the value of the mapping of (page + 2), since it is used for THP deferred list;
2) change the lru value of (page + 1), since it is used for THP’s dtor.

Both can lead to data corruption of these two pages.

Pragmatically and from the point of view of the memory_hotplug subsys, the effect is a kernel crash when pages are being migrated during a memory hot remove offline and migration target pages are found in a bad state.

Best,
Andrea

--
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>

#4 lore raw
In reply to Zi Yan
Quoted 11 lines · Zi Yan

From: Zi Yan <[email protected]>

In [1], Andrea reported that during memory hotplug/hot remove prep_transhuge_page() is called incorrectly on non-THP pages for migration, when THP is on but THP migration is not enabled. This leads to a bad state of target pages for migration.

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

[1] https://lkml.org/lkml/2017/11/20/411

lkml.org tends to be quite unstable so a
http://lkml.kernel.org/r/$msg-id is usually a preferred way.

Quoted 16 lines
Fixes 8135d8926c08 ("mm: memory_hotplug: memory hotremove supports thp migration")
Cc Naoya Horiguchi <[email protected]>
Cc "J�r�me Glisse" <[email protected]>
---
 include/linux/migrate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/migrate.h +0 -0
index 895ec0c4942e..a2246cf670ba 100644

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 6 lines
include/linux/migrate.h +1 -1
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}

How come it is safe to allocate an order-0 page if !thp_migration_supported() when we are about to migrate THP? This doesn't make any sense to me. Are we working around this somewhere else? Why shouldn't we simply return NULL here?

Nayoa, could you explain please? 8135d8926c08 ("mm: memory_hotplug:
memory hotremove supports thp migration") changelog is less than satisfactory.

Signature · 8 lines
Michal Hocko
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>
#5 lore raw
Quoted 8 lines · Michal Hocko
Quoted 7 lines · Zi Yan

From: Zi Yan <[email protected]>

In [1], Andrea reported that during memory hotplug/hot remove prep_transhuge_page() is called incorrectly on non-THP pages for migration, when THP is on but THP migration is not enabled. This leads to a bad state of target pages for migration.

Quoted 7 lines
Quoted 4 lines

This patch fixes it by only calling prep_transhuge_page() when we are certain that the target page is THP.

[1] https://lkml.org/lkml/2017/11/20/411

lkml.org tends to be quite unstable so a
http://lkml.kernel.org/r/$msg-id is usually a preferred way.

Got it. Thanks.

Quoted 32 lines
Quoted 17 lines
Fixes 8135d8926c08 ("mm: memory_hotplug: memory hotremove supports thp migration")
Cc Naoya Horiguchi <[email protected]>
Cc "Jérôme Glisse" <[email protected]>
---
 include/linux/migrate.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/migrate.h +0 -0
index 895ec0c4942e..a2246cf670ba 100644

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 6 lines
include/linux/migrate.h +1 -1
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}
Quoted 4 lines

How come it is safe to allocate an order-0 page if !thp_migration_supported() when we are about to migrate THP? This doesn't make any sense to me. Are we working around this somewhere else? Why shouldn't we simply return NULL here?

If !thp_migration_supported(), we will first split a THP and migrate its head page. This process is done in unmap_and_move() after get_new_page() (the function pointer to this new_page_nodemask()) is called. The situation can be PageTransHuge(page) is true here, but the page is split in unmap_and_move(), so we want to return a order-0 page here.

I think the confusion comes from that there is no guarantee of THP allocation when we are doing THP migration. If we can allocate a THP during THP migration, we are good. Otherwise, we want to fallback to the old way, splitting the original THP and migrating the head page, to preserve the original code behavior.

Does it clarify your confusion?

—
Best Regards,
Yan Zi

#6 lore raw
Quoted 1 line · Zi Yan

On 22 Nov 2017, at 3:54, Michal Hocko wrote:

[...]

Quoted 13 lines
Quoted 8 lines

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}
Quoted 4 lines

How come it is safe to allocate an order-0 page if !thp_migration_supported() when we are about to migrate THP? This doesn't make any sense to me. Are we working around this somewhere else? Why shouldn't we simply return NULL here?

Quoted 6 lines

If !thp_migration_supported(), we will first split a THP and migrate its head page. This process is done in unmap_and_move() after get_new_page() (the function pointer to this new_page_nodemask()) is called. The situation can be PageTransHuge(page) is true here, but the page is split in unmap_and_move(), so we want to return a order-0 page here.

This deserves a big fat comment in the code because this is not clear from the code!

Quoted 5 lines

I think the confusion comes from that there is no guarantee of THP allocation when we are doing THP migration. If we can allocate a THP during THP migration, we are good. Otherwise, we want to fallback to the old way, splitting the original THP and migrating the head page, to preserve the original code behavior.

I understand that but that should be done explicitly rather than relying on two functions doing the right thing because this is just too fragile.

Moreover I am not really sure this is really working properly. Just look at the split_huge_page. It moves all the tail pages to the LRU list while migrate_pages has a list of pages to migrate. So we will migrate the head page and all the rest will get back to the LRU list. What guarantees that they will get migrated as well.

This all looks like a mess!

Signature · 8 lines
Michal Hocko
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>
#7 lore raw

On Wed 22-11-17 10:35:10, Michal Hocko wrote:
[...]

Quoted 5 lines

Moreover I am not really sure this is really working properly. Just look at the split_huge_page. It moves all the tail pages to the LRU list while migrate_pages has a list of pages to migrate. So we will migrate the head page and all the rest will get back to the LRU list. What guarantees that they will get migrated as well.

OK, so this is as I've expected. It doesn't work! Some pfn walker based migration will just skip tail pages see madvise_inject_error. __alloc_contig_migrate_range will simply fail on THP page see isolate_migratepages_block so we even do not try to migrate it. do_move_page_to_node_array will simply migrate head and do not care about tail pages. do_mbind splits the page and then fall back to pte walk when thp migration is not supported but it doesn't handle tail pages if the THP migration path is not able to allocate a fresh THP AFAICS. Memory hotplug should be safe because it doesn't skip the whole THP when doing pfn walk.

Unless I am missing something here this looks like a huge mess to me.

Signature · 8 lines
Michal Hocko
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>
#8 lore raw
Quoted 19 lines · Michal Hocko

On Wed 22-11-17 10:35:10, Michal Hocko wrote:
[...]

Quoted 5 lines

Moreover I am not really sure this is really working properly. Just look at the split_huge_page. It moves all the tail pages to the LRU list while migrate_pages has a list of pages to migrate. So we will migrate the head page and all the rest will get back to the LRU list. What guarantees that they will get migrated as well.

OK, so this is as I've expected. It doesn't work! Some pfn walker based migration will just skip tail pages see madvise_inject_error. __alloc_contig_migrate_range will simply fail on THP page see isolate_migratepages_block so we even do not try to migrate it. do_move_page_to_node_array will simply migrate head and do not care about tail pages. do_mbind splits the page and then fall back to pte walk when thp migration is not supported but it doesn't handle tail pages if the THP migration path is not able to allocate a fresh THP AFAICS. Memory hotplug should be safe because it doesn't skip the whole THP when doing pfn walk.

Quoted 1 line

Unless I am missing something here this looks like a huge mess to me.

+Kirill

First, I agree with you that splitting a THP and only migrating its head page is a mess. But what you describe is also the behavior of migrate_page() _before_ THP migration support is added. I thought that was intended.

Look at http://elixir.free-electrons.com/linux/v4.13.15/source/mm/migrate.c#L1091,
unmap_and_move() splits THPs and only migrates the head page in v4.13 before THP migration is added. I think the behavior was introduced since v4.5 (I just skimmed v4.0 to v4.13 code and did not have time to use git blame), before that THPs are not migrated but shown as successfully migrated (at least from v4.4’s code).

Naoya and I had a discussion on this ‘splitting a THP and migrating its head page’ before. We think we should try to spilt the THP and migrate all its subpages. I did not have time to get the code out yet.

I am traveling today, so I may not be able to do anything useful. I will be on a break for a month and will not have good accesses to any machines. I can try to fix this ‘splitting a THP and migrating its head page’ after that.

—
Best Regards,
Yan Zi

#9 lore raw
Quoted 29 lines · Zi Yan
Quoted 19 lines · Michal Hocko

On Wed 22-11-17 10:35:10, Michal Hocko wrote:
[...]

Quoted 5 lines

Moreover I am not really sure this is really working properly. Just look at the split_huge_page. It moves all the tail pages to the LRU list while migrate_pages has a list of pages to migrate. So we will migrate the head page and all the rest will get back to the LRU list. What guarantees that they will get migrated as well.

OK, so this is as I've expected. It doesn't work! Some pfn walker based migration will just skip tail pages see madvise_inject_error. __alloc_contig_migrate_range will simply fail on THP page see isolate_migratepages_block so we even do not try to migrate it. do_move_page_to_node_array will simply migrate head and do not care about tail pages. do_mbind splits the page and then fall back to pte walk when thp migration is not supported but it doesn't handle tail pages if the THP migration path is not able to allocate a fresh THP AFAICS. Memory hotplug should be safe because it doesn't skip the whole THP when doing pfn walk.

Quoted 1 line

Unless I am missing something here this looks like a huge mess to me.

+Kirill

First, I agree with you that splitting a THP and only migrating its head page is a mess. But what you describe is also the behavior of migrate_page() _before_ THP migration support is added. I thought that was intended.

Quoted 5 lines

Look at http://elixir.free-electrons.com/linux/v4.13.15/source/mm/migrate.c#L1091,
unmap_and_move() splits THPs and only migrates the head page in v4.13 before THP migration is added. I think the behavior was introduced since v4.5 (I just skimmed v4.0 to v4.13 code and did not have time to use git blame), before that THPs are not migrated but shown as successfully migrated (at least from v4.4’s code).

Sorry, I misread v4.4’s code, it also does ‘splitting a THP and migrating its head page’. This behavior was there for a long time, at least since v3.0.

The code in unmap_and_move() is:

if (unlikely(PageTransHuge(page)))

		if (unlikely(split_huge_page(page)))
			goto out;

Hope I did not miss anything else.

—
Best Regards,
Yan Zi

#10 lore raw
Quoted 37 lines · Zi Yan
Quoted 29 lines · Zi Yan
Quoted 19 lines · Michal Hocko

On Wed 22-11-17 10:35:10, Michal Hocko wrote:
[...]

Quoted 5 lines

Moreover I am not really sure this is really working properly. Just look at the split_huge_page. It moves all the tail pages to the LRU list while migrate_pages has a list of pages to migrate. So we will migrate the head page and all the rest will get back to the LRU list. What guarantees that they will get migrated as well.

OK, so this is as I've expected. It doesn't work! Some pfn walker based migration will just skip tail pages see madvise_inject_error. __alloc_contig_migrate_range will simply fail on THP page see isolate_migratepages_block so we even do not try to migrate it. do_move_page_to_node_array will simply migrate head and do not care about tail pages. do_mbind splits the page and then fall back to pte walk when thp migration is not supported but it doesn't handle tail pages if the THP migration path is not able to allocate a fresh THP AFAICS. Memory hotplug should be safe because it doesn't skip the whole THP when doing pfn walk.

Quoted 1 line

Unless I am missing something here this looks like a huge mess to me.

+Kirill

First, I agree with you that splitting a THP and only migrating its head page is a mess. But what you describe is also the behavior of migrate_page() _before_ THP migration support is added. I thought that was intended.

Quoted 5 lines

Look at http://elixir.free-electrons.com/linux/v4.13.15/source/mm/migrate.c#L1091,
unmap_and_move() splits THPs and only migrates the head page in v4.13 before THP migration is added. I think the behavior was introduced since v4.5 (I just skimmed v4.0 to v4.13 code and did not have time to use git blame), before that THPs are not migrated but shown as successfully migrated (at least from v4.4’s code).

Quoted 8 lines

Sorry, I misread v4.4’s code, it also does ‘splitting a THP and migrating its head page’. This behavior was there for a long time, at least since v3.0.

The code in unmap_and_move() is:

if (unlikely(PageTransHuge(page)))

		if (unlikely(split_huge_page(page)))
			goto out;

I _think_ that this all should be handled at migrate_pages layer. Try to migrate THP and fallback to split_huge_page into to the list when it fails. I haven't checked whether there is something which would prevent that though. THP tricks in specific paths then should be removed.

Signature · 8 lines
Michal Hocko
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>
#11 lore raw
In reply to Michal Hocko
Quoted 1 line · Michal Hocko

On Mon 20-11-17 21:18:55, Zi Yan wrote:

[...]

Quoted 15 lines

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 11 lines
include/linux/migrate.h +1 -1
index 895ec0c4942e..a2246cf670ba 100644
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

Quoted 4 lines
	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}

And one more question/note. Why do we need thp_migration_supported in the first place? 9c670ea37947 ("mm: thp: introduce CONFIG_ARCH_ENABLE_THP_MIGRATION") says
: Introduce CONFIG_ARCH_ENABLE_THP_MIGRATION to limit thp migration : functionality to x86_64, which should be safer at the first step.

but why is unsafe to enable the feature on other arches which support THP? Is there any plan to do the next step and remove this config option?

Signature · 8 lines
Michal Hocko
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>
#12 lore raw
Quoted 28 lines · Michal Hocko
Quoted 1 line · Michal Hocko

On Mon 20-11-17 21:18:55, Zi Yan wrote:

[...]

Quoted 14 lines

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 11 lines
include/linux/migrate.h +1 -1
index 895ec0c4942e..a2246cf670ba 100644
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

Quoted 4 lines
	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}

And one more question/note. Why do we need thp_migration_supported in the first place? 9c670ea37947 ("mm: thp: introduce CONFIG_ARCH_ENABLE_THP_MIGRATION") says
: Introduce CONFIG_ARCH_ENABLE_THP_MIGRATION to limit thp migration : functionality to x86_64, which should be safer at the first step.

Quoted 3 lines

but why is unsafe to enable the feature on other arches which support THP? Is there any plan to do the next step and remove this config option?

Because different architectures have their own way of specifying a swap entry. This means, to support THP migration, each architecture needs to add its own __pmd_to_swp_entry() and __swp_entry_to_pmd(), which are used for arch-independent pmd_to_swp_entry() and swp_entry_to_pmd().

We need this CONFIG_ARCH_ENABLE_THP_MIGRATION before archs that support THP add code for pmd swap entry.

Signature · 2 lines
Best Regards,
Yan Zi
#13 lore raw
Quoted 31 lines · Zi Yan
Quoted 28 lines · Michal Hocko
Quoted 1 line · Michal Hocko

On Mon 20-11-17 21:18:55, Zi Yan wrote:

[...]

Quoted 14 lines

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 11 lines
include/linux/migrate.h +1 -1
index 895ec0c4942e..a2246cf670ba 100644
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

Quoted 4 lines
	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}

And one more question/note. Why do we need thp_migration_supported in the first place? 9c670ea37947 ("mm: thp: introduce CONFIG_ARCH_ENABLE_THP_MIGRATION") says
: Introduce CONFIG_ARCH_ENABLE_THP_MIGRATION to limit thp migration : functionality to x86_64, which should be safer at the first step.

Quoted 8 lines
Quoted 3 lines

but why is unsafe to enable the feature on other arches which support THP? Is there any plan to do the next step and remove this config option?

Because different architectures have their own way of specifying a swap entry. This means, to support THP migration, each architecture needs to add its own __pmd_to_swp_entry() and __swp_entry_to_pmd(), which are used for arch-independent pmd_to_swp_entry() and swp_entry_to_pmd().

I understand that part. But this smells like a matter of coding, no? I was suprised to see the note about safety which didn't make much sense to me.

Signature · 8 lines
Michal Hocko
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>
#14 lore raw
Quoted 33 lines · Michal Hocko
Quoted 32 lines · Zi Yan
Quoted 30 lines · Michal Hocko
Quoted 1 line · Michal Hocko

On Mon 20-11-17 21:18:55, Zi Yan wrote:

[...]

Quoted 14 lines

include/linux/migrate.h static inline struct page *new_page_nodemask(struct page *page, · line 58

Quoted 11 lines
include/linux/migrate.h +1 -1
index 895ec0c4942e..a2246cf670ba 100644
@@ -54,7 +54,7 @@ static inline struct page *new_page_nodemask(struct page *page,
 	new_page = __alloc_pages_nodemask(gfp_mask, order,
 				preferred_nid, nodemask);
 
-	if (new_page && PageTransHuge(page))
+	if (new_page && PageTransHuge(new_page))
 		prep_transhuge_page(new_page);

I would keep the two checks consistent. But that leads to a more interesting question. new_page_nodemask does

Quoted 4 lines
	if (thp_migration_supported() && PageTransHuge(page)) {
		order = HPAGE_PMD_ORDER;
		gfp_mask |= GFP_TRANSHUGE;
	}

And one more question/note. Why do we need thp_migration_supported in the first place? 9c670ea37947 ("mm: thp: introduce CONFIG_ARCH_ENABLE_THP_MIGRATION") says
: Introduce CONFIG_ARCH_ENABLE_THP_MIGRATION to limit thp migration : functionality to x86_64, which should be safer at the first step.

but why is unsafe to enable the feature on other arches which support THP? Is there any plan to do the next step and remove this config option?

Quoted 8 lines
Quoted 4 lines

Because different architectures have their own way of specifying a swap entry. This means, to support THP migration, each architecture needs to add its own __pmd_to_swp_entry() and __swp_entry_to_pmd(), which are used for arch-independent pmd_to_swp_entry() and swp_entry_to_pmd().

I understand that part. But this smells like a matter of coding, no? I was suprised to see the note about safety which didn't make much sense to me.

And testing as well. I had powerpc book3s support in my initial patch submission, but removed it because I do not have access to the powerpc machine any more. I also tried ARM64, which seems working by adding the code, but I have no hardware to test it now.

Any suggestions?

Signature · 2 lines
Best Regards,
Yan Zi
#15 lore raw
Quoted 6 lines · Zi Yan
Quoted 3 lines · Michal Hocko
Quoted 2 lines · Zi Yan

Michal Hocko wrote:

[...]

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

but why is unsafe to enable the feature on other arches which support THP? Is there any plan to do the next step and remove this config option?

Because different architectures have their own way of specifying a swap entry. This means, to support THP migration, each architecture needs to add its own __pmd_to_swp_entry() and __swp_entry_to_pmd(), which are used for arch-independent pmd_to_swp_entry() and swp_entry_to_pmd().

I understand that part. But this smells like a matter of coding, no? I was suprised to see the note about safety which didn't make much sense to me.

Quoted 6 lines

And testing as well. I had powerpc book3s support in my initial patch submission, but removed it because I do not have access to the powerpc machine any more. I also tried ARM64, which seems working by adding the code, but I have no hardware to test it now.

Any suggestions?

Cc arch maintainers and mailing lists?

Signature · 8 lines
Michal Hocko
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>