Skip to contentSkip to conversation

Allow persistent memory to be used like normal RAM

PATCH In review Dave Hansen 9 participants 26 messages Oct 22, 2018 – Dec 3, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Allow persistent memory to be used like normal RAM

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

Here's how I set up a system to test this thing:

1. Boot qemu with lots of memory: "-m 4096", for instance
2. Reserve 512MB of physical memory. Reserving a spot a 2GB physical seems to work: memmap=512M!0x0000000080000000 This will end up looking like a pmem device at boot.
3. When booted, convert fsdax device to "device dax":
ndctl create-namespace -fe namespace0.0 -m dax
4. In the background, the kmem driver will probably bind to the new device.
5. Now, online the new memory sections. Perhaps:

grep ^MemTotal /proc/meminfo
for f in grep -vl online /sys/devices/system/memory/*/state; do
echo $f: cat $f
echo online > $f
grep ^MemTotal /proc/meminfo
done

Cc: Dan Williams <[email protected]>
Cc: Dave Jiang <[email protected]>
Cc: Ross Zwisler <[email protected]>
Cc: Vishal Verma <[email protected]>
Cc: Tom Lendacky <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Huang Ying <[email protected]>
Cc: Fengguang Wu <[email protected]>
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#1 lore raw

PATCH 1/9 mm/resource: return real error codes from walk failures

walk_system_ram_range() can return an error code either becuase *it* failed, or because the 'func' that it calls returned an error. The memory hotplug does the following:

        ret = walk_system_ram_range(..., func);
        if (ret)
		return ret;

and 'ret' makes it out to userspace, eventually. The problem is, walk_system_ram_range() failues that result from *it* failing (as opposed to 'func') return -1. That leads to a very odd -EPERM (-1) return code out to userspace.

Make walk_system_ram_range() return -EINVAL for internal failures to keep userspace less confused.

This return code is compatible with all the callers that I audited.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/kernel/resource.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/resource.c renamed from kernel/resource.c~memory-hotplug-walk_system_ram_range-returns-neg-1 +2 -2
diff -puN kernel/resource.c~memory-hotplug-walk_system_ram_range-returns-neg-1 kernel/resource.c
@@ -375,7 +375,7 @@ static int __walk_iomem_res_desc(resourc
 				 int (*func)(struct resource *, void *))
 {
 	struct resource res;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	while (start < end &&
 	       !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) {
@@ -453,7 +453,7 @@ int walk_system_ram_range(unsigned long
 	unsigned long flags;
 	struct resource res;
 	unsigned long pfn, end_pfn;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	start = (u64) start_pfn << PAGE_SHIFT;
 	end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw

PATCH 2/9 dax: kernel memory driver for mm ownership of DAX

In reply to Dave Hansen

Add the actual driver to which will own the DAX range. This allows very nice party with the other possible "owners" of a DAX region: device DAX and filesystem DAX. It also greatly simplifies the process of handing off control of the memory between the different owners since it's just a matter of unbinding and rebinding the device to different drivers.

I tried to do this all internally to the kernel and the locking and "self-destruction" of the old device context was a nightmare. Having userspace drive it is a wonderful simplification.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/dax/kmem.c |  152 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 152 insertions(+)
drivers/dax/kmem.c new file +152 -0
diff -puN /dev/null drivers/dax/kmem.c
@@ -0,0 +1,152 @@
+// this just just a copy of drivers/dax/pmem.c with
+// s/dax_pmem/dax_kmem' for now.
+//
+// need real license
+/*
+ * Copyright(c) 2016-2018 Intel Corporation. All rights reserved.
+ */
+#include <linux/percpu-refcount.h>
+#include <linux/memremap.h>
+#include <linux/module.h>
+#include <linux/pfn_t.h>
+#include "../nvdimm/pfn.h"
+#include "../nvdimm/nd.h"
+#include "device-dax.h"
+
+struct dax_kmem {
+	struct device *dev;
+	struct percpu_ref ref;
+	struct dev_pagemap pgmap;
+	struct completion cmp;
+};
+
+static struct dax_kmem *to_dax_kmem(struct percpu_ref *ref)
+{
+	return container_of(ref, struct dax_kmem, ref);
+}
+
+static void dax_kmem_percpu_release(struct percpu_ref *ref)
+{
+	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+
+	dev_dbg(dax_kmem->dev, "trace\n");
+	complete(&dax_kmem->cmp);
+}
+
+static void dax_kmem_percpu_exit(void *data)
+{
+	struct percpu_ref *ref = data;
+	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+
+	dev_dbg(dax_kmem->dev, "trace\n");
+	wait_for_completion(&dax_kmem->cmp);
+	percpu_ref_exit(ref);
+}
+
+static void dax_kmem_percpu_kill(void *data)
+{
+	struct percpu_ref *ref = data;
+	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+
+	dev_dbg(dax_kmem->dev, "trace\n");
+	percpu_ref_kill(ref);
+}
+
+static int dax_kmem_probe(struct device *dev)
+{
+	void *addr;
+	struct resource res;
+	int rc, id, region_id;
+	struct nd_pfn_sb *pfn_sb;
+	struct dev_dax *dev_dax;
+	struct dax_kmem *dax_kmem;
+	struct nd_namespace_io *nsio;
+	struct dax_region *dax_region;
+	struct nd_namespace_common *ndns;
+	struct nd_dax *nd_dax = to_nd_dax(dev);
+	struct nd_pfn *nd_pfn = &nd_dax->nd_pfn;
+
+	ndns = nvdimm_namespace_common_probe(dev);
+	if (IS_ERR(ndns))
+		return PTR_ERR(ndns);
+	nsio = to_nd_namespace_io(&ndns->dev);
+
+	dax_kmem = devm_kzalloc(dev, sizeof(*dax_kmem), GFP_KERNEL);
+	if (!dax_kmem)
+		return -ENOMEM;
+
+	/* parse the 'pfn' info block via ->rw_bytes */
+	rc = devm_nsio_enable(dev, nsio);
+	if (rc)
+		return rc;
+	rc = nvdimm_setup_pfn(nd_pfn, &dax_kmem->pgmap);
+	if (rc)
+		return rc;
+	devm_nsio_disable(dev, nsio);
+
+	pfn_sb = nd_pfn->pfn_sb;
+
+	if (!devm_request_mem_region(dev, nsio->res.start,
+				resource_size(&nsio->res),
+				dev_name(&ndns->dev))) {
+		dev_warn(dev, "could not reserve region %pR\n", &nsio->res);
+		return -EBUSY;
+	}
+
+	dax_kmem->dev = dev;
+	init_completion(&dax_kmem->cmp);
+	rc = percpu_ref_init(&dax_kmem->ref, dax_kmem_percpu_release, 0,
+			GFP_KERNEL);
+	if (rc)
+		return rc;
+
+	rc = devm_add_action_or_reset(dev, dax_kmem_percpu_exit,
+							&dax_kmem->ref);
+	if (rc)
+		return rc;
+
+	dax_kmem->pgmap.ref = &dax_kmem->ref;
+	addr = devm_memremap_pages(dev, &dax_kmem->pgmap);
+	if (IS_ERR(addr))
+		return PTR_ERR(addr);
+
+	rc = devm_add_action_or_reset(dev, dax_kmem_percpu_kill,
+							&dax_kmem->ref);
+	if (rc)
+		return rc;
+
+	/* adjust the dax_region resource to the start of data */
+	memcpy(&res, &dax_kmem->pgmap.res, sizeof(res));
+	res.start += le64_to_cpu(pfn_sb->dataoff);
+
+	rc = sscanf(dev_name(&ndns->dev), "namespace%d.%d", &region_id, &id);
+	if (rc != 2)
+		return -EINVAL;
+
+	dax_region = alloc_dax_region(dev, region_id, &res,
+			le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP);
+	if (!dax_region)
+		return -ENOMEM;
+
+	/* TODO: support for subdividing a dax region... */
+	dev_dax = devm_create_dev_dax(dax_region, id, &res, 1);
+
+	/* child dev_dax instances now own the lifetime of the dax_region */
+	dax_region_put(dax_region);
+
+	return PTR_ERR_OR_ZERO(dev_dax);
+}
+
+static struct nd_device_driver dax_kmem_driver = {
+	.probe = dax_kmem_probe,
+	.drv = {
+		.name = "dax_kmem",
+	},
+	.type = ND_DRIVER_DAX_PMEM,
+};
+
+module_nd_driver(dax_kmem_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Intel Corporation");
+MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

Re: [PATCH 2/9] dax: kernel memory driver for mm ownership of DAX

Quoted 2 lines · Dave Hansen

Add the actual driver to which will own the DAX range. This allows very nice party with the other possible "owners" of

Good to see a nice party sometimes. :)

