* [LTP] [PATCH 1/2] move_pages_support: use only allowed nodes
@ 2012-05-25 9:12 Jan Stancek
2012-05-25 16:52 ` Garrett Cooper
0 siblings, 1 reply; 2+ messages in thread
From: Jan Stancek @ 2012-05-25 9:12 UTC (permalink / raw)
To: ltp-list; +Cc: Jeffrey Burke
[-- Attachment #1: Type: text/plain, Size: 366 bytes --]
Some setups can lack memory on arbitrary nodes, use only nodes
returned by get_mempolicy(..., MPOL_F_MEMS_ALLOWED).
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
.../syscalls/move_pages/move_pages_support.c | 74 ++++++++++++++++----
.../syscalls/move_pages/move_pages_support.h | 1 +
2 files changed, 62 insertions(+), 13 deletions(-)
[-- Attachment #2: 0001-move_pages_support-use-only-allowed-nodes.patch --]
[-- Type: text/x-patch, Size: 4371 bytes --]
diff --git a/testcases/kernel/syscalls/move_pages/move_pages_support.c b/testcases/kernel/syscalls/move_pages/move_pages_support.c
index 320486f..83a841b 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages_support.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages_support.c
@@ -22,6 +22,7 @@
#include <semaphore.h>
#include "test.h"
#include "usctest.h"
+#include "safe_macros.h"
#include "move_pages_support.h"
long get_page_size()
@@ -98,6 +99,46 @@ int alloc_pages_on_nodes(void **pages, unsigned int num, int *nodes)
}
/*
+ * get_allowed_nodes - get number and array of available nodes
+ * @num_allowed_nodes: pointer where number of available nodes will be stored
+ * @allowed_nodes: array of available node ids, this is MPOL_F_MEMS_ALLOWED
+ * node bitmask compacted (without holes), so that each field
+ * contains node number. If NULL only num_allowed_nodes is
+ * returned, otherwise it cotains new allocated array,
+ * which caller is responsible to free.
+ */
+void get_allowed_nodes(int *num_allowed_nodes, int **allowed_nodes)
+{
+#if HAVE_NUMA_H
+ int i;
+ struct bitmask *allowed_nodemask = NULL;
+
+ *num_allowed_nodes = 0;
+ allowed_nodemask = numa_allocate_nodemask();
+ if (allowed_nodes)
+ *allowed_nodes = SAFE_MALLOC(NULL,
+ sizeof(int)*allowed_nodemask->size);
+ /*
+ * avoid numa_get_mems_allowed(), because of bug in getpol()
+ * utility function in older versions:
+ * http://www.spinics.net/lists/linux-numa/msg00849.html
+ */
+ if (syscall(__NR_get_mempolicy, NULL, allowed_nodemask->maskp,
+ allowed_nodemask->size, 0, MPOL_F_MEMS_ALLOWED) < 0)
+ tst_resm(TFAIL|TERRNO, "get_mempolicy: MPOL_F_MEMS_ALLOWED");
+
+ for (i = 0; i < allowed_nodemask->size; i++) {
+ if (numa_bitmask_isbitset(allowed_nodemask, i)) {
+ if (allowed_nodes)
+ (*allowed_nodes)[*num_allowed_nodes] = i;
+ (*num_allowed_nodes)++;
+ }
+ }
+ numa_bitmask_free(allowed_nodemask);
+#endif
+}
+
+/*
* alloc_pages_linear() - allocate pages in each NUMA node
* @pages: array in which the page pointers will be stored
* @num: no. of pages to allocate
@@ -114,16 +155,18 @@ int alloc_pages_linear(void **pages, unsigned int num)
#if HAVE_NUMA_H
unsigned int i;
- unsigned int n;
+ unsigned int n = 0;
+ int num_allowed_nodes;
+ int *allowed_nodes;
- n = 0;
+ get_allowed_nodes(&num_allowed_nodes, &allowed_nodes);
for (i = 0; i < num; i++) {
- nodes[i] = n;
-
+ nodes[i] = allowed_nodes[n];
n++;
- if (n > numa_max_node())
+ if (n >= num_allowed_nodes)
n = 0;
}
+ free(allowed_nodes);
#endif
return alloc_pages_on_nodes(pages, num, nodes);
@@ -210,18 +253,19 @@ void verify_pages_linear(void **pages, int *status, unsigned int num)
{
#if HAVE_NUMA_H
unsigned int i;
- unsigned int n;
+ unsigned int n = 0;
int nodes[num];
+ int num_allowed_nodes;
+ int *allowed_nodes;
- n = 0;
-
+ get_allowed_nodes(&num_allowed_nodes, &allowed_nodes);
for (i = 0; i < num; i++) {
- nodes[i] = i;
-
+ nodes[i] = allowed_nodes[n];
n++;
- if (n > numa_max_node())
+ if (n >= num_allowed_nodes)
n = 0;
}
+ free(allowed_nodes);
verify_pages_on_nodes(pages, status, num, nodes);
#endif
@@ -381,10 +425,14 @@ void free_sem(sem_t * sem, int num)
void check_config(unsigned int min_nodes)
{
#if HAVE_NUMA_H && HAVE_NUMAIF_H
+ int num_allowed_nodes;
+ get_allowed_nodes(&num_allowed_nodes, NULL);
+
if (numa_available() < 0) {
tst_brkm(TCONF, NULL, "NUMA support is not available");
- } else if (numa_max_node() < (min_nodes - 1)) {
- tst_brkm(TCONF, NULL, "atleast 2 NUMA nodes are required");
+ } else if (num_allowed_nodes < min_nodes) {
+ tst_brkm(TCONF, NULL, "at least %d allowed NUMA nodes"
+ " are required", min_nodes);
} else if (tst_kvercmp(2, 6, 18) < 0) {
tst_brkm(TCONF, NULL, "2.6.18 or greater kernel required");
}
diff --git a/testcases/kernel/syscalls/move_pages/move_pages_support.h b/testcases/kernel/syscalls/move_pages/move_pages_support.h
index fd78572..a10293b 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages_support.h
+++ b/testcases/kernel/syscalls/move_pages/move_pages_support.h
@@ -29,6 +29,7 @@
#include <semaphore.h>
long get_page_size();
+void get_allowed_nodes(int *num_allowed_nodes, int **allowed_nodes);
void free_pages(void **pages, unsigned int num);
[-- Attachment #3: Type: text/plain, Size: 395 bytes --]
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH 1/2] move_pages_support: use only allowed nodes
2012-05-25 9:12 [LTP] [PATCH 1/2] move_pages_support: use only allowed nodes Jan Stancek
@ 2012-05-25 16:52 ` Garrett Cooper
0 siblings, 0 replies; 2+ messages in thread
From: Garrett Cooper @ 2012-05-25 16:52 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp-list, Jeffrey Burke
On Fri, May 25, 2012 at 2:12 AM, Jan Stancek <jstancek@redhat.com> wrote:
>
> Some setups can lack memory on arbitrary nodes, use only nodes
> returned by get_mempolicy(..., MPOL_F_MEMS_ALLOWED).
>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
> .../syscalls/move_pages/move_pages_support.c | 74 ++++++++++++++++----
> .../syscalls/move_pages/move_pages_support.h | 1 +
> 2 files changed, 62 insertions(+), 13 deletions(-)
+ if (syscall(__NR_get_mempolicy, NULL, allowed_nodemask->maskp,
+ allowed_nodemask->size, 0, MPOL_F_MEMS_ALLOWED) < 0)
+ tst_resm(TFAIL|TERRNO, "get_mempolicy: MPOL_F_MEMS_ALLOWED");
+
Would tst_brkm be better here? Also, what happens in the negative case
(HAVE_NUMA_H is not defined)? Wouldn't that segfault accessing random
memory or something along those lines?
I think it would be better to design the API (get_allowed_nodes) to
return an integer value to denote success or failure, then test for
that in main and report errors there.
Thanks!
-Garrett
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-25 16:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 9:12 [LTP] [PATCH 1/2] move_pages_support: use only allowed nodes Jan Stancek
2012-05-25 16:52 ` Garrett Cooper
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox