Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Out Of Memory (OOM) for NUMA |
| 3 | * |
| 4 | * The program is designed to cope with unpredictable like amount and |
| 5 | * system physical memory, swap size and other VMM technology like KSM, |
| 6 | * memcg, memory hotplug and so on which may affect the OOM |
| 7 | * behaviours. It simply increase the memory consumption 3G each time |
| 8 | * until all the available memory is consumed and OOM is triggered. |
| 9 | * |
| 10 | * Copyright (C) 2010 Red Hat, Inc. |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of version 2 of the GNU General Public |
| 13 | * License as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it would be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 18 | * |
| 19 | * Further, this software is distributed without any warranty that it |
| 20 | * is free of the rightful claim of any third person regarding |
| 21 | * infringement or the like. Any license provided herein, whether |
| 22 | * implied or otherwise, applies only to this software file. Patent |
| 23 | * licenses, if any, provided herein do not apply to combinations of |
| 24 | * this program with other software, or any other product whatsoever. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write the Free Software |
| 28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 29 | * 02110-1301, USA. |
| 30 | */ |
| 31 | #include "test.h" |
| 32 | #include "usctest.h" |
| 33 | #include "config.h" |
| 34 | |
| 35 | char *TCID = "oom02"; |
| 36 | int TST_TOTAL = 1; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 37 | |
| 38 | #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \ |
| 39 | && HAVE_MPOL_CONSTANTS |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/stat.h> |
| 42 | #include <fcntl.h> |
| 43 | #include <stdio.h> |
| 44 | #include <errno.h> |
| 45 | #include "lib/oom.h" |
| 46 | |
| 47 | static void setup(void); |
| 48 | |
| 49 | int main(int argc, char *argv[]) |
| 50 | { |
| 51 | char *msg; |
| 52 | int lc, fd; |
| 53 | unsigned long nnodes = 1; |
| 54 | |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 55 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
| 56 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 57 | |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 58 | #ifdef __WORDSIZE == 32 |
| 59 | tst_brkm(TCONF, NULL, |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 60 | "this test is not designed for 32-bit system."); |
| 61 | #endif /* __i386__ */ |
| 62 | |
| 63 | nnodes = count_numa(); |
| 64 | if (count_numa() == 1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 65 | tst_brkm(TCONF, NULL, "required a NUMA system."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 66 | |
| 67 | setup(); |
| 68 | |
| 69 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 70 | Tst_count = 0; |
| 71 | fd = open(SYSFS_OVER, O_WRONLY); |
| 72 | if (fd == -1) |
| 73 | tst_brkm(TBROK|TERRNO, cleanup, "open"); |
| 74 | if (write(fd, "1", 1) != 1) |
| 75 | tst_brkm(TBROK|TERRNO, cleanup, "write"); |
| 76 | close(fd); |
| 77 | |
| 78 | tst_resm(TINFO, "process mempolicy."); |
| 79 | testoom(1, 0); |
| 80 | |
| 81 | tst_resm(TINFO, "process cpuset."); |
| 82 | testoom(0, 0); |
| 83 | } |
| 84 | cleanup(); |
| 85 | } |
| 86 | |
| 87 | void setup(void) |
| 88 | { |
| 89 | int fd; |
| 90 | |
| 91 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 92 | TEST_PAUSE; |
| 93 | |
| 94 | fd = open(SYSFS_OVER, O_RDONLY); |
| 95 | if (fd == -1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 96 | tst_brkm(TBROK|TERRNO, NULL, "open"); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 97 | if (read(fd, &overcommit, 1) != 1) |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 98 | tst_brkm(TBROK|TERRNO, NULL, "read"); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 99 | close(fd); |
| 100 | |
| 101 | mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); |
| 102 | } |
| 103 | |
| 104 | void cleanup(void) |
| 105 | { |
| 106 | int fd; |
| 107 | |
| 108 | fd = open(SYSFS_OVER, O_WRONLY); |
| 109 | if (fd == -1) |
| 110 | tst_brkm(TBROK|TERRNO, cleanup, "open"); |
| 111 | if (write(fd, &overcommit, 1) != 1) |
| 112 | tst_brkm(TBROK|TERRNO, cleanup, "write"); |
| 113 | close(fd); |
| 114 | |
| 115 | umount_mem(CPATH, CPATH_NEW); |
| 116 | |
| 117 | TEST_CLEANUP; |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | #else /* no NUMA */ |
| 121 | int main(void) |
| 122 | { |
Garrett Cooper | 15619ba | 2011-01-18 01:48:15 -0800 | [diff] [blame^] | 123 | tst_brkm(TCONF, NULL, "no NUMA development packages installed."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 124 | } |
| 125 | #endif |