Skip to contentSkip to conversation

Label initialization time optimizations

PATCH In review Alexander Duyck 3 participants 10 messages Oct 10, 2018 – Oct 12, 2018 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

cover Label initialization time optimizations

This patch set is intended to improve NVDIMM label read times by first increasing the upper limit on the label read/write size, and then reducing the number of reads by making use of the free label bitmap in the index to determine what labels are actually populated and only read those labels. In my testing on a system populated with 24 NVDIMM modules I see the total label init time drop from about 24 seconds down to 2 to 3 seconds.

In the process of coding this up I came across a few minor issues that I felt should be addressed so I have added a few patches for those fixes along the way.

---

Alexander Duyck (5):
nvdimm: Sanity check labeloff
nvdimm: Clarify comment in sizeof_namespace_index
nvdimm: Remove empty if statement
nvdimm: Split label init out from the logic for getting config data
nvdimm: Use namespace index data to reduce number of label reads needed

Dan Williams (1):
libnvdimm, dimm: Maximize label transfer size

 drivers/nvdimm/dimm.c      |    6 --
 drivers/nvdimm/dimm_devs.c |   60 +++++++------------
 drivers/nvdimm/label.c     |  142 ++++++++++++++++++++++++++++++++++++++++++--
 drivers/nvdimm/label.h     |    4 -
 drivers/nvdimm/nd.h        |    2 +
 5 files changed, 163 insertions(+), 51 deletions(-)

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

#1 lore raw

PATCH 1/6 libnvdimm, dimm: Maximize label transfer size

From: Dan Williams <[email protected]>

Use kvzalloc() to bypass the arbitrary PAGE_SIZE limit of label transfer operations. Given the expense of calling into firmware, maximize the amount of label data we transfer per call to be up to the total label space if allowed by the firmware.

Instead of limiting based on PAGE_SIZE we can instead simply limit the maximum size based on either the config_size int he case of the get operation, or the length of the write based on the set operation.

On a system with 24 NVDIMM modules each with a config_size of 128K and a maximum transfer size of 64K - 4, this patch reduces the init time for the label data from around 24 seconds down to between 4-5 seconds.

---

I think I only did a few minor tweaks on this so I thought I would leave Dan as the author and just add my Signed-off-by.

 drivers/nvdimm/dimm_devs.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/nvdimm/dimm_devs.c +6 -7
index 863cabc35215..75ac78017b15 100644
@@ -111,8 +111,8 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
 	if (!ndd->data)
 		return -ENOMEM;
 
-	max_cmd_size = min_t(u32, PAGE_SIZE, ndd->nsarea.max_xfer);
-	cmd = kzalloc(max_cmd_size + sizeof(*cmd), GFP_KERNEL);
+	max_cmd_size = min_t(u32, ndd->nsarea.config_size, ndd->nsarea.max_xfer);
+	cmd = kvzalloc(max_cmd_size + sizeof(*cmd), GFP_KERNEL);
 	if (!cmd)
 		return -ENOMEM;
 
@@ -134,7 +134,7 @@ int nvdimm_init_config_data(struct nvdimm_drvdata *ndd)
 		memcpy(ndd->data + offset, cmd->out_buf, cmd->in_length);
 	}
 	dev_dbg(ndd->dev, "len: %zu rc: %d\n", offset, rc);
-	kfree(cmd);
+	kvfree(cmd);
 
 	return rc;
 }
@@ -157,9 +157,8 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
 	if (offset + len > ndd->nsarea.config_size)
 		return -ENXIO;
 
-	max_cmd_size = min_t(u32, PAGE_SIZE, len);
-	max_cmd_size = min_t(u32, max_cmd_size, ndd->nsarea.max_xfer);
-	cmd = kzalloc(max_cmd_size + sizeof(*cmd) + sizeof(u32), GFP_KERNEL);
+	max_cmd_size = min_t(u32, len, ndd->nsarea.max_xfer);
+	cmd = kvzalloc(max_cmd_size + sizeof(*cmd) + sizeof(u32), GFP_KERNEL);
 	if (!cmd)
 		return -ENOMEM;
 
@@ -183,7 +182,7 @@ int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
 			break;
 		}
 	}
-	kfree(cmd);
+	kvfree(cmd);
 
 	return rc;
 }

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

#2 lore raw

PATCH 2/6 nvdimm: Sanity check labeloff

In reply to Alexander Duyck

This patch adds validation for the labeloff field in the indexes.

---
 drivers/nvdimm/label.c |    7 +++++++
 1 file changed, 7 insertions(+)
drivers/nvdimm/label.c +7 -0
index 1d28cd656536..1f5842509dbc 100644
@@ -183,6 +183,13 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd)
 					__le64_to_cpu(nsindex[i]->otheroff));
 			continue;
 		}
+		if (__le64_to_cpu(nsindex[i]->labeloff)
+				!= 2 * sizeof_namespace_index(ndd)) {
+			dev_dbg(dev, "nsindex%d labeloff: %#llx invalid\n",
+					i, (unsigned long long)
+					__le64_to_cpu(nsindex[i]->labeloff));
+			continue;
+		}
 
 		size = __le64_to_cpu(nsindex[i]->mysize);
 		if (size > sizeof_namespace_index(ndd)

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

#3 lore raw

PATCH 3/6 nvdimm: Clarify comment in sizeof_namespace_index

In reply to Alexander Duyck

When working on the label code I found it rather confusing to see several spots that reference a minimum label size of 256 while working with labels that are 128 bytes in size.

This patch is meant to provide a clarification on one of the comments that was at the heart of the issue. Specifically for version 1.2 and later of the namespace specification the minimum label size is 256, prior to that the minimum label size was 128. So we should state that as such to avoid confusion.

---
 drivers/nvdimm/label.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvdimm/label.c +2 -1
index 1f5842509dbc..bb813b8e8ace 100644
@@ -75,7 +75,8 @@ size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
 	/*
 	 * Per UEFI 2.7, the minimum size of the Label Storage Area is large
 	 * enough to hold 2 index blocks and 2 labels.  The minimum index
-	 * block size is 256 bytes, and the minimum label size is 256 bytes.
+	 * block size is 256 bytes. The label size is 128 for namespaces
+	 * prior to version 1.2 and at minimum 256 for version 1.2 and later.
 	 */
 	nslot = nvdimm_num_label_slots(ndd);
 	space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd);

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

#4 lore raw

PATCH 4/6 nvdimm: Remove empty if statement

In reply to Alexander Duyck

This patch removes an empty statement from an if expression and promotes the else statement to the if expression with the expression logic reversed.

I feel this is more readable as the empty statement can lead to issues if any additional logic was ever added.

---
 drivers/nvdimm/label.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/nvdimm/label.c +2 -3
index bb813b8e8ace..43bad0d5bdb6 100644
@@ -261,9 +261,8 @@ int nd_label_validate(struct nvdimm_drvdata *ndd)
 void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
 		struct nd_namespace_index *src)
 {
-	if (dst && src)
-		/* pass */;
-	else
+	/* just exit if either destination or source is NULL */
+	if (!dst || !src)
 		return;
 
 	memcpy(dst, src, sizeof_namespace_index(ndd));

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

#5 lore raw

PATCH 5/6 nvdimm: Split label init out from the logic for getting config data

In reply to Alexander Duyck

This patch splits the initialization of the label data into two functions. One for doing the init, and another for reading the actual configuration data. The idea behind this is that by doing this we create a symmetry between the getting and setting of config data in that we have a function for both. In addition it will make it easier for us to identify the bits that are related to init versus the pieces that are a wrapper for reading data from the ACPI interface.

So for example by splitting things out like this it becomes much more obvious that we were performing checks that weren't necessarily related to the set/get operations such as relying on ndd->data being present when the set and get ops should not care about a locally cached copy of the label area.

---
 drivers/nvdimm/dimm.c      |    2 +-
 drivers/nvdimm/dimm_devs.c |   49 +++++++++++++++++---------------------------
 drivers/nvdimm/label.c     |   38 ++++++++++++++++++++++++++++++++++
 drivers/nvdimm/label.h     |    1 +
 drivers/nvdimm/nd.h        |    2 ++
 5 files changed, 61 insertions(+), 31 deletions(-)
drivers/nvdimm/dimm.c +1 -1
index 6c8fb7590838..07bf96948553 100644
@@ -75,7 +75,7 @@ static int nvdimm_probe(struct device *dev)
 	 * DIMM capacity. We fail the dimm probe to prevent regions from
 	 * attempting to parse the label area.
 	 */
-	rc = nvdimm_init_config_data(ndd);
+	rc = nd_label_data_init(ndd);
 	if (rc == -EACCES)
 		nvdimm_set_locked(dev);
 	if (rc)
drivers/nvdimm/dimm_devs.c +19 -30

83 lines not on this page · raw message

drivers/nvdimm/label.c +38 -0
index 43bad0d5bdb6..563f24af01b5 100644
@@ -417,6 +417,44 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd)
 	return 0;
 }
 
+int nd_label_data_init(struct nvdimm_drvdata *ndd)
+{
+	size_t config_size, read_size;
+	int rc = 0;
+
+	if (ndd->data)
+		return 0;
+
+	if (ndd->nsarea.status || ndd->nsarea.max_xfer == 0) {
+		dev_dbg(ndd->dev, "failed to init config data area: (%u:%u)\n",
+			ndd->nsarea.max_xfer, ndd->nsarea.config_size);
+		return -ENXIO;
+	}
+
+	/*
+	 * We need to determine the maximum index area as this is the section
+	 * we must read and validate before we can start processing labels.
+	 *
+	 * If the area is too small to contain the two indexes and 2 labels
+	 * then we abort.
+	 *
+	 * Start at a label size of 128 as this should result in the largest
+	 * possible namespace index size.
+	 */
+	ndd->nslabel_size = 128;
+	read_size = sizeof_namespace_index(ndd) * 2;
+	if (!read_size)
+		return -ENXIO;
+
+	/* Allocate config data */
+	config_size = ndd->nsarea.config_size;
+	ndd->data = kvzalloc(config_size, GFP_KERNEL);
+	if (!ndd->data)
+		return -ENOMEM;
+
+	return nvdimm_get_config_data(ndd, ndd->data, 0, config_size);
+}
+
 int nd_label_active_count(struct nvdimm_drvdata *ndd)
 {
 	struct nd_namespace_index *nsindex;
drivers/nvdimm/label.h +1 -0
index 18bbe183b3a9..685afb3de0fe 100644
@@ -141,6 +141,7 @@ static inline int nd_label_next_nsindex(int index)
 int nd_label_validate(struct nvdimm_drvdata *ndd);
 void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
 		struct nd_namespace_index *src);
+int nd_label_data_init(struct nvdimm_drvdata *ndd);
 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
 int nd_label_active_count(struct nvdimm_drvdata *ndd);
 struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
drivers/nvdimm/nd.h +2 -0
index 98317e7ce5b5..e79cc8e5c114 100644
@@ -241,6 +241,8 @@ ssize_t nd_size_select_store(struct device *dev, const char *buf,
 int nvdimm_check_config_data(struct device *dev);
 int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd);
 int nvdimm_init_config_data(struct nvdimm_drvdata *ndd);
+int nvdimm_get_config_data(struct nvdimm_drvdata *ndd, void *buf,
+			   size_t offset, size_t len);
 int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset,
 		void *buf, size_t len);
 long nvdimm_clear_poison(struct device *dev, phys_addr_t phys,

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

#6 lore raw

PATCH 6/6 nvdimm: Use namespace index data to reduce number of label reads needed

In reply to Alexander Duyck

This patch adds logic that is meant to make use of the namespace index data to reduce the number of reads that are needed to initialize a given namespace. The general idea is that once we have enough data to validate the namespace index we do so and then proceed to fetch only those labels that are not listed as being "free". By doing this I am seeing a total time reduction from about 4-5 seconds to 2-3 seconds for 24 NVDIMM modules each with 128K of label config area.

---
 drivers/nvdimm/dimm.c  |    4 --
 drivers/nvdimm/label.c |   93 +++++++++++++++++++++++++++++++++++++++++++++---
 drivers/nvdimm/label.h |    3 --
 3 files changed, 88 insertions(+), 12 deletions(-)
drivers/nvdimm/dimm.c +0 -4
index 07bf96948553..9899c97138a3 100644
@@ -84,10 +84,6 @@ static int nvdimm_probe(struct device *dev)
 	dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size);
 
 	nvdimm_bus_lock(dev);
