linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] fix THP migration for CMA allocations
@ 2020-02-27 21:32 Rik van Riel
  2020-02-27 21:32 ` [PATCH 1/2] mm,compaction,cma: add alloc_contig flag to compact_control Rik van Riel
  2020-02-27 21:32 ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Rik van Riel
  0 siblings, 2 replies; 11+ messages in thread
From: Rik van Riel @ 2020-02-27 21:32 UTC (permalink / raw)
  To: linux-kernel, riel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy, Rik van Riel

Transparent huge pages are allocated with __GFP_MOVABLE, and can end
up in CMA memory blocks. Transparent huge pages also have most of the
infrastructure in place to allow migration.

However, a few pieces were missing, causing THP migration to fail when
attempting to use CMA to allocate 1GB hugepages.

With these patches in place, THP migration from CMA blocks seems to
work, both for anonymous THPs and for tmpfs/shmem THPs.

v2:
- addressed comments by Vlastimil Babka and Zi Yan

Rik van Riel (2):
  mm,compaction,cma: add alloc_contig flag to compact_control
  mm,thp,compaction,cma: allow THP migration for CMA allocations

 mm/compaction.c | 16 +++++++++-------
 mm/internal.h   |  1 +
 mm/page_alloc.c |  7 +++++--
 3 files changed, 15 insertions(+), 9 deletions(-)

-- 
2.24.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/2] mm,compaction,cma: add alloc_contig flag to compact_control
  2020-02-27 21:32 [PATCH v2 0/2] fix THP migration for CMA allocations Rik van Riel
@ 2020-02-27 21:32 ` Rik van Riel
  2020-02-27 21:32 ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Rik van Riel
  1 sibling, 0 replies; 11+ messages in thread
From: Rik van Riel @ 2020-02-27 21:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy, Rik van Riel

Add information to struct compact_control to indicate that the allocator
would really like to clear out this specific part of memory, used by for
example CMA.

Signed-off-by: Rik van Riel <riel@surriel.com>
Reviewed-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/internal.h   | 1 +
 mm/page_alloc.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/mm/internal.h b/mm/internal.h
index 3cf20ab3ca01..78492d9815b4 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -206,6 +206,7 @@ struct compact_control {
 	bool whole_zone;		/* Whole zone should/has been scanned */
 	bool contended;			/* Signal lock or sched contention */
 	bool rescan;			/* Rescanning the same pageblock */
+	bool alloc_contig;		/* alloc_contig_range allocation */
 };
 
 /*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3c4eb750a199..a36736812596 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8402,6 +8402,7 @@ int alloc_contig_range(unsigned long start, unsigned long end,
 		.ignore_skip_hint = true,
 		.no_set_skip_hint = true,
 		.gfp_mask = current_gfp_context(gfp_mask),
+		.alloc_contig = true,
 	};
 	INIT_LIST_HEAD(&cc.migratepages);
 
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-27 21:32 [PATCH v2 0/2] fix THP migration for CMA allocations Rik van Riel
  2020-02-27 21:32 ` [PATCH 1/2] mm,compaction,cma: add alloc_contig flag to compact_control Rik van Riel
@ 2020-02-27 21:32 ` Rik van Riel
  2020-02-27 23:41   ` Mike Kravetz
  2020-03-02  9:32   ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Vlastimil Babka
  1 sibling, 2 replies; 11+ messages in thread
From: Rik van Riel @ 2020-02-27 21:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy, Rik van Riel

The code to implement THP migrations already exists, and the code
for CMA to clear out a region of memory already exists.

Only a few small tweaks are needed to allow CMA to move THP memory
when attempting an allocation from alloc_contig_range.

With these changes, migrating THPs from a CMA area works when
allocating a 1GB hugepage from CMA memory.

Signed-off-by: Rik van Riel <riel@surriel.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
---
 mm/compaction.c | 22 +++++++++++++---------
 mm/page_alloc.c |  9 +++++++--
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index 672d3c78c6ab..000ade085b89 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -894,12 +894,13 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 
 		/*
 		 * Regardless of being on LRU, compound pages such as THP and
-		 * hugetlbfs are not to be compacted. We can potentially save
-		 * a lot of iterations if we skip them at once. The check is
-		 * racy, but we can consider only valid values and the only
-		 * danger is skipping too much.
+		 * hugetlbfs are not to be compacted unless we are attempting
+		 * an allocation much larger than the huge page size (eg CMA).
+		 * We can potentially save a lot of iterations if we skip them
+		 * at once. The check is racy, but we can consider only valid
+		 * values and the only danger is skipping too much.
 		 */
