Re: [PATCH] mm/memory_hotplug: factor out node_is_memoryless()

From: Gregory Price

Date: Wed Sep 02 2026 - 20:52:55 EST


On Wed, Sep 02, 2026 at 03:55:07PM -0400, Gregory Price wrote:
> A memoryless node neither spans present pages (populated or ZONE_DEVICE)
> nor has an offline-but-added memory block still linked to it in sysfs.
>
> try_offline_node() presently open-codes this memoryless check.
>
> Pull that into a node_is_memoryless() helper and pull the existing
> check_no_memblock_for_node_cb() helper ahead of the add/online path
> so it's clearer what is happening here.
>
> No functional change.
>
> Signed-off-by: Gregory Price <gourry@xxxxxxxxxx>
> ---
> mm/memory_hotplug.c | 60 +++++++++++++++++++++++----------------------
> 1 file changed, 31 insertions(+), 29 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 226ab9cb078ad..d0e94057682af 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1491,6 +1491,36 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
> return ret;
> }
>
> +static int check_no_memblock_for_node_cb(struct memory_block *mem, void *arg)
> +{
> + int nid = *(int *)arg;
> +
> + /*
> + * If a memory block belongs to multiple nodes, the stored nid is not
> + * reliable. However, such blocks are always online (e.g., cannot get
> + * offlined) and, therefore, are still spanned by the node.
> + */
> + return mem->nid == nid ? -EEXIST : 0;
> +}
> +
> +/* Caller must hold the memory hotplug lock for this check. */
> +static bool node_is_memoryless(int nid)
> +{
> + /*
> + * A node still spanning pages (especially ZONE_DEVICE) is not
> + * memoryless. A node spans memory after move_pfn_range_to_zone(),
> + * e.g. once a memory block has been onlined.
> + */
> + if (node_spanned_pages(nid))
> + return false;

browsing sashiko feedback:

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but can
this lockless read of node_spanned_pages() race with ZONE_DEVICE memory
hotplug?

---

This seems legit and worth addressing (other notes are addressible as
well, but this is maybe noteworthy).

I actually have some old patches sandbagged that tried to marry the
ZONE_DEVICE hotplug pattern through mm/memory_hotplug.c rather than its
separare entry-point. Might be worth a revisit.

I don't know that I want to predicate this particular fix on this patch
but it's worth a think.

~Gregory