[PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed

David Hildenbrand posted 29 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by David Hildenbrand 3 months, 1 week ago
Let the page freeing code handle clearing the page type.

Acked-by: Zi Yan <ziy@nvidia.com>
Acked-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/linux/balloon_compaction.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index b9f19da37b089..bfc6e50bd004b 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -140,7 +140,7 @@ static inline void balloon_page_finalize(struct page *page)
 		__ClearPageMovable(page);
 		set_page_private(page, 0);
 	}
-	__ClearPageOffline(page);
+	/* PageOffline is sticky until the page is freed to the buddy. */
 }
 
 /*
-- 
2.49.0
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by Lorenzo Stoakes 3 months, 1 week ago
On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
> Let the page freeing code handle clearing the page type.

Why is this advantageous? We want to keep the page marked offline for longer?

>
> Acked-by: Zi Yan <ziy@nvidia.com>
> Acked-by: Harry Yoo <harry.yoo@oracle.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
guess:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  include/linux/balloon_compaction.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
> index b9f19da37b089..bfc6e50bd004b 100644
> --- a/include/linux/balloon_compaction.h
> +++ b/include/linux/balloon_compaction.h
> @@ -140,7 +140,7 @@ static inline void balloon_page_finalize(struct page *page)
>  		__ClearPageMovable(page);
>  		set_page_private(page, 0);
>  	}
> -	__ClearPageOffline(page);
> +	/* PageOffline is sticky until the page is freed to the buddy. */

OK so we are relying on this UINT_MAX thing in free_pages_prepare() to handle this.

>  }
>
>  /*
> --
> 2.49.0
>
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by David Hildenbrand 3 months, 1 week ago
On 30.06.25 18:01, Lorenzo Stoakes wrote:
> On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
>> Let the page freeing code handle clearing the page type.
> 
> Why is this advantageous? We want to keep the page marked offline for longer?

Less code? ;)

I will add:

"Being able to identify balloon pages until actually freed is a 
requirement for upcoming movable_ops migration changes."

Note that the documentation is extended in patch #27 to mention that.

> 
>>
>> Acked-by: Zi Yan <ziy@nvidia.com>
>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
> guess:
 > > Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> 
>> ---
>>   include/linux/balloon_compaction.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
>> index b9f19da37b089..bfc6e50bd004b 100644
>> --- a/include/linux/balloon_compaction.h
>> +++ b/include/linux/balloon_compaction.h
>> @@ -140,7 +140,7 @@ static inline void balloon_page_finalize(struct page *page)
>>   		__ClearPageMovable(page);
>>   		set_page_private(page, 0);
>>   	}
>> -	__ClearPageOffline(page);
>> +	/* PageOffline is sticky until the page is freed to the buddy. */
> 
> OK so we are relying on this UINT_MAX thing in free_pages_prepare() to handle this.

Yes. Resetting the page_type -> _mapcount to the initial value -1.

-- 
Cheers,

David / dhildenb
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by Zi Yan 3 months, 1 week ago
On 30 Jun 2025, at 12:01, Lorenzo Stoakes wrote:

> On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
>> Let the page freeing code handle clearing the page type.
>
> Why is this advantageous? We want to keep the page marked offline for longer?
>
>>
>> Acked-by: Zi Yan <ziy@nvidia.com>
>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>
> On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
> guess:

This is how page type is cleared.
See: https://elixir.bootlin.com/linux/v6.15.4/source/include/linux/page-flags.h#L1013.

I agree with you that patch 4 should have a comment in free_pages_prepare()
about what the code is for and why UINT_MAX is used.


Best Regards,
Yan, Zi
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by David Hildenbrand 3 months, 1 week ago
On 30.06.25 18:14, Zi Yan wrote:
> On 30 Jun 2025, at 12:01, Lorenzo Stoakes wrote:
> 
>> On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
>>> Let the page freeing code handle clearing the page type.
>>
>> Why is this advantageous? We want to keep the page marked offline for longer?
>>
>>>
>>> Acked-by: Zi Yan <ziy@nvidia.com>
>>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>
>> On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
>> guess:
> 
> This is how page type is cleared.
> See: https://elixir.bootlin.com/linux/v6.15.4/source/include/linux/page-flags.h#L1013.
> 
> I agree with you that patch 4 should have a comment in free_pages_prepare()
> about what the code is for and why UINT_MAX is used.

