From: Vlastimil Babka <vbabka@suse.cz>
To: Zi Yan <ziy@nvidia.com>, David Hildenbrand <david@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Mel Gorman <mgorman@techsingularity.net>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>,
Richard Chang <richardycc@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 4/6] mm/page_isolation: remove migratetype from move_freepages_block_isolate()
Date: Tue, 27 May 2025 12:50:43 +0200 [thread overview]
Message-ID: <2d8017fb-474f-493c-84ad-df172987e65e@suse.cz> (raw)
In-Reply-To: <20250523191258.339826-5-ziy@nvidia.com>
On 5/23/25 21:12, Zi Yan wrote:
> Since migratetype is no longer overwritten during pageblock isolation,
> moving a pageblock out of MIGRATE_ISOLATE no longer needs a new
> migratetype.
>
> Add pageblock_isolate_and_move_free_pages() and
> pageblock_unisolate_and_move_free_pages() to be explicit about the page
> isolation operations. Both share the common code in
> __move_freepages_block_isolate(), which is renamed from
> move_freepages_block_isolate().
>
> Add toggle_pageblock_isolate() to flip pageblock isolation bit in
> __move_freepages_block_isolate().
>
> Make set_pageblock_migratetype() only accept non MIGRATE_ISOLATE types,
> so that one should use set_pageblock_isolate() to isolate pageblocks.
> As a result, move pageblock migratetype code out of
> __move_freepages_block().
>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
> include/linux/page-isolation.h | 5 +-
> mm/page_alloc.c | 97 ++++++++++++++++++++++++++++------
> mm/page_isolation.c | 21 ++++----
> 3 files changed, 92 insertions(+), 31 deletions(-)
>
> diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
> index 14c6a5f691c2..7241a6719618 100644
> --- a/include/linux/page-isolation.h
> +++ b/include/linux/page-isolation.h
> @@ -44,10 +44,9 @@ static inline void set_pageblock_isolate(struct page *page)
> void __meminit init_pageblock_migratetype(struct page *page,
> enum migratetype migratetype,
> bool isolate);
> -void set_pageblock_migratetype(struct page *page, enum migratetype migratetype);
>
> -bool move_freepages_block_isolate(struct zone *zone, struct page *page,
> - int migratetype);
> +bool pageblock_isolate_and_move_free_pages(struct zone *zone, struct page *page);
> +bool pageblock_unisolate_and_move_free_pages(struct zone *zone, struct page *page);
>
> int start_isolate_page_range(unsigned long start_pfn, unsigned long end_pfn,
> int migratetype, int flags);
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 8fcbd7fa13c2..44a08b1a9de4 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -524,13 +524,36 @@ void clear_pfnblock_bit(const struct page *page, unsigned long pfn,
> __clear_bit(bitidx + pb_bit, bitmap_word);
> }
>
> +#ifdef CONFIG_MEMORY_ISOLATION
> +/**
> + * toggle_pfnblock_bit - Toggle a standalone bit of a pageblock
> + * @page: The page within the block of interest
> + * @pfn: The target page frame number
> + * @pb_bit: pageblock bit to toggle
> + */
> +static void toggle_pfnblock_bit(const struct page *page, unsigned long pfn,
> + enum pageblock_bits pb_bit)
> +{
> + unsigned long *bitmap_word;
> + unsigned long bitidx;
> +
> + if (WARN_ON_ONCE(pb_bit <= PB_migrate_end ||
> + pb_bit >= __NR_PAGEBLOCK_BITS))
> + return;
> +
> + get_pfnblock_bitmap_bitidx(page, pfn, &bitmap_word, &bitidx);
> +
> + __change_bit(bitidx + pb_bit, bitmap_word);
Again the non-atomic variant, but actually below I suggest we drop this.
> +}
> +#endif
> +
> /**
> * set_pageblock_migratetype - Set the migratetype of a pageblock
> * @page: The page within the block of interest
> * @migratetype: migratetype to set
> */
> -__always_inline void set_pageblock_migratetype(struct page *page,
> - enum migratetype migratetype)
> +static void set_pageblock_migratetype(struct page *page,
> + enum migratetype migratetype)
> {
> unsigned long mask = MIGRATETYPE_MASK;
>
> @@ -540,11 +563,15 @@ __always_inline void set_pageblock_migratetype(struct page *page,
>
> #ifdef CONFIG_MEMORY_ISOLATION
> if (migratetype == MIGRATE_ISOLATE) {
> - set_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate);
> + VM_WARN_ONCE(1,
> + "Use set_pageblock_isolate() for pageblock isolation");
> return;
> }
> /* change mask to clear PB_migrate_isolate if it is set */
> mask = MIGRATETYPE_AND_ISO_MASK;
> + VM_WARN_ONCE(get_pfnblock_bit(page, page_to_pfn(page),
> + PB_migrate_isolate),
> + "Use clear_pageblock_isolate() to unisolate pageblock");
> #endif
We might be too paranoid with the warnings given these are all local
functions to this file so risk of misuse should be low. Maybe we could
remove later...
> __set_pfnblock_flags_mask(page, page_to_pfn(page),
> (unsigned long)migratetype, mask);
> @@ -1931,8 +1958,8 @@ static inline struct page *__rmqueue_cma_fallback(struct zone *zone,
> #endif
>
> /*
> - * Change the type of a block and move all its free pages to that
> - * type's freelist.
> + * Move all free pages of a block to new type's freelist. Caller needs to
> + * change the block type.
> */
> static int __move_freepages_block(struct zone *zone, unsigned long start_pfn,
> int old_mt, int new_mt)
> @@ -1964,8 +1991,6 @@ static int __move_freepages_block(struct zone *zone, unsigned long start_pfn,
> pages_moved += 1 << order;
> }
>
> - set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt);
> -
> return pages_moved;
> }
>
> @@ -2023,11 +2048,16 @@ static int move_freepages_block(struct zone *zone, struct page *page,
> int old_mt, int new_mt)
> {
> unsigned long start_pfn;
> + int res;
>
> if (!prep_move_freepages_block(zone, page, &start_pfn, NULL, NULL))
> return -1;
>
> - return __move_freepages_block(zone, start_pfn, old_mt, new_mt);
> + res = __move_freepages_block(zone, start_pfn, old_mt, new_mt);
> + set_pageblock_migratetype(pfn_to_page(start_pfn), new_mt);
> +
> + return res;
> +
> }
>
> #ifdef CONFIG_MEMORY_ISOLATION
> @@ -2055,11 +2085,16 @@ static unsigned long find_large_buddy(unsigned long start_pfn)
> return start_pfn;
> }
>
> +static inline void toggle_pageblock_isolate(struct page *page)
> +{
> + toggle_pfnblock_bit(page, page_to_pfn(page), PB_migrate_isolate);
> +}
I'm wary about the togle action, as we should always know what action we
want to do anyway. So we could just add a "bool isolate" parameter and call
set or clear explicitly? Allows for some hypothetical DEBUG_VM checks too
(pageblock is not already in the state we want it to be).
next prev parent reply other threads:[~2025-05-27 10:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 19:12 [PATCH v5 0/6] Make MIGRATE_ISOLATE a standalone bit Zi Yan
2025-05-23 19:12 ` [PATCH v5 1/6] mm/page_alloc: pageblock flags functions clean up Zi Yan
2025-05-27 9:46 ` Vlastimil Babka
2025-05-27 14:47 ` Zi Yan
2025-05-23 19:12 ` [PATCH v5 2/6] mm/page_isolation: make page isolation a standalone bit Zi Yan
2025-05-27 10:11 ` Vlastimil Babka
2025-05-27 14:56 ` Zi Yan
2025-05-23 19:12 ` [PATCH v5 3/6] mm/page_alloc: add support for initializing pageblock as isolated Zi Yan
2025-05-27 10:31 ` Vlastimil Babka
2025-05-23 19:12 ` [PATCH v5 4/6] mm/page_isolation: remove migratetype from move_freepages_block_isolate() Zi Yan
2025-05-27 10:50 ` Vlastimil Babka [this message]
2025-05-27 15:02 ` Zi Yan
2025-05-23 19:12 ` [PATCH v5 5/6] mm/page_isolation: remove migratetype from undo_isolate_page_range() Zi Yan
2025-05-27 10:56 ` Vlastimil Babka
2025-05-23 19:12 ` [PATCH v5 6/6] mm/page_isolation: remove migratetype parameter from more functions Zi Yan
2025-05-26 1:33 ` Zi Yan
2025-05-27 12:55 ` Vlastimil Babka
2025-05-27 15:04 ` Zi Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d8017fb-474f-493c-84ad-df172987e65e@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=richardycc@google.com \
--cc=surenb@google.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).