From: Cyril H. <su...@li...> - 2013-05-08 08:22:05
|
The branch, master, has been updated via 630f90dab055df23a31e6c7585b944af2383de17 (commit) from 981d33aad3b33c4625b88990fbf2fad5470d47e0 (commit) - Log ----------------------------------------------------------------- commit 630f90dab055df23a31e6c7585b944af2383de17 Author: Zhouping Liu <zl...@re...> Date: Mon Apr 29 14:07:17 2013 +0800 mem/oom: fixed a cpuset error For the below special NUMA system, oom0[4|5] failed: # numactl -H available: 2 nodes (0-1) node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 node 0 size: 0 MB node 0 free: 0 MB node 1 cpus: node 1 size: 16384 MB node 1 free: 14173 MB node distances: node 0 1 0: 10 40 1: 40 10 failed log: oom04 1 TBROK : write /dev/cpuset/1/cpuset.mems: errno=EINVAL(22): Invalid argument The reason is that node0 only contains all CPUs, no any memory, and node1 contains all memory, but no CPUs. In the previous codes, we only do cpuset testing on an independent node, which caused the sub-cpuset cgroup to only contain CPUs or memory in one node, but that's not permitted in the scenario described above. Signed-off-by: Zhouping Liu <zl...@re...> Reviewed-by: Caspar Zhang <ca...@ca...> Acked-by: Wanlong Gao <gao...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/mem/lib/mem.c | 13 ++++++++++++- testcases/kernel/mem/oom/oom04.c | 20 ++++++++++++++------ testcases/kernel/mem/oom/oom05.c | 26 ++++++++++++++++---------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index 5397177..1232b4f 100644 --- a/testcases/kernel/mem/lib/mem.c +++ b/testcases/kernel/mem/lib/mem.c @@ -792,7 +792,18 @@ void write_cpusets(long nd) write_cpuset_files(CPATH_NEW, "mems", buf); gather_node_cpus(cpus, nd); - write_cpuset_files(CPATH_NEW, "cpus", cpus); + /* + * If the 'nd' node doesn't contain any CPUs, + * the first ID of CPU '0' will be used as + * the value of cpuset.cpus. + */ + if (strlen(cpus) != 0) { + write_cpuset_files(CPATH_NEW, "cpus", cpus); + } else { + tst_resm(TINFO, "No CPUs in the node%ld; " + "using only CPU0", nd); + write_cpuset_files(CPATH_NEW, "cpus", "0"); + } SAFE_FILE_PRINTF(NULL, CPATH_NEW "/tasks", "%d", getpid()); } diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c index 4d3f2f4..ac48c36 100644 --- a/testcases/kernel/mem/oom/oom04.c +++ b/testcases/kernel/mem/oom/oom04.c @@ -85,6 +85,8 @@ int main(int argc, char *argv[]) void setup(void) { + int memnode, ret; + tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; @@ -93,12 +95,18 @@ void setup(void) set_sys_tune("overcommit_memory", 1, 1); mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); - if (is_numa(cleanup) > 0) - /* For NUMA system, using the first node for cpuset.mems */ - write_cpusets(get_a_numa_node(cleanup)); - else - /* For nonNUMA system, using node0 for cpuset.mems */ - write_cpusets(0); + + /* + * Some nodes do not contain memory, so use + * get_allowed_nodes(NH_MEMS) to get a memory + * node. This operation also applies to Non-NUMA + * systems. + */ + ret = get_allowed_nodes(NH_MEMS, 1, &memnode); + if (ret < 0) + tst_brkm(TBROK, NULL, "Failed to get a memory node " + "using get_allowed_nodes()"); + write_cpusets(memnode); } void cleanup(void) diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c index 15feba5..545b5f0 100644 --- a/testcases/kernel/mem/oom/oom05.c +++ b/testcases/kernel/mem/oom/oom05.c @@ -108,24 +108,30 @@ int main(int argc, char *argv[]) void setup(void) { + int ret, memnode; + tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; + overcommit = get_sys_tune("overcommit_memory"); + set_sys_tune("overcommit_memory", 1, 1); + mount_mem("memcg", "cgroup", "memory", MEMCG_PATH, MEMCG_PATH_NEW); mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); write_memcg(); - set_sys_tune("overcommit_memory", 1, 1); - - if (is_numa(cleanup)) - /* For NUMA system, using the first node for cpuset.mems */ - write_cpusets(get_a_numa_node(cleanup)); - else - /* For nonNUMA system, using node0 for cpuset.mems */ - write_cpusets(0); - - overcommit = get_sys_tune("overcommit_memory"); + /* + * Some nodes do not contain memory, so use + * get_allowed_nodes(NH_MEMS) to get a memory + * node. This operation also applies to Non-NUMA + * systems. + */ + ret = get_allowed_nodes(NH_MEMS, 1, &memnode); + if (ret < 0) + tst_brkm(TBROK, NULL, "Failed to get a memory node " + "using get_allowed_nodes()"); + write_cpusets(memnode); } void cleanup(void) hooks/post-receive -- ltp |