nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH] ndctl: fail NUMA filtering when unsupported
@ 2018-03-09 23:34 Ross Zwisler
  2018-03-09 23:47 ` Verma, Vishal L
  0 siblings, 1 reply; 5+ messages in thread
From: Ross Zwisler @ 2018-03-09 23:34 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm, Verma, Vishal L

For systems that don't support NUMA, numactl gives a loud and fatal error:

  # numactl -N 0 ls
  numactl: This system does not support NUMA policy

Follow this model in ndctl for NUMA based filtering:

  # ./ndctl/ndctl list --numa-node=0
    Error: This system does not support NUMA

This is done instead of just quietly filtering out all dimms, regions and
namespaces because the NUMA node they were trying to match didn't exist in
the system.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
---
 util/filter.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/util/filter.c b/util/filter.c
index 291d7ed..fdc46a3 100644
--- a/util/filter.c
+++ b/util/filter.c
@@ -14,7 +14,10 @@
 #include <string.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <unistd.h>
+#include <sys/stat.h>
 #include <util/util.h>
+#include <sys/types.h>
 #include <ndctl/ndctl.h>
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
@@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
 	}
 
 	if (param->numa_node && strcmp(param->numa_node, "all") != 0) {
+		struct stat st;
+
+		if (stat("/sys/devices/system/node", &st)) {
+			error("This system does not support NUMA\n");
+			return -EINVAL;
+		}
+
 		numa_node = strtol(param->numa_node, &end, 0);
 		if (end == param->numa_node || end[0]) {
 			error("invalid numa_node: '%s'\n", param->numa_node);
-- 
2.14.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [ndctl PATCH] ndctl: fail NUMA filtering when unsupported
  2018-03-09 23:34 [ndctl PATCH] ndctl: fail NUMA filtering when unsupported Ross Zwisler
@ 2018-03-09 23:47 ` Verma, Vishal L
  2018-03-10  0:20   ` Dan Williams
  0 siblings, 1 reply; 5+ messages in thread
From: Verma, Vishal L @ 2018-03-09 23:47 UTC (permalink / raw)
  To: Williams, Dan J, ross.zwisler, linux-nvdimm


On Fri, 2018-03-09 at 16:34 -0700, Ross Zwisler wrote:
> For systems that don't support NUMA, numactl gives a loud and fatal
> error:
> 
>   # numactl -N 0 ls
>   numactl: This system does not support NUMA policy
> 
> Follow this model in ndctl for NUMA based filtering:
> 
>   # ./ndctl/ndctl list --numa-node=0
>     Error: This system does not support NUMA
> 
> This is done instead of just quietly filtering out all dimms, regions
> and
> namespaces because the NUMA node they were trying to match didn't
> exist in
> the system.
> 
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  util/filter.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/util/filter.c b/util/filter.c
> index 291d7ed..fdc46a3 100644
> --- a/util/filter.c
> +++ b/util/filter.c
> @@ -14,7 +14,10 @@
>  #include <string.h>
>  #include <stdlib.h>
>  #include <limits.h>
> +#include <unistd.h>
> +#include <sys/stat.h>
>  #include <util/util.h>
> +#include <sys/types.h>
>  #include <ndctl/ndctl.h>
>  #include <util/filter.h>
>  #include <ndctl/libndctl.h>
> @@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx,
> struct util_filter_ctx *fctx,
>  	}
>  
>  	if (param->numa_node && strcmp(param->numa_node, "all") !=
> 0) {
> +		struct stat st;
> +
> +		if (stat("/sys/devices/system/node", &st)) {
> +			error("This system does not support
> NUMA\n");
> +			return -EINVAL;
> +		}

Is it ok to just directly read sysfs here? Alternatively we could use
the get_mempolicy syscall (like libnuma does) but that requires linking
with -lnuma..

https://github.com/numactl/numactl/blob/master/libnuma.c#L800

> +
>  		numa_node = strtol(param->numa_node, &end, 0);
>  		if (end == param->numa_node || end[0]) {
>  			error("invalid numa_node: '%s'\n", param-
> >numa_node);
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ndctl PATCH] ndctl: fail NUMA filtering when unsupported
  2018-03-09 23:47 ` Verma, Vishal L
