Skip to contentSkip to conversation

daxctl: range mapping allocation

PATCH In review Joao Martins 2 participants 7 messages Dec 18, 2020 – Dec 19, 2020

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

v2 cover daxctl: range mapping allocation

Hey,

This series adds support for:

1) Listing mappings when passing -M to ´daxctl list´. These are ommited by default.

2) Iteration APIs for the mappings.

3) Allow passing an input JSON file with the manually selected ranges to be used when creating the device-dax instance.

This applies on top of 'jm/devdax_subdiv' branch in github.com:pmem/ndctl.git

Testing requires a 5.10+ kernel.

v1 -> v2:
* List mappings only with -M|--mappings option
* Adds a unit test for --input file (while testing with -M listing too)
* Rename --restore to --input
* Add Documentation for -M and for --input

Joao Martins (5):
libdaxctl: add mapping iterator APIs
daxctl: include mappings when listing
libdaxctl: add daxctl_dev_set_mapping()
daxctl: allow creating devices from input json daxctl/test: add a test for daxctl-create with input file

 Documentation/daxctl/daxctl-create-device.txt |  13 +++
 Documentation/daxctl/daxctl-list.txt          |   4 +
 daxctl/device.c                               | 128 +++++++++++++++++++++++++-
 daxctl/lib/libdaxctl-private.h                |   8 ++
 daxctl/lib/libdaxctl.c                        | 118 +++++++++++++++++++++++-
 daxctl/lib/libdaxctl.sym                      |   7 ++
 daxctl/libdaxctl.h                            |  14 +++
 daxctl/list.c                                 |   4 +
 test/daxctl-create.sh                         |  31 ++++++-
 util/json.c                                   |  57 +++++++++++-
 util/json.h                                   |   4 +
 11 files changed, 380 insertions(+), 8 deletions(-)
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw

PATCH v2 1/5 libdaxctl: add mapping iterator APIs

Add the following APIs to be able to iterate over a dynamic device-dax mapping list, as well as fetching each of the mapping attributes.

---
 daxctl/lib/libdaxctl-private.h |  8 ++++
 daxctl/lib/libdaxctl.c         | 91 +++++++++++++++++++++++++++++++++++++++++-
 daxctl/lib/libdaxctl.sym       |  6 +++
 daxctl/libdaxctl.h             | 12 ++++++
 4 files changed, 116 insertions(+), 1 deletion(-)
daxctl/lib/libdaxctl-private.h +8 -0
index b307a8bc9438..6d05aefbeda0 100644
@@ -91,6 +91,12 @@ struct daxctl_region {
 	struct list_head devices;
 };
 
+struct daxctl_mapping {
+	struct daxctl_dev *dev;
+	unsigned long long pgoff, start, end;
+	struct list_node list;
+};
+
 struct daxctl_dev {
 	int id, major, minor;
 	void *dev_buf;
@@ -104,6 +110,8 @@ struct daxctl_dev {
 	struct daxctl_region *region;
 	struct daxctl_memory *mem;
 	int target_node;
+	int num_mappings;
+	struct list_head mappings;
 };
 
 struct daxctl_memory {
daxctl/lib/libdaxctl.c +90 -1

103 lines not on this page · raw message

daxctl/lib/libdaxctl.sym +6 -0
index c3d08179c9fd..08362b683678 100644
@@ -83,4 +83,10 @@ global:
 	daxctl_region_destroy_dev;
 	daxctl_dev_get_align;
 	daxctl_dev_set_align;
+	daxctl_mapping_get_first;
+	daxctl_mapping_get_next;
+	daxctl_mapping_get_start;
+	daxctl_mapping_get_end;
+	daxctl_mapping_get_offset;
+	daxctl_mapping_get_size;
 } LIBDAXCTL_7;
daxctl/libdaxctl.h +12 -0
index b0bb5d78d357..f94a72fed85b 100644
@@ -103,6 +103,18 @@ int daxctl_memory_online_no_movable(struct daxctl_memory *mem);
              region != NULL; \
              region = daxctl_region_get_next(region))
 
+struct daxctl_mapping;
+struct daxctl_mapping *daxctl_mapping_get_first(struct daxctl_dev *dev);
+struct daxctl_mapping *daxctl_mapping_get_next(struct daxctl_mapping *mapping);
+#define daxctl_mapping_foreach(dev, mapping) \
+        for (mapping = daxctl_mapping_get_first(dev); \
+             mapping != NULL; \
+             mapping = daxctl_mapping_get_next(mapping))
+unsigned long long daxctl_mapping_get_start(struct daxctl_mapping *mapping);
+unsigned long long daxctl_mapping_get_end(struct daxctl_mapping *mapping);
+unsigned long long  daxctl_mapping_get_offset(struct daxctl_mapping *mapping);
+unsigned long long daxctl_mapping_get_size(struct daxctl_mapping *mapping);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#2 lore raw

