diff mbox series

mm: remove lru_add_drain_all in alloc_contig_range

Message ID 20210209175048.361638-1-minchan@kernel.org (mailing list archive)
State New, archived
Headers show
Series mm: remove lru_add_drain_all in alloc_contig_range | expand

Commit Message

Minchan Kim Feb. 9, 2021, 5:50 p.m. UTC
__alloc_contig_migrate_range already has lru_add_drain_all call
via migrate_prep. It's necessary to move LRU taget pages into
LRU list to be able to isolated. However, lru_add_drain_all call
after __alloc_contig_migrate_range is called is pointless.

This patch removes it.

Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 mm/page_alloc.c | 2 --
 1 file changed, 2 deletions(-)

Comments

David Hildenbrand Feb. 9, 2021, 6:17 p.m. UTC | #1
On 09.02.21 18:50, Minchan Kim wrote:
> __alloc_contig_migrate_range already has lru_add_drain_all call
> via migrate_prep. It's necessary to move LRU taget pages into
> LRU list to be able to isolated. However, lru_add_drain_all call
> after __alloc_contig_migrate_range is called is pointless.
> 
> This patch removes it.
> 
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>   mm/page_alloc.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6446778cbc6b..f8fbee73dd6d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8603,8 +8603,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>   	 * isolated thus they won't get removed from buddy.
>   	 */
>   
> -	lru_add_drain_all();
> -
>   	order = 0;
>   	outer_start = start;
>   	while (!PageBuddy(pfn_to_page(outer_start))) {
> 

I was expecting some magical reason why this is still required but I am 
not able to find a compelling one. Maybe this is really some historical 
artifact.

Let's see if other people know why this call here still exists.
Oscar Salvador Feb. 9, 2021, 7:03 p.m. UTC | #2
On Tue, Feb 09, 2021 at 07:17:59PM +0100, David Hildenbrand wrote:
> On 09.02.21 18:50, Minchan Kim wrote:
> > __alloc_contig_migrate_range already has lru_add_drain_all call
> > via migrate_prep. It's necessary to move LRU taget pages into
> > LRU list to be able to isolated. However, lru_add_drain_all call
> > after __alloc_contig_migrate_range is called is pointless.
> > 
> > This patch removes it.
> > 
> > Signed-off-by: Minchan Kim <minchan@kernel.org>
> > ---
> >   mm/page_alloc.c | 2 --
> >   1 file changed, 2 deletions(-)
> > 
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> > index 6446778cbc6b..f8fbee73dd6d 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -8603,8 +8603,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,
> >   	 * isolated thus they won't get removed from buddy.
> >   	 */
> > -	lru_add_drain_all();
> > -
> >   	order = 0;
> >   	outer_start = start;
> >   	while (!PageBuddy(pfn_to_page(outer_start))) {
> > 
> 
> I was expecting some magical reason why this is still required but I am not
> able to find a compelling one. Maybe this is really some historical
> artifact.
> 
> Let's see if other people know why this call here still exists.

I also stumbled upon this while working on adding hugetlb support for
alloc_acontig_range [1].
I have to confess I puzzled me a bit.

I saw it going back to when the function was first introduced by 

commit 041d3a8cdc18dc375a128d90bbb753949a81b1fb
Author: Michal Nazarewicz <mina86@mina86.com>
Date:   Thu Dec 29 13:09:50 2011 +0100

    mm: page_alloc: introduce alloc_contig_range()


It does not make much sense to me. At this point our pages are free, so
we do not care about LRU handling here.
But I might be missing something.

[1] https://lore.kernel.org/linux-mm/20210208103935.GA32103@linux/T/#md651fc6e73c656105179382f92f8b2d6073051d1
Vlastimil Babka Feb. 10, 2021, 12:13 p.m. UTC | #3
On 2/9/21 6:50 PM, Minchan Kim wrote:
> __alloc_contig_migrate_range already has lru_add_drain_all call
> via migrate_prep. It's necessary to move LRU taget pages into
> LRU list to be able to isolated. However, lru_add_drain_all call
> after __alloc_contig_migrate_range is called is pointless.
> 
> This patch removes it.
> 
> Signed-off-by: Minchan Kim <minchan@kernel.org>

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

> ---
>  mm/page_alloc.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6446778cbc6b..f8fbee73dd6d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8603,8 +8603,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	 * isolated thus they won't get removed from buddy.
>  	 */
>  
> -	lru_add_drain_all();
> -
>  	order = 0;
>  	outer_start = start;
>  	while (!PageBuddy(pfn_to_page(outer_start))) {
>
Vlastimil Babka Feb. 10, 2021, 12:17 p.m. UTC | #4
On 2/9/21 8:03 PM, Oscar Salvador wrote:
> On Tue, Feb 09, 2021 at 07:17:59PM +0100, David Hildenbrand wrote:
>> I was expecting some magical reason why this is still required but I am not
>> able to find a compelling one. Maybe this is really some historical
>> artifact.
>> 
>> Let's see if other people know why this call here still exists.
> 
> I also stumbled upon this while working on adding hugetlb support for
> alloc_acontig_range [1].
> I have to confess I puzzled me a bit.
> 
> I saw it going back to when the function was first introduced by 
> 
> commit 041d3a8cdc18dc375a128d90bbb753949a81b1fb
> Author: Michal Nazarewicz <mina86@mina86.com>
> Date:   Thu Dec 29 13:09:50 2011 +0100
> 
>     mm: page_alloc: introduce alloc_contig_range()
> 
> 
> It does not make much sense to me. At this point our pages are free, so
> we do not care about LRU handling here.
> But I might be missing something.

AFAICS, at the time page migration used putback_lru_page() to release the
migration source page. This would put the page on lru pvec even if it was in
fact not mapped anywhere anymore, and only the drain would actually free it.
Seems Minchan optimized this in 2016 by c6c919eb90e0 ("mm: use put_page() to
free page instead of putback_lru_page()")

> [1] https://lore.kernel.org/linux-mm/20210208103935.GA32103@linux/T/#md651fc6e73c656105179382f92f8b2d6073051d1
> 
>
Michal Hocko Feb. 10, 2021, 12:23 p.m. UTC | #5
On Wed 10-02-21 13:17:33, Vlastimil Babka wrote:
> On 2/9/21 8:03 PM, Oscar Salvador wrote:
> > On Tue, Feb 09, 2021 at 07:17:59PM +0100, David Hildenbrand wrote:
> >> I was expecting some magical reason why this is still required but I am not
> >> able to find a compelling one. Maybe this is really some historical
> >> artifact.
> >> 
> >> Let's see if other people know why this call here still exists.
> > 
> > I also stumbled upon this while working on adding hugetlb support for
> > alloc_acontig_range [1].
> > I have to confess I puzzled me a bit.
> > 
> > I saw it going back to when the function was first introduced by 
> > 
> > commit 041d3a8cdc18dc375a128d90bbb753949a81b1fb
> > Author: Michal Nazarewicz <mina86@mina86.com>
> > Date:   Thu Dec 29 13:09:50 2011 +0100
> > 
> >     mm: page_alloc: introduce alloc_contig_range()
> > 
> > 
> > It does not make much sense to me. At this point our pages are free, so
> > we do not care about LRU handling here.
> > But I might be missing something.
> 
> AFAICS, at the time page migration used putback_lru_page() to release the
> migration source page. This would put the page on lru pvec even if it was in
> fact not mapped anywhere anymore, and only the drain would actually free it.
> Seems Minchan optimized this in 2016 by c6c919eb90e0 ("mm: use put_page() to
> free page instead of putback_lru_page()")

This would be a great addition to the changelog. Thanks a lot Vlastimil,
you saved me from some archeology. With that mentioned feel free to add

Acked-by: Michal Hocko <mhocko@usse.com>

> 
> > [1] https://lore.kernel.org/linux-mm/20210208103935.GA32103@linux/T/#md651fc6e73c656105179382f92f8b2d6073051d1
> > 
> > 
>
Oscar Salvador Feb. 10, 2021, 2:27 p.m. UTC | #6
On Wed, Feb 10, 2021 at 01:17:33PM +0100, Vlastimil Babka wrote:
> AFAICS, at the time page migration used putback_lru_page() to release the
> migration source page. This would put the page on lru pvec even if it was in
> fact not mapped anywhere anymore, and only the drain would actually free it.
> Seems Minchan optimized this in 2016 by c6c919eb90e0 ("mm: use put_page() to
> free page instead of putback_lru_page()")

Ok, I see. Thanks for this valuable information Vlastimil.
Oscar Salvador Feb. 10, 2021, 2:28 p.m. UTC | #7
On Tue, Feb 09, 2021 at 09:50:48AM -0800, Minchan Kim wrote:
> __alloc_contig_migrate_range already has lru_add_drain_all call
> via migrate_prep. It's necessary to move LRU taget pages into
> LRU list to be able to isolated. However, lru_add_drain_all call
> after __alloc_contig_migrate_range is called is pointless.
> 
> This patch removes it.
> 
> Signed-off-by: Minchan Kim <minchan@kernel.org>

I agree with Michal that the changelog could benefit from Vastimil's
clarification, so with that:

Reviewed-by: Oscar Salvador <osalvador@suse.de>

> ---
>  mm/page_alloc.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6446778cbc6b..f8fbee73dd6d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -8603,8 +8603,6 @@ int alloc_contig_range(unsigned long start, unsigned long end,
>  	 * isolated thus they won't get removed from buddy.
>  	 */
>  
> -	lru_add_drain_all();
> -
>  	order = 0;
>  	outer_start = start;
>  	while (!PageBuddy(pfn_to_page(outer_start))) {
> -- 
> 2.30.0.478.g8a0d178c01-goog
> 
>
Minchan Kim Feb. 10, 2021, 3:58 p.m. UTC | #8
On Wed, Feb 10, 2021 at 01:17:33PM +0100, Vlastimil Babka wrote:
> On 2/9/21 8:03 PM, Oscar Salvador wrote:
> > On Tue, Feb 09, 2021 at 07:17:59PM +0100, David Hildenbrand wrote:
> >> I was expecting some magical reason why this is still required but I am not
> >> able to find a compelling one. Maybe this is really some historical
> >> artifact.
> >> 
> >> Let's see if other people know why this call here still exists.
> > 
> > I also stumbled upon this while working on adding hugetlb support for
> > alloc_acontig_range [1].
> > I have to confess I puzzled me a bit.
> > 
> > I saw it going back to when the function was first introduced by 
> > 
> > commit 041d3a8cdc18dc375a128d90bbb753949a81b1fb
> > Author: Michal Nazarewicz <mina86@mina86.com>
> > Date:   Thu Dec 29 13:09:50 2011 +0100
> > 
> >     mm: page_alloc: introduce alloc_contig_range()
> > 
> > 
> > It does not make much sense to me. At this point our pages are free, so
> > we do not care about LRU handling here.
> > But I might be missing something.
> 
> AFAICS, at the time page migration used putback_lru_page() to release the
> migration source page. This would put the page on lru pvec even if it was in
> fact not mapped anywhere anymore, and only the drain would actually free it.
> Seems Minchan optimized this in 2016 by c6c919eb90e0 ("mm: use put_page() to
> free page instead of putback_lru_page()")
> 
> > [1] https://lore.kernel.org/linux-mm/20210208103935.GA32103@linux/T/#md651fc6e73c656105179382f92f8b2d6073051d1

Thanks for digging history, Vlastimil!
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6446778cbc6b..f8fbee73dd6d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8603,8 +8603,6 @@  int alloc_contig_range(unsigned long start, unsigned long end,
 	 * isolated thus they won't get removed from buddy.
 	 */
 
-	lru_add_drain_all();
-
 	order = 0;
 	outer_start = start;
 	while (!PageBuddy(pfn_to_page(outer_start))) {