From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEE463D4128 for ; Fri, 5 Jun 2026 18:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684514; cv=none; b=crvYyGPfZchaFqpdcUBDKwpme2rQwJVMdOzMfXrk75j40K4O6cCpso8jhZD/eo4FaPl30dYI23FXjLufBfHgqJ+MAJj9pEi8zEZ3Evu5CtVGCJrDs1ICSLsc8vOCyhzntz8xKOdxNGVQ5v9i7RBMFhjQJQrC38JO7/5Y3E0nLk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684514; c=relaxed/simple; bh=S4DSDlfobwC9ikTjMfgBc2bJPDUqgvV2dgSdoKggLIY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Z2zi1f2c77svL/kAT3H4wTKS6OTuAa8SfPP5tRIiGfzUDqComZWRdnp+3Zr9iUfvymSRskyXXeSd9YPPeZIaTZdmhRJ0QJOReQkd3WymJGxu3aTLLoeyiEyqlwghEtwT235JZvdwTtqnWK5PMEfZng0/bLzlyNXwkU6vE6hI76w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B4SkuHOw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B4SkuHOw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50BE11F00893; Fri, 5 Jun 2026 18:35:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780684512; bh=YfLHlVxyR5EYNIvS2b9hctrQDZeBzNQYJP8K26NqgQo=; h=From:To:Cc:Subject:Date; b=B4SkuHOwbpSMPXI9ruNO7rv/8yWdd8bv8ro0F9nWQkm6nqfl+gyMpWpb0cKTLPHie z/XNlFaOrjGa4VmKsmdR+GkdbJld7zgVRxUgGudXk3+BbEzNetVxmx5HHBp54QJLB6 niasdzmUY36GOFGOUfi1DPrL8DSjIv7gcq2VZYdpjECJtyP+NUoXAPI1CZkniE0VB7 zfWER+QtNuRfTU6o5Vu9HD6dRTd7zj2b4pU49RpuriOG/7MPIM0mkcXoiv5H987Ljk V58MtYDpC8vh8tEyZhOH5BAvoQrG27WKhS0+Va/VqG3yjfig4ipQJL3dQ42cAim+b1 VIHJwm+goFsLg== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu , Jork Loeser Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 00/18] kho: make boot time huge page allocation work nicely with KHO Date: Fri, 5 Jun 2026 20:34:33 +0200 Message-ID: <20260605183501.3884950-1-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" Hi, Gigantic huge page allocation is somewhat broken currently with KHO. First, they break scratch size accounting. Since they are allocated using the memblock alloc APIs, they count towards RSRV_KERN, and this scratch size when using scratch_scale. This means if huge pages take a large enough chunk of system memory scratch size will blow up and fail to allocate. Second, scratch can not contain preserved memory, and if hugepages are allocated from scratch, they will fail to be preserved with the upcoming hugetlb preservation series [0]. Fix this by introducing the concept of extended scratch areas. They are areas that the kernel discovers on boot by walking the radix tree and finding free memory ranges. See patch 10 for more details. Discovering the scratch areas needs some preparatory changes to KHO, the radix tree APIs, and to memblock. Patches 1-14 do that. Patch 15 adds the scratch discovery logic. Patch 16 adds the dedicated memblock hugetlb allocator. Patch 17-18 fix the scratch size calculation with using scratch_scale. [0] https://lore.kernel.org/linux-mm/20251206230222.853493-1-pratyush@kernel.org/T/#u Changes in v2: Detailed changelog below. At a high level, the major change in this version is to remove MEMBLOCK_KHO_SCRATCH_EXT. Keep MEMBLOCK_KHO_SCRATCH as the only memory type and mark the discovered areas with it. For HugeTLB, add a dedicated allocation routine and if allocated memory lands in scratch, do a retry. Also introduce MEMBLOCK_RSRV_HUGETLB to help with accounting of scratch area sizes. - Fixup commit message in patch 1 to make namespacing change clearer. - Use @key in kernel-doc for radix functions. - Add a runtime check on key width. - Move all mem retrieval logic to kho_mem_retrieve(). - Add a comment in kho_mem_retrieve() explaining why mem_map won't be NULL. - Rename callbacks to ->leaf() and ->node(). - Fixup commit messages. - Clear tree->root in kho_radix_destroy_tree(). This lets the tree be re-initialized by calling kho_radix_init_tree() - Add kho_get_mem_map() earlier in the series. - Export kho_scratch_overlap() and use it in memblock_is_kho_scratch_memory(). - Get rid of MEMBLOCK_KHO_SCRATCH_EXT. - Introduce MEMBLOCK_RSRV_HUGETLB. - Introduce memblock_alloc_hugetlb() for hugetlb bootmem allocations. - Refactor memblock_reserved_kern_size() to allow calculating size by flags. - Exclude hugetlb memory from scratch size calculation. - Collect R-bys. Regards, Pratyush Yadav Pratyush Yadav (Google) (18): kho: generalize radix tree APIs kho: disallow wide keys in radix tree kho: return virtual address of mem_map kho: store incoming radix tree in kho_in kho: move all memory retrieval logic to kho_mem_retrieve() kho: add a struct for radix callbacks kho: add callback for table pages kho: add data argument to radix walk callback kho: allow early-boot usage of the KHO radix tree kho: allow destroying KHO radix tree kho: add kho_radix_init_tree() kho: export kho_scratch_overlap() kho: initialize kho_scratch pointer earlier in boot memblock: use kho_scratch_overlap() to decide migratetype kho: extend scratch memblock: make HugeTLB bootmem allocation work with KHO memblock: allow calculating reserved size by flags kho: exclude hugetlb memory from scratch size calculation include/linux/kexec_handover.h | 10 + include/linux/kho/abi/kexec_handover.h | 8 + include/linux/kho_radix_tree.h | 44 +- include/linux/memblock.h | 9 +- kernel/liveupdate/Makefile | 1 - kernel/liveupdate/kexec_handover.c | 495 +++++++++++++++----- kernel/liveupdate/kexec_handover_debug.c | 25 - kernel/liveupdate/kexec_handover_internal.h | 9 - mm/hugetlb.c | 22 +- mm/memblock.c | 120 ++++- mm/mm_init.c | 1 + 11 files changed, 540 insertions(+), 204 deletions(-) delete mode 100644 kernel/liveupdate/kexec_handover_debug.c base-commit: 2935777b418d2bfcbfe96705bb2c0fa6c0d94e18 -- 2.54.0.1032.g2f8565e1d1-goog