@ 2018-03-10  0:20   ` Dan Williams
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Williams @ 2018-03-10  0:20 UTC (permalink / raw)
  To: Verma, Vishal L; +Cc: linux-nvdimm

On Fri, Mar 9, 2018 at 3:47 PM, Verma, Vishal L
<vishal.l.verma@intel.com> wrote:
>
> On Fri, 2018-03-09 at 16:34 -0700, Ross Zwisler wrote:
>> For systems that don't support NUMA, numactl gives a loud and fatal
>> error:
>>
>>   # numactl -N 0 ls
>>   numactl: This system does not support NUMA policy
>>
>> Follow this model in ndctl for NUMA based filtering:
>>
>>   # ./ndctl/ndctl list --numa-node=0
>>     Error: This system does not support NUMA
>>
>> This is done instead of just quietly filtering out all dimms, regions
>> and
>> namespaces because the NUMA node they were trying to match didn't
>> exist in
>> the system.
>>
>> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>> ---
>>  util/filter.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/util/filter.c b/util/filter.c
>> index 291d7ed..fdc46a3 100644
>> --- a/util/filter.c
>> +++ b/util/filter.c
>> @@ -14,7 +14,10 @@
>>  #include <string.h>
>>  #include <stdlib.h>
>>  #include <limits.h>
>> +#include <unistd.h>
>> +#include <sys/stat.h>
>>  #include <util/util.h>
>> +#include <sys/types.h>
>>  #include <ndctl/ndctl.h>
>>  #include <util/filter.h>
>>  #include <ndctl/libndctl.h>
>> @@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx,
>> struct util_filter_ctx *fctx,
>>       }
>>
>>       if (param->numa_node && strcmp(param->numa_node, "all") !=
>> 0) {
>> +             struct stat st;
>> +
>> +             if (stat("/sys/devices/system/node", &st)) {
>> +                     error("This system does not support
>> NUMA\n");
>> +                     return -EINVAL;
>> +             }
>
> Is it ok to just directly read sysfs here? Alternatively we could use
> the get_mempolicy syscall (like libnuma does) but that requires linking
> with -lnuma..
>
> https://github.com/numactl/numactl/blob/master/libnuma.c#L800

I don't mind linking against libnuma if the goal is to mimic the
behavior of numactl.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ndctl PATCH] ndctl: fail NUMA filtering when unsupported
  2018-03-23 23:08 Ross Zwisler
@ 2018-03-23 23:31 ` Dan Williams
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Williams @ 2018-03-23 23:31 UTC (permalink / raw)
  To: Ross Zwisler; +Cc: linux-nvdimm

On Fri, Mar 23, 2018 at 4:08 PM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> For systems that don't support NUMA, numactl gives a loud and fatal error:
>
>   # numactl -N 0 ls
>   numactl: This system does not support NUMA policy
>
> Follow this model in ndctl for NUMA based filtering:
>
>   # ./ndctl/ndctl list --numa-node=0
>     Error: This system does not support NUMA
>
> This is done instead of just quietly filtering out all dimms, regions and
> namespaces because the NUMA node they were trying to match didn't exist in
> the system.
>
> libnuma tests whether NUMA is enabled via the get_mempolicy() syscall,
> passing in all NULLs and 0s for arguments to always get the default policy.
> See numa_available() in numa(3) and in the numactl source.
>
> ndctl checks sysfs for the existence of the /sys/devices/system/node
> directory to avoid a dependency on libnuma.  If we had a dependency on
> libnuma we would have to choose whether this was fulfilled or not at
> compile time, which would potentially mean that we could be on a
> NUMA-enabled kernel but with an ndctl where NUMA support was disabled.
> It's better to always have NUMA support in ndctl and only depend on the
> kernel config.
>
> I've inspected the code for both get_mempolicy() and the code that creates
> the /sys/devices/system/node directory, and they both seem to completely
> rely on CONFIG_NUMA being defined.  If CONFIG_NUMA is set, get_mempolicy()
> will always be able to return a default policy and /sys/devices/system/node
> will always exist.  Otherwise, both checks will always fail.  So, numactl
> and ndctl should always agree on whether NUMA is supported on a given
> system.
>
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> ---
>
> v3: Changed back to checking /sys/devices/system/node instead of using
>     libnuma, and added more info to the changelog.

