Skip to contentSkip to conversation

Namespace creation fixups

PATCH Superseded Keith Busch 3 participants 11 messages Jun 26, 2018 – Jul 5, 2018 libnvdimm: non-volatile memory device

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Namespace creation fixups

This is a three-part fixup to the warning that occurs when the available capacity is fragmented. When this occurs, the user may believe they can create a larger namespace than is actually possible. This was resulting in the following kernel warning:

nd_region region0: allocation underrun: 0x0 of 0x1400000000 bytes

  WARNING: CPU: 32 PID: 1975 at drivers/nvdimm/namespace_devs.c:913 size_store+0x879/0x8d0 [libnvdimm]

The kernel side of this determines the maximum size by calculating the largest contiguous extent that can be allocated. If the requested size exceeds that, an error is returned early instead of reaching the alarming kernel warning.

To make it possible for the user to know the maximum size it may request, a new attribute is exported that shows the largest available extent.

Finally, separate from this series, ndctl is updated to make use of this new attribute when creating a namespace.

Keith Busch (2):
libnvdimm: Use largest contiguous area for namespace size
libnvdimm: Export max available extent

 drivers/nvdimm/dimm_devs.c      | 29 +++++++++++++++++++++++++++++
 drivers/nvdimm/namespace_devs.c |  2 +-
 drivers/nvdimm/nd-core.h        |  3 +++
 drivers/nvdimm/region_devs.c    | 39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 1 deletion(-)
Signature · 6 lines
2.14.3

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

PATCH 1/2 libnvdimm: Use largest contiguous area for namespace size

This patch will find the largest free extent to determine the max size for a namespace that can be created.

---
 drivers/nvdimm/dimm_devs.c      | 29 +++++++++++++++++++++++++++++
 drivers/nvdimm/namespace_devs.c |  2 +-
 drivers/nvdimm/nd-core.h        |  3 +++
 drivers/nvdimm/region_devs.c    | 23 +++++++++++++++++++++++
 4 files changed, 56 insertions(+), 1 deletion(-)
drivers/nvdimm/dimm_devs.c +29 -0
index 8d348b22ba45..147613e0f872 100644
@@ -536,6 +536,35 @@ resource_size_t nd_blk_available_dpa(struct nd_region *nd_region)
 	return info.available;
 }
 