PATCH v2 2/5 daxctl: include mappings when listing

In reply to Joao Martins

Iterate over the device mappings and print @page_offset,
@start, @end and a computed size, but only if user passes -M|--mappings to daxctl list as the output can
get verbose with a lot of mapping entries.

---
 Documentation/daxctl/daxctl-list.txt |  4 +++
 daxctl/list.c                        |  4 +++
 util/json.c                          | 57 +++++++++++++++++++++++++++++++++++-
 util/json.h                          |  4 +++
 4 files changed, 68 insertions(+), 1 deletion(-)
Documentation/daxctl/daxctl-list.txt +4 -0
index cb82c3cc6fb2..5a6a98e73849 100644
@@ -67,6 +67,10 @@ OPTIONS
 --devices::
 	Include device-dax instance info in the listing (default)
 
+-M::
+--mappings::
+	Include device-dax instance mappings info in the listing
+
 -R::
 --regions::
 	Include region info in the listing
daxctl/list.c +4 -0
index 6c6251b4de37..6860a460e4c0 100644
@@ -25,6 +25,7 @@
 static struct {
 	bool devs;
 	bool regions;
+	bool mappings;
 	bool idle;
 	bool human;
 } list;
@@ -35,6 +36,8 @@ static unsigned long listopts_to_flags(void)
 
 	if (list.devs)
 		flags |= UTIL_JSON_DAX_DEVS;
+	if (list.mappings)
+		flags |= UTIL_JSON_DAX_MAPPINGS;
 	if (list.idle)
 		flags |= UTIL_JSON_IDLE;
 	if (list.human)
@@ -70,6 +73,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx)
 				"filter by dax device instance name"),
 		OPT_BOOLEAN('D', "devices", &list.devs, "include dax device info"),
 		OPT_BOOLEAN('R', "regions", &list.regions, "include dax region info"),
+		OPT_BOOLEAN('M', "mappings", &list.mappings, "include dax mappings info"),
 		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
 		OPT_BOOLEAN('u', "human", &list.human,
 				"use human friendly number formats "),
util/json.c +56 -1

75 lines not on this page · raw message

util/json.h +4 -0
index 39a33789bac9..e26875a5ecd8 100644
@@ -15,6 +15,7 @@
 #include <stdio.h>
 #include <stdbool.h>
 #include <ndctl/libndctl.h>
+#include <daxctl/libdaxctl.h>
 #include <ccan/short_types/short_types.h>
 
 enum util_json_flags {
@@ -27,6 +28,7 @@ enum util_json_flags {
 	UTIL_JSON_CAPABILITIES	= (1 << 6),
 	UTIL_JSON_CONFIGURED	= (1 << 7),
 	UTIL_JSON_FIRMWARE	= (1 << 8),
+	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
 };
 
 struct json_object;
@@ -38,6 +40,8 @@ struct json_object *util_dimm_to_json(struct ndctl_dimm *dimm,
 		unsigned long flags);
 struct json_object *util_mapping_to_json(struct ndctl_mapping *mapping,
 		unsigned long flags);
+struct json_object *util_daxctl_mapping_to_json(struct daxctl_mapping *mapping,
+		unsigned long flags);
 struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 		unsigned long flags);
 struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#3 lore raw

PATCH v2 3/5 libdaxctl: add daxctl_dev_set_mapping()

In reply to Joao Martins

This API adds the ability to manually pick a range within the region device. Such routine allows for a admin to restore the mappings of a device after kexec. This is specially useful for hmem dynamic devdax which do not persistent ranges allocation through say a e.g. namespace label storage area. It also allows an userspace application to pick it's own ranges, should it want to avoid relying on kernel's policy.

---
 daxctl/lib/libdaxctl.c   | 27 +++++++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym |  1 +
 daxctl/libdaxctl.h       |  2 ++
 3 files changed, 30 insertions(+)
daxctl/lib/libdaxctl.c +27 -0
index 3781e9ed27d5..59fe84fee409 100644
@@ -1123,6 +1123,33 @@ DAXCTL_EXPORT int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long ali
 	return 0;
 }
 
