From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F490606A323 for ; Sun, 29 Nov 2026 19:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=jBPkSxMs; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fyaw8MuN 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=R3Ve4QyxY+phXEH5iBcIBo/0RFaduPiV1250yCJyQis=; b=jBPkSxMsIUr16hAhjeZ4Cs1DcR ns9WGrW+Q+vfWtmp6dxCr0Ly3ip0WSiJETSzhQe/KcdVuz+j4fqejV0FW/JIVCpeX38Gfl6dUFHFH mhZvP8RHgww8KfKVORoQfzM5n34Wjzg+L8KXaslFtpcj5HwEw31CbQmTJwGCZy1P0giAXgkqc77pC PbXW0PFHVTRh9I2ZzWUTfcFpzMQZOkLVKAJvpbni/hPaLtN/iiIm2zVn1U9fgo3J7n0UQZlr7SFyy lEImN+eIkYt7gWxKckmQpWjUcV6OHCiV58ClsBvN3IfeJSCD+h7hBhEV55GN1Z9kp2cDfKAMiQO1z bLcriTsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXktP-00000002QHX-3mjD; Sun, 29 Nov 2026 19:48:59 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXktN-00000002QHQ-3hok for kexec@lists.infradead.org; Sun, 29 Nov 2026 19:48:58 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F41F460F04; Sun, 29 Nov 2026 19:48:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DEB1F00898; Sun, 29 Nov 2026 19:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795981736; bh=R3Ve4QyxY+phXEH5iBcIBo/0RFaduPiV1250yCJyQis=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=Fyaw8MuNOq4gvgXe+8aYFs24BrZhsdNqEwPVeK0kW8OTOOECq7KUz55AFQmFBBIb8 OCRz8cUxHlk+kGNMD/G4ujxkYDPI4ZV9TM+9i564A0yGRaxIjycv2B4w06A4zb/kyW 7YlXaqMNF4FEsU6bkqI8NLmoRXRuRD8wLG7ZDwpsI0RMmwUAV9jIbnFIwxSyPx6uFF MPlL+BiA3CZFco84XKS7Mx9/u12UArmFDHV3twtlHEB1SWyCp8cFRccl5HSgykugBB aEQ/h5/yhRdPcgL8ADcoNojS6WvKEe8uoCUZWXRTy9ijCwWUf7dsl4Uo2rZk2f45Hi hWI9awYbqj+kw== Date: Sun, 29 Nov 2026 21:48:50 +0200 From: Mike Rapoport To: Chris Down Cc: Pasha Tatashin , Pratyush Yadav , Alexander Graf , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, David Hildenbrand Subject: Re: [PATCH 1/2] kho: count bootmem in zoneinfo's cma after a KHO kexec Message-ID: References: <435620830fafd0b7458b583485967cdbbb848d3f.1795928397.git.chris@chrisdown.name> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <435620830fafd0b7458b583485967cdbbb848d3f.1795928397.git.chris@chrisdown.name> X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi Chris, Overall LGTM, just a few nits below. On Sat, Nov 28, 2026 at 09:01:48PM -0800, Chris Down wrote: > On a cold boot, kho_init() releases bootmem to the buddy allocator with > init_cma_reserved_pageblock(), which adds each pageblock to > zone->cma_pages. > > A KHO boot takes a different path, because bootmem isn't reserved in > memblock: > > 1. kho_bootmem_migratetype() makes its pageblocks MIGRATE_CMA during > memmap init. > 2. memblock_free_all() releases the free pages. > 3. kho_init() returns before it gets to the bootmem loop. I'd say it bypasses bootmem initialization. > Nothing adds bootmem to zone->cma_pages, so the cma line in > /proc/zoneinfo goes to 0 after a KHO kexec, even though the memory is > still MIGRATE_CMA and its free pages are still counted in CmaFree. For > example, with 4 GiB over two nodes and kho_bootmem=32M,512M,256M, in > pages: > > cold boot after KHO kexec > Node 0, DMA32 65536 0 > Node 1, DMA32 8192 0 > Node 1, Normal 196608 0 It would be great to see "before" and "after" tables. > zone->cma_pages is also what the auto-movable memory onlining policy > treats as movable memory, so after a KHO kexec it counts bootmem as > kernel memory instead. > > Let's count the MIGRATE_CMA pageblocks in bootmem from kho_init() on a > KHO boot. > > You might wonder why we don't count pageblocks as they are made > MIGRATE_CMA in pageblock_migratetype_init_range() and > __init_deferred_page(). The reason is that, with deferred struct page > init, __init_deferred_page() makes bootmem MIGRATE_CMA on a cold boot > too, where init_cma_reserved_pageblock() then counts it again. > deferred_free_pages() also runs in several padata threads at once, which > would race on the counter. > > Fixes: c609c144b0e8 ("kexec: add KHO parsing support") > Signed-off-by: Chris Down > --- > kernel/liveupdate/kexec_handover.c | 33 ++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c > index 38e65d210cb9..7cc87338df24 100644 > --- a/kernel/liveupdate/kexec_handover.c > +++ b/kernel/liveupdate/kexec_handover.c > @@ -1860,12 +1860,45 @@ static int __init kho_kexec_metadata_init(const void *fdt) > return err; > } > > +static int __init kho_cma_area_intersects(struct cma *cma, void *data) > +{ > + phys_addr_t start = *(phys_addr_t *)data; > + > + return cma_intersects(cma, start, > + start + pageblock_nr_pages * PAGE_SIZE - 1); > +} > + > +static void __init kho_account_incoming_bootmem(void) > +{ > + for (int i = 0; i < kho_bootmem_cnt; i++) { > + unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr); > + unsigned long count = kho_bootmem[i].size >> PAGE_SHIFT; > + unsigned long pfn; > + > + for (pfn = base_pfn; pfn < base_pfn + count; > + pfn += pageblock_nr_pages) { > + struct page *page = pfn_to_page(pfn); > + phys_addr_t start = PFN_PHYS(pfn); > + > + if (!is_migrate_cma_page(page)) > + continue; > + if (cma_for_each_area(kho_cma_area_intersects, &start)) > + continue; A curious reader may also wonder why we need this check ;-) A short comment would be nice. > + > + page_zone(page)->cma_pages += pageblock_nr_pages; > + } > + } > +} > + > static __init int kho_init(void) > { > struct kho_radix_tree *tree = &kho_out.radix_tree; > const void *fdt = kho_get_fdt(); > int err = 0; > > + if (is_kho_boot()) > + kho_account_incoming_bootmem(); > + > if (!kho_enable) > return 0; > > -- > 2.56.1 > -- Sincerely yours, Mike.