Re: [PATCH] mm/page_alloc: Add lockdep assertion for pageblock type change

From: Andrew Morton
Date: Thu Feb 27 2025 - 17:33:11 EST


On Thu, 27 Feb 2025 16:15:47 +0000 Brendan Jackman <jackmanb@xxxxxxxxxx> wrote:

> Since the migratetype hygiene patches [0], the locking here is
> a bit more formalised, so write it down with an assert.
>
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -417,6 +417,10 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
>
> void set_pageblock_migratetype(struct page *page, int migratetype)
> {
> + lockdep_assert_once(system_state == SYSTEM_BOOTING ||
> + in_mem_hotplug() ||
> + lockdep_is_held(&page_zone(page)->lock));
> +
> if (unlikely(page_group_by_mobility_disabled &&
> migratetype < MIGRATE_PCPTYPES))
> migratetype = MIGRATE_UNMOVABLE;
>

We could add such assertions all over the place. Why this place in
particular?