From: Mike Rapoport <rppt@kernel.org>
To: Jason Miu <jasonmiu@google.com>
Cc: Alexander Graf <graf@amazon.com>,
Andrew Morton <akpm@linux-foundation.org>,
Baoquan He <bhe@redhat.com>,
Changyuan Lyu <changyuanl@google.com>,
David Matlack <dmatlack@google.com>,
David Rientjes <rientjes@google.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Pratyush Yadav <pratyush@kernel.org>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH v8 1/2] kho: Adopt radix tree for preserved memory tracking
Date: Tue, 3 Feb 2026 18:16:05 +0200 [thread overview]
Message-ID: <aYIfRa5fDBaLVR5y@kernel.org> (raw)
In-Reply-To: <20260130005739.3163049-2-jasonmiu@google.com>
On Thu, Jan 29, 2026 at 04:57:38PM -0800, Jason Miu wrote:
> Introduce a radix tree implementation for tracking preserved memory
> pages and switch the KHO memory tracking mechanism to use it. This
> lays the groundwork for a stateless KHO implementation that eliminates
> the need for serialization and the associated "finalize" state.
>
> This patch introduces the core radix tree data structures and
> constants to the KHO ABI. It adds the radix tree node and leaf
> structures, along with documentation for the radix tree key encoding
> scheme that combines a page's physical address and order.
>
> To support broader use by other kernel subsystems, such as hugetlb
> preservation, the core radix tree manipulation functions are exported
> as a public API.
>
> The xarray-based memory tracking is replaced with this new radix tree
> implementation. The core KHO preservation and unpreservation functions
> are wired up to use the radix tree helpers. On boot, the second kernel
> restores the preserved memory map by walking the radix tree whose root
> physical address is passed via the FDT.
>
> The ABI `compatible` version is bumped to "kho-v2" to reflect the
> structural changes in the preserved memory map and sub-FDT property
> names. This includes renaming "fdt" to "preserved-data" to better
> reflect that preserved state may use formats other than FDT.
>
> Signed-off-by: Jason Miu <jasonmiu@google.com>
With minor comments below
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
...
> +static int __kho_radix_walk_tree(struct kho_radix_node *root,
> + unsigned int level, unsigned long start,
> + kho_radix_tree_walk_callback_t cb)
> +{
> + struct kho_radix_node *node;
> + struct kho_radix_leaf *leaf;
> + unsigned long key, i;
> + unsigned int shift;
> + int err;
> +
> + for (i = 0; i < PAGE_SIZE / sizeof(phys_addr_t); i++) {
> + if (!root->table[i])
> + continue;
> +
> + shift = ((level - 1) * KHO_TABLE_SIZE_LOG2) +
> + KHO_BITMAP_SIZE_LOG2;
> + key = start | (i << shift);
> +
> + node = phys_to_virt(root->table[i]);
> +
> + if (level == 1) {
> + /*
> + * we are at level 1,
> + * node is pointing to the level 0 bitmap.
> + */
> + leaf = (struct kho_radix_leaf *)node;
> + err = kho_radix_walk_leaf(leaf, key, cb);
> + if (err)
> + return err;
> + } else {
> + err = __kho_radix_walk_tree(node, level - 1,
> + key, cb);
> + if (err)
> + return err;
Nit: if (err) can be moved outside if (level == 1)
> + }
> + }
> +
> + return 0;
> +}
> +
> +/**
> + * kho_radix_walk_tree - Traverses the radix tree and calls a callback for each preserved page.
> + * @tree: A pointer to the KHO radix tree to walk.
> + * @cb: A callback function of type kho_radix_tree_walk_callback_t that will be
> + * invoked for each preserved page found in the tree. The callback receives
> + * the physical address and order of the preserved page.
> + *
> + * This function walks the radix tree, searching from the specified top level
> + * (@level) down to the lowest level (level 0). For each preserved page found,
Hmm, why do we need @level here?
Or it rather remained from the older versions?
> + * it invokes the provided callback, passing the page's physical address and
> + * order.
> + *
> + * Return: 0 if the walk completed the specified tree, or the non-zero return
> + * value from the callback that stopped the walk.
> + */
> +int kho_radix_walk_tree(struct kho_radix_tree *tree,
> + kho_radix_tree_walk_callback_t cb)
> +{
> + if (WARN_ON_ONCE(!tree->root))
> + return -EINVAL;
> +
> + guard(mutex)(&tree->lock);
> +
> + return __kho_radix_walk_tree(tree->root, KHO_TREE_MAX_DEPTH - 1, 0, cb);
> +}
> +EXPORT_SYMBOL_GPL(kho_radix_walk_tree);
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-02-03 16:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 0:57 [PATCH v8 0/2] Make KHO Stateless Jason Miu
2026-01-30 0:57 ` [PATCH v8 1/2] kho: Adopt radix tree for preserved memory tracking Jason Miu
2026-01-30 10:28 ` kernel test robot
2026-02-03 16:16 ` Mike Rapoport [this message]
2026-02-06 2:17 ` Jason Miu
2026-01-30 0:57 ` [PATCH v8 2/2] kho: Remove finalize state and clients Jason Miu
2026-02-03 16:18 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aYIfRa5fDBaLVR5y@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=changyuanl@google.com \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=jgg@nvidia.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.