+DAXCTL_EXPORT int daxctl_dev_set_mapping(struct daxctl_dev *dev,
+					unsigned long long start,
+					unsigned long long end)
+{
+	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
+	unsigned long long size = end - start + 1;
+	char buf[SYSFS_ATTR_SIZE];
+	char *path = dev->dev_buf;
+	int len = dev->buf_len;
+
+	if (snprintf(path, len, "%s/mapping", dev->dev_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+
+	sprintf(buf, "%#llx-%#llx\n", start, end);
+	if (sysfs_write_attr(ctx, path, buf) < 0) {
+		err(ctx, "%s: failed to set mapping\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+	dev->size += size;
+
+	return 0;
+}
+
 DAXCTL_EXPORT int daxctl_dev_get_target_node(struct daxctl_dev *dev)
 {
 	return dev->target_node;
daxctl/lib/libdaxctl.sym +1 -0
index 08362b683678..a4e16848494b 100644
@@ -89,4 +89,5 @@ global:
 	daxctl_mapping_get_end;
 	daxctl_mapping_get_offset;
 	daxctl_mapping_get_size;
+	daxctl_dev_set_mapping;
 } LIBDAXCTL_7;
daxctl/libdaxctl.h +2 -0
index f94a72fed85b..09439c16d6df 100644
@@ -73,6 +73,8 @@ unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev);
 int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long size);
 unsigned long daxctl_dev_get_align(struct daxctl_dev *dev);
 int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align);
+int daxctl_dev_set_mapping(struct daxctl_dev *dev, unsigned long long start,
+			unsigned long long end);
 struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev);
 int daxctl_dev_is_enabled(struct daxctl_dev *dev);
 int daxctl_dev_disable(struct daxctl_dev *dev);
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#4 lore raw

PATCH v2 4/5 daxctl: allow creating devices from input json

In reply to Joao Martins

Add an option namely --input which passes a parameter which is a JSON file path. The JSON file contains the data usually returned by:

	$ daxctl list -d dax0.1 | jq -er '.[]' > device.json
	{
	  "chardev":"dax0.1",
	  "size":34359738368,
	  "target_node":0,
	  "align":1073741824,
	  "mode":"devdax",
	  "mappings":[
	    {
	      "page_offset":4194304,
	      "start":25769803776,
	      "end":42949672959,
	      "size":17179869184
	    },
	    {
	      "page_offset":0,
	      "start":8589934592,
	      "end":25769803775,
	      "size":17179869184
	    }
	  ]
	}

The input values in the mapping json are decimal
for now. A device can then be created by specifying this same data to re-create it e.g.

	$ daxctl create-device -u --input device.json
	{
	  "chardev":"dax0.1",
	  "size":"32.00 GiB (34.36 GB)",
	  "target_node":0,
	  "align":"1024.00 MiB (1073.74 MB)",
	  "mode":"devdax",
	}
	$ daxctl list -d dax0.1
	{
	  "chardev":"dax0.1",
	  "size":34359738368,
	  "target_node":0,
	  "align":1073741824,
	  "mode":"devdax",
	  "mappings":[
	    {
	      "page_offset":4194304,
	      "start":25769803776,
	      "end":42949672959,
	      "size":17179869184
	    },
	    {
	      "page_offset":0,
	      "start":8589934592,
	      "end":25769803775,
	      "size":17179869184
	    }
	  ]
	}

created 1 device

This means we can restore/recreate previously established mappings.

---
 Documentation/daxctl/daxctl-create-device.txt |  13 +++
 daxctl/device.c                               | 128 +++++++++++++++++++++++++-
 2 files changed, 136 insertions(+), 5 deletions(-)
Documentation/daxctl/daxctl-create-device.txt +13 -0
index 7f64719d16f2..05f4dbd9d61c 100644
@@ -90,6 +90,19 @@ include::region-option.txt[]
 	to 2M. Note that "devdax" mode enforces all mappings to be
 	aligned to this value, i.e. it fails unaligned mapping attempts.
 
+--input::
+	Applications that want to select ranges assigned to a device-dax
+	instance, or wanting to establish previously created devices, can
+	pass an input JSON file. The file option lets a user pass a JSON
+	object similar to the one listed with "daxctl list".
+
+	The device name is not re-created, but if a "chardev" is passed in
+	the JSON file, it will use that to get the region id.
+
+	Note that the JSON content in the file cannot be an array of
+	JSON objects but rather a single JSON object i.e. without the
+	array enclosing brackets.
+
 include::human-option.txt[]
 
 include::verbose-option.txt[]
daxctl/device.c +123 -5

180 lines not on this page · raw message

Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#5 lore raw