-		if (PageCompound(page)) {
+		if (PageCompound(page) && !cc->alloc_contig) {
 			const unsigned int order = compound_order(page);
 
 			if (likely(order < MAX_ORDER))
@@ -969,7 +970,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 			 * and it's on LRU. It can only be a THP so the order
 			 * is safe to read and it's 0 for tail pages.
 			 */
-			if (unlikely(PageCompound(page))) {
+			if (unlikely(PageCompound(page) && !cc->alloc_contig)) {
 				low_pfn += compound_nr(page) - 1;
 				goto isolate_fail;
 			}
@@ -981,12 +982,15 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
 		if (__isolate_lru_page(page, isolate_mode) != 0)
 			goto isolate_fail;
 
-		VM_BUG_ON_PAGE(PageCompound(page), page);
+		/* The whole page is taken off the LRU; skip the tail pages. */
+		if (PageCompound(page))
+			low_pfn += compound_nr(page) - 1;
 
 		/* Successfully isolated */
 		del_page_from_lru_list(page, lruvec, page_lru(page));
-		inc_node_page_state(page,
-				NR_ISOLATED_ANON + page_is_file_cache(page));
+		mod_node_page_state(page_pgdat(page),
+				NR_ISOLATED_ANON + page_is_file_cache(page),
+				hpage_nr_pages(page));
 
 isolate_success:
 		list_add(&page->lru, &cc->migratepages);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index a36736812596..6257c849cc00 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
 
 		/*
 		 * Hugepages are not in LRU lists, but they're movable.
+		 * THPs are on the LRU, but need to be counted as #small pages.
 		 * We need not scan over tail pages because we don't
 		 * handle each tail page individually in migration.
 		 */
-		if (PageHuge(page)) {
+		if (PageHuge(page) || PageTransCompound(page)) {
 			struct page *head = compound_head(page);
 			unsigned int skip_pages;
 
-			if (!hugepage_migration_supported(page_hstate(head)))
+			if (PageHuge(page) &&
+			    !hugepage_migration_supported(page_hstate(head)))
+				return page;
+
+			if (!PageLRU(head) && !__PageMovable(head))
 				return page;
 
 			skip_pages = compound_nr(head) - (page - head);
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-27 21:32 ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Rik van Riel
@ 2020-02-27 23:41   ` Mike Kravetz
  2020-02-28  1:21     ` Rik van Riel
  2020-03-02  9:32   ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Vlastimil Babka
  1 sibling, 1 reply; 11+ messages in thread
From: Mike Kravetz @ 2020-02-27 23:41 UTC (permalink / raw)
  To: Rik van Riel, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy

On 2/27/20 1:32 PM, Rik van Riel wrote:
> The code to implement THP migrations already exists, and the code
> for CMA to clear out a region of memory already exists.
> 
> Only a few small tweaks are needed to allow CMA to move THP memory
> when attempting an allocation from alloc_contig_range.
> 
> With these changes, migrating THPs from a CMA area works when
> allocating a 1GB hugepage from CMA memory.
> 
> Signed-off-by: Rik van Riel <riel@surriel.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>
> ---
>  mm/compaction.c | 22 +++++++++++++---------
>  mm/page_alloc.c |  9 +++++++--
>  2 files changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/mm/compaction.c b/mm/compaction.c
> index 672d3c78c6ab..000ade085b89 100644
> --- a/mm/compaction.c
> +++ b/mm/compaction.c
> @@ -894,12 +894,13 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  
>  		/*
>  		 * Regardless of being on LRU, compound pages such as THP and
> -		 * hugetlbfs are not to be compacted. We can potentially save
> -		 * a lot of iterations if we skip them at once. The check is
> -		 * racy, but we can consider only valid values and the only
> -		 * danger is skipping too much.
> +		 * hugetlbfs are not to be compacted unless we are attempting
> +		 * an allocation much larger than the huge page size (eg CMA).
> +		 * We can potentially save a lot of iterations if we skip them
> +		 * at once. The check is racy, but we can consider only valid
> +		 * values and the only danger is skipping too much.
>  		 */
> -		if (PageCompound(page)) {
> +		if (PageCompound(page) && !cc->alloc_contig) {
>  			const unsigned int order = compound_order(page);
>  
>  			if (likely(order < MAX_ORDER))
> @@ -969,7 +970,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  			 * and it's on LRU. It can only be a THP so the order
>  			 * is safe to read and it's 0 for tail pages.
>  			 */
> -			if (unlikely(PageCompound(page))) {
> +			if (unlikely(PageCompound(page) && !cc->alloc_contig)) {
>  				low_pfn += compound_nr(page) - 1;
>  				goto isolate_fail;
>  			}
> @@ -981,12 +982,15 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn,
>  		if (__isolate_lru_page(page, isolate_mode) != 0)
>  			goto isolate_fail;
>  
> -		VM_BUG_ON_PAGE(PageCompound(page), page);
> +		/* The whole page is taken off the LRU; skip the tail pages. */
> +		if (PageCompound(page))
> +			low_pfn += compound_nr(page) - 1;
>  
>  		/* Successfully isolated */
>  		del_page_from_lru_list(page, lruvec, page_lru(page));
> -		inc_node_page_state(page,
> -				NR_ISOLATED_ANON + page_is_file_cache(page));
> +		mod_node_page_state(page_pgdat(page),
> +				NR_ISOLATED_ANON + page_is_file_cache(page),
> +				hpage_nr_pages(page));
>  
>  isolate_success:
>  		list_add(&page->lru, &cc->migratepages);
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index a36736812596..6257c849cc00 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
>  
>  		/*
>  		 * Hugepages are not in LRU lists, but they're movable.
> +		 * THPs are on the LRU, but need to be counted as #small pages.
>  		 * We need not scan over tail pages because we don't
>  		 * handle each tail page individually in migration.
>  		 */
> -		if (PageHuge(page)) {
> +		if (PageHuge(page) || PageTransCompound(page)) {
>  			struct page *head = compound_head(page);
>  			unsigned int skip_pages;
>  
> -			if (!hugepage_migration_supported(page_hstate(head)))
> +			if (PageHuge(page) &&
> +			    !hugepage_migration_supported(page_hstate(head)))
> +				return page;
> +
> +			if (!PageLRU(head) && !__PageMovable(head))

Pretty sure this is going to be true for hugetlb pages.  So, this will change
behavior and make all hugetlb pages look unmovable.  Perhaps, only check this
condition for THP pages?
-- 
Mike Kravetz

>  				return page;
>  
>  			skip_pages = compound_nr(head) - (page - head);
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-27 23:41   ` Mike Kravetz
@ 2020-02-28  1:21     ` Rik van Riel
  2020-02-28  4:30       ` Mike Kravetz
  2020-02-28  8:25       ` Vlastimil Babka
  0 siblings, 2 replies; 11+ messages in thread
From: Rik van Riel @ 2020-02-28  1:21 UTC (permalink / raw)
  To: Mike Kravetz, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy

[-- Attachment #1: Type: text/plain, Size: 1461 bytes --]

On Thu, 2020-02-27 at 15:41 -0800, Mike Kravetz wrote:
> On 2/27/20 1:32 PM, Rik van Riel wrote:
> > 
> > +++ b/mm/page_alloc.c
> > @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct
> > zone *zone, struct page *page,
> >  
> >  		/*
> >  		 * Hugepages are not in LRU lists, but they're movable.
> > +		 * THPs are on the LRU, but need to be counted as
> > #small pages.
> >  		 * We need not scan over tail pages because we don't
> >  		 * handle each tail page individually in migration.
> >  		 */
> > -		if (PageHuge(page)) {
> > +		if (PageHuge(page) || PageTransCompound(page)) {
> >  			struct page *head = compound_head(page);
> >  			unsigned int skip_pages;
> >  
> > -			if
> > (!hugepage_migration_supported(page_hstate(head)))
> > +			if (PageHuge(page) &&
> > +			    !hugepage_migration_supported(page_hstate(h
> > ead)))
> > +				return page;
> > +
> > +			if (!PageLRU(head) && !__PageMovable(head))
> 
> Pretty sure this is going to be true for hugetlb pages.  So, this
> will change
> behavior and make all hugetlb pages look unmovable.  Perhaps, only
> check this
> condition for THP pages?

Does that need to be the following, then?

     if (PageTransHuge(head) && !PageHuge(page) && !PageLRU(head) &&
!__PageMovable(head))
                 return page;

That's an easy one liner I would be happy to send in
if everybody agrees that should fix things :)

-- 
All Rights Reversed.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-28  1:21     ` Rik van Riel
@ 2020-02-28  4:30       ` Mike Kravetz
  2020-02-28  8:25       ` Vlastimil Babka
  1 sibling, 0 replies; 11+ messages in thread
From: Mike Kravetz @ 2020-02-28  4:30 UTC (permalink / raw)
  To: Rik van Riel, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, vbabka, mgorman, rientjes,
	aarcange, ziy

On 2/27/20 5:21 PM, Rik van Riel wrote:
> On Thu, 2020-02-27 at 15:41 -0800, Mike Kravetz wrote:
>> On 2/27/20 1:32 PM, Rik van Riel wrote:
>>>
>>> +++ b/mm/page_alloc.c
>>> @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct
>>> zone *zone, struct page *page,
>>>  
>>>  		/*
>>>  		 * Hugepages are not in LRU lists, but they're movable.
>>> +		 * THPs are on the LRU, but need to be counted as
>>> #small pages.
>>>  		 * We need not scan over tail pages because we don't
>>>  		 * handle each tail page individually in migration.
>>>  		 */
>>> -		if (PageHuge(page)) {
>>> +		if (PageHuge(page) || PageTransCompound(page)) {
>>>  			struct page *head = compound_head(page);
>>>  			unsigned int skip_pages;
>>>  
>>> -			if
>>> (!hugepage_migration_supported(page_hstate(head)))
>>> +			if (PageHuge(page) &&
>>> +			    !hugepage_migration_supported(page_hstate(h
>>> ead)))
>>> +				return page;
>>> +
>>> +			if (!PageLRU(head) && !__PageMovable(head))
>>
>> Pretty sure this is going to be true for hugetlb pages.  So, this
>> will change
>> behavior and make all hugetlb pages look unmovable.  Perhaps, only
>> check this
>> condition for THP pages?
> 
> Does that need to be the following, then?
> 
>      if (PageTransHuge(head) && !PageHuge(page) && !PageLRU(head) &&
> !__PageMovable(head))
>                  return page;

Yes, that is what I would suggest.  Results of a simple test on small VM.

Unmodified Kernel
-----------------
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
50
# hugeadm --hard --pool-pages-min DEFAULT:4G
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
50

V2 patches
----------
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
50
# hugeadm --hard --pool-pages-min DEFAULT:4G
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
14

V2 patches + above modification
-------------------------------
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
50
# hugeadm --hard --pool-pages-min DEFAULT:4G
# cat /sys/devices/system/memory/memory*/removable | grep 1 | wc -l
50

> That's an easy one liner I would be happy to send in
> if everybody agrees that should fix things :)

Another option might be to make hugetlb pages more like other pages and
__SetPageMovable on movable hugetlb pages.  This could be used instead
of hugepage_migration_supported() calls.  That is only a quick thought
and would be beyond the scope of this patch.  If people think that is
worth doing, and I have not overlooked something,  I could look into it
separately.
-- 
Mike Kravetz


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-28  1:21     ` Rik van Riel
  2020-02-28  4:30       ` Mike Kravetz
@ 2020-02-28  8:25       ` Vlastimil Babka
  2020-02-28 14:32         ` Rik van Riel
  1 sibling, 1 reply; 11+ messages in thread
From: Vlastimil Babka @ 2020-02-28  8:25 UTC (permalink / raw)
  To: Rik van Riel, Mike Kravetz, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, mgorman, rientjes, aarcange, ziy

On 2/28/20 2:21 AM, Rik van Riel wrote:
> On Thu, 2020-02-27 at 15:41 -0800, Mike Kravetz wrote:
>> On 2/27/20 1:32 PM, Rik van Riel wrote:
>>>
>>> +++ b/mm/page_alloc.c
>>> @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct
>>> zone *zone, struct page *page,
>>>  
>>>  		/*
>>>  		 * Hugepages are not in LRU lists, but they're movable.
>>> +		 * THPs are on the LRU, but need to be counted as
>>> #small pages.
>>>  		 * We need not scan over tail pages because we don't
>>>  		 * handle each tail page individually in migration.
>>>  		 */
>>> -		if (PageHuge(page)) {
>>> +		if (PageHuge(page) || PageTransCompound(page)) {
>>>  			struct page *head = compound_head(page);
>>>  			unsigned int skip_pages;
>>>  
>>> -			if
>>> (!hugepage_migration_supported(page_hstate(head)))
>>> +			if (PageHuge(page) &&
>>> +			    !hugepage_migration_supported(page_hstate(h
>>> ead)))
>>> +				return page;
>>> +
>>> +			if (!PageLRU(head) && !__PageMovable(head))
>>
>> Pretty sure this is going to be true for hugetlb pages.  So, this
>> will change
>> behavior and make all hugetlb pages look unmovable.  Perhaps, only
>> check this
>> condition for THP pages?

Oh right you are.

> Does that need to be the following, then?
> 
>      if (PageTransHuge(head) && !PageHuge(page) && !PageLRU(head) &&
> !__PageMovable(head))
>                  return page;

I would instead make it an "else if" to the "if (PageHuge(page)...)" above.

> That's an easy one liner I would be happy to send in
> if everybody agrees that should fix things :)
> 



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-28  8:25       ` Vlastimil Babka
@ 2020-02-28 14:32         ` Rik van Riel
  2020-02-28 14:39           ` Vlastimil Babka
  0 siblings, 1 reply; 11+ messages in thread
From: Rik van Riel @ 2020-02-28 14:32 UTC (permalink / raw)
  To: Vlastimil Babka, Mike Kravetz, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, mgorman, rientjes, aarcange, ziy

[-- Attachment #1: Type: text/plain, Size: 1932 bytes --]

On Fri, 2020-02-28 at 09:25 +0100, Vlastimil Babka wrote:
> On 2/28/20 2:21 AM, Rik van Riel wrote:
> > On Thu, 2020-02-27 at 15:41 -0800, Mike Kravetz wrote:
> > > On 2/27/20 1:32 PM, Rik van Riel wrote:
> > > > +++ b/mm/page_alloc.c
> > > > @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct
> > > > zone *zone, struct page *page,
> > > >  
> > > >  		/*
> > > >  		 * Hugepages are not in LRU lists, but they're
> > > > movable.
> > > > +		 * THPs are on the LRU, but need to be counted
> > > > as
> > > > #small pages.
> > > >  		 * We need not scan over tail pages because we
> > > > don't
> > > >  		 * handle each tail page individually in
> > > > migration.
> > > >  		 */
> > > > -		if (PageHuge(page)) {
> > > > +		if (PageHuge(page) || PageTransCompound(page))
> > > > {
> > > >  			struct page *head =
> > > > compound_head(page);
> > > >  			unsigned int skip_pages;
> > > >  
> > > > -			if
> > > > (!hugepage_migration_supported(page_hstate(head)))
> > > > +			if (PageHuge(page) &&
> > > > +			    !hugepage_migration_supported(page_
> > > > hstate(h
> > > > ead)))
> > > > +				return page;
> > > > +
> > > > +			if (!PageLRU(head) &&
> > > > !__PageMovable(head))
> > > 
> > > Pretty sure this is going to be true for hugetlb pages.  So, this
> > > will change
> > > behavior and make all hugetlb pages look unmovable.  Perhaps,
> > > only
> > > check this
> > > condition for THP pages?
> 
> Oh right you are.
> 
> > Does that need to be the following, then?
> > 
> >      if (PageTransHuge(head) && !PageHuge(page) && !PageLRU(head)
> > &&
> > !__PageMovable(head))
> >                  return page;
> 
> I would instead make it an "else if" to the "if (PageHuge(page)...)"
> above.

That was my first thought too, but that could break on
pages that are PageHuge when hugepage_migration_supported
returns true.

-- 
All Rights Reversed.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-28 14:32         ` Rik van Riel
@ 2020-02-28 14:39           ` Vlastimil Babka
  2020-02-28 15:47             ` [PATCH] fix mmthpcompactioncma-allow-thp-migration-for-cma-allocations.patch Rik van Riel
  0 siblings, 1 reply; 11+ messages in thread
From: Vlastimil Babka @ 2020-02-28 14:39 UTC (permalink / raw)
  To: Rik van Riel, Mike Kravetz, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, mgorman, rientjes, aarcange, ziy

On 2/28/20 3:32 PM, Rik van Riel wrote:

>>> Does that need to be the following, then?
>>>
>>>      if (PageTransHuge(head) && !PageHuge(page) && !PageLRU(head)
>>> &&
>>> !__PageMovable(head))
>>>                  return page;
>>
>> I would instead make it an "else if" to the "if (PageHuge(page)...)"
>> above.
> 
> That was my first thought too, but that could break on
> pages that are PageHuge when hugepage_migration_supported
> returns true.

Right, so then

if (PageHuge()) {
	if (!migration_supported) return false;
} else if (!PageLRU(head) ...) {
   etc...

IMHO it's better than adding more tests to the second if.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] fix mmthpcompactioncma-allow-thp-migration-for-cma-allocations.patch
  2020-02-28 14:39           ` Vlastimil Babka
@ 2020-02-28 15:47             ` Rik van Riel
  0 siblings, 0 replies; 11+ messages in thread
From: Rik van Riel @ 2020-02-28 15:47 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Mike Kravetz, linux-kernel, kernel-team, akpm, linux-mm, mhocko,
	mgorman, rientjes, aarcange, ziy

Thank you Mike & Vlastimil!

---8<---

commit 27f3cd5473d8bbf591b61d8b93b98bc333980d0d
Author: Rik van Riel <riel@surriel.com>
Date:   Fri Feb 28 10:41:48 2020 -0500

Subject: fix mmthpcompactioncma-allow-thp-migration-for-cma-allocations.patch
    
Mike Kravetz pointed out that the second if condition could do the
wrong thing for hugetlbfs pages, and that check really only needs
to run on THPs.
    
Cleanup suggested by Vlastimil.
  
Thank you both!
    
Suggested-by: Mike Kravetz <mike.kravetz@oracle.com>
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Rik van Riel <riel@surriel.com>

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4afa13dd3738..71f78a590236 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8274,12 +8274,12 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,
 			struct page *head = compound_head(page);
 			unsigned int skip_pages;
 
-			if (PageHuge(page) &&
-			    !hugepage_migration_supported(page_hstate(head)))
-				return page;
-
-			if (!PageLRU(head) && !__PageMovable(head))
+			if (PageHuge(page)) {
+				if (!hugepage_migration_supported(page_hstate(head)))
+					return page;
+			} else if (!PageLRU(head) && !__PageMovable(head)) {
 				return page;
+			}
 
 			skip_pages = compound_nr(head) - (page - head);
 			iter += skip_pages - 1;


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
  2020-02-27 21:32 ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Rik van Riel
  2020-02-27 23:41   ` Mike Kravetz
@ 2020-03-02  9:32   ` Vlastimil Babka
  1 sibling, 0 replies; 11+ messages in thread
From: Vlastimil Babka @ 2020-03-02  9:32 UTC (permalink / raw)
  To: Rik van Riel, linux-kernel
  Cc: kernel-team, akpm, linux-mm, mhocko, mgorman, rientjes, aarcange, ziy

On 2/27/20 10:32 PM, Rik van Riel wrote:
> The code to implement THP migrations already exists, and the code
> for CMA to clear out a region of memory already exists.
> 
> Only a few small tweaks are needed to allow CMA to move THP memory
> when attempting an allocation from alloc_contig_range.
> 
> With these changes, migrating THPs from a CMA area works when
> allocating a 1GB hugepage from CMA memory.
> 
> Signed-off-by: Rik van Riel <riel@surriel.com>
> Reviewed-by: Zi Yan <ziy@nvidia.com>

With the followup fix,

Reviewed-by: Vlastimil Babka <vbabka@suse.cz>

Thanks.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-02  9:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 21:32 [PATCH v2 0/2] fix THP migration for CMA allocations Rik van Riel
2020-02-27 21:32 ` [PATCH 1/2] mm,compaction,cma: add alloc_contig flag to compact_control Rik van Riel
2020-02-27 21:32 ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Rik van Riel
2020-02-27 23:41   ` Mike Kravetz
2020-02-28  1:21     ` Rik van Riel
2020-02-28  4:30       ` Mike Kravetz
2020-02-28  8:25       ` Vlastimil Babka
2020-02-28 14:32         ` Rik van Riel
2020-02-28 14:39           ` Vlastimil Babka
2020-02-28 15:47             ` [PATCH] fix mmthpcompactioncma-allow-thp-migration-for-cma-allocations.patch Rik van Riel
2020-03-02  9:32   ` [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).