+/**
+ * nd_pmem_largest_contiguous_available_dpa - For the given dimm+region,
+ * 	return the larges contiguous dpa range.
+ * @nd_region: constrain available space check to this reference region
+ * @nd_mapping: container of dpa-resource-root + labels
+ */
+resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
+					   struct nd_mapping *nd_mapping)
+{
+	struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
+	resource_size_t start, end, max = 0;
+	struct resource *res;
+
+	if (!ndd)
+		return 0;
+
+	start = nd_mapping->start;
+	end = start + nd_mapping->size;
+
+	for_each_dpa_resource(ndd, res) {
+		if ((res->start - start) > max)
+			max = res->start - start;
+		start = res->start + resource_size(res);
+	}
+	if (start < end && end - start > max)
+		max = end - start;
+	return max;
+}
+
 /**
  * nd_pmem_available_dpa - for the given dimm+region account unallocated dpa
  * @nd_mapping: container of dpa-resource-root + labels
drivers/nvdimm/namespace_devs.c +1 -1
index 28afdd668905..c00d1d2d48f9 100644
@@ -1032,7 +1032,7 @@ static ssize_t __size_store(struct device *dev, unsigned long long val)
 
 		allocated += nvdimm_allocated_dpa(ndd, &label_id);
 	}
-	available = nd_region_available_dpa(nd_region);
+	available = nd_region_contiguous_max(nd_region);
 
 	if (val > available + allocated)
 		return -ENOSPC;
drivers/nvdimm/nd-core.h +3 -0
index 79274ead54fb..8e4acd075b0f 100644
@@ -100,6 +100,9 @@ struct nd_region;
 struct nvdimm_drvdata;
 struct nd_mapping;
 void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
+resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
+					   struct nd_mapping *nd_mapping);
+resource_size_t nd_region_contiguous_max(struct nd_region *nd_region);
 resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
 		struct nd_mapping *nd_mapping, resource_size_t *overlap);
 resource_size_t nd_blk_available_dpa(struct nd_region *nd_region);
drivers/nvdimm/region_devs.c +23 -0
index ec3543b83330..8af483d7ef57 100644
@@ -357,6 +357,29 @@ static ssize_t set_cookie_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(set_cookie);
 
+resource_size_t nd_region_contiguous_max(struct nd_region *nd_region)
+{
+	resource_size_t available = 0;
+	int i;
+
+	WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
+	for (i = 0; i < nd_region->ndr_mappings; i++) {
+		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
+		struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
+
+		/* if a dimm is disabled the available capacity is zero */
+		if (!ndd)
+			return 0;
+
+		if (is_memory(&nd_region->dev))
+			available += nd_pmem_max_contiguous_dpa(nd_region,
+								nd_mapping);
+		else if (is_nd_blk(&nd_region->dev))
+			available += nd_blk_available_dpa(nd_region);
+	}
+	return available;
+}
+
 resource_size_t nd_region_available_dpa(struct nd_region *nd_region)
 {
 	resource_size_t blk_max_overlap = 0, available, overlap;
Signature · 6 lines
2.14.3

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

Re: [PATCH 1/2] libnvdimm: Use largest contiguous area for namespace size

Quoted 3 lines · Keith Busch

This patch will find the largest free extent to determine the max size for a namespace that can be created.

This also fixes the "underrun" WARN_ON, right? Can you resend with that detail in the changelog and add the Fixes tags with a cc: stable?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

Re: [PATCH 1/2] libnvdimm: Use largest contiguous area for namespace size

Quoted 7 lines · Dan Williams
Quoted 3 lines · Keith Busch

This patch will find the largest free extent to determine the max size for a namespace that can be created.

This also fixes the "underrun" WARN_ON, right? Can you resend with that detail in the changelog and add the Fixes tags with a cc: stable?

Sure thing, will resend shortly.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#4 lore raw

PATCH 2/2 libnvdimm: Export max available extent

In reply to Keith Busch

The 'available_size' attribute showing the combined total of all unallocated space isn't always useful to know how large of a namespace a user may be able to allocate if the region is fragmented. This patch will export the largest extent of contiguous unallocated space that may be allocated to create a new namespace.

---
 drivers/nvdimm/region_devs.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/nvdimm/region_devs.c +16 -0
index 8af483d7ef57..82aaf7d6488d 100644
@@ -433,6 +433,21 @@ static ssize_t available_size_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(available_size);
 
+static ssize_t max_available_extent_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct nd_region *nd_region = to_nd_region(dev);
+	unsigned long long available = 0;
+
+	nvdimm_bus_lock(dev);
+	wait_nvdimm_bus_probe_idle(dev);
+	available = nd_region_contiguous_max(nd_region);
+	nvdimm_bus_unlock(dev);
+
+	return sprintf(buf, "%llu\n", available);
+}
+static DEVICE_ATTR_RO(max_available_extent);
+
 static ssize_t init_namespaces_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
@@ -584,6 +599,7 @@ static struct attribute *nd_region_attributes[] = {
 	&dev_attr_read_only.attr,
 	&dev_attr_set_cookie.attr,
 	&dev_attr_available_size.attr,
+	&dev_attr_max_available_extent.attr,
 	&dev_attr_namespace_seed.attr,
 	&dev_attr_init_namespaces.attr,
 	&dev_attr_badblocks.attr,
Signature · 6 lines
2.14.3

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

PATCH 1/1 ndctl: Use max_available_extent for creating namespaces

In reply to Keith Busch

The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)
ndctl/lib/libndctl.c +30 -0
index 47e005e..a820fb3 100644
@@ -2025,6 +2025,36 @@ NDCTL_EXPORT unsigned long long ndctl_region_get_available_size(
 	return strtoull(buf, NULL, 0);
 }
 
+NDCTL_EXPORT unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region)
+{
+	unsigned int nstype = ndctl_region_get_nstype(region);
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+
+	switch (nstype) {
+	case ND_DEVICE_NAMESPACE_PMEM:
+	case ND_DEVICE_NAMESPACE_BLK:
+		break;
+	default:
+		return 0;
+	}
+
+	if (snprintf(path, len,
+		     "%s/max_available_extent", region->region_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return ULLONG_MAX;
+	}
+
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		return ULLONG_MAX;
+
+	return strtoull(buf, NULL, 0);
+}
+
 NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct ndctl_region *region)
 {
 	return region->range_index;
ndctl/lib/libndctl.sym +1 -0
index c1228e5..22fd026 100644
@@ -123,6 +123,7 @@ global:
 	ndctl_region_get_mappings;
 	ndctl_region_get_size;
 	ndctl_region_get_available_size;
+	ndctl_region_get_max_available_extent;
 	ndctl_region_get_type;
 	ndctl_region_get_namespace_seed;
 	ndctl_region_get_btt_seed;
ndctl/libndctl.h +2 -0
index be997ac..624115d 100644
@@ -338,6 +338,8 @@ unsigned int ndctl_region_get_interleave_ways(struct ndctl_region *region);
 unsigned int ndctl_region_get_mappings(struct ndctl_region *region);
 unsigned long long ndctl_region_get_size(struct ndctl_region *region);
 unsigned long long ndctl_region_get_available_size(struct ndctl_region *region);
+unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region);
 unsigned int ndctl_region_get_range_index(struct ndctl_region *region);
 unsigned int ndctl_region_get_type(struct ndctl_region *region);
 struct ndctl_namespace *ndctl_region_get_namespace_seed(
ndctl/namespace.c +1 -1
index fe86d82..4a562a2 100644
@@ -764,7 +764,7 @@ static int namespace_create(struct ndctl_region *region)
 		return -EAGAIN;
 	}
 
-	available = ndctl_region_get_available_size(region);
+	available = ndctl_region_get_max_available_extent(region);
 	if (!available || p.size > available) {
 		debug("%s: insufficient capacity size: %llx avail: %llx\n",
 			devname, p.size, available);
Signature · 6 lines
2.14.3

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

Re: [PATCH] ndctl: Use max_available_extent for creating namespaces

Quoted 5 lines · Keith Busch

The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

Quoted 7 lines
---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)

Hi Keith,

The patch looks good, but just a couple of 'meta' comments.
1. We typically send ndctl patches separately from kernel patches (i.e. not thraded together).
2. for ndctl patches, an 'ndctl PATCH' prefix is recommended. You can set a repo local config parameter for doing this automatically on git format- patch.
git config format.subjectprefix "ndctl PATCH"

I'm thinking the kernel changes will be queued for 4.19, which means the ndctl changes will go into v62.

Thanks,
-Vishal

Quoted 85 lines
ndctl/lib/libndctl.c +0 -0
index 47e005e..a820fb3 100644
@@ -2025,6 +2025,36 @@ NDCTL_EXPORT unsigned long long

ndctl_region_get_available_size(

ndctl/lib/libndctl.c +19 -0
 	return strtoull(buf, NULL, 0);
 }
 
+NDCTL_EXPORT unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region)
+{
+	unsigned int nstype = ndctl_region_get_nstype(region);
+	struct ndctl_ctx *ctx = ndctl_region_get_ctx(region);
+	char *path = region->region_buf;
+	int len = region->buf_len;
+	char buf[SYSFS_ATTR_SIZE];
+
+	switch (nstype) {
+	case ND_DEVICE_NAMESPACE_PMEM:
+	case ND_DEVICE_NAMESPACE_BLK:
+		break;
+	default:
+		return 0;
+	}
+
+	if (snprintf(path, len,
+		     "%s/max_available_extent", region->region_path) >=

len) {

ndctl/lib/libndctl.c +11 -0
+		err(ctx, "%s: buffer too small!\n",
+				ndctl_region_get_devname(region));
+		return ULLONG_MAX;
+	}
+
+	if (sysfs_read_attr(ctx, path, buf) < 0)
+		return ULLONG_MAX;
+
+	return strtoull(buf, NULL, 0);
+}
+
 NDCTL_EXPORT unsigned int ndctl_region_get_range_index(struct

ndctl_region *region)
{

ndctl/lib/libndctl.c +0 -0
 	return region->range_index;
ndctl/lib/libndctl.sym +1 -0
index c1228e5..22fd026 100644
@@ -123,6 +123,7 @@ global:
 	ndctl_region_get_mappings;
 	ndctl_region_get_size;
 	ndctl_region_get_available_size;
+	ndctl_region_get_max_available_extent;
 	ndctl_region_get_type;
 	ndctl_region_get_namespace_seed;
 	ndctl_region_get_btt_seed;
ndctl/libndctl.h +2 -0
index be997ac..624115d 100644
@@ -338,6 +338,8 @@ unsigned int ndctl_region_get_interleave_ways(struct
 ndctl_region *region);
 unsigned int ndctl_region_get_mappings(struct ndctl_region *region);
 unsigned long long ndctl_region_get_size(struct ndctl_region *region);
 unsigned long long ndctl_region_get_available_size(struct ndctl_region
 *region);
+unsigned long long ndctl_region_get_max_available_extent(
+		struct ndctl_region *region);
 unsigned int ndctl_region_get_range_index(struct ndctl_region *region);

unsigned int ndctl_region_get_type(struct ndctl_region *region); struct ndctl_namespace *ndctl_region_get_namespace_seed(

ndctl/namespace.c +1 -1
index fe86d82..4a562a2 100644
@@ -764,7 +764,7 @@ static int namespace_create(struct ndctl_region
 *region)
 		return -EAGAIN;
 	}
 
-	available = ndctl_region_get_available_size(region);
+	available = ndctl_region_get_max_available_extent(region);
 	if (!available || p.size > available) {
 		debug("%s: insufficient capacity size: %llx avail:
Quoted 2 lines

%llx\n",
devname, p.size, available);

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

#7 lore raw

Re: [PATCH] ndctl: Use max_available_extent for creating namespaces

Quoted 24 lines · Vishal L
Quoted 5 lines · Keith Busch

The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

Quoted 7 lines
---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)

Hi Keith,

The patch looks good, but just a couple of 'meta' comments.
1. We typically send ndctl patches separately from kernel patches (i.e. not thraded together).
2. for ndctl patches, an 'ndctl PATCH' prefix is recommended. You can set a repo local config parameter for doing this automatically on git format- patch.
git config format.subjectprefix "ndctl PATCH"

Quoted 2 lines

I'm thinking the kernel changes will be queued for 4.19, which means the ndctl changes will go into v62.

Thanks for the info. I'll make those changes for next time.

I think I may need to send a v2 for this. Should we have this fall back to the available_size for the older kernels where the max_available_extents attribute is not provided? I actually had that in my repo and used a slightly older patch here, but I'm not sure if its okay to strongly couple an ndctl release to a kernel version.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#8 lore raw

Re: [PATCH] ndctl: Use max_available_extent for creating namespaces

Quoted 31 lines · Keith Busch
Quoted 26 lines · Vishal L
Quoted 5 lines · Keith Busch

The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

Quoted 7 lines
---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)

Hi Keith,

The patch looks good, but just a couple of 'meta' comments.
1. We typically send ndctl patches separately from kernel patches (i.e. not
thraded together).
2. for ndctl patches, an 'ndctl PATCH' prefix is recommended. You can set a
repo local config parameter for doing this automatically on git format- patch.
git config format.subjectprefix "ndctl PATCH"

Quoted 3 lines

I'm thinking the kernel changes will be queued for 4.19, which means the
ndctl changes will go into v62.

Quoted 8 lines

Thanks for the info. I'll make those changes for next time.

I think I may need to send a v2 for this. Should we have this fall back to
the available_size for the older kernels where the max_available_extents attribute is not provided? I actually had that in my repo and used a slightly older patch here, but I'm not sure if its okay to strongly couple an ndctl release to a kernel version.

I was thinking that too. Typically we don't guarantee ndctl to work with old kernels, but this does seem like a bit of an invasive change.

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

#9 lore raw

Re: [PATCH] ndctl: Use max_available_extent for creating namespaces

Quoted 41 lines · Vishal L
Quoted 31 lines · Keith Busch
Quoted 26 lines · Vishal L
Quoted 5 lines · Keith Busch

The available_size attribute returns all the unused regions, but a namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

Quoted 7 lines
---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)

Hi Keith,

The patch looks good, but just a couple of 'meta' comments.
1. We typically send ndctl patches separately from kernel patches (i.e. not
thraded together).
2. for ndctl patches, an 'ndctl PATCH' prefix is recommended. You can set a
repo local config parameter for doing this automatically on git format- patch.
git config format.subjectprefix "ndctl PATCH"

Quoted 3 lines

I'm thinking the kernel changes will be queued for 4.19, which means the
ndctl changes will go into v62.

Quoted 8 lines

Thanks for the info. I'll make those changes for next time.

I think I may need to send a v2 for this. Should we have this fall back to
the available_size for the older kernels where the max_available_extents attribute is not provided? I actually had that in my repo and used a slightly older patch here, but I'm not sure if its okay to strongly couple an ndctl release to a kernel version.

Quoted 4 lines

I was thinking that too. Typically we don't guarantee ndctl to work with old kernels, but this does seem like a bit of an invasive change.

Dan, thoughts?

It should fall back if the attribute is not available. Our *tests* aren't guaranteed to pass on older kernels, but ndctl proper should try it's best to accommodate old kernels.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#10 lore raw

Re: [PATCH] ndctl: Use max_available_extent for creating namespaces

Quoted 54 lines · Dan Williams
Quoted 52 lines · Vishal L
Quoted 38 lines · Keith Busch
Quoted 30 lines · Vishal L
Quoted 6 lines · Keith Busch

The available_size attribute returns all the unused regions, but a
namespace has to use contiguous free regions. This patch uses the attribute returning the largest capacity that can be created for determining if the namespace can be created.

Quoted 7 lines
---
 ndctl/lib/libndctl.c   | 30 ++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  1 +
 ndctl/libndctl.h       |  2 ++
 ndctl/namespace.c      |  2 +-
 4 files changed, 34 insertions(+), 1 deletion(-)

Hi Keith,

The patch looks good, but just a couple of 'meta' comments.
1. We typically send ndctl patches separately from kernel patches (i.e.
not
thraded together).
2. for ndctl patches, an 'ndctl PATCH' prefix is recommended. You can
set a
repo local config parameter for doing this automatically on git format-
patch.
git config format.subjectprefix "ndctl PATCH"

Quoted 4 lines

I'm thinking the kernel changes will be queued for 4.19, which means
the
ndctl changes will go into v62.

Thanks for the info. I'll make those changes for next time.

Quoted 8 lines

I think I may need to send a v2 for this. Should we have this fall back
to
the available_size for the older kernels where the max_available_extents
attribute is not provided? I actually had that in my repo and used a slightly older patch here, but I'm not sure if its okay to strongly couple an ndctl release to a kernel version.

I was thinking that too. Typically we don't guarantee ndctl to work with
old kernels, but this does seem like a bit of an invasive change.

Quoted 5 lines
Quoted 1 line

Dan, thoughts?

It should fall back if the attribute is not available. Our *tests* aren't guaranteed to pass on older kernels, but ndctl proper should try it's best to accommodate old kernels.

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