Looks good, applied.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ndctl PATCH] ndctl: fail NUMA filtering when unsupported
@ 2018-03-23 23:08 Ross Zwisler
  2018-03-23 23:31 ` Dan Williams
  0 siblings, 1 reply; 5+ messages in thread
From: Ross Zwisler @ 2018-03-23 23:08 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm, Verma, Vishal L

For systems that don't support NUMA, numactl gives a loud and fatal error:

  # numactl -N 0 ls
  numactl: This system does not support NUMA policy

Follow this model in ndctl for NUMA based filtering:

  # ./ndctl/ndctl list --numa-node=0
    Error: This system does not support NUMA

This is done instead of just quietly filtering out all dimms, regions and
namespaces because the NUMA node they were trying to match didn't exist in
the system.

libnuma tests whether NUMA is enabled via the get_mempolicy() syscall,
passing in all NULLs and 0s for arguments to always get the default policy.
See numa_available() in numa(3) and in the numactl source.

ndctl checks sysfs for the existence of the /sys/devices/system/node
directory to avoid a dependency on libnuma.  If we had a dependency on
libnuma we would have to choose whether this was fulfilled or not at
compile time, which would potentially mean that we could be on a
NUMA-enabled kernel but with an ndctl where NUMA support was disabled.
It's better to always have NUMA support in ndctl and only depend on the
kernel config.

I've inspected the code for both get_mempolicy() and the code that creates
the /sys/devices/system/node directory, and they both seem to completely
rely on CONFIG_NUMA being defined.  If CONFIG_NUMA is set, get_mempolicy()
will always be able to return a default policy and /sys/devices/system/node
will always exist.  Otherwise, both checks will always fail.  So, numactl
and ndctl should always agree on whether NUMA is supported on a given
system.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
---

v3: Changed back to checking /sys/devices/system/node instead of using
    libnuma, and added more info to the changelog.
---
 util/filter.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/util/filter.c b/util/filter.c
index 291d7ed..6ab391a 100644
--- a/util/filter.c
+++ b/util/filter.c
@@ -14,7 +14,10 @@
 #include <string.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <unistd.h>
+#include <sys/stat.h>
 #include <util/util.h>
+#include <sys/types.h>
 #include <ndctl/ndctl.h>
 #include <util/filter.h>
 #include <ndctl/libndctl.h>
@@ -328,6 +331,13 @@ int util_filter_walk(struct ndctl_ctx *ctx, struct util_filter_ctx *fctx,
 	}
 
 	if (param->numa_node && strcmp(param->numa_node, "all") != 0) {
+		struct stat st;
+
+		if (stat("/sys/devices/system/node", &st) != 0) {
+			error("This system does not support NUMA");
+			return -EINVAL;
+		}
+
 		numa_node = strtol(param->numa_node, &end, 0);
 		if (end == param->numa_node || end[0]) {
 			error("invalid numa_node: '%s'\n", param->numa_node);
-- 
2.14.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-23 23:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09 23:34 [ndctl PATCH] ndctl: fail NUMA filtering when unsupported Ross Zwisler
2018-03-09 23:47 ` Verma, Vishal L
2018-03-10  0:20   ` Dan Williams
2018-03-23 23:08 Ross Zwisler
2018-03-23 23:31 ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).