PATCH v2 5/5 daxctl/test: add a test for daxctl-create with input file

In reply to Joao Martins

The test creates a multi-range device (4 mappings) using the same setup as one of the tests. Afterwards we validate that the size/nr-mappings are the same as the original test.

---
 test/daxctl-create.sh | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
test/daxctl-create.sh +30 -1
index 41d5ba5888f7..e1d733916851 100755
@@ -199,6 +199,7 @@ daxctl_test_multi()
 daxctl_test_multi_reconfig()
 {
 	local ncfgs=$1
+	local dump=$2
 	local daxdev
 
 	size=$((available / ncfgs))
@@ -226,6 +227,10 @@ daxctl_test_multi_reconfig()
 	test "$(daxctl_get_nr_mappings "$testdev")" -eq $((ncfgs / 2))
 	test "$(daxctl_get_nr_mappings "$daxdev_1")" -eq $((ncfgs / 2))
 
+	if [[ $dump ]]; then
+		"$DAXCTL" list -M -d "$daxdev_1" | jq -er '.[]' > $dump
+	fi
+
 	fail_if_available
 
 	"$DAXCTL" disable-device "$daxdev_1" && "$DAXCTL" destroy-device "$daxdev_1"
@@ -328,7 +333,7 @@ daxctl_test3()
 # pick at the end of the region
 daxctl_test4()
 {
-	daxctl_test_multi_reconfig 8
+	daxctl_test_multi_reconfig 8 ""
 	clear_dev
 	test_pass
 }
@@ -371,6 +376,29 @@ daxctl_test6()
 	test_pass
 }
 
+# Test 7: input device
+# Successfully creates a device with an input file from the multi-range
+# device test, and checking that we have the same number of mappings/size.
+daxctl_test7()
+{
+	daxctl_test_multi_reconfig 8 "input.json"
+
+	# The parameter should parse the region_id from the chardev entry
+	# therefore using the same region_id as test4
+	daxdev_1=$("$DAXCTL" create-device --input input.json | jq -er '.[].chardev')
+
+	# Validate if it's the same mappings as done by test4
+	# It also validates the size computed from the mappings
+	# A zero value means it failed, and four mappings is what's
+	# created by daxctl_test4
+	test "$(daxctl_get_nr_mappings "$daxdev_1")" -eq 4
+
+	"$DAXCTL" disable-device "$daxdev_1" && "$DAXCTL" destroy-device "$daxdev_1"
+
+	clear_dev
+	test_pass
+}
+
 find_testdev
 rc=1
 setup_dev
@@ -381,5 +409,6 @@ daxctl_test3
 daxctl_test4
 daxctl_test5
 daxctl_test6
+daxctl_test7
 reset_dev
 exit 0
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
maintainer
#6 lore raw
In reply to Joao Martins
Quoted 29 lines · Joao Martins

Hey,

This series adds support for:

1) Listing mappings when passing -M to ´daxctl list´. These are ommited by default.

2) Iteration APIs for the mappings.

3) Allow passing an input JSON file with the manually selected ranges to be used when creating the device-dax instance.

This applies on top of 'jm/devdax_subdiv' branch in github.com:pmem/ndctl.git

Testing requires a 5.10+ kernel.

v1 -> v2:
* List mappings only with -M|--mappings option
* Adds a unit test for --input file (while testing with -M listing too)
* Rename --restore to --input
* Add Documentation for -M and for --input

Joao Martins (5):
libdaxctl: add mapping iterator APIs
daxctl: include mappings when listing
libdaxctl: add daxctl_dev_set_mapping()
daxctl: allow creating devices from input json daxctl/test: add a test for daxctl-create with input file

Quoted 13 lines
 Documentation/daxctl/daxctl-create-device.txt |  13 +++
 Documentation/daxctl/daxctl-list.txt          |   4 +
 daxctl/device.c                               | 128 +++++++++++++++++++++++++-
 daxctl/lib/libdaxctl-private.h                |   8 ++
 daxctl/lib/libdaxctl.c                        | 118 +++++++++++++++++++++++-
 daxctl/lib/libdaxctl.sym                      |   7 ++
 daxctl/libdaxctl.h                            |  14 +++
 daxctl/list.c                                 |   4 +
 test/daxctl-create.sh                         |  31 ++++++-
 util/json.c                                   |  57 +++++++++++-
 util/json.h                                   |   4 +
 11 files changed, 380 insertions(+), 8 deletions(-)

Hi Joao,

These all look good, applied. Thanks for the quick turnaround!

-Vishal
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]