Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <pratyush@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: Pratyush Yadav <pratyush@kernel.org>,
	 Pasha Tatashin <pasha.tatashin@soleen.com>,
	 Alexander Graf <graf@amazon.com>,
	 Muchun Song <muchun.song@linux.dev>,
	 Oscar Salvador <osalvador@suse.de>,
	 David Hildenbrand <david@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	 Jason Miu <jasonmiu@google.com>,
	 Jork Loeser <jloeser@linux.microsoft.com>,
	 kexec@lists.infradead.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 19/21] memblock: make HugeTLB bootmem allocation work with KHO
Date: Fri, 24 Jul 2026 18:51:59 +0200	[thread overview]
Message-ID: <2vxzo6fwgwk0.fsf@kernel.org> (raw)
In-Reply-To: <178410811939.820181.7248948033992831535.b4-review@b4> (Mike Rapoport's message of "Wed, 15 Jul 2026 12:35:19 +0300")

On Wed, Jul 15 2026, Mike Rapoport wrote:

>> Gigantic huge page allocation is somewhat broken currently when KHO is
>> used.
>> 
>> Firstly, they break KHO scratch size accounting. RSRV_KERN is used to
>> track how much memory is reserved for use by the kernel. Since
>> hugetlb::alloc_bootmem() calls the memblock_alloc*() APIs, the hugepages
>> allocated also get marked as RSRV_KERN.
>> 
>> Allocations marked RSRV_KERN are used by KHO to calculate how much
>> scratch space it should reserve to make sure the next kernel has enough
>> memory to boot when it is in scratch-only phase. Counting hugepages in
>> that blows up scratch size, and can lead to the scratch allocation
>> failing, making KHO unusable. This will show up when huge pages make up
>> more than 50% of the system, which is a fairly common use case.
>> 
>> Secondly, while not supported right now, huge pages are user memory and
>> can be preserved via KHO. The scratch spaces should not have any
>> preserved memory. Allocating hugepages from scratch (on a KHO boot) can
>> lead to them being un-preservable.
>> 
>> Introduce memblock_alloc_hugetlb(). This lets memblock tailor to the
>> needs of hugetb without exposing those details to the general allocation
>> routines.
>> 
>> First, it does not use mirrored memory for hugetlb. Mirrored memory is a
>> limited resource that is best saved for kernel data structures, not user
>> memory.
>> 
>> Second, if the free memory area found by memblock_find_in_range_node()
>> is a part of a KHO scratch area, the free area is not used. Allocation
>> is retried starting after the free area to ensure no hugepages come from
>> KHO scratch.
>> 
>> Third, it simplifies the argument list by baking in some hugetlb
>> assumptions like alignment and exact_nid. This also simplifies
>> allocation logic in alloc_bootmem().
>> 
>> Also introduce MEMBLOCK_RSRV_HUGETLB to mark reservations made for
>> HugeTLB. This will be used by KHO in future patches to correctly
>> calculate scratch sizes.
>> 
>> Refactor some of the preparation logic like kmemleak tracking and
>> accepting memory into a separate helper memblock_prep_allocation(), and
>> use it from both memblock_alloc_hugetlb() and the usual
>> memblock_alloc_range_nid().
>> 
>> Add a stub for kho_scratch_overlap to memblock tests to make sure it
>> compiles.
>> 
>> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
[...]
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index 8b2e551435ae9..ba6d887ea18eb 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -1506,6 +1506,32 @@ int __init_memblock memblock_set_node(phys_addr_t base, phys_addr_t size,
>>  	return 0;
>>  }
>>  
>> +static void memblock_prep_allocation(phys_addr_t start, phys_addr_t size,
>> +				     bool leaktrace)
>
> Let's call this kmemleak_trace

ACK.

>
>> +{
>> +	/*
>> +	 * Skip kmemleak for those places like kasan_init() and
>> +	 * early_pgtable_alloc() due to high volume.
>> +	 */
>> +	if (leaktrace)
>> +		/*
>> +		 * Memblock allocated blocks are never reported as
>> +		 * leaks. This is because many of these blocks are
>> +		 * only referred via the physical address which is
>> +		 * not looked up by kmemleak.
>> +		 */
>> +		kmemleak_alloc_phys(start, size, 0);
[...]
>> diff --git a/tools/testing/memblock/internal.h b/tools/testing/memblock/internal.h
>> index b6b1d147fd750..e86bb9000b22f 100644
>> --- a/tools/testing/memblock/internal.h
>> +++ b/tools/testing/memblock/internal.h
>> @@ -66,4 +66,9 @@ static inline void init_deferred_page(unsigned long pfn, int nid)
>>  
>>  #define __SetPageReserved(p)	((void)(p))
>>  
>> +static inline bool kho_scratch_overlap(phys_addr_t phys, size_t size)
>> +{
>> +	return false;
>> +}
>> +
>
> This should be in the patch that exposes kho_scratch_overlap() to kexec_handover.h

Hm, sure, why not. I added it here because _this patch_ uses
kho_scratch_overlap() for the first time on memblock.c, and with that
breaks build of the memblock tests. So I recokned it makes sense to have
it in the place that broke it.

But I don't mind, I can move it to the other patch as well.

-- 
Regards,
Pratyush Yadav


  parent reply	other threads:[~2026-07-24 16:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 17:37 [PATCH v3 00/21] kho: make boot time huge page allocation work nicely with KHO Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 01/21] kho: generalize radix tree APIs Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 02/21] kho: make radix max key width more obvious Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 03/21] kho: disallow wide keys in radix tree Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 04/21] kho: return virtual address of mem_map Pratyush Yadav
     [not found]   ` <178410811938.820181.15709073379301681705.b4-review@b4>
2026-07-24 16:45     ` Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 05/21] kho: store incoming radix tree in kho_in Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 06/21] kho: move all memory retrieval logic to kho_mem_retrieve() Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 07/21] kho: add a struct for radix callbacks Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 08/21] kho: add callback for table pages Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 09/21] kho: add data argument to radix walk callback Pratyush Yadav
2026-07-09 17:37 ` [PATCH v3 10/21] kho: allow early-boot usage of the KHO radix tree Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 11/21] kho: allow destroying " Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 12/21] kho: add kho_radix_init_tree() Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 13/21] kho: expose kho_scratch_overlap() to kexec_handover.h Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 14/21] kho: initialize kho_scratch pointer earlier in boot Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 15/21] kho: initialize preserved memory map radix tree earlier Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 16/21] mm/mm_init: init deferred page migratetype in deferred_init_pages() Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 17/21] mm/mm_init: don't rely on memblock to get KHO scratch migratetype Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 18/21] kho: extend scratch Pratyush Yadav
     [not found]   ` <178410811939.820181.9175877917181976639.b4-review@b4>
2026-07-24 16:54     ` Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 19/21] memblock: make HugeTLB bootmem allocation work with KHO Pratyush Yadav
     [not found]   ` <178410811939.820181.7248948033992831535.b4-review@b4>
2026-07-24 16:51     ` Pratyush Yadav [this message]
2026-07-09 17:38 ` [PATCH v3 20/21] memblock: add memblock_reserved_hugetlb_size() Pratyush Yadav
2026-07-09 17:38 ` [PATCH v3 21/21] kho: exclude hugetlb memory from scratch size calculation Pratyush Yadav

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=2vxzo6fwgwk0.fsf@kernel.org \
    --to=pratyush@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=graf@amazon.com \
    --cc=jasonmiu@google.com \
    --cc=jloeser@linux.microsoft.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=rppt@kernel.org \
    /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