Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 1 | /* |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 2 | * Out Of Memory (OOM) for mempolicy - need NUMA system support |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 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 | * |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 10 | * Copyright (C) 2010-2017 Red Hat, Inc. |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 11 | * |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 16 | * |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 20 | * the GNU General Public License for more details. |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 21 | */ |
Caspar Zhang | 79667fa | 2012-03-12 14:41:46 +0800 | [diff] [blame] | 22 | |
| 23 | #include "config.h" |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <errno.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <stdio.h> |
Zhouping Liu | 4849bb3 | 2013-03-19 11:40:52 +0800 | [diff] [blame] | 29 | #include "numa_helper.h" |
Caspar Zhang | 79667fa | 2012-03-12 14:41:46 +0800 | [diff] [blame] | 30 | #include "mem.h" |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 31 | |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 32 | #if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \ |
| 33 | && HAVE_MPOL_CONSTANTS |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 34 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 35 | static void verify_oom(void) |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 36 | { |
Garrett Cooper | 10e5d88 | 2011-01-20 01:29:53 -0800 | [diff] [blame] | 37 | #if __WORDSIZE == 32 |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 38 | tst_brk(TCONF, "test is not designed for 32-bit system."); |
Garrett Cooper | 4bab335 | 2011-01-18 01:59:16 -0800 | [diff] [blame] | 39 | #endif |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 40 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 41 | tst_res(TINFO, "OOM on MPOL_BIND mempolicy..."); |
| 42 | testoom(MPOL_BIND, 0, ENOMEM, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 43 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 44 | tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy..."); |
| 45 | testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 46 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 47 | tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy..."); |
| 48 | testoom(MPOL_PREFERRED, 0, ENOMEM, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 51 | static void setup(void) |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 52 | { |
Jan Stancek | b8c69af | 2016-02-23 11:00:32 +0100 | [diff] [blame] | 53 | if (!is_numa(NULL, NH_MEMS, 2)) |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 54 | tst_brk(TCONF, "The case need a NUMA system."); |
Zhouping Liu | 62d50b7 | 2013-03-19 11:40:50 +0800 | [diff] [blame] | 55 | |
Caspar Zhang | ff74ba5 | 2012-02-27 16:13:18 +0800 | [diff] [blame] | 56 | overcommit = get_sys_tune("overcommit_memory"); |
| 57 | set_sys_tune("overcommit_memory", 1, 1); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 60 | static void cleanup(void) |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 61 | { |
Caspar Zhang | ff74ba5 | 2012-02-27 16:13:18 +0800 | [diff] [blame] | 62 | set_sys_tune("overcommit_memory", overcommit, 0); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 65 | static struct tst_test test = { |
| 66 | .needs_root = 1, |
| 67 | .forks_child = 1, |
| 68 | .setup = setup, |
| 69 | .cleanup = cleanup, |
| 70 | .test_all = verify_oom, |
| 71 | }; |
| 72 | |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 73 | #else /* no NUMA */ |
Li Wang | c8f6231 | 2017-07-18 16:22:59 +0800 | [diff] [blame^] | 74 | TST_TEST_TCONF("no NUMA development packages installed."); |
Garrett Cooper | d2deda9 | 2011-01-18 01:43:39 -0800 | [diff] [blame] | 75 | #endif |