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 D71B43F9F4D for ; Sat, 25 Jul 2026 17:22:39 +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=1785000161; cv=none; b=JpCT5yFQU23ppuL6BdRnHX3dbvQ6sCzj5w+Wa9bU8Ozh3IBhCCtpDbNNhuWEuclO3BZxYHEQXFhBqnrYHwBJ88BeZ4QniwtFnZSDlgg3BD6okjkdDYQ0qbNbGQ8aLSKdhjCcGQW70ISOfiemgr98Z4Mz5pt3L5wi7MeOgtH7tJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785000161; c=relaxed/simple; bh=IaoA2w4uc1KsHe5AiDYfVrKzsVrA62ZiowX0+KIre9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KG8/2uDlA86ySK22xp4FnnSj231iBrYxxJi8pXdVH4ImA9vYdhdpIS0q2vcK8MyrZPXfJ4Y2YbVN0BUsBUfkMufXVspCdxWzX6A9bAFr85Gu4nAAgtjMNgNsBt1e2z+KXD37ZgoVtaZrZ43S1rv0G2flY2kTIr0uzBE2decLAjI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RTVZKU93; 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="RTVZKU93" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A821F000E9; Sat, 25 Jul 2026 17:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785000159; bh=wZ0f3zzDp/LQ46aQcmeTItf+xyrvDOtmTEeK5N5Eqi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RTVZKU93XLuef/FPziOCK1SLynmjuq2VnSb6EOKmXdOrLeUGAruKnssIkEH9FR3gW 9gJ03CDqbnSr5tRJ9BhIJ49Mpr3+5HlGcO1dbMeKpQ0zRcvRCG9Fwhj+qkOmpCeuJU CX3hyEH2p+20pFyrbX14XFRufgs3ALEvDeFbobVfPrV0gPyxHIjR/STDFMZWX54P9b Cvh8dQuS8FwF3O4hDeFAIn11cA3PhHeq6LGCdi5wl1huGzgVHsQHuy7KtBS7uqgMBZ 6rY5wSyhj84wU3YLWAT1wfYkTynvLt7id0gwyxSkzsGdOaHpUxnbwvkclI1Oqb5rq6 ZQd4sqATNdMCQ== 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 v4 21/21] kho: exclude hugetlb memory from scratch size calculation Date: Sat, 25 Jul 2026 19:21:21 +0200 Message-ID: <20260725172133.4018491-22-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog In-Reply-To: <20260725172133.4018491-1-pratyush@kernel.org> References: <20260725172133.4018491-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 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.229.g6434b31f56-goog