diff mbox series

[v5,5/5] mm,page_alloc: Drop unnecessary checks from pfn_range_valid_contig

Message ID 20210317111251.17808-6-osalvador@suse.de (mailing list archive)
State New, archived
Headers show
Series Make alloc_contig_range handle Hugetlb pages | expand

Commit Message

Oscar Salvador March 17, 2021, 11:12 a.m. UTC
pfn_range_valid_contig() bails out when it finds an in-use page or a
hugetlb page, among other things.
We can drop the in-use page check since __alloc_contig_pages can migrate
away those pages, and the hugetlb page check can go too since
isolate_migratepages_range is now capable of dealing with hugetlb pages.
Either way, those checks are racy so let the end function handle it
when the time comes.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
Suggested-by: David Hildenbrand <david@redhat.com>
---
 mm/page_alloc.c | 6 ------
 1 file changed, 6 deletions(-)

Comments

David Hildenbrand March 17, 2021, 11:15 a.m. UTC | #1
On 17.03.21 12:12, Oscar Salvador wrote:
> pfn_range_valid_contig() bails out when it finds an in-use page or a
> hugetlb page, among other things.
> We can drop the in-use page check since __alloc_contig_pages can migrate
> away those pages, and the hugetlb page check can go too since
> isolate_migratepages_range is now capable of dealing with hugetlb pages.
> Either way, those checks are racy so let the end function handle it
> when the time comes.
> 
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Suggested-by: David Hildenbrand <david@redhat.com>
> ---
>   mm/page_alloc.c | 6 ------
>   1 file changed, 6 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4cb455355f6d..50d73e68b79e 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8685,12 +8685,6 @@ static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
>   
>   		if (PageReserved(page))
>   			return false;
> -
> -		if (page_count(page) > 0)
> -			return false;
> -
> -		if (PageHuge(page))
> -			return false;
>   	}
>   	return true;
>   }
> 

Reviewed-by: David Hildenbrand <david@redhat.com>
Michal Hocko March 17, 2021, 2:31 p.m. UTC | #2
On Wed 17-03-21 12:12:51, Oscar Salvador wrote:
> pfn_range_valid_contig() bails out when it finds an in-use page or a
> hugetlb page, among other things.
> We can drop the in-use page check since __alloc_contig_pages can migrate
> away those pages, and the hugetlb page check can go too since
> isolate_migratepages_range is now capable of dealing with hugetlb pages.
> Either way, those checks are racy so let the end function handle it
> when the time comes.

I haven't realized PageHuge check is done this early. This means that
previous patches are not actually active until now which is not really
greate for bisectability. Can we remove the HugePage check earlier?

Act to the page_count check removal. We should rely on migrate_pages
here.

> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Suggested-by: David Hildenbrand <david@redhat.com>
> ---
>  mm/page_alloc.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 4cb455355f6d..50d73e68b79e 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8685,12 +8685,6 @@ static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
>  
>  		if (PageReserved(page))
>  			return false;
> -
> -		if (page_count(page) > 0)
> -			return false;
> -
> -		if (PageHuge(page))
> -			return false;
>  	}
>  	return true;
>  }
> -- 
> 2.16.3
David Hildenbrand March 17, 2021, 2:36 p.m. UTC | #3
On 17.03.21 15:31, Michal Hocko wrote:
> On Wed 17-03-21 12:12:51, Oscar Salvador wrote:
>> pfn_range_valid_contig() bails out when it finds an in-use page or a
>> hugetlb page, among other things.
>> We can drop the in-use page check since __alloc_contig_pages can migrate
>> away those pages, and the hugetlb page check can go too since
>> isolate_migratepages_range is now capable of dealing with hugetlb pages.
>> Either way, those checks are racy so let the end function handle it
>> when the time comes.
> 
> I haven't realized PageHuge check is done this early. This means that
> previous patches are not actually active until now which is not really
> greate for bisectability. Can we remove the HugePage check earlier?

