The patch titled Subject: mm/memory-hotplug: add sysfs hot-remove trigger has been added to the -mm tree. Its filename is mm-memory-hotplug-add-sysfs-hot-remove-trigger.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-memory-hotplug-add-sysfs-hot-remove-trigger.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-memory-hotplug-add-sysfs-hot-remove-trigger.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Robin Murphy <robin.murphy@xxxxxxx> Subject: mm/memory-hotplug: add sysfs hot-remove trigger ARCH_MEMORY_PROBE is a useful thing for testing and debugging hotplug, but being able to exercise the (arguably trickier) hot-remove path would be even more useful. Extend the feature to allow removal of offline sections to be triggered manually to aid development. Since process dictates the new sysfs entry be documented, let's also document the existing probe entry to match - better 13-and-a-half years late than never, as they say... Link: http://lkml.kernel.org/r/49ef5e6c12f5ede189419d4dcced5dc04957c34d.1549906631.git.robin.murphy@xxxxxxx Signed-off-by: Robin Murphy <robin.murphy@xxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: "Rafael J. Wysocki" <rafael@xxxxxxxxxx> Cc: Oscar Salvador <osalvador@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- Documentation/ABI/testing/sysfs-devices-memory | 25 ++++++++ drivers/base/memory.c | 42 ++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) --- a/Documentation/ABI/testing/sysfs-devices-memory~mm-memory-hotplug-add-sysfs-hot-remove-trigger +++ a/Documentation/ABI/testing/sysfs-devices-memory @@ -91,3 +91,28 @@ Description: memory section directory. For example, the following symbolic link is created for memory section 9 on node0. /sys/devices/system/node/node0/memory9 -> ../../memory/memory9 + +What: /sys/devices/system/memory/probe +Date: October 2005 +Contact: Linux Memory Management list <linux-mm@xxxxxxxxx> +Description: + The file /sys/devices/system/memory/probe is write-only, and + when written will simulate a physical hot-add of a memory + section at the given address. For example, assuming a section + of unused memory exists at physical address 0x80000000, it can + be introduced to the kernel with the following command: + # echo 0x80000000 > /sys/devices/system/memory/probe +Users: Memory hotplug testing and development + +What: /sys/devices/system/memory/memoryX/remove +Date: February 2019 +Contact: Linux Memory Management list <linux-mm@xxxxxxxxx> +Description: + The file /sys/devices/system/memory/memoryX/remove is + write-only, and when written with a boolean 'true' value will + simulate a physical hot-remove of that memory section. For + example, assuming a 1GB section size, the section added by the + above "probe" example could be removed again with the following + command: + # echo 1 > /sys/devices/system/memory/memory2/remove +Users: Memory hotplug testing and development --- a/drivers/base/memory.c~mm-memory-hotplug-add-sysfs-hot-remove-trigger +++ a/drivers/base/memory.c @@ -521,7 +521,44 @@ out: } static DEVICE_ATTR_WO(probe); -#endif + +#ifdef CONFIG_MEMORY_HOTREMOVE +static ssize_t remove_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct memory_block *mem = to_memory_block(dev); + unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr); + bool remove; + int ret; + + ret = kstrtobool(buf, &remove); + if (ret) + return ret; + if (!remove) + return count; + + if (!is_memblock_offlined(mem)) + return -EBUSY; + + ret = lock_device_hotplug_sysfs(); + if (ret) + return ret; + + if (device_remove_file_self(dev, attr)) { + __remove_memory(pfn_to_nid(start_pfn), PFN_PHYS(start_pfn), + MIN_MEMORY_BLOCK_SIZE * sections_per_block); + ret = count; + } else { + ret = -EBUSY; + } + + unlock_device_hotplug(); + return ret; +} + +static DEVICE_ATTR_WO(remove); +#endif /* CONFIG_MEMORY_HOTREMOVE */ +#endif /* CONFIG_ARCH_MEMORY_PROBE */ #ifdef CONFIG_MEMORY_FAILURE /* @@ -615,6 +652,9 @@ static struct attribute *memory_memblk_a &dev_attr_removable.attr, #ifdef CONFIG_MEMORY_HOTREMOVE &dev_attr_valid_zones.attr, +#ifdef CONFIG_ARCH_MEMORY_PROBE + &dev_attr_remove.attr, +#endif #endif NULL }; _ Patches currently in -mm which might be from robin.murphy@xxxxxxx are mm-memory-hotplug-add-sysfs-hot-remove-trigger.patch