From: Andrea Reale <ar@linux.vnet.ibm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: m.bielski@virtualopensystems.com, ar@linux.vnet.ibm.com,
scott.branden@broadcom.com, will.deacon@arm.com,
qiuxishi@huawei.com, f.fainelli@gmail.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] Add "remove" probe driver for memory hot-remove
Date: Tue, 11 Apr 2017 15:56:04 +0100 [thread overview]
Message-ID: <0547052acd62958af1336281fcee8735c9d91d07.1491920514.git.ar@linux.vnet.ibm.com> (raw)
In-Reply-To: <cover.1491920513.git.ar@linux.vnet.ibm.com>
Allows to remove sections of memory that have been previously offlined
from userspace.
This is symmetric to the "memory probe" interface, as described in
Documentation/memory-hotplug.txt. It can be used to manually notify the
OS that one memory section has been removed.
Please, remind that a memory section can only be removed after it has
been logically off-lined; trying to remove a section which has not been
previously off-lined is not supported and will have undefined (but most
likely very bad) behaviour.
To offline a section one can:
# echo offline > /sys/devices/system/memory/memoryXXX/state
To use the remove interface to remove the section:
# echo $((0xYYYYYY)) > /sys/devices/system/memory/remove
where 0xYYYYYY is the physical address of the memory section to remove.
Signed-off-by: Andrea Reale <ar@linux.vnet.ibm.com>
Signed-off-by: Maciej Bielski <m.bielski@virtualopensystems.com>
---
drivers/base/memory.c | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index cc4f1d0..8e033b5 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -511,7 +511,36 @@ static DEVICE_ATTR(auto_online_blocks, 0644, show_auto_online_blocks,
}
static DEVICE_ATTR(probe, S_IWUSR, NULL, memory_probe_store);
-#endif
+
+#ifdef CONFIG_MEMORY_HOTREMOVE
+static ssize_t
+memory_remove_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ u64 phys_addr;
+ int nid, ret;
+ unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block;
+
+ ret = kstrtoull(buf, 0, &phys_addr);
+ if (ret)
+ return ret;
+
+ if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
+ return -EINVAL;
+
+ nid = memory_add_physaddr_to_nid(phys_addr);
+ ret = lock_device_hotplug_sysfs();
+ if (ret)
+ return ret;
+
+ remove_memory(nid, phys_addr,
+ MIN_MEMORY_BLOCK_SIZE * sections_per_block);
+ unlock_device_hotplug();
+ return count;
+}
+static DEVICE_ATTR(remove, S_IWUSR, NULL, memory_remove_store);
+#endif /* CONFIG_MEMORY_HOTREMOVE */
+#endif /* CONFIG_ARCH_MEMORY_PROBE */
#ifdef CONFIG_MEMORY_FAILURE
/*
@@ -776,6 +805,9 @@ bool is_memblock_offlined(struct memory_block *mem)
static struct attribute *memory_root_attrs[] = {
#ifdef CONFIG_ARCH_MEMORY_PROBE
&dev_attr_probe.attr,
+#ifdef CONFIG_MEMORY_HOTREMOVE
+ &dev_attr_remove.attr,
+#endif
#endif
#ifdef CONFIG_MEMORY_FAILURE
--
1.9.1
prev parent reply other threads:[~2017-04-11 14:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 14:54 [PATCH 0/5] Memory hotplug support for arm64 - complete patchset Andrea Reale
2017-04-11 14:54 ` [PATCH 1/5] arm64: memory-hotplug: Add MEMORY_HOTPLUG, MEMORY_HOTREMOVE, MEMORY_PROBE Andrea Reale
2017-04-12 0:20 ` kbuild test robot
2017-04-11 14:54 ` [PATCH 2/5] arm64: defconfig: enable MEMORY_HOTPLUG config options Andrea Reale
2017-04-11 14:55 ` [PATCH 3/5] Memory hotplug support for arm64 platform (v2) Andrea Reale
2017-04-11 15:58 ` Mark Rutland
2017-04-24 16:44 ` Maciej Bielski
2017-04-24 17:35 ` Maciej Bielski
2017-04-11 14:55 ` [PATCH 4/5] Hot-remove implementation for arm64 Andrea Reale
2017-04-11 17:12 ` Mark Rutland
2017-04-14 14:01 ` Andrea Reale
2017-04-18 18:21 ` Mark Rutland
2017-04-18 18:48 ` Ard Biesheuvel
2017-04-19 15:53 ` Laura Abbott
2017-04-21 10:05 ` Andrea Reale
2017-04-24 23:59 ` Laura Abbott
2017-04-21 10:02 ` Andrea Reale
2017-04-11 14:56 ` Andrea Reale [this message]
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=0547052acd62958af1336281fcee8735c9d91d07.1491920514.git.ar@linux.vnet.ibm.com \
--to=ar@linux.vnet.ibm.com \
--cc=f.fainelli@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.bielski@virtualopensystems.com \
--cc=qiuxishi@huawei.com \
--cc=scott.branden@broadcom.com \
--cc=will.deacon@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®