blob: 3434a34baadecdb4583ddc847c08e34f670cb33a [file] [log] [blame]
Garrett Cooperd2deda92011-01-18 01:43:39 -08001/*
Zhouping Liu62d50b72013-03-19 11:40:50 +08002 * Out Of Memory (OOM) for mempolicy - need NUMA system support
Garrett Cooperd2deda92011-01-18 01:43:39 -08003 *
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 Wangc8f62312017-07-18 16:22:59 +080010 * Copyright (C) 2010-2017 Red Hat, Inc.
Garrett Cooperd2deda92011-01-18 01:43:39 -080011 *
Li Wangc8f62312017-07-18 16:22:59 +080012 * 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 Cooperd2deda92011-01-18 01:43:39 -080016 *
Li Wangc8f62312017-07-18 16:22:59 +080017 * 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 Cooperd2deda92011-01-18 01:43:39 -080021 */
Caspar Zhang79667fa2012-03-12 14:41:46 +080022
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 Liu4849bb32013-03-19 11:40:52 +080029#include "numa_helper.h"
Caspar Zhang79667fa2012-03-12 14:41:46 +080030#include "mem.h"
Garrett Cooperd2deda92011-01-18 01:43:39 -080031
Garrett Cooperd2deda92011-01-18 01:43:39 -080032#if HAVE_NUMA_H && HAVE_LINUX_MEMPOLICY_H && HAVE_NUMAIF_H \
33 && HAVE_MPOL_CONSTANTS
Zhouping Liu62d50b72013-03-19 11:40:50 +080034
Li Wangc8f62312017-07-18 16:22:59 +080035static void verify_oom(void)
Garrett Cooperd2deda92011-01-18 01:43:39 -080036{
Garrett Cooper10e5d882011-01-20 01:29:53 -080037#if __WORDSIZE == 32
Li Wangc8f62312017-07-18 16:22:59 +080038 tst_brk(TCONF, "test is not designed for 32-bit system.");
Garrett Cooper4bab3352011-01-18 01:59:16 -080039#endif
Garrett Cooperd2deda92011-01-18 01:43:39 -080040
Li Wangc8f62312017-07-18 16:22:59 +080041 tst_res(TINFO, "OOM on MPOL_BIND mempolicy...");
42 testoom(MPOL_BIND, 0, ENOMEM, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080043
Li Wangc8f62312017-07-18 16:22:59 +080044 tst_res(TINFO, "OOM on MPOL_INTERLEAVE mempolicy...");
45 testoom(MPOL_INTERLEAVE, 0, ENOMEM, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080046
Li Wangc8f62312017-07-18 16:22:59 +080047 tst_res(TINFO, "OOM on MPOL_PREFERRED mempolicy...");
48 testoom(MPOL_PREFERRED, 0, ENOMEM, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080049}
50
Li Wangc8f62312017-07-18 16:22:59 +080051static void setup(void)
Garrett Cooperd2deda92011-01-18 01:43:39 -080052{
Jan Stancekb8c69af2016-02-23 11:00:32 +010053 if (!is_numa(NULL, NH_MEMS, 2))
Li Wangc8f62312017-07-18 16:22:59 +080054 tst_brk(TCONF, "The case need a NUMA system.");
Zhouping Liu62d50b72013-03-19 11:40:50 +080055
Caspar Zhangff74ba52012-02-27 16:13:18 +080056 overcommit = get_sys_tune("overcommit_memory");
57 set_sys_tune("overcommit_memory", 1, 1);
Garrett Cooperd2deda92011-01-18 01:43:39 -080058}
59
Li Wangc8f62312017-07-18 16:22:59 +080060static void cleanup(void)
Garrett Cooperd2deda92011-01-18 01:43:39 -080061{
Caspar Zhangff74ba52012-02-27 16:13:18 +080062 set_sys_tune("overcommit_memory", overcommit, 0);
Garrett Cooperd2deda92011-01-18 01:43:39 -080063}
64
Li Wangc8f62312017-07-18 16:22:59 +080065static struct tst_test test = {
66 .needs_root = 1,
67 .forks_child = 1,
Li Wang94823cf2017-07-18 16:23:00 +080068 .timeout = -1,
Li Wangc8f62312017-07-18 16:22:59 +080069 .setup = setup,
70 .cleanup = cleanup,
71 .test_all = verify_oom,
72};
73
Garrett Cooperd2deda92011-01-18 01:43:39 -080074#else /* no NUMA */
Li Wangc8f62312017-07-18 16:22:59 +080075 TST_TEST_TCONF("no NUMA development packages installed.");
Garrett Cooperd2deda92011-01-18 01:43:39 -080076#endif