Quoted 4 lines

a DAX region: device DAX and filesystem DAX. It also greatly simplifies the process of handing off control of the memory between the different owners since it's just a matter of unbinding and rebinding the device to different drivers.

Signature · 1 line
~Randy
#4 lore raw

PATCH 3/9 dax: add more kmem device infrastructure

In reply to Dave Hansen

The previous patch is a simple copy of the pmem driver. This makes it easy while this is in development to keep the pmem and kmem code in sync.

This actually adds some necessary infrastructure for the new driver to compile.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/dax/kmem.c         |   10 +++++-----
 b/include/uapi/linux/ndctl.h |    2 ++
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/dax/kmem.c renamed from drivers/dax/kmem.c~dax-kmem-try-again-2018-2-header +5 -5
diff -puN drivers/dax/kmem.c~dax-kmem-try-again-2018-2-header drivers/dax/kmem.c
@@ -27,7 +27,7 @@ static struct dax_kmem *to_dax_kmem(stru
 
 static void dax_kmem_percpu_release(struct percpu_ref *ref)
 {
-	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+	struct dax_kmem *dax_kmem = to_dax_kmem(ref);
 
 	dev_dbg(dax_kmem->dev, "trace\n");
 	complete(&dax_kmem->cmp);
@@ -36,7 +36,7 @@ static void dax_kmem_percpu_release(stru
 static void dax_kmem_percpu_exit(void *data)
 {
 	struct percpu_ref *ref = data;
-	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+	struct dax_kmem *dax_kmem = to_dax_kmem(ref);
 
 	dev_dbg(dax_kmem->dev, "trace\n");
 	wait_for_completion(&dax_kmem->cmp);
@@ -46,7 +46,7 @@ static void dax_kmem_percpu_exit(void *d
 static void dax_kmem_percpu_kill(void *data)
 {
 	struct percpu_ref *ref = data;
-	struct dax_kmem *dax_kmem = to_dax_pmem(ref);
+	struct dax_kmem *dax_kmem = to_dax_kmem(ref);
 
 	dev_dbg(dax_kmem->dev, "trace\n");
 	percpu_ref_kill(ref);
@@ -142,11 +142,11 @@ static struct nd_device_driver dax_kmem_
 	.drv = {
 		.name = "dax_kmem",
 	},
-	.type = ND_DRIVER_DAX_PMEM,
+	.type = ND_DRIVER_DAX_KMEM,
 };
 
 module_nd_driver(dax_kmem_driver);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Intel Corporation");
-MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_PMEM);
+MODULE_ALIAS_ND_DEVICE(ND_DEVICE_DAX_KMEM);
include/uapi/linux/ndctl.h renamed from include/uapi/linux/ndctl.h~dax-kmem-try-again-2018-2-header +2 -0
diff -puN include/uapi/linux/ndctl.h~dax-kmem-try-again-2018-2-header include/uapi/linux/ndctl.h
@@ -197,6 +197,7 @@ static inline const char *nvdimm_cmd_nam
 #define ND_DEVICE_NAMESPACE_PMEM 5  /* PMEM namespace (may alias with BLK) */
 #define ND_DEVICE_NAMESPACE_BLK 6   /* BLK namespace (may alias with PMEM) */
 #define ND_DEVICE_DAX_PMEM 7        /* Device DAX interface to pmem */
+#define ND_DEVICE_DAX_KMEM 8        /* Normal kernel-managed system memory */
 
 enum nd_driver_flags {
 	ND_DRIVER_DIMM            = 1 << ND_DEVICE_DIMM,
@@ -206,6 +207,7 @@ enum nd_driver_flags {
 	ND_DRIVER_NAMESPACE_PMEM  = 1 << ND_DEVICE_NAMESPACE_PMEM,
 	ND_DRIVER_NAMESPACE_BLK   = 1 << ND_DEVICE_NAMESPACE_BLK,
 	ND_DRIVER_DAX_PMEM	  = 1 << ND_DEVICE_DAX_PMEM,
+	ND_DRIVER_DAX_KMEM	  = 1 << ND_DEVICE_DAX_KMEM,
 };
 
 enum {

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#5 lore raw

PATCH 4/9 dax/kmem: allow PMEM devices to bind to KMEM driver

In reply to Dave Hansen

Currently, a persistent memory device's mode must be coordinated with the driver to which it needs to bind. To change it from the fsdax to the device-dax driver, you first change the mode of the device itself.

Instead of adding a new device mode, allow the PMEM mode to also bind to the KMEM driver.

As I write this, I'm realizing that it might have just been better to add a new device mode, rather than hijacking the PMEM eode. If this is the case, please speak up, NVDIMM folks. :)

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/nvdimm/bus.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/nvdimm/bus.c renamed from drivers/nvdimm/bus.c~dax-kmem-try-again-2018-3-bus-match-override +14 -1
diff -puN drivers/nvdimm/bus.c~dax-kmem-try-again-2018-3-bus-match-override drivers/nvdimm/bus.c
@@ -464,11 +464,24 @@ static struct nd_device_driver nd_bus_dr
 static int nvdimm_bus_match(struct device *dev, struct device_driver *drv)
 {
 	struct nd_device_driver *nd_drv = to_nd_device_driver(drv);
+	bool match;
 
 	if (is_nvdimm_bus(dev) && nd_drv == &nd_bus_driver)
 		return true;
 
-	return !!test_bit(to_nd_device_type(dev), &nd_drv->type);
+	match = !!test_bit(to_nd_device_type(dev), &nd_drv->type);
+
+	/*
+	 * We allow PMEM devices to be bound to the KMEM driver.
+	 * Force a match if we detect a PMEM device type but
+	 * a KMEM device driver.
+	 */
+	if (!match &&
+	    (to_nd_device_type(dev) == ND_DEVICE_DAX_PMEM) &&
+	    (nd_drv->type == ND_DRIVER_DAX_KMEM))
+		match = true;
+
+	return match;
 }
 
 static ASYNC_DOMAIN_EXCLUSIVE(nd_async_domain);

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#6 lore raw

PATCH 5/9 dax/kmem: add more nd dax kmem infrastructure

In reply to Dave Hansen

Each DAX mode has a set of wrappers and helpers. Add them for the kmem mode.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/nvdimm/bus.c      |    2 ++
 b/drivers/nvdimm/dax_devs.c |   35 +++++++++++++++++++++++++++++++++++
 b/drivers/nvdimm/nd.h       |    6 ++++++
 3 files changed, 43 insertions(+)
drivers/nvdimm/bus.c renamed from drivers/nvdimm/bus.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem +2 -0
diff -puN drivers/nvdimm/bus.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/bus.c
@@ -46,6 +46,8 @@ static int to_nd_device_type(struct devi
 		return ND_DEVICE_REGION_BLK;
 	else if (is_nd_dax(dev))
 		return ND_DEVICE_DAX_PMEM;
+	else if (is_nd_dax_kmem(dev))
+		return ND_DEVICE_DAX_KMEM;
 	else if (is_nd_region(dev->parent))
 		return nd_region_to_nstype(to_nd_region(dev->parent));
 
drivers/nvdimm/dax_devs.c renamed from drivers/nvdimm/dax_devs.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem +35 -0
diff -puN drivers/nvdimm/dax_devs.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/dax_devs.c
@@ -51,6 +51,41 @@ struct nd_dax *to_nd_dax(struct device *
 }
 EXPORT_SYMBOL(to_nd_dax);
 
+/* nd_dax_kmem */
+static void nd_dax_kmem_release(struct device *dev)
+{
+	struct nd_region *nd_region = to_nd_region(dev->parent);
+	struct nd_dax_kmem *nd_dax_kmem = to_nd_dax_kmem(dev);
+	struct nd_pfn *nd_pfn = &nd_dax_kmem->nd_pfn;
+
+	dev_dbg(dev, "trace\n");
+	nd_detach_ndns(dev, &nd_pfn->ndns);
+	ida_simple_remove(&nd_region->dax_ida, nd_pfn->id);
+	kfree(nd_pfn->uuid);
+	kfree(nd_dax_kmem);
+}
+
+static struct device_type nd_dax_kmem_device_type = {
+	.name = "nd_dax_kmem",
+	.release = nd_dax_kmem_release,
+};
+
+bool is_nd_dax_kmem(struct device *dev)
+{
+	return dev ? dev->type == &nd_dax_kmem_device_type : false;
+}
+EXPORT_SYMBOL(is_nd_dax_kmem);
+
+struct nd_dax_kmem *to_nd_dax_kmem(struct device *dev)
+{
+	struct nd_dax_kmem *nd_dax_kmem = container_of(dev, struct nd_dax_kmem, nd_pfn.dev);
+
+	WARN_ON(!is_nd_dax_kmem(dev));
+	return nd_dax_kmem;
+}
+EXPORT_SYMBOL(to_nd_dax_kmem);
+/* end nd_dax_kmem */
+
 static const struct attribute_group *nd_dax_attribute_groups[] = {
 	&nd_pfn_attribute_group,
 	&nd_device_attribute_group,
drivers/nvdimm/nd.h renamed from drivers/nvdimm/nd.h~dax-kmem-try-again-2018-4-bus-dev-type-kmem +6 -0
diff -puN drivers/nvdimm/nd.h~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/nd.h
@@ -215,6 +215,10 @@ struct nd_dax {
 	struct nd_pfn nd_pfn;
 };
 
+struct nd_dax_kmem {
+	struct nd_pfn nd_pfn;
+};
+
 enum nd_async_mode {
 	ND_SYNC,
 	ND_ASYNC,
@@ -318,9 +322,11 @@ static inline int nd_pfn_validate(struct
 #endif
 
 struct nd_dax *to_nd_dax(struct device *dev);
+struct nd_dax_kmem *to_nd_dax_kmem(struct device *dev);
 #if IS_ENABLED(CONFIG_NVDIMM_DAX)
 int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns);
 bool is_nd_dax(struct device *dev);
+bool is_nd_dax_kmem(struct device *dev);
 struct device *nd_dax_create(struct nd_region *nd_region);
 #else
 static inline int nd_dax_probe(struct device *dev,

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#7 lore raw

PATCH 6/9 mm/memory-hotplug: allow memory resources to be children

In reply to Dave Hansen

The mm/resource.c code is used to manage the physical address space. We can view the current resource configuration in /proc/iomem. An example of this is at the bottom of this description.

The nvdimm subsystem "owns" the physical address resources which map to persistent memory and has resources inserted for them as "Persistent Memory". We want to use this persistent memory, but as volatile memory, just like RAM. The best way to do this is to leave the existing resource in place, but add a "System RAM" resource underneath it. This clearly communicates the ownership relationship of this memory.

The request_resource_conflict() API only deals with the top-level resources. Replace it with __request_region() which will search for !IORESOURCE_BUSY areas lower in the resource tree than the top level.

We also rework the old error message a bit since we do not get the conflicting entry back: only an indication that we *had* a conflict.

We *could* also simply truncate the existing top-level "Persistent Memory" resource and take over the released address space. But, this means that if we ever decide to hot-unplug the "RAM" and give it back, we need to recreate the original setup, which may mean going back to the BIOS tables.

This should have no real effect on the existing collision detection because the areas that truly conflict should be marked IORESOURCE_BUSY.

00000000-00000fff : Reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : Reserved
000a0000-000bffff : PCI Bus 0000:00
000c0000-000c97ff : Video ROM
000c9800-000ca5ff : Adapter ROM
000f0000-000fffff : Reserved
000f0000-000fffff : System ROM
00100000-9fffffff : System RAM
01000000-01e071d0 : Kernel code
01e071d1-027dfdff : Kernel data
02dc6000-0305dfff : Kernel bss
a0000000-afffffff : Persistent Memory (legacy)
a0000000-a7ffffff : System RAM
b0000000-bffdffff : System RAM
bffe0000-bfffffff : Reserved
c0000000-febfffff : PCI Bus 0000:00

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/mm/memory_hotplug.c |   31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory-hotplug-allow-memory-resource-to-be-child +14 -17
diff -puN mm/memory_hotplug.c~mm-memory-hotplug-allow-memory-resource-to-be-child mm/memory_hotplug.c
@@ -99,24 +99,21 @@ void mem_hotplug_done(void)
 /* add this memory to iomem resource */
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
-	struct resource *res, *conflict;
-	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
-	if (!res)
-		return ERR_PTR(-ENOMEM);
+	struct resource *res;
+	unsigned long flags =  IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
+	char resource_name[] = "System RAM";
 
-	res->name = "System RAM";
-	res->start = start;
-	res->end = start + size - 1;
-	res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
-	conflict =  request_resource_conflict(&iomem_resource, res);
-	if (conflict) {
-		if (conflict->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY) {
-			pr_debug("Device unaddressable memory block "
-				 "memory hotplug at %#010llx !\n",
-				 (unsigned long long)start);
-		}
-		pr_debug("System RAM resource %pR cannot be added\n", res);
-		kfree(res);
+	/*
+	 * Request ownership of the new memory range.  This might be
+	 * a child of an existing resource that was present but
+	 * not marked as busy.
+	 */
+	res = __request_region(&iomem_resource, start, size,
+			       resource_name, flags);
+
+	if (!res) {
+		pr_debug("Unable to reserve System RAM region: %016llx->%016llx\n",
+				start, start + size);
 		return ERR_PTR(-EEXIST);
 	}
 	return res;

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#8 lore raw

PATCH 7/9 dax/kmem: actually perform memory hotplug

In reply to Dave Hansen

This is the meat of this whole series. When the "kmem" device's probe function is called and we know we have a good persistent memory device, hotplug the memory back into the main kernel.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/dax/kmem.c |   28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/dax/kmem.c renamed from drivers/dax/kmem.c~dax-kmem-hotplug +25 -3
diff -puN drivers/dax/kmem.c~dax-kmem-hotplug drivers/dax/kmem.c
@@ -55,10 +55,12 @@ static void dax_kmem_percpu_kill(void *d
 static int dax_kmem_probe(struct device *dev)
 {
 	void *addr;
+	int numa_node;
 	struct resource res;
 	int rc, id, region_id;
 	struct nd_pfn_sb *pfn_sb;
 	struct dev_dax *dev_dax;
+	struct resource *new_res;
 	struct dax_kmem *dax_kmem;
 	struct nd_namespace_io *nsio;
 	struct dax_region *dax_region;
@@ -86,13 +88,30 @@ static int dax_kmem_probe(struct device
 
 	pfn_sb = nd_pfn->pfn_sb;
 
-	if (!devm_request_mem_region(dev, nsio->res.start,
-				resource_size(&nsio->res),
-				dev_name(&ndns->dev))) {
+	new_res = devm_request_mem_region(dev, nsio->res.start,
+					  resource_size(&nsio->res),
+					  "System RAM (pmem)");
+	if (!new_res) {
 		dev_warn(dev, "could not reserve region %pR\n", &nsio->res);
 		return -EBUSY;
 	}
 
+	/*
+	 * Set flags appropriate for System RAM.  Leave ..._BUSY clear
+	 * so that add_memory() can add a child resource.
+	 */
+	new_res->flags = IORESOURCE_SYSTEM_RAM;
+
+	numa_node = dev_to_node(dev);
+	if (numa_node < 0) {
+		pr_warn_once("bad numa_node: %d, forcing to 0\n", numa_node);
+		numa_node = 0;
+	}
+
+	rc = add_memory(numa_node, nsio->res.start, resource_size(&nsio->res));
+	if (rc)
+		return rc;
+
 	dax_kmem->dev = dev;
 	init_completion(&dax_kmem->cmp);
 	rc = percpu_ref_init(&dax_kmem->ref, dax_kmem_percpu_release, 0,
@@ -106,6 +125,9 @@ static int dax_kmem_probe(struct device
 		return rc;
 
 	dax_kmem->pgmap.ref = &dax_kmem->ref;
+
+	dax_kmem->pgmap.res.name = "name_kmem_override2";
+
 	addr = devm_memremap_pages(dev, &dax_kmem->pgmap);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#9 lore raw

PATCH 8/9 dax/kmem: let walk_system_ram_range() search child resources

In reply to Dave Hansen

In the process of onlining memory, we use walk_system_ram_range() to find the actual RAM areas inside of the area being onlined.

However, it currently only finds memory resources which are "top-level" iomem_resources. Children are not currently searched which causes it to skip System RAM in areas like this (in the format of /proc/iomem):

a0000000-bfffffff : Persistent Memory (legacy)
a0000000-afffffff : System RAM

Changing the true->false here allows children to be searched as well. We need this because we add a new "System RAM" resource underneath the "persistent memory" resource when we use persistent memory in a volatile mode.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/kernel/resource.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/resource.c renamed from kernel/resource.c~mm-walk_system_ram_range-search-child-resources +4 -1
diff -puN kernel/resource.c~mm-walk_system_ram_range-search-child-resources kernel/resource.c
@@ -445,6 +445,9 @@ int walk_mem_res(u64 start, u64 end, voi
  * This function calls the @func callback against all memory ranges of type
  * System RAM which are marked as IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY.
  * It is to be used only for System RAM.
+ *
+ * This will find System RAM ranges that are children of top-level resources
+ * in addition to top-level System RAM resources.
  */
 int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
 			  void *arg, int (*func)(unsigned long, unsigned long, void *))
@@ -460,7 +463,7 @@ int walk_system_ram_range(unsigned long
 	flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
 	while (start < end &&
 	       !find_next_iomem_res(start, end, flags, IORES_DESC_NONE,
-				    true, &res)) {
+				    false, &res)) {
 		pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
 		end_pfn = (res.end + 1) >> PAGE_SHIFT;
 		if (end_pfn > pfn)

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#10 lore raw

PATCH 9/9 dax/kmem: actually enable the code in Makefile

In reply to Dave Hansen

Most of the new code was dead up to this point. Now that all the pieces are in place, enable it.

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

---

 b/drivers/dax/Makefile |    2 ++
 1 file changed, 2 insertions(+)
drivers/dax/Makefile renamed from drivers/dax/Makefile~dax-kmem-makefile +2 -0
diff -puN drivers/dax/Makefile~dax-kmem-makefile drivers/dax/Makefile
@@ -2,7 +2,9 @@
 obj-$(CONFIG_DAX) += dax.o
 obj-$(CONFIG_DEV_DAX) += device_dax.o
 obj-$(CONFIG_DEV_DAX_PMEM) += dax_pmem.o
+obj-$(CONFIG_DEV_DAX_PMEM) += dax_kmem.o
 
 dax-y := super.o
 dax_pmem-y := pmem.o
+dax_kmem-y := kmem.o
 device_dax-y := device.o

_
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#11 lore raw
In reply to Dave Hansen
Quoted 20 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Quoted 11 lines

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

So I don't think we want to do patch 2, 3, or 5. Just jump to patch 7 and remove all the devm_memremap_pages() infrastructure and dax_region infrastructure.

The driver should be a dead simple turn around to call add_memory() for the passed in range. The hard part is, as you say, arranging for the kmem driver to not stand in the way of typical range / device claims by the dax_pmem device.

To me this looks like teaching the nvdimm-bus and this dax_kmem driver to require explicit matching based on 'id'. The attachment scheme would look like this:

modprobe dax_kmem
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/new_id
echo dax0.0 > /sys/bus/nd/drivers/dax_pmem/unbind
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/bind

At step1 the dax_kmem drivers will match no devices and stays out of the way of dax_pmem. It learns about devices it cares about by being explicitly told about them. Then unbind from the typical dax_pmem driver and attach to dax_kmem to perform the one way hotplug.

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

#12 lore raw
Quoted 52 lines · Dan Williams
Quoted 20 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Quoted 11 lines

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

So I don't think we want to do patch 2, 3, or 5. Just jump to patch 7 and remove all the devm_memremap_pages() infrastructure and dax_region infrastructure.

The driver should be a dead simple turn around to call add_memory() for the passed in range. The hard part is, as you say, arranging for the kmem driver to not stand in the way of typical range / device claims by the dax_pmem device.

To me this looks like teaching the nvdimm-bus and this dax_kmem driver to require explicit matching based on 'id'. The attachment scheme would look like this:

modprobe dax_kmem
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/new_id
echo dax0.0 > /sys/bus/nd/drivers/dax_pmem/unbind
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/bind

Quoted 8 lines

At step1 the dax_kmem drivers will match no devices and stays out of the way of dax_pmem. It learns about devices it cares about by being explicitly told about them. Then unbind from the typical dax_pmem driver and attach to dax_kmem to perform the one way hotplug.

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

The next question is how to support this for ranges that don't originate from the pmem sub-system. I expect we want dax_kmem to register a generic platform device representing the range and have a generic platofrm driver that turns around and does the add_memory().

#13 lore raw

Hi Dan,

How about let the BIOS report a new type for kmem in e820 table? e.g.
#define E820_PMEM 7
#define E820_KMEM 8

Then pmem and kmem are separately, and we can easily hotadd kmem to the memory subsystem, no disturb the existing code (e.g. pmem, nvdimm, dax...).

I don't know whether Intel will change some hardware features for pmem which used like a volatility memory in the future. Perhaps faster than pmem, cheaper, but volatility, and no need to care about atomicity, consistency, L2/L3 cache...

Another question, why call it kmem? what does the "k" mean?

Thanks,
Xishi Qiu

Quoted 67 lines · Dan Williams
Quoted 52 lines · Dan Williams
Quoted 20 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Quoted 11 lines

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

So I don't think we want to do patch 2, 3, or 5. Just jump to patch 7 and remove all the devm_memremap_pages() infrastructure and dax_region infrastructure.

The driver should be a dead simple turn around to call add_memory() for the passed in range. The hard part is, as you say, arranging for the kmem driver to not stand in the way of typical range / device claims by the dax_pmem device.

To me this looks like teaching the nvdimm-bus and this dax_kmem driver to require explicit matching based on 'id'. The attachment scheme would look like this:

modprobe dax_kmem
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/new_id
echo dax0.0 > /sys/bus/nd/drivers/dax_pmem/unbind
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/bind

Quoted 8 lines

At step1 the dax_kmem drivers will match no devices and stays out of the way of dax_pmem. It learns about devices it cares about by being explicitly told about them. Then unbind from the typical dax_pmem driver and attach to dax_kmem to perform the one way hotplug.

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

The next question is how to support this for ranges that don't originate from the pmem sub-system. I expect we want dax_kmem to register a generic platform device representing the range and have a generic platofrm driver that turns around and does the add_memory().

#14 lore raw
Quoted 4 lines · Xishi Qiu

How about let the BIOS report a new type for kmem in e820 table? e.g.
#define E820_PMEM 7
#define E820_KMEM 8

It would be best if the BIOS just did this all for us. But, what you're describing would take years to get from concept to showing up in someone's hands. I'd rather not wait.

Plus, doing it the way I suggested gives the OS the most control. The BIOS isn't in the critical path to do the right thing.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#15 lore raw
In reply to Dan Williams
Quoted 59 lines · Dan Williams
Quoted 57 lines · Dan Williams
Quoted 20 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Quoted 11 lines

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

So I don't think we want to do patch 2, 3, or 5. Just jump to patch 7 and remove all the devm_memremap_pages() infrastructure and dax_region infrastructure.

The driver should be a dead simple turn around to call add_memory() for the passed in range. The hard part is, as you say, arranging for the kmem driver to not stand in the way of typical range / device claims by the dax_pmem device.

To me this looks like teaching the nvdimm-bus and this dax_kmem driver to require explicit matching based on 'id'. The attachment scheme would look like this:

modprobe dax_kmem
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/new_id
echo dax0.0 > /sys/bus/nd/drivers/dax_pmem/unbind
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/bind

At step1 the dax_kmem drivers will match no devices and stays out of the way of dax_pmem. It learns about devices it cares about by being explicitly told about them. Then unbind from the typical dax_pmem driver and attach to dax_kmem to perform the one way hotplug.

Quoted 8 lines
Quoted 3 lines

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

The next question is how to support this for ranges that don't originate from the pmem sub-system. I expect we want dax_kmem to register a generic platform device representing the range and have a generic platofrm driver that turns around and does the add_memory().

I forgot I have some old patches that do something along these lines and make device-dax it's own bus. I'll dust those off so we can discern what's left.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#16 lore raw
In reply to Dan Williams
Quoted 8 lines

-----Original Message-----
From: Linux-nvdimm [mailto:[email protected]] On Behalf Of Dan Williams
Sent: Monday, October 22, 2018 8:05 PM
Subject: Re: [PATCH 0/9] Allow persistent memory to be used like normal RAM

On Mon, Oct 22, 2018 at 1:18 PM Dave Hansen <[email protected]> wrote:

...

Quoted 3 lines

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On

Would this memory be considered volatile (with the driver initializing it to zeros), or persistent (contents are presented unchanged, applications may guarantee persistence by using cache flush instructions, fence instructions, and writing to flush hint addresses per the persistent memory programming model)?

Quoted 3 lines
Quoted 3 lines

1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.

...

Quoted 9 lines

To me this looks like teaching the nvdimm-bus and this dax_kmem driver to require explicit matching based on 'id'. The attachment scheme would look like this:

modprobe dax_kmem
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/new_id
echo dax0.0 > /sys/bus/nd/drivers/dax_pmem/unbind
echo dax0.0 > /sys/bus/nd/drivers/dax_kmem/bind

Quoted 8 lines

At step1 the dax_kmem drivers will match no devices and stays out of the way of dax_pmem. It learns about devices it cares about by being explicitly told about them. Then unbind from the typical dax_pmem driver and attach to dax_kmem to perform the one way hotplug.

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

Where would that rule be stored? Storing it on another device is problematic. If that rule is lost, it could confuse other drivers trying to grab device DAX devices for use as persistent memory.

A new namespace mode would record the intended usage in the device itself, eliminating dependencies. It could join the other modes like:

ndctl create-namespace -m raw
create /dev/pmem4 block device
ndctl create-namespace -m sector
create /dev/pmem4s block device
ndctl create-namespace -m fsdax
create /dev/pmem4 block device
ndctl create-namespace -m devdax
create /dev/dax4.3 character device for use as persistent memory
ndctl create-namespace -m mem
create /dev/mem4.3 character device for use as volatile memory

---
Robert Elliott, HPE Persistent Memory

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#17 lore raw
Quoted 9 lines
Quoted 3 lines

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On

Would this memory be considered volatile (with the driver initializing it to zeros), or persistent (contents are presented unchanged, applications may guarantee persistence by using cache flush instructions, fence instructions, and writing to flush hint addresses per the persistent memory programming model)?

Volatile.

Quoted 8 lines
Quoted 3 lines

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

Where would that rule be stored? Storing it on another device is problematic. If that rule is lost, it could confuse other drivers trying to grab device DAX devices for use as persistent memory.

Well, we do lots of things like stable device naming from udev scripts.
We depend on them not being lost. At least this "fails safe" so we'll
default to persistence instead of defaulting to "eat your data".

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#18 lore raw
Quoted 17 lines · Dave Hansen
Quoted 10 lines
Quoted 4 lines

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On

Would this memory be considered volatile (with the driver initializing it to zeros), or persistent (contents are presented unchanged, applications may guarantee persistence by using cache flush instructions, fence instructions, and writing to flush hint addresses per the persistent memory programming model)?

Volatile.

Quoted 4 lines
Quoted 3 lines

I expect udev can automate this by setting up a rule to watch for device-dax instances by UUID and call a script to do the detach / reattach dance.

Quoted 9 lines
Quoted 4 lines

Where would that rule be stored? Storing it on another device is problematic. If that rule is lost, it could confuse other drivers trying to grab device DAX devices for use as persistent memory.

Well, we do lots of things like stable device naming from udev scripts.
We depend on them not being lost. At least this "fails safe" so we'll
default to persistence instead of defaulting to "eat your data".

Right, and at least for the persistent memory to volatile conversion case we will have the UUID to positively identify the DAX device. So it will indeed "fail safe" and just become a dax_pmem device again if the configuration is lost. We'll likely need to create/use a "by-path" scheme for non-pmem use cases.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#19 lore raw
In reply to Dave Hansen

Hi Dave,

This patchset hotadd a pmem and use it like a normal DRAM, I have some questions here, and I think my production line may also concerned.

1) How to set the AEP (Apache Pass) usage percentage for one process (or a vma)?
e.g. there are two vms from two customers, they pay different money for the vm. So if we alloc and convert AEP/DRAM by global, the high load vm may get 100% DRAM, and the low load vm may get 100% AEP, this is unfair. The low load is compared to another one, for himself, the actual low load maybe is high load.

2) I find page idle only check the access bit, _PAGE_BIT_ACCESSED, as we know AEP read performance is much higher than write, so I think we should also check the dirty bit, _PAGE_BIT_DIRTY. Test and clear dirty bit is safe for anon page, but unsafe for file page, e.g. should call clear_page_dirty_for_io first, right?

3) I think we should manage the AEP memory separately instead of together with the DRAM. Manage them together maybe change less code, but it will cause some problems at high priority DRAM allocation if there is no DRAM, then should convert (steal DRAM) from another one, it takes much time.
How about create a new zone, e.g. ZONE_AEP, and use madvise to set a new flag VM_AEP, which will enable the vma to alloc AEP memory in page fault later, then use vma_rss_stat(like mm_rss_stat) to control the AEP usage percentage for a vma.

4) I am interesting about the conversion mechanism betweent AEP and DRAM. I think numa balancing will cause page fault, this is unacceptable for some apps, it cause performance jitter. And the kswapd is not precise enough. So use a daemon kernel thread (like khugepaged) maybe a good solution, add the AEP used processes to a list, then scan the VM_AEP marked vmas, get the access state, and do the conversion.

Thanks,
Xishi Qiu

Quoted 63 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

Here's how I set up a system to test this thing:

1. Boot qemu with lots of memory: "-m 4096", for instance
2. Reserve 512MB of physical memory. Reserving a spot a 2GB physical seems to work: memmap=512M!0x0000000080000000 This will end up looking like a pmem device at boot.
3. When booted, convert fsdax device to "device dax":
ndctl create-namespace -fe namespace0.0 -m dax
4. In the background, the kmem driver will probably bind to the new device.
5. Now, online the new memory sections. Perhaps:

grep ^MemTotal /proc/meminfo
for f in grep -vl online /sys/devices/system/memory/*/state; do
echo $f: cat $f
echo online > $f
grep ^MemTotal /proc/meminfo
done

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>
#20 lore raw

Hi Xishi,

I can help answer the migration and policy related questions.

Quoted 6 lines · Xishi Qiu

Hi Dave,

This patchset hotadd a pmem and use it like a normal DRAM, I have some questions here, and I think my production line may also concerned.

Quoted 7 lines

1) How to set the AEP (Apache Pass) usage percentage for one process (or a vma)?
e.g. there are two vms from two customers, they pay different money for the vm. So if we alloc and convert AEP/DRAM by global, the high load vm may get 100% DRAM, and the low load vm may get 100% AEP, this is unfair. The low load is compared to another one, for himself, the actual low load maybe is high load.

Per VM, process, VMA policies are possible. They can be implemented in user space migration daemon. We can dip into details when user space code is released.

Quoted 3 lines

2) I find page idle only check the access bit, _PAGE_BIT_ACCESSED, as we know AEP read performance is much higher than write, so I think we should also check the dirty bit, _PAGE_BIT_DIRTY. Test

Yeah dirty bit could be considered later. The initial version will only check accessed bit.

Quoted 2 lines

and clear dirty bit is safe for anon page, but unsafe for file page, e.g. should call clear_page_dirty_for_io first, right?

We'll only migrate anonymous pages in the initial version.

Quoted 2 lines

3) I think we should manage the AEP memory separately instead of together with the DRAM.

I guess the intention of this patchset is to use different NUMA nodes for AEP and DRAM.

Quoted 9 lines

Manage them together maybe change less
code, but it will cause some problems at high priority DRAM allocation if there is no DRAM, then should convert (steal DRAM) from another one, it takes much time.
How about create a new zone, e.g. ZONE_AEP, and use madvise to set a new flag VM_AEP, which will enable the vma to alloc AEP memory in page fault later, then use vma_rss_stat(like mm_rss_stat) to control the AEP usage percentage for a vma.

Quoted 3 lines

4) I am interesting about the conversion mechanism betweent AEP and DRAM. I think numa balancing will cause page fault, this is unacceptable for some apps, it cause performance jitter. And the

NUMA balancing can be taught to be enabled per task. I'm not sure there is already such knob, but it looks easy to implement such a policy.

Quoted 4 lines

kswapd is not precise enough. So use a daemon kernel thread (like khugepaged) maybe a good solution, add the AEP used processes to a list, then scan the VM_AEP marked vmas, get the access state, and do the conversion.

If that's a desirable policy, our user space migration daemon could possibly do that, too.

Thanks,
Fengguang

Quoted 51 lines · Dave Hansen
Quoted 50 lines

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

Here's how I set up a system to test this thing:

1. Boot qemu with lots of memory: "-m 4096", for instance
2. Reserve 512MB of physical memory. Reserving a spot a 2GB physical seems to work: memmap=512M!0x0000000080000000 This will end up looking like a pmem device at boot.
3. When booted, convert fsdax device to "device dax":
ndctl create-namespace -fe namespace0.0 -m dax
4. In the background, the kmem driver will probably bind to the new device.
5. Now, online the new memory sections. Perhaps:

grep ^MemTotal /proc/meminfo
for f in grep -vl online /sys/devices/system/memory/*/state; do
echo $f: cat $f
echo online > $f
grep ^MemTotal /proc/meminfo
done

Quoted 14 lines
Quoted 4 lines
Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Quoted 9 lines
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#22 lore raw
In reply to Dave Hansen
Quoted 7 lines · Dave Hansen

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

Quoted 7 lines

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

Could you please elaborate this? I'm supposed you mean the pmem will be a separate NUMA node, right?

I would like to try the patches on real hardware, any prerequisite is needed?

Thanks,
Yang

Quoted 50 lines

This is highly RFC, and I really want the feedback from the nvdimm/pmem folks about whether this is a viable long-term perversion of their code and device mode. It's insufficiently documented and probably not bisectable either.

Todo:
1. The device re-binding hacks are ham-fisted at best. We need a better way of doing this, especially so the kmem driver does not get in the way of normal pmem devices.
2. When the device has no proper node, we default it to NUMA node 0. Is that OK?
3. We muck with the 'struct resource' code quite a bit. It definitely needs a once-over from folks more familiar with it than I.
4. Is there a better way to do this than starting with a copy of pmem.c?

Here's how I set up a system to test this thing:

1. Boot qemu with lots of memory: "-m 4096", for instance
2. Reserve 512MB of physical memory. Reserving a spot a 2GB physical seems to work: memmap=512M!0x0000000080000000 This will end up looking like a pmem device at boot.
3. When booted, convert fsdax device to "device dax":
ndctl create-namespace -fe namespace0.0 -m dax
4. In the background, the kmem driver will probably bind to the new device.
5. Now, online the new memory sections. Perhaps:

grep ^MemTotal /proc/meminfo
for f in grep -vl online /sys/devices/system/memory/*/state; do
echo $f: cat $f
echo online > $f
grep ^MemTotal /proc/meminfo
done

Cc Dan Williams <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Vishal Verma <[email protected]>
Cc Tom Lendacky <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Huang Ying <[email protected]>
Cc Fengguang Wu <[email protected]>
#23 lore raw
In reply to Dave Hansen

Le 22/10/2018 à 22:13, Dave Hansen a écrit :

Quoted 6 lines

Persistent memory is cool. But, currently, you have to rewrite your applications to use it. Wouldn't it be cool if you could just have it show up in your system like normal RAM and get to it like a slow blob of memory? Well... have I got the patch series for you!

Quoted 7 lines

This series adds a new "driver" to which pmem devices can be attached. Once attached, the memory "owned" by the device is hot-added to the kernel and managed like any other memory. On systems with an HMAT (a new ACPI table), each socket (roughly) will have a separate NUMA node for its persistent memory so this newly-added memory can be selected by its unique NUMA node.

Hello Dave

What happens on systems without an HMAT? Does this new memory get merged into existing NUMA nodes?

Also, do you plan to have a way for applications to find out which NUMA nodes are "real DRAM" while others are "pmem-backed"? (something like a new attribute in /sys/devices/system/node/nodeX/) Or should we use HMAT performance attributes for this?

Brice

#24 lore raw
Quoted 3 lines · Brice Goglin

Le 22/10/2018 à 22:13, Dave Hansen a écrit :
What happens on systems without an HMAT? Does this new memory get merged into existing NUMA nodes?

It gets merged into the persistent memory device's node, as told by the firmware. Intel's persistent memory should always be in its own node, separate from DRAM.

Quoted 4 lines

Also, do you plan to have a way for applications to find out which NUMA nodes are "real DRAM" while others are "pmem-backed"? (something like a new attribute in /sys/devices/system/node/nodeX/) Or should we use HMAT performance attributes for this?

The best way is to use the sysfs-generic interfaces to the HMAT that Keith Busch is pushing. In the end, we really think folks will only care about the memory's performance properties rather than whether it's *actually* persistent memory or not.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#25 lore raw
Quoted 15 lines · Dave Hansen
Quoted 3 lines · Brice Goglin

Le 22/10/2018 à 22:13, Dave Hansen a écrit :
What happens on systems without an HMAT? Does this new memory get merged into existing NUMA nodes?

It gets merged into the persistent memory device's node, as told by the firmware. Intel's persistent memory should always be in its own node, separate from DRAM.

Quoted 4 lines

Also, do you plan to have a way for applications to find out which NUMA nodes are "real DRAM" while others are "pmem-backed"? (something like a new attribute in /sys/devices/system/node/nodeX/) Or should we use HMAT performance attributes for this?

Quoted 4 lines

The best way is to use the sysfs-generic interfaces to the HMAT that Keith Busch is pushing. In the end, we really think folks will only care about the memory's performance properties rather than whether it's *actually* persistent memory or not.

It's also important to point out that "persistent memory" by itself is an ambiguous memory type. It's anything from new media with distinct performance characteristics to battery backed DRAM. I.e. the performance of "persistent memory" may be indistinguishable from "real DRAM".
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm