diff -Nru stress-ng-0.09.42/debian/changelog stress-ng-0.09.42/debian/changelog --- stress-ng-0.09.42/debian/changelog 2018-11-14 17:28:22.000000000 +0000 +++ stress-ng-0.09.42/debian/changelog 2019-04-04 16:47:11.000000000 +0000 @@ -1,3 +1,12 @@ +stress-ng (0.09.42-1ubuntu2) cosmic; urgency=medium + + [Alfonso Sanchez-Beato] + * stress-numa: fix calculation of max nodes (LP: #1823208) + - use the count of bits in "Mems_allowed" to calculate the + maximum number of NUMA nodes + + -- Colin King Thu, 4 Apr 2019 17:47:11 +0100 + stress-ng (0.09.42-1ubuntu1) cosmic; urgency=medium * stress-affinity: fix set affinity setting across all diff -Nru stress-ng-0.09.42/debian/patches/0005-stress-numa-fix-calculation-of-max-nodes-LP-1803468.patch stress-ng-0.09.42/debian/patches/0005-stress-numa-fix-calculation-of-max-nodes-LP-1803468.patch --- stress-ng-0.09.42/debian/patches/0005-stress-numa-fix-calculation-of-max-nodes-LP-1803468.patch 1970-01-01 00:00:00.000000000 +0000 +++ stress-ng-0.09.42/debian/patches/0005-stress-numa-fix-calculation-of-max-nodes-LP-1803468.patch 2019-04-04 16:47:11.000000000 +0000 @@ -0,0 +1,130 @@ +From 2d4859745fd35f82081ddf8087350f85f2964971 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= + +Date: Thu, 4 Apr 2019 17:38:22 +0200 +Subject: [PATCH] stress-numa: fix calculation of max nodes (LP: #1803468) +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +Previously we were getting an upper bound to the number of max nodes +instead of the actual number. That made migrate_pages() fail in some +devices due to having bits in the masks set beyond the maximum node +identifier. + +We use now the count of bits in "Mems_allowed" to calculate the maximum +number of NUMA nodes. Fixes LP: #1803468. + +Signed-off-by: Alfonso Sanchez-Beato +Signed-off-by: Colin Ian King +--- + stress-numa.c | 56 +++++++++++++++------------------------------------ + 1 file changed, 16 insertions(+), 40 deletions(-) + +Index: stress-ng-0.09.42/stress-numa.c +=================================================================== +--- stress-ng-0.09.42.orig/stress-numa.c ++++ stress-ng-0.09.42/stress-numa.c +@@ -56,34 +56,6 @@ typedef struct node { + } node_t; + + /* +- * stress_numa_get_max_nodes() +- * probe for maximum number of nodes +- */ +-static unsigned long stress_numa_get_max_nodes(void) +-{ +- unsigned long sz = BITS_PER_BYTE, *mask = NULL; +- +- do { +- int mode = 0; +- unsigned long *newmask = realloc(mask, sz / BITS_PER_BYTE); +- +- if (!newmask) +- break; +- mask = newmask; +- if (shim_get_mempolicy(&mode, mask, sz, 0, 0) == 0) +- goto done; +- sz <<= 1; +- } while ((sz < 0x100000) && (errno == EINVAL)); +- +- /* Failed */ +- sz = 0; +-done: +- free(mask); +- +- return sz; +-} +- +-/* + * stress_numa_free_nodes() + * free circular list of node info + */ +@@ -120,9 +92,11 @@ static inline int hex_to_int(const char + /* + * stress_numa_get_mem_nodes(void) + * collect number of NUMA memory nodes, add them to a +- * circular linked list ++ * circular linked list - also, return maximum number ++ * of nodes + */ +-static int stress_numa_get_mem_nodes(node_t **node_ptr) ++static int stress_numa_get_mem_nodes(node_t **node_ptr, ++ unsigned long *max_nodes) + { + FILE *fp; + unsigned long n = 0, node_id = 0; +@@ -185,6 +159,7 @@ static int stress_numa_get_mem_nodes(nod + ptr--; + } + ++ *max_nodes = node_id; + return n; + } + +@@ -203,20 +178,13 @@ static int stress_numa(const args_t *arg + node_t *n; + int rc = EXIT_FAILURE; + +- numa_nodes = stress_numa_get_mem_nodes(&n); ++ numa_nodes = stress_numa_get_mem_nodes(&n, &max_nodes); + if (numa_nodes < 1) { +- pr_inf("%s: no NUMA nodes not found, " ++ pr_inf("%s: no NUMA nodes found, " + "aborting test\n", args->name); + rc = EXIT_NO_RESOURCE; + goto numa_free; + } +- max_nodes = stress_numa_get_max_nodes(); +- if (max_nodes == 0) { +- pr_inf("%s: cannot determine maximum number " +- "of NUMA nodes, aborting test\n", args->name); +- rc = EXIT_NO_RESOURCE; +- goto numa_free; +- } + if (!args->instance) { + pr_inf("%s: system has %lu of a maximum %lu memory NUMA nodes\n", + args->name, numa_nodes, max_nodes); +@@ -237,6 +205,7 @@ static int stress_numa(const args_t *arg + do { + int j, mode, ret, status[num_pages], dest_nodes[num_pages]; + unsigned long i, node_mask[lbits], old_node_mask[lbits]; ++ unsigned long max_node_id_count; + void *pages[num_pages]; + uint8_t *ptr; + node_t *n_tmp; +@@ -312,7 +281,14 @@ static int stress_numa(const args_t *arg + /* + * Migrate all this processes pages to the current new node + */ +- (void)memset(old_node_mask, 0xff, sizeof(old_node_mask)); ++ (void)memset(old_node_mask, 0, sizeof(old_node_mask)); ++ max_node_id_count = max_nodes; ++ for (i = 0; max_node_id_count >= lbits && i < lbits; i++) { ++ old_node_mask[i] = ULONG_MAX; ++ max_node_id_count -= lbits; ++ } ++ if (i < lbits) ++ old_node_mask[i] = (1 << max_node_id_count) - 1; + (void)memset(node_mask, 0, sizeof(node_mask)); + STRESS_SETBIT(node_mask, n->node_id); + ret = shim_migrate_pages(args->pid, max_nodes, diff -Nru stress-ng-0.09.42/debian/patches/series stress-ng-0.09.42/debian/patches/series --- stress-ng-0.09.42/debian/patches/series 2018-11-14 17:28:22.000000000 +0000 +++ stress-ng-0.09.42/debian/patches/series 2019-04-04 16:47:11.000000000 +0000 @@ -2,3 +2,4 @@ 0002-stress-seccomp-add-sanity-check-to-see-if-SECCOMP_SE.patch 0003-stress-dev-remove-FIBMAP-ioctl-on-device-LP-1800609.patch 0004-stress-revio-ensure-fiemap-extent-struct-is-zero-d-L.patch +0005-stress-numa-fix-calculation-of-max-nodes-LP-1803468.patch