Re: [PATCH v6 06/10] mm/memory_hotplug: add offline_and_remove_memory_ranges()

From: David Hildenbrand (Arm)

Date: Wed Jul 01 2026 - 04:33:50 EST


On 6/30/26 23:18, Gregory Price wrote:
> offline_and_remove_memory() handles a single contiguous range.
>
> Callers that manage a device composed of several ranges (dax/kmem)
> currently have to call it in a loop, which gives up atomicity.
>
> In addition to pushing rollback logic into the driver, the lack
> of atomicity creates a race condition between system daemons trying
> to manage the same resource:
>
> - Manager 1: Offlines memory blocks. Removes device.
> ^^^^
> - Manager 2: Detects offline memory blocks, re-onlines them.
>
> Add offline_and_remove_memory_ranges(), which takes an array of ranges
> and processes them as one operation under a single lock_device_hotplug():
>
> - Phase 1 offlines every block of every range.
> - Phase 2 removes the ranges only if all ranges are offline.
> - If any offline fails, the whole operation is reverted.
>
> This gives callers all-or-nothing semantics for the offline step, so a
> failed or interrupted unplug leaves the device in a consistent state.
>
> This also resolves the battling managers race - the second manager's
> operation simply fails when the block is destroyed / cannot be onlined.
>
> offline_and_remove_memory() becomes a thin wrapper that passes its single
> range to the new helper, so the offline/rollback logic lives in one place.
>
> Suggested-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Signed-off-by: Gregory Price <gourry@xxxxxxxxxx>
> ---

Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David