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 2E73D3FCB22 for ; Fri, 5 Jun 2026 18:35:56 +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=1780684558; cv=none; b=b8pGl5Z+tFAFa4UJsx06y3a63loBlEfnNzRA5iABwtNr8FEr+3zGbyV3VTnwPjMH34RZQMfJf9Rm0oWuAe2oYb843G1L/tXYe6TAzdC2OLqhM+tkDIrmEhjQCNz78QW6razkcYuu1qs48dxG+F3M37T1fctAaKGF93pfKpk5sPE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780684558; c=relaxed/simple; bh=0efo/ycGcd2WP7drmYEXYpmg66GfnAWUymidyYhZlTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tNw1dJ/aJ5sjL8sce2JAkQSlSe2EAhomAQPRwZ5VZXohZDjdTWoaCugcbgo+ChxaWq/bupYOjte6hm6GpyuGjMzGlFonJ9+p0WJXyfQhxPbkPiGXRblQ1CmZpuMGwKrC5D93Bm/dnATRfXDSga1hiI3w0zLlqwXA9oAxNTKcQ+g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bUfHWrW5; 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="bUfHWrW5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A913E1F0089C; Fri, 5 Jun 2026 18:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780684556; bh=1Hq29nobeHte/zgkXSzWoaRdOwXra0la1omlEHsUXW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bUfHWrW5rXMnv2UvKJJvwS1trNmxa2rXAjoYxroYpe1q5lIcs760w3ankAJ6BB1Py g73wErrnH91np/zObpNmIFsHWrAUvhr3VJlJAcj4xTTHk/cvcRExmAy12bklfYEH+w kAaKAZcTcXTI0uCCo5vFlyOqxzHlqa46oLSVDq6qe5fpJTloUX20PBsylCddF9x0z1 wSJgYCMJGOGDk0bXCPolKk9SFYRhFNmMU1wQ2M0lk0ybHyOBjtAtQX1FwVJvlUEqUg bVjPGABJTG6H4zot5hDdg1Ua9KeRvqsn0epir31a1xmaTVbNjXDhZhjEnok0JZYRXG YmdbPzofSIHPA== 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 18/18] kho: exclude hugetlb memory from scratch size calculation Date: Fri, 5 Jun 2026 20:34:51 +0200 Message-ID: <20260605183501.3884950-19-pratyush@kernel.org> X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog In-Reply-To: <20260605183501.3884950-1-pratyush@kernel.org> References: <20260605183501.3884950-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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c index b3c33f150e85..0d106c9197d9 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -744,7 +744,8 @@ static void __init scratch_size_update(void) { /* * If fixed sizes are not provided via command line, calculate them - * now. + * now. Use RSRV_KERN to count allocated memory, but remove HugeTLB + * allocations from it because they never get allocated from scratch. */ if (scratch_scale) { phys_addr_t size; @@ -752,12 +753,19 @@ static void __init scratch_size_update(void) size = memblock_reserved_size_flags(ARCH_LOW_ADDRESS_LIMIT, NUMA_NO_NODE, MEMBLOCK_RSRV_KERN); + size -= memblock_reserved_size_flags(ARCH_LOW_ADDRESS_LIMIT, + NUMA_NO_NODE, + MEMBLOCK_RSRV_HUGETLB); + size = size * scratch_scale / 100; scratch_size_lowmem = size; size = memblock_reserved_size_flags(MEMBLOCK_ALLOC_ANYWHERE, NUMA_NO_NODE, MEMBLOCK_RSRV_KERN); + size -= memblock_reserved_size_flags(MEMBLOCK_ALLOC_ANYWHERE, + NUMA_NO_NODE, + MEMBLOCK_RSRV_HUGETLB); size = size * scratch_scale / 100 - scratch_size_lowmem; scratch_size_global = size; } @@ -777,6 +785,9 @@ static phys_addr_t __init scratch_size_node(int nid) if (scratch_scale) { size = memblock_reserved_size_flags(MEMBLOCK_ALLOC_ANYWHERE, nid, MEMBLOCK_RSRV_KERN); + /* Do not count HugeTLB pages. */ + size -= memblock_reserved_size_flags(MEMBLOCK_ALLOC_ANYWHERE, + nid, MEMBLOCK_RSRV_HUGETLB); size = size * scratch_scale / 100; } else { size = scratch_size_pernode; -- 2.54.0.1032.g2f8565e1d1-goog