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 0EC8042AFB5 for ; Sat, 1 Aug 2026 08:49:49 +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=1785574192; cv=none; b=FWDtAko5qTxz7PhAefVuhG41RZmOJipHvxS7I8jJ6U9ZlXLlPQ6bSgOnuxil6Bxf4dYKMWtV17aDmCMraWNnvjAAbilXnZ73Sw3X3p59FGmKoSvvbSleO7Tb2hD0NJ1Pjko7zACtb30evDsvNVVLqcLJfROTTG8wFtqvnQEqwPI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785574192; c=relaxed/simple; bh=mgeEvqDhXLXQOIZFH6u68X37SnNPzfddAQN8BbrCCeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SbnO9xdAuYN8xEymdibrR7zoEuAz1/im5irSsQIkKxsny3tRBhNLbMguzfNMeJKffRCUV+agTJr1F9NAfFSAWx5xMkSCN4K2Z85/9YlmuewAQq12pe6z4WASJ4QQBrussl9HEWoTsVnL5toGxtMnRDmez6i/BjJQNWYSTha+p+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jZzxYM20; 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="jZzxYM20" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05D6F1F00ADE; Sat, 1 Aug 2026 08:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785574188; bh=dQosUYO4otaOOPBXErhM9wH/IqlhFzgBsL4CwmngTEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jZzxYM209HdmuQs30ywMfS7hGTM1kcicCg8/+nKZSHT/B4aWmsgh0pYDT4AHJS5sy KLTCnkXYlUorqpNTo+oVGuaRKqhC0IVqxNVDUJzpnjRiXZy2Bid21v1ijonazhLp4p 6DQT87sHYkjHrTWG1SDtkXfkxUKQjmOI5AzrFiu8JjBiHxr9HjNkg9quprLHb5xUyg pq2U74ogPuOFHNb2BAHa6BrhDK0uamUN7bRifth+94/EIcA/2GsOqTz8y3s6o3Iz57 ZLHT7BsI+r6b7Mf9ZUSvUKO0HHbqQVpjx6XEub7pGkg2S1MRCZjljIf0avZJhJtFQJ a9KawhTP3qkRA== 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 v6 22/22] kho: exclude hugetlb memory from scratch size calculation Date: Sat, 1 Aug 2026 10:48:31 +0200 Message-ID: <20260801084833.1897543-23-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.571.g244d577d93-goog In-Reply-To: <20260801084833.1897543-1-pratyush@kernel.org> References: <20260801084833.1897543-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 e649e68d861f..861621faa557 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.571.g244d577d93-goog