[PATCH v8 1/2] kho: fix deferred initialization of scratch areas
Pratyush Yadav
pratyush at kernel.org
Thu Apr 23 01:41:11 PDT 2026
On Wed, Apr 22 2026, Mike Rapoport wrote:
> On Tue, Apr 21, 2026 at 12:20:27PM +0200, Michał Cłapiński wrote:
>> On Tue, Apr 21, 2026 at 8:08 AM Mike Rapoport <rppt at kernel.org> wrote:
>> >
>> > On Mon, Apr 20, 2026 at 03:11:03PM +0200, Michał Cłapiński wrote:
>> > > On Thu, Apr 16, 2026 at 6:13 PM Mike Rapoport <rppt at kernel.org> wrote:
>> > > >
>> > > > On Thu, Apr 16, 2026 at 05:06:10PM +0200, Michał Cłapiński wrote:
>> > > > > On Thu, Apr 16, 2026 at 4:45 PM Mike Rapoport <rppt at kernel.org> wrote:
>> > > > > >
>> > > > > > Hi Michal,
>> > > > > >
>> > > > > > On Thu, Apr 16, 2026 at 01:06:53PM +0200, Michal Clapinski wrote:
>> > > > > > > @@ -2262,6 +2253,12 @@ static void __init memmap_init_reserved_range(phys_addr_t start,
>> > > > > > > * access it yet.
>> > > > > > > */
>> > > > > > > __SetPageReserved(page);
>> > > > > > > +
>> > > > > > > +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
>> > > > > >
>> > > > > > No need for #ifdef here, there's a stub returning false for
>> > > > > > CONFIG_MEMBLOCK_KHO_SCRATCH=n case.
>> > > > >
>> > > > > In all 3 places the #ifdef is there because MIGRATE_CMA might be
>> > > > > undefined. I already broke mm-new branch in the past because of that.
>> > > >
>> > > > Hmm, that hurts :/
>> > > >
>> > > > The best I can think of is to add a static inline in memblock.h and ifdefs
>> > > > around it.
>> > >
>> > > Sorry, I don't understand what you mean. What would that static inline contain?
>> >
>> > Something like this:
>> >
>> > #ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
>> > static inline enum migratetype kho_scratch_migratetype(unsigned long pfn,
>> > enum migratetype mt)
>> > {
>> > if (memblock_is_kho_scratch_memory(PFN_PHYS(pfn)))
>> > return MIGRATE_CMA
>> > return mt;
>> > }
>> > #else
>> > static inline enum migratetype kho_scratch_migratetype(unsigned long pfn,
>> > enum migratetype mt)
>> > {
>> > return mt;
>> > }
>> > #endif
>>
>> How would I use it for this code?
>>
>> +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH
>> + if (memblock_is_kho_scratch_memory(PFN_PHYS(pfn)) &&
>> + pageblock_aligned(pfn))
>> + init_pageblock_migratetype(page, MIGRATE_CMA, false);
>> +#endif
>
> Something like this
>
> enum migratetype mt = kho_scratch_migratetype(pfn, MIGRATE_MOVABLE);
>
> ...
>
> if (memblock_is_kho_scratch_memory(PFN_PHYS(pfn)) &&
> pageblock_aligned(pfn))
> init_pageblock_migratetype(page, mt, false);
You can optimize this a tiny bit by doing something like this:
if (pageblock_aligned(pfn)) {
enum migratetype mt = kho_scratch_migratetype(pfn, MIGRATE_MOVABLE);
init_pageblock_migratetype(page, mt, false);
}
The kho_scratch_migratetype() you suggested already calls
memblock_is_kho_scratch_memory() so no need to duplicate the search.
Plus, this way this only executes for each pageblock instead for each
page.
>
> seems better to me than ifdef, even though MIGRATE_MOVABLE is bogus here.
>
> And since we anyway changing init_pageblock_migratetype() callers in
> mm_init.c the entire block in memmap_init_reserved_range() can be dropped
> and the change can be done in __init_page_from_nid().
>
>>
>> It doesn't invoke init_pageblock_migratetype unless pfn is kho scratch.
>>
>> > Can't say I'm happy about the name, but could not think of something
>> > better.
>> >
>> > > > > > > + if (memblock_is_kho_scratch_memory(PFN_PHYS(pfn)) &&
>> > > > > > > + pageblock_aligned(pfn))
>> > > > > > > + init_pageblock_migratetype(page, MIGRATE_CMA, false);
>> > > > > > > +#endif
>> > > > > > > }
>> > > > > > > }
>> > > >
>> > > > --
>> > > > Sincerely yours,
>> > > > Mike.
>> >
>> > --
>> > Sincerely yours,
>> > Mike.
--
Regards,
Pratyush Yadav
More information about the kexec
mailing list