alloc_contig_pages() vs. alloc_contig_range(). The patches are active 
for virtio-mem and CMA AFAIKS.
Michal Hocko March 17, 2021, 3:03 p.m. UTC | #4
On Wed 17-03-21 15:36:35, David Hildenbrand wrote:
> On 17.03.21 15:31, Michal Hocko wrote:
> > On Wed 17-03-21 12:12:51, Oscar Salvador wrote:
> > > pfn_range_valid_contig() bails out when it finds an in-use page or a
> > > hugetlb page, among other things.
> > > We can drop the in-use page check since __alloc_contig_pages can migrate
> > > away those pages, and the hugetlb page check can go too since
> > > isolate_migratepages_range is now capable of dealing with hugetlb pages.
> > > Either way, those checks are racy so let the end function handle it
> > > when the time comes.
> > 
> > I haven't realized PageHuge check is done this early. This means that
> > previous patches are not actually active until now which is not really
> > greate for bisectability. Can we remove the HugePage check earlier?
> 
> alloc_contig_pages() vs. alloc_contig_range(). The patches are active for
> virtio-mem and CMA AFAIKS.

yeah, I meant to say "are not actually fully active".
Oscar Salvador March 18, 2021, 8:44 a.m. UTC | #5
On Wed, Mar 17, 2021 at 04:03:06PM +0100, Michal Hocko wrote:
> > alloc_contig_pages() vs. alloc_contig_range(). The patches are active for
> > virtio-mem and CMA AFAIKS.
> 
> yeah, I meant to say "are not actually fully active".

We could place this patch earlier in this patchset.
The only thing is that we would lose the prevalidation (at leat for
HugeTLB page) which is done upfront to find later on that we do not
support hugetlb handling in isolate_migratepates_block.
So the bad thing about placing it earlier, is that wrt. hugetlb pages,
alloc_gigantic_page will take longer to fail (when we already know that
will fail).

Then we have the page_count check, which is also racy and
isolate_migratepages_block will take care of it.
So I guess can think of this patch as a preparatory patch that removes racy
checks that will be re-checked later on in the end function which does
the actual handling.

What do you think?
Michal Hocko March 18, 2021, 8:55 a.m. UTC | #6
On Thu 18-03-21 09:44:19, Oscar Salvador wrote:
> On Wed, Mar 17, 2021 at 04:03:06PM +0100, Michal Hocko wrote:
> > > alloc_contig_pages() vs. alloc_contig_range(). The patches are active for
> > > virtio-mem and CMA AFAIKS.
> > 
> > yeah, I meant to say "are not actually fully active".
> 
> We could place this patch earlier in this patchset.
> The only thing is that we would lose the prevalidation (at leat for
> HugeTLB page) which is done upfront to find later on that we do not
> support hugetlb handling in isolate_migratepates_block.
> So the bad thing about placing it earlier, is that wrt. hugetlb pages,
> alloc_gigantic_page will take longer to fail (when we already know that
> will fail).

From a bisactability POV this shouldn't be a major concern. If you are
too worried then just drop the HugePage check in the patch allowing to
migrate free hugetlb pages. It is unlikely that somebody will run with
that patch alone but if the said patch introduces some sort of bug it
would be good to bisect down to it.

> Then we have the page_count check, which is also racy and
> isolate_migratepages_block will take care of it.
> So I guess can think of this patch as a preparatory patch that removes racy
> checks that will be re-checked later on in the end function which does
> the actual handling.

TBH, I do not care much about the page count check. It is comletely
orthogonal to the migration changes in this series. So both preparatory
and follow up are ok.
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4cb455355f6d..50d73e68b79e 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8685,12 +8685,6 @@  static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn,
 
 		if (PageReserved(page))
 			return false;
-
-		if (page_count(page) > 0)
-			return false;
-
-		if (PageHuge(page))
-			return false;
 	}
 	return true;
 }