[PATCH v7 00/10] dax/kmem: atomic whole-device hotplug via sysfs
From: Gregory Price
Date: Sun Jul 12 2026 - 11:45:21 EST
The dax kmem driver onlines memory during probe using the system
default policy, with no atomic control for the state of an entire
region at runtime - only by toggling individual memory blocks.
Offlining and removing a whole region therefore races with other
userland controllers that interfere between the two steps.
This series adds a sysfs "state" attribute for atomic whole-device
hotplug control, plus the mm and dax plumbing to support it.
Transitions are atomic across every range of the device. The state
names mirror the per-block memoryX/state ABI with one modification:
- "unplugged": memory blocks are not present
- "online": online as system RAM, zone chosen by the kernel
- "online_kernel": online in ZONE_NORMAL
- "online_movable": online in ZONE_MOVABLE
"offline" (blocks present but offline) is reportable for backward
compatibility but is not writable because it entices the race condition
we are trying to solve (separate atomic steps for offline and unplug).
'unplugged' (atomic offline+remove of the whole device) is the new
capability provided by the new kmem sysfs attribute.
dax/kmem probe still creates the memory blocks by default when the
default policy is "offline", to preserve backwards compatibility.
mm preparation:
1. mm/memory: add memory_block_aligned_range() helper.
2. mm/memory_hotplug: add mhp_online_type_to_str() and export the
online-type string helpers.
3. mm/memory_hotplug: pass online_type to online_memory_block().
4. mm/memory_hotplug: export mhp_get_default_online_type().
5. mm/memory_hotplug: add __add_memory_driver_managed() so a driver can
select the online policy. The override is restricted to in-tree
modules via EXPORT_SYMBOL_FOR_MODULES().
6. mm/memory_hotplug: add offline_and_remove_memory_ranges() for atomic,
all-or-nothing offline+remove of several ranges under a single
lock_device_hotplug().
dax/kmem:
7. Resolve mhp default online type at probe time
8. Extract hotplug/hotremove into helper functions (refactor).
9. Add the "state" sysfs attribute.
10. selftests/dax: regression test for the attribute.
---
v7 changes
- picked up tags
- dropped !data checks (Dan)
- re-defined 'DAX_KMEM_UNPLUGGED (-1)' (Dan)
- converted `state` to static ATTRIBUTE_GROUPS (Dan)
- dropped DEFAULT until later commit with per-driver settings (Dan)
- state_store now frees reservations on total hotplug failure (sashiko)
- kmalloc_array -> kmalloc_objs (Dan)
- unbind reworked to just remove_memory() (still never offlines, no deadlock)
- added memoryN/state and daxX.Y/state desync test
- gated destructive unbind tests behind DAX_KMEM_TEST_UNBIND
- added DAX_KMEM_TEST_DEV environment variable for target dax device
- added comment in offline_and_remove_memory_ranges for clarity
- minor spellcheck, whitespace, doc fixups
Gregory Price (10):
mm/memory: add memory_block_aligned_range() helper
mm/memory_hotplug: add mhp_online_type_to_str() and export string
helpers
mm/memory_hotplug: pass online_type to online_memory_block() via arg
mm/memory_hotplug: export mhp_get_default_online_type
mm/memory_hotplug: add __add_memory_driver_managed() with online_type
arg
mm/memory_hotplug: add offline_and_remove_memory_ranges()
dax/kmem: resolve default online type at probe time
dax/kmem: extract hotplug/hotremove helper functions
dax/kmem: add sysfs interface for atomic whole-device hotplug
selftests/dax: add dax/kmem hotplug sysfs regression test
Documentation/ABI/testing/sysfs-bus-dax | 24 +
drivers/base/memory.c | 9 +
drivers/dax/bus.h | 2 +
drivers/dax/kmem.c | 500 ++++++++++++++----
include/linux/memory.h | 27 +
include/linux/memory_hotplug.h | 14 +
mm/memory_hotplug.c | 162 ++++--
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/dax/Makefile | 6 +
tools/testing/selftests/dax/config | 4 +
.../testing/selftests/dax/dax-kmem-hotplug.sh | 317 +++++++++++
tools/testing/selftests/dax/settings | 1 +
12 files changed, 928 insertions(+), 139 deletions(-)
create mode 100644 tools/testing/selftests/dax/Makefile
create mode 100644 tools/testing/selftests/dax/config
create mode 100755 tools/testing/selftests/dax/dax-kmem-hotplug.sh
create mode 100644 tools/testing/selftests/dax/settings
--
2.53.0-Meta