-	ndd->ns_current = nd_label_validate(ndd);
-	ndd->ns_next = nd_label_next_nsindex(ndd->ns_current);
-	nd_label_copy(ndd, to_next_namespace_index(ndd),
-			to_current_namespace_index(ndd));
 	if (ndd->ns_current >= 0) {
 		rc = nd_label_reserve_dpa(ndd);
 		if (rc == 0)
drivers/nvdimm/label.c +88 -5

117 lines not on this page · raw message

drivers/nvdimm/label.h +0 -3
index 685afb3de0fe..e9a2ad3c2150 100644
@@ -138,9 +138,6 @@ static inline int nd_label_next_nsindex(int index)
 }
 
 struct nvdimm_drvdata;
-int nd_label_validate(struct nvdimm_drvdata *ndd);
-void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
-		struct nd_namespace_index *src);
 int nd_label_data_init(struct nvdimm_drvdata *ndd);
 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
 int nd_label_active_count(struct nvdimm_drvdata *ndd);

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

#7 lore raw

Re: [nvdimm PATCH 6/6] nvdimm: Use namespace index data to reduce number of label reads needed

Quoted 21 lines · Alexander Duyck

This patch adds logic that is meant to make use of the namespace index data to reduce the number of reads that are needed to initialize a given namespace. The general idea is that once we have enough data to validate the namespace index we do so and then proceed to fetch only those labels that are not listed as being "free". By doing this I am seeing a total time reduction from about 4-5 seconds to 2-3 seconds for 24 NVDIMM modules each with 128K of label config area.

---
 drivers/nvdimm/dimm.c  |    4 --
 drivers/nvdimm/label.c |   93 +++++++++++++++++++++++++++++++++++++++++++++---
 drivers/nvdimm/label.h |    3 --
 3 files changed, 88 insertions(+), 12 deletions(-)
drivers/nvdimm/dimm.c +0 -0
index 07bf96948553..9899c97138a3 100644
@@ -452,7 +455,87 @@ int nd_label_data_init(struct nvdimm_drvdata *ndd)

[..]

drivers/nvdimm/dimm.c

Quoted 2 lines
drivers/nvdimm/dimm.c +2 -0
+       /* Loop through the free list pulling in any active labels */
+       for (i = 0; i < nsindex->nslot; i++, offset += ndd->nslabel_size) {

0day points out a sparse warning on that usage of nslot which is an __le32. I'll append a fixup.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#8 lore raw
In reply to Alexander Duyck
Quoted 9 lines · Alexander Duyck

This patch set is intended to improve NVDIMM label read times by first increasing the upper limit on the label read/write size, and then reducing the number of reads by making use of the free label bitmap in the index to determine what labels are actually populated and only read those labels. In my testing on a system populated with 24 NVDIMM modules I see the total label init time drop from about 24 seconds down to 2 to 3 seconds.

Quoted 3 lines

In the process of coding this up I came across a few minor issues that I felt should be addressed so I have added a few patches for those fixes along the way.

Thanks, this all looks good to me, the split looks good, and the commentary in patch6 made it easy to review.

I quibble with "Remove empty if statement" because I find positive logic easier to read than negative logic, but removing more lines than it adds made me reserve that quibble for another time.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reviewed-by on the v1 series
#9 lore raw
In reply to Alexander Duyck
Quoted 21 lines · Alexander Duyck

This patch set is intended to improve NVDIMM label read times by first increasing the upper limit on the label read/write size, and then reducing the number of reads by making use of the free label bitmap in the index to determine what labels are actually populated and only read those labels. In my testing on a system populated with 24 NVDIMM modules I see the total label init time drop from about 24 seconds down to 2 to 3 seconds.

In the process of coding this up I came across a few minor issues that I felt should be addressed so I have added a few patches for those fixes along the way.

---

Alexander Duyck (5):
nvdimm: Sanity check labeloff
nvdimm: Clarify comment in sizeof_namespace_index
nvdimm: Remove empty if statement
nvdimm: Split label init out from the logic for getting config data
nvdimm: Use namespace index data to reduce number of label reads needed

Quoted 3 lines

Dan Williams (1):
libnvdimm, dimm: Maximize label transfer size

This series really helps us a lot!! The change looks good to me.

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