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 E53564195B8 for ; Thu, 9 Jul 2026 17:39:25 +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=1783618767; cv=none; b=lN6H8BXIwdEywo3ej3SIhot4nnC8waHG8c7fg5Yq1O+eDuvlDNuE/qpdselv7W6zH1DrLRqM4KtNB8wOZ1SLzYdl3scrj/LBQaevhbEG5glIsmjeY5ph1uZzmXsEiTASeuE+rvZu2uIUPbA55YIEHjFQ1OySmECi2ZspmDDU7AQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618767; c=relaxed/simple; bh=nzLt2dPNWE3sruXvsNN93tMcm2IGbobnGusXGnFDF+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JZG2IGHzgnsRkpEmelU5PVuBoObUBu3kRwfLMdXks8oISEPJbwqNZ2LAg0hn3q+wrFlUS+wiEafvfO84ITD5Ybfz27t+LvBxtWgU/7sCdp1CJvSciUGCZGZPPGEEKZc6mdJgGVQxVa3g2r73Yjlb7k3qLuw/VLHG59FINosAP1s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uc5holxa; 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="Uc5holxa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A70881F00A3D; Thu, 9 Jul 2026 17:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618765; bh=Jo6vG8Fck92Ec2ICF08h9HWgylgcmuoyS4qHd/4tb4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uc5holxavp4JQIp7OghW6d0zZ/963AZ+EpsBk1yFU1Od1tM2H46v8cfDKe5Y/1b7a zPE+Jce/p0bDpwIpMAO+1TNlNXAM+3aOHUK6MvXSfJDwrqzKOh164kDbHktkLBbm+p uRIeolRBn7n6PqIoyLDfxFWUWoJw4SCHffrXva6IJV314NFnGKEQ9r7jnm3SReA++R He/+e8OXxBI5iiy5LFPHG5Rt4eb80rcmRcILB6xzCJY7T2/wZ7WVbVFLWFm8+btt2x UXyNXG6EoAwJXHWTKr1OZEuEIbAL9+HY410UK9qfnlU7sC++R2yFAwiv8cu+cuYR3E XQPAq4T1QQlAw== 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 v3 21/21] kho: exclude hugetlb memory from scratch size calculation Date: Thu, 9 Jul 2026 19:38:10 +0200 Message-ID: <20260709173821.429921-22-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-1-pratyush@kernel.org> 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)" 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 2c4848874629..9dc79b7103bd 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.141.g00534a21ce-goog