From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795986816; b=xIObkAlk2IxYg07iEsa5NoMaELQbfI0HL2bl9tO7FvHeLoCGuko9D+DXeoDreWP3yofB w0nX+4+cPpkPvRansVtREh2e2NO9rhVorrXvPBL7cn9aUq9h2IorG9NVfK0KVV5O3ScKS Cxfk65YX4sVHDyyXyFntbz+qSkFJGMSCUEvxum7WD6vZuGd0xGGUqebrCHb26ccS311Wv R4ucgP671vAzsJbKFp81xohhKVQSVmi0N8VRXKDH9BGXQXtf6zjLUi9EdNF0BsAYWWaia ngOceUib1jGokZXtQl8GBm8K0py2/rfoIBoTLJeeqeyBay44yfOVIrmQMNXPRP6UfdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795986816; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=8u2MX8zMiRrvaGCi9t6plJTs+JJ36w5YqQq+DPSXk2k=; b=ad3nq3L/tQpO+d5uXhf2E/V2HDfRQ1LHxV/4i4VFnGT2VucQBxfEX7ggxbOjMxHeCbWJ qzK1CHy3Tm9jFF2WMF8C7vpJ7S0Sk3r/cotsWS16OJJvLlJLiQskHwIpjIZ50/y2r/r1G L9H4RlywYeiLca9XNfbr84IZCm8W6SUGdXHtpzHs8mZTLQg5PBVReqs4jUig3d8WCNmPv lMp5riw3TL8LH2K6MaC95my5lmJgISuFfo1xk7WNJPVc/cQpkwZNy/kSsxw3eVh27Y9Iy SLribHKP+CBhbkVSM0/FNUz7LTDC2jE+nl0Dubozb2DHYCaNFqagAfB8Eb8kUDuxVJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kVG4Xz9d; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B4CC606A31C; Sun, 29 Nov 2026 21:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kVG4Xz9d Received: by smtp.kernel.org (Postfix) with ESMTPSA id 631C61F00896; Sun, 29 Nov 2026 21:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795986816; bh=8u2MX8zMiRrvaGCi9t6plJTs+JJ36w5YqQq+DPSXk2k=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=kVG4Xz9dbCoe9HGkI91yaELgKGWQgZKCuU5ufrkMnOU7Zw2JI5w+0KK9rJlYS1mTk IjRkU3RuARN1BgC1+IlJVaJZGiMchaQmc5YSxjDHeRnFs+24oi+5NUAvixS3Yw+fHD ts+DqQvHunzcDxuUGv/8Tb1V6JTkA0UYsPMgsfLgfX4P+0qK//nPD2KkkTBwXqVfvd Udk+87TsUOi9vT+2sG5cSgWzXatD3kbxW6Ywoyjz2gBoo40dZThfWdYdvQVqAyxGnT T/u20Z4Drs9rB1p6YJ9WG4t8pC+uJo4V1l39+Ol6KzM7v7MFUvT+Uk3BKoHOh5ZVzy uMuTRbSibPtuw== Date: Sun, 29 Nov 2026 23:13:28 +0200 From: Mike Rapoport To: Chris Down Cc: Pasha Tatashin , Pratyush Yadav , Alexander Graf , Baoquan He , Jonathan Corbet , Shuah Khan , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@meta.com, Breno Leitao , sashiko-bot@kernel.org Subject: Re: [PATCH v2 5/7] kho: Report how much handover memory is preserved and restored Message-ID: References: <1b0354d4bd39765d151632c0d7ab38bbae96dffa.1795857773.git.chris@chrisdown.name> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1b0354d4bd39765d151632c0d7ab38bbae96dffa.1795857773.git.chris@chrisdown.name> On Sat, Nov 28, 2026 at 10:27:40AM -0800, Chris Down wrote: > Most memory the previous kernel preserved stays reserved until its user > restores it through KHO, either to use it again or to free it. If > nothing does, it stays reserved for as long as the kernel runs. On a > hypervisor host that can be gigabytes, but amusingly nothing really > shows it reliably. The host simply has less memory than it should, which > is not exactly obvious. > > All preserved memory is reserved in kho_preserved_memory_reserve(), and > everything restored through KHO goes through kho_restore_page(), so KHO > can count both easily. Let's add preserved_size and restored_size, in > bytes, to /sys/kernel/kho/incoming/. > > For example, after a live update preserving a 64 MiB memfd: > > preserved_size restored_size > before retrieval 67403776 8192 > after finish 67403776 67395584 > > The 8 KiB left are the incoming KHO FDT and LUO's FLB header. > > Signed-off-by: Chris Down > --- > Documentation/ABI/testing/sysfs-kernel-kho | 10 ++++++++++ > Documentation/admin-guide/mm/kho.rst | 3 +++ > kernel/liveupdate/kexec_handover.c | 15 +++++++++++++++ > kernel/liveupdate/kexec_handover_internal.h | 2 ++ > kernel/liveupdate/kho_sysfs.c | 16 ++++++++++++++++ > 5 files changed, 46 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-kernel-kho b/Documentation/ABI/testing/sysfs-kernel-kho > index 21488e35d1f3..a8251d663ce6 100644 > --- a/Documentation/ABI/testing/sysfs-kernel-kho > +++ b/Documentation/ABI/testing/sysfs-kernel-kho > @@ -9,3 +9,13 @@ Description: read only > the walk of its preserved memory map. > "failed" The kernel rejected the handover. > Users: system monitoring > + > +What: /sys/kernel/kho/incoming/preserved_size > +What: /sys/kernel/kho/incoming/restored_size > +Date: Nov 2026 > +Contact: kexec@lists.infradead.org > +Description: read only > + Bytes preserved by the previous kernel and bytes restored > + through KHO, respectively. Both are 0 unless the incoming > + state is "revived". > +Users: system monitoring > diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-guide/mm/kho.rst > index 8810813a5d0a..a12c1398eff2 100644 > --- a/Documentation/admin-guide/mm/kho.rst > +++ b/Documentation/admin-guide/mm/kho.rst > @@ -87,6 +87,9 @@ sysfs Interfaces > ``/sys/kernel/kho/incoming/state`` > Status of the incoming KHO handover. > > +``/sys/kernel/kho/incoming/preserved_size`` and ``restored_size`` > + Bytes preserved by the previous kernel and bytes restored through KHO. > + > See Documentation/ABI/testing/sysfs-kernel-kho for the sysfs ABI. > > debugfs Interfaces > diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c > index aff96aa401f8..5d9b724ab754 100644 > --- a/kernel/liveupdate/kexec_handover.c > +++ b/kernel/liveupdate/kexec_handover.c > @@ -103,6 +103,8 @@ struct kho_in { > char previous_release[__NEW_UTS_LEN + 1]; > u32 kexec_count; > enum kho_incoming_state state; > + unsigned long preserved_pages; > + atomic_long_t restored_pages; > struct kho_debugfs dbg; > struct kho_radix_tree radix_tree; > }; > @@ -545,6 +547,7 @@ static struct page *kho_restore_page(phys_addr_t phys, bool is_folio, > kho_init_pages(page, nr_pages); > > adjust_managed_page_count(page, nr_pages); > + atomic_long_add(nr_pages, &kho_in.restored_pages); > return page; > } > > @@ -636,6 +639,7 @@ static int __init kho_preserved_memory_reserve(unsigned long key, void *data) > info.magic = KHO_PAGE_MAGIC; > info.order = order; > page->private = info.page_private; > + kho_in.preserved_pages += 1UL << order; > > return 0; > } > @@ -1746,6 +1750,7 @@ err: > kho_in.fdt_phys = 0; > kho_in.radix_tree.root = NULL; > kho_in.state = KHO_INCOMING_FAILED; > + kho_in.preserved_pages = 0; I'm not sure we need to reset that if kho_mem_retrieve() fails. The memory is still preserved by the previous kernel. > } > > static __init int kho_out_fdt_setup(void) > @@ -1777,6 +1782,16 @@ enum kho_incoming_state kho_in_state(void) > return kho_in.state; > } > > +u64 kho_in_preserved_size(void) > +{ > + return (u64)kho_in.preserved_pages << PAGE_SHIFT; Any reason to declare .reserved_pages as unsigned long and cast here? And since KHO depends on CONFIG_64BIT, why do we need to return u64 here? I don't mind either, but let's remove the casting :) > +} > + > +u64 kho_in_restored_size(void) > +{ > + return (u64)atomic_long_read(&kho_in.restored_pages) << PAGE_SHIFT; I'd add a local variable to make this clearer. > +} > + > static void __init kho_in_kexec_metadata(void) > { > struct kho_kexec_metadata *metadata; -- Sincerely yours, Mike.