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 19EC7C55174 for ; Sat, 1 Aug 2026 08:49:52 +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=dQosUYO4otaOOPBXErhM9wH/IqlhFzgBsL4CwmngTEI=; b=2LpQC+2TTY7F8UI+dUKY34okY1 x1GG7jtX8GQpy3fTZHSiZ/GJi+QlIycM4bEIgeC+bKIDNpT5Tjw7ehPYN5LGSos7+oTCKSdIyNV/s gk29wGD8vySWqOXcsmt2qfADlhBwsPKJwKfbXG+zucoiZBmvJryXc4odd4iHRgb8vrbcA9Vmb0+3v v8tWto0W52weS73NRin2SgVyMYRUkwI93LfR32tggqZJRqEzitQtptrpE3sN+w0HtqMaikNI0WBYy +up6mUOjHzo7oNOP6XzeVwssBELkWXrdBytBt63BpCdUEje4pVmo4mpPNm+oUOyYBA98EiVKW1uFP 4s6z534w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5Pi-0000000E5FQ-44Hi; Sat, 01 Aug 2026 08:49:50 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wq5Ph-0000000E5DJ-2nnA for kexec@lists.infradead.org; Sat, 01 Aug 2026 08:49:49 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 4D6804008C; Sat, 1 Aug 2026 08:49:48 +0000 (UTC) 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> 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 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