From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D656C54FCD for ; Wed, 29 Jul 2026 14:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=t+FsuwC2RrexyYjQNFP6CQ0ttOXgehh40MLyehj+reg=; b=x6rO8XJUwJ5pmevI27OvQDsBXU ZI3sr6yvzeL7cNe7diond4kV/OI3TVkXUdNIJAs9EbvSz7y3A7EEVa6G1qgjlCkDOKO6fARpVVK9y 3zQFBcOb/0EiVNB3YRN2KS+qcUJ+F0XIrRpLbEKIB+W8UNhMVYCUWO/HpDcRSP5/EoACEFlPwfKcg lVGIo7bUbdzpbYvE5zE45ZA4foYGXmkGW0AYkJJU1RXlFVLUj2S3onqo80agey9E/+KGGkpCmBEd4 UUHDy1MVqbeUFI+DLqgM/iO5D4vY61ktDB5JPC04uL2cKtdHQpo/Js/HuzIgD0YLGDV9Mu3vM7A7C K63vHcBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wp5ij-00000008JgW-2tWR; Wed, 29 Jul 2026 14:57:21 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wp5ii-00000008Jf8-0Sya for kexec@lists.infradead.org; Wed, 29 Jul 2026 14:57:20 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8D5DB60A8F; Wed, 29 Jul 2026 14:57:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19AE01F00A3E; Wed, 29 Jul 2026 14:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785337039; bh=t+FsuwC2RrexyYjQNFP6CQ0ttOXgehh40MLyehj+reg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=efO7ojKAzloBKSRmnh9bcoj08OaYUtZKHmgRXQQoS1KBUEifIe+XxH3QyOsf0G6VV usL/CcWEmlzNfD8Tv1C56UKLk4oYUl7wB6023NThMVHCiuu7UkWg+phiT7oPRovW56 YKx+LYBTx/ItWVA73ZhkceBrPQeRLsDl5E8sUsc22lpMGb8CSDTZJ/M2Yuhclak3kd awsuKZlV4O4h/SB0X4P5C+Q3q8FFva+zgyE/69msRNycjrCsv41yNO3aFD+ewIBs/b 0xak86gc+hOhS2Xz+t1U05C5LLPbLC7aaSQlxIws5+G5y3VzqVbNp3wTjdXiwSlJJW oB52WTFwFd7Cg== 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 v5 22/22] kho: exclude hugetlb memory from scratch size calculation Date: Wed, 29 Jul 2026 16:56:07 +0200 Message-ID: <20260729145610.2827231-23-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.508.g3f0d502094-goog In-Reply-To: <20260729145610.2827231-1-pratyush@kernel.org> References: <20260729145610.2827231-1-pratyush@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org From: "Pratyush Yadav (Google)" HugeTLB pages can be preserved memory. So they are never allocated from scratch. Instead, they are allocated from the memory blocks with no preserved memory. These areas are detected at runtime on each boot. But since they are allocated via memblock, they show up as RSRV_KERN, and blow up the scratch size when scratch scale is in use. All hugetlb pages are marked RSRV_HUGETLB. Subtract their size from RSRV_KERN when calculating scratch sizes. Signed-off-by: Pratyush Yadav (Google) --- kernel/liveupdate/kexec_handover.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index 4c0756993b1f..1ccd7b7c59a1 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -742,19 +742,24 @@ early_param("kho_scratch", kho_parse_scratch_size); static void __init scratch_size_update(void) { /* - * If fixed sizes are not provided via command line, calculate them - * now. + * If fixed sizes are not provided via command line, calculate them now. + * Remove HugeTLB allocations from it because they never get allocated + * from scratch. */ if (scratch_scale) { phys_addr_t size; size = memblock_reserved_kern_size(ARCH_LOW_ADDRESS_LIMIT, NUMA_NO_NODE); + size -= memblock_reserved_hugetlb_size(ARCH_LOW_ADDRESS_LIMIT, + NUMA_NO_NODE); size = size * scratch_scale / 100; scratch_size_lowmem = size; size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE, NUMA_NO_NODE); + size -= memblock_reserved_hugetlb_size(MEMBLOCK_ALLOC_ANYWHERE, + NUMA_NO_NODE); size = size * scratch_scale / 100 - scratch_size_lowmem; scratch_size_global = size; } @@ -774,6 +779,9 @@ static phys_addr_t __init scratch_size_node(int nid) if (scratch_scale) { size = memblock_reserved_kern_size(MEMBLOCK_ALLOC_ANYWHERE, nid); + /* Do not count HugeTLB pages. */ + size -= memblock_reserved_hugetlb_size(MEMBLOCK_ALLOC_ANYWHERE, + nid); size = size * scratch_scale / 100; } else { size = scratch_size_pernode; -- 2.55.0.508.g3f0d502094-goog