I can add a comment

/* Reset the page_type -> _mapcount to -1 */

To patch #4.

-- 
Cheers,

David / dhildenb
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by Harry Yoo 3 months, 1 week ago
On Mon, Jun 30, 2025 at 12:14:01PM -0400, Zi Yan wrote:
> On 30 Jun 2025, at 12:01, Lorenzo Stoakes wrote:
> 
> > On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
> >> Let the page freeing code handle clearing the page type.
> >
> > Why is this advantageous? We want to keep the page marked offline for longer?
> >
> >>
> >> Acked-by: Zi Yan <ziy@nvidia.com>
> >> Acked-by: Harry Yoo <harry.yoo@oracle.com>
> >> Signed-off-by: David Hildenbrand <david@redhat.com>
> >
> > On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
> > guess:
> 
> This is how page type is cleared.
> See: https://elixir.bootlin.com/linux/v6.15.4/source/include/linux/page-flags.h#L1013.
> 
> I agree with you that patch 4 should have a comment in free_pages_prepare()
> about what the code is for and why UINT_MAX is used.

Or instead of comment, maybe something like this:

/* Clear any page type */
static __always_inline void __ClearPageType(struct page *page)
{
	VM_WARN_ON_ONCE_PAGE(!page_has_type(page), page);
	page->page_type = UINT_MAX;
}

in patch 4:

if (unlikely(page_has_type(page)))
	__ClearPageType(page);

-- 
Cheers,
Harry / Hyeonggon
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by David Hildenbrand 3 months, 1 week ago
On 01.07.25 08:13, Harry Yoo wrote:
> On Mon, Jun 30, 2025 at 12:14:01PM -0400, Zi Yan wrote:
>> On 30 Jun 2025, at 12:01, Lorenzo Stoakes wrote:
>>
>>> On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
>>>> Let the page freeing code handle clearing the page type.
>>>
>>> Why is this advantageous? We want to keep the page marked offline for longer?
>>>
>>>>
>>>> Acked-by: Zi Yan <ziy@nvidia.com>
>>>> Acked-by: Harry Yoo <harry.yoo@oracle.com>
>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>
>>> On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
>>> guess:
>>
>> This is how page type is cleared.
>> See: https://elixir.bootlin.com/linux/v6.15.4/source/include/linux/page-flags.h#L1013.
>>
>> I agree with you that patch 4 should have a comment in free_pages_prepare()
>> about what the code is for and why UINT_MAX is used.
> 
> Or instead of comment, maybe something like this:
> 
> /* Clear any page type */
> static __always_inline void __ClearPageType(struct page *page)
> {
> 	VM_WARN_ON_ONCE_PAGE(!page_has_type(page), page);
> 	page->page_type = UINT_MAX;
> }
> 
> in patch 4:
> 
> if (unlikely(page_has_type(page)))
> 	__ClearPageType(page);
> 

I don't think we should do that. It's very specialized code that nobody 
should be reusing.

And it will all change once Willy reworks the page_type vs. _mapcount 
overlay.

-- 
Cheers,

David / dhildenb
Re: [PATCH v1 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed
Posted by Lorenzo Stoakes 3 months, 1 week ago
On Mon, Jun 30, 2025 at 12:14:01PM -0400, Zi Yan wrote:
> On 30 Jun 2025, at 12:01, Lorenzo Stoakes wrote:
>
> > On Mon, Jun 30, 2025 at 02:59:46PM +0200, David Hildenbrand wrote:
> >> Let the page freeing code handle clearing the page type.
> >
> > Why is this advantageous? We want to keep the page marked offline for longer?
> >
> >>
> >> Acked-by: Zi Yan <ziy@nvidia.com>
> >> Acked-by: Harry Yoo <harry.yoo@oracle.com>
> >> Signed-off-by: David Hildenbrand <david@redhat.com>
> >
> > On assumption this UINT_MAX stuff is sane :)) I mean this is straightforward I
> > guess:
>
> This is how page type is cleared.
> See: https://elixir.bootlin.com/linux/v6.15.4/source/include/linux/page-flags.h#L1013.

Doh did go looking there but missed this!

I hate these macros so much. Almost designed to obfuscate.

>
> I agree with you that patch 4 should have a comment in free_pages_prepare()
> about what the code is for and why UINT_MAX is used.

Thx!

>
>
> Best Regards,
> Yan, Zi