void cleanup(void) { set_sys_tune("overcommit_memory", old_overcommit, 0); set_sys_tune("max_map_count", old_max_map_count, 0); TEST_CLEANUP; }
static void overcommit_memory_test(void) { #if __WORDSIZE == 32 tst_brk(TCONF, "test is not designed for 32-bit system."); #endif /* start to test overcommit_memory=2 */ set_sys_tune("overcommit_memory", 2, 1); update_mem_commit(); alloc_and_check(commit_left * 2, EXPECT_FAIL); alloc_and_check(commit_limit, EXPECT_FAIL); update_mem_commit(); alloc_and_check(commit_left / 2, EXPECT_PASS); /* start to test overcommit_memory=0 */ set_sys_tune("overcommit_memory", 0, 1); update_mem(); alloc_and_check(free_total / 2, EXPECT_PASS); update_mem(); alloc_and_check(free_total * 2, EXPECT_FAIL); alloc_and_check(sum_total, EXPECT_FAIL); /* start to test overcommit_memory=1 */ set_sys_tune("overcommit_memory", 1, 1); alloc_and_check(sum_total / 2, EXPECT_PASS); alloc_and_check(sum_total, EXPECT_PASS); alloc_and_check(sum_total * 2, EXPECT_PASS); }
static void cleanup(void) { if (old_overcommit_memory != -1) set_sys_tune("overcommit_memory", old_overcommit_memory, 0); if (old_overcommit_ratio != -1) set_sys_tune("overcommit_ratio", old_overcommit_ratio, 0); }
int main(int argc, char *argv[]) { int lc; tst_parse_opts(argc, argv, NULL, NULL); #if __WORDSIZE == 32 tst_brkm(TCONF, NULL, "test is not designed for 32-bit system."); #endif setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* we expect mmap to fail before OOM is hit */ set_sys_tune("overcommit_memory", 2, 1); oom(OVERCOMMIT, 0, ENOMEM, 0); /* with overcommit_memory set to 0 or 1 there's no * guarantee that mmap fails before OOM */ set_sys_tune("overcommit_memory", 0, 1); oom(OVERCOMMIT, 0, ENOMEM, 1); set_sys_tune("overcommit_memory", 1, 1); testoom(0, 0, ENOMEM, 1); } cleanup(); tst_exit(); }
void cleanup(void) { set_sys_tune("overcommit_memory", old_overcommit_memory, 0); set_sys_tune("overcommit_ratio", old_overcommit_ratio, 0); TEST_CLEANUP; }
static void overcommit_memory_test(void) { /* start to test overcommit_memory=2 */ set_sys_tune("overcommit_memory", 2, 1); update_mem(); alloc_and_check(commit_left * 2, EXPECT_FAIL); alloc_and_check(commit_limit, EXPECT_FAIL); update_mem(); alloc_and_check(commit_left / 2, EXPECT_PASS); /* start to test overcommit_memory=0 */ set_sys_tune("overcommit_memory", 0, 1); update_mem(); alloc_and_check(free_total / 2, EXPECT_PASS); update_mem(); alloc_and_check(free_total * 2, EXPECT_FAIL); alloc_and_check(sum_total, EXPECT_FAIL); /* start to test overcommit_memory=1 */ set_sys_tune("overcommit_memory", 1, 1); alloc_and_check(sum_total / 2, EXPECT_PASS); alloc_and_check(sum_total, EXPECT_PASS); alloc_and_check(sum_total * 2, EXPECT_PASS); }
void setup(void) { long hpage_size; tst_require_root(); check_hugepage(); tst_sig(FORK, DEF_HANDLER, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(cleanup); shm_id_1 = shmget(shmkey, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); if (shm_id_1 == -1) tst_brkm(TBROK | TERRNO, cleanup, "shmget"); /* get the userid for a non root user */ ltp_uid = getuserid(cleanup, ltp_user); TEST_PAUSE; }
void setup(void) { int ret, memnode; tst_require_root(); tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; if (!is_numa(NULL, NH_MEMS, 1)) tst_brkm(TCONF, NULL, "requires NUMA with at least 1 node"); 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(); /* * 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, cleanup, "Failed to get a memory node " "using get_allowed_nodes()"); write_cpusets(memnode); }
void setup(void) { long hpage_size; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(); /* create a shared memory segment without read or write permissions */ shm_id_1 = shmget(shmkey, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL); if (shm_id_1 == -1) tst_brkm(TBROK | TERRNO, cleanup, "shmget #1"); /* create a shared memory segment with read and write permissions */ shm_id_2 = shmget(shmkey + 1, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); if (shm_id_2 == -1) tst_brkm(TBROK | TERRNO, cleanup, "shmget #2"); TEST_PAUSE; }
void setup(void) { long mem_total, hpage_size; tst_require_root(); mem_total = read_meminfo("MemTotal:"); SAFE_FILE_SCANF(NULL, PATH_SHMMAX, "%ld", &orig_shmmax); SAFE_FILE_PRINTF(NULL, PATH_SHMMAX, "%ld", (long)SIZE); SAFE_FILE_SCANF(NULL, PATH_SHMMAX, "%ld", &new_shmmax); if (mem_total < 2L*1024*1024) tst_brkm(TCONF, NULL, "Needed > 2GB RAM, have: %ld", mem_total); if (new_shmmax < SIZE) tst_brkm(TCONF, NULL, "shmmax too low, have: %ld", new_shmmax); orig_hugepages = get_sys_tune("nr_hugepages"); hpage_size = read_meminfo("Hugepagesize:") * 1024; hugepages = (orig_hugepages * hpage_size + SIZE) / hpage_size; set_sys_tune("nr_hugepages", hugepages, 1); TEST_PAUSE; }
void setup(void) { long hpage_size; tst_require_root(NULL); tst_sig(NOFORK, sighandler, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(); /* create a shared memory resource with read and write permissions */ shm_id_1 = shmget(shmkey, shm_size, SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL); if (shm_id_1 == -1) tst_brkm(TBROK | TERRNO, cleanup, "shmget"); /* attach the shared memory segment */ shared = shmat(shm_id_1, 0, 0); if (shared == (void *)-1) tst_brkm(TBROK | TERRNO, cleanup, "shmat #1"); /* give a value to the shared memory integer */ *shared = 4; TEST_PAUSE; }
static void setup(void) { int memnode, ret; if (!is_numa(NULL, NH_MEMS, 1)) tst_brk(TCONF, "requires NUMA with at least 1 node"); overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); mount_mem("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); cpuset_mounted = 1; /* * 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_brk(TBROK, "Failed to get a memory node " "using get_allowed_nodes()"); write_cpusets(memnode); }
void setup(void) { int memnode, ret; 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("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); /* * 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) { set_sys_tune("overcommit_memory", overcommit, 0); umount_mem(CPATH, CPATH_NEW); TEST_CLEANUP; }
void setup(void) { long mem_total, swap_total; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; if (access(PATH_SYSVM "overcommit_memory", F_OK) == -1 || access(PATH_SYSVM "overcommit_ratio", F_OK) == -1) tst_brkm(TCONF, NULL, "The system " "can't support to test %s", TCID); old_overcommit_memory = get_sys_tune("overcommit_memory"); old_overcommit_ratio = get_sys_tune("overcommit_ratio"); set_sys_tune("overcommit_ratio", overcommit_ratio, 1); mem_total = read_meminfo("MemTotal:"); tst_resm(TINFO, "MemTotal is %ld kB", mem_total); swap_total = read_meminfo("SwapTotal:"); tst_resm(TINFO, "SwapTotal is %ld kB", swap_total); sum_total = mem_total + swap_total; commit_limit = read_meminfo("CommitLimit:"); tst_resm(TINFO, "CommitLimit is %ld kB", commit_limit); }
static void cleanup(void) { if (overcommit != -1) set_sys_tune("overcommit_memory", overcommit, 0); if (cpuset_mounted) umount_mem(CPATH, CPATH_NEW); }
void cleanup(void) { rm_shm(shm_id_1); set_sys_tune("nr_hugepages", orig_hugepages, 0); tst_rmdir(); }
void cleanup(void) { unlink(TEMPFILE); set_sys_tune("nr_hugepages", orig_hugepages, 0); umount(Hopt); tst_rmdir(); }
void setup(void) { 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); }
void setup(void) { 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("cpuset", "cpuset", NULL, CPATH, CPATH_NEW); }
void setup(void) { TEST_PAUSE; tst_require_root(); if (mount("none", Hopt, "hugetlbfs", 0, NULL) < 0) tst_brkm(TBROK | TERRNO, NULL, "mount failed on %s", Hopt); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid()); }
void cleanup(void) { TEST_CLEANUP; rm_shm(shm_id_1); rm_shm(shm_id_2); set_sys_tune("nr_hugepages", orig_hugepages, 0); tst_rmdir(); }
void cleanup(void) { TEST_CLEANUP; unlink(TEMPFILE); set_sys_tune("nr_hugepages", orig_hugepages, 0); umount(Hopt); if (!Hflag) tst_rmdir(); }
void setup(void) { tst_require_root(); tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; if (!is_numa(NULL)) tst_brkm(TCONF, NULL, "The case need a NUMA system."); overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 1, 1); }
void setup(void) { save_nr_hugepages(); if (!Hopt) Hopt = tst_get_tmpdir(); SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL); if (nr_opt) hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX); set_sys_tune("nr_hugepages", hugepages, 1); snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid()); }
void setup(void) { tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; if (access(PATH_SYSVM "max_map_count", F_OK) != 0) tst_brkm(TBROK | TERRNO, NULL, "Can't support to test max_map_count"); old_max_map_count = get_sys_tune("max_map_count"); old_overcommit = get_sys_tune("overcommit_memory"); set_sys_tune("overcommit_memory", 2, 1); }
void cleanup(void) { int i; char buf[BUFSIZ]; TEST_CLEANUP; for (i = 0; i < num_shms; i++) rm_shm(shm_id_arr[i]); snprintf(buf, BUFSIZ, "%ld", orig_shmmni); write_file(PATH_SHMMNI, buf); set_sys_tune("nr_hugepages", orig_hugepages, 0); tst_rmdir(); }
void setup(void) { long hpage_size; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(); TEST_PAUSE; }
void setup(void) { long hpage_size; tst_require_root(); check_hugepage(); tst_sig(FORK, sighandler, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size * hugepages / 2; update_shm_size(&shm_size); shmkey = getipckey(cleanup); TEST_PAUSE; }
void setup(void) { long hpage_size; char buf[BUFSIZ]; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); tst_tmpdir(); orig_hugepages = get_sys_tune("nr_hugepages"); set_sys_tune("nr_hugepages", hugepages, 1); hpage_size = read_meminfo("Hugepagesize:") * 1024; shm_size = hpage_size; read_file(PATH_SHMMNI, buf); orig_shmmni = SAFE_STRTOL(cleanup, buf, 0, LONG_MAX); snprintf(buf, BUFSIZ, "%ld", hugepages / 2); write_file(PATH_SHMMNI, buf); /* * Use a while loop to create the maximum number of memory segments. * If the loop exceeds MAXIDS, then break the test and cleanup. */ num_shms = 0; shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); while (shm_id_1 != -1) { shm_id_arr[num_shms++] = shm_id_1; if (num_shms == MAXIDS) tst_brkm(TBROK, cleanup, "The maximum number of " "shared memory ID's has been reached. " "Please increase the MAXIDS value in " "the test."); shm_id_1 = shmget(IPC_PRIVATE, shm_size, SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); } if (errno != ENOSPC) tst_brkm(TBROK | TERRNO, cleanup, "shmget #setup"); TEST_PAUSE; }