aboutsummaryrefslogtreecommitdiff
path: root/testcases/kernel/mem
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-04-02 20:24:18 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-02 20:24:18 +0000
commitcdb9cd95d819b7d394f63db8dd87804de5aa3e69 (patch)
tree21df5650189a18b6e92f11a618bac3deb1adf361 /testcases/kernel/mem
parent26a125c969109073ae74a948b3d8e4035cda4f7c (diff)
parent74f79dc224f4a1e79829ddfa11fa9439bf561423 (diff)
downloadltp-cdb9cd95d819b7d394f63db8dd87804de5aa3e69.tar.gz
Merge changes from topic "ltp-20230929-android14-tests" into android14-tests-dev
* changes: cgroup: Fix scanning V1 mount options cgroup: Handle trailing new line in cgroup.controllers compare_ltp_projects.py: Fix test sorting, adjust printing madvise11: Allow test to skip if MADV_SOFT_OFFLINE is not supported madvise11: Replace /etc/mtab with /proc/mounts syscalls/process_madvise01: fix smaps scan and min_swap_avail tst_clocks.c: Fix stack smashing on 32bit tst_kvercmp: Handle larger kernel version numbers getpgid01: On Android, pgid(1) is 0 instead of 1 pipe07: refactor exp_num_pipes pipe07: close /proc/self/fd after counting fds config.h: Compile with linux/ioprio.h to fix ioprio_set03 sched.h: Don't exclude clone_args_minimal when HAVE_STRUCT_CLONE_ARGS is set ltp-version.h: Generate with genrule mq_notify03: disable test because don't have mqueue kvm: Disable kvm tests make_parser.py: Handle as (gnu assembler) command in makefile android_build_generator.py: Print more info when failing with compile target LTP 20230929 Merge tag '20230929'
Diffstat (limited to 'testcases/kernel/mem')
-rw-r--r--testcases/kernel/mem/.gitignore1
-rw-r--r--testcases/kernel/mem/hugetlb/hugemmap/Makefile1
-rw-r--r--testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c13
-rw-r--r--testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c9
-rw-r--r--testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c95
-rw-r--r--testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c19
-rw-r--r--testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c29
-rw-r--r--testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c37
-rw-r--r--testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c14
-rw-r--r--testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c2
-rw-r--r--testcases/kernel/mem/hugetlb/lib/hugetlb.h6
-rw-r--r--testcases/kernel/mem/include/mem.h1
-rw-r--r--testcases/kernel/mem/ksm/ksm05.c4
-rw-r--r--testcases/kernel/mem/lib/mem.c2
-rw-r--r--testcases/kernel/mem/oom/oom01.c17
-rw-r--r--testcases/kernel/mem/oom/oom02.c14
-rw-r--r--testcases/kernel/mem/oom/oom03.c14
-rw-r--r--testcases/kernel/mem/oom/oom04.c14
-rw-r--r--testcases/kernel/mem/oom/oom05.c14
-rw-r--r--testcases/kernel/mem/thp/thp03.c1
-rw-r--r--testcases/kernel/mem/thp/thp04.c2
-rw-r--r--testcases/kernel/mem/tunable/max_map_count.c27
-rw-r--r--testcases/kernel/mem/tunable/min_free_kbytes.c16
-rw-r--r--testcases/kernel/mem/tunable/overcommit_memory.c20
-rwxr-xr-xtestcases/kernel/mem/vma/vma05.sh1
25 files changed, 219 insertions, 154 deletions
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 06e125d03..7258489ed 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -33,6 +33,7 @@
/hugetlb/hugemmap/hugemmap29
/hugetlb/hugemmap/hugemmap30
/hugetlb/hugemmap/hugemmap31
+/hugetlb/hugemmap/hugemmap32
/hugetlb/hugeshmat/hugeshmat01
/hugetlb/hugeshmat/hugeshmat02
/hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index 6f10807cd..2d651b4aa 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -8,5 +8,4 @@ include $(top_srcdir)/include/mk/testcases.mk
include $(abs_srcdir)/../Makefile.inc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
-hugemmap15: CFLAGS+=-O0
hugemmap06: CFLAGS+=-pthread
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
index 07e65a160..4d1984070 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
@@ -19,6 +19,10 @@
* remap, or because the icache happens to get flushed in the interim.
*/
+#if defined(__clang__)
+ #pragma clang optimize off
+#endif
+
#define _GNU_SOURCE
#include "hugetlb.h"
@@ -27,16 +31,7 @@
defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) || \
defined(__i386__) || defined(__x86_64__) || defined(__arm__)
-#include <stdio.h>
-#include <stdlib.h>
#include <setjmp.h>
-#include <unistd.h>
-#include <signal.h>
-#include <sys/mman.h>
-#include <ucontext.h>
-#include <limits.h>
-#include <sys/param.h>
-#include <sys/types.h>
#define SUCC_JMP 1
#define FAIL_JMP 2
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c
index a465aadec..158a03010 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap24.c
@@ -23,7 +23,7 @@
static int fd = -1;
static unsigned long slice_boundary;
-static long hpage_size, page_size;
+static unsigned long hpage_size, page_size;
static int init_slice_boundary(int fd)
{
@@ -44,6 +44,13 @@ static int init_slice_boundary(int fd)
heap = malloc(1);
free(heap);
+ /* Avoid underflow on systems with large huge pages.
+ * The additionally plus heap address is to reduce the possibility
+ * of MAP_FIXED stomp over existing mappings.
+ */
+ while (slice_boundary + slice_size < (unsigned long)heap + 2*hpage_size)
+ slice_boundary += slice_size;
+
/* Find 2 neighbour slices with couple huge pages free
* around slice boundary.
* 16 is the maximum number of slices (low/high)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
new file mode 100644
index 000000000..d27e5b8b2
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2023, IBM Corporation.
+ * Author: Tarun Sahu
+ */
+
+/*\
+ * [Description]
+ *
+ * Before kernel version 5.10-rc7, there was a bug that resulted in a "Bad Page
+ * State" error when freeing gigantic hugepages. This happened because the
+ * struct page entry compound_nr, which overlapped with page->mapping in the
+ * first tail page, was not cleared, causing the error. To ensure that this
+ * issue does not reoccur as struct page keeps changing and some fields are
+ * managed by folio, this test checks that freeing gigantic hugepages does not
+ * produce the above-mentioned error.
+ */
+
+#define _GNU_SOURCE
+#include <dirent.h>
+
+#include <stdio.h>
+
+#include "hugetlb.h"
+
+#define PATH_HUGEPAGE "/sys/kernel/mm/hugepages"
+#define GIGANTIC_MIN_ORDER 10
+
+static int org_g_hpages;
+static char g_hpage_path[4096];
+
+static void run_test(void)
+{
+ if (FILE_PRINTF(g_hpage_path, "%d", 1))
+ tst_brk(TCONF, "Can't update the gigantic hugepages.");
+ SAFE_FILE_PRINTF(g_hpage_path, "%d", 0);
+
+ if (tst_taint_check())
+ tst_res(TFAIL, "Freeing Gigantic pages resulted in Bad Page State bug.");
+ else
+ tst_res(TPASS, "Successfully freed the gigantic hugepages");
+}
+
+static void setup(void)
+{
+ DIR *dir;
+ struct dirent *ent;
+ unsigned long hpage_size;
+
+ if (access(PATH_HUGEPAGE, F_OK))
+ tst_brk(TCONF, "hugetlbfs is not supported");
+
+ dir = SAFE_OPENDIR(PATH_HUGEPAGE);
+ while ((ent = SAFE_READDIR(dir))) {
+ if ((sscanf(ent->d_name, "hugepages-%lukB", &hpage_size) == 1) &&
+ is_hugetlb_gigantic(hpage_size * 1024)) {
+ sprintf(g_hpage_path, "%s/%s/%s", PATH_HUGEPAGE,
+ ent->d_name, "nr_hugepages");
+ break;
+ }
+ }
+ if (!g_hpage_path[0])
+ tst_brk(TCONF, "Gigantic hugepages not supported");
+
+ SAFE_CLOSEDIR(dir);
+
+ SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
+ SAFE_FILE_PRINTF("/proc/sys/vm/compact_memory", "1");
+
+ if (tst_available_mem() < (long long)hpage_size) {
+ g_hpage_path[0] = '\0';
+ tst_brk(TCONF, "No enough memory for gigantic hugepage reservation");
+ }
+
+ SAFE_FILE_LINES_SCANF(g_hpage_path, "%d", &org_g_hpages);
+}
+
+static void cleanup(void)
+{
+ if (g_hpage_path[0])
+ SAFE_FILE_PRINTF(g_hpage_path, "%d", org_g_hpages);
+}
+
+static struct tst_test test = {
+ .tags = (struct tst_tag[]) {
+ {"linux-git", "ba9c1201beaa"},
+ {"linux-git", "a01f43901cfb"},
+ {}
+ },
+ .needs_root = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .taint_check = TST_TAINT_B,
+};
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 50efa8a52..8ad745d5b 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -27,7 +27,6 @@
static long huge_free;
static long huge_free2;
-static long orig_shmmax = -1, new_shmmax;
static void shared_hugepage(void);
@@ -81,14 +80,13 @@ static void shared_hugepage(void)
static void setup(void)
{
long hpage_size, orig_hugepages;
+ unsigned long new_shmmax;
orig_hugepages = get_sys_tune("nr_hugepages");
- SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
- SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
- SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &new_shmmax);
+ SAFE_FILE_SCANF(PATH_SHMMAX, "%lu", &new_shmmax);
if (new_shmmax < SIZE)
- tst_brk(TCONF, "shmmax too low, have: %ld", new_shmmax);
+ tst_brk(TCONF, "shmmax too low, have: %lu", new_shmmax);
hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
@@ -96,12 +94,6 @@ static void setup(void)
tst_reserve_hugepages(&hp);
}
-static void cleanup(void)
-{
- if (orig_shmmax != -1)
- SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
-}
-
static struct tst_test test = {
.tags = (const struct tst_tag[]) {
{"linux-git", "c5c99429fa57"},
@@ -114,6 +106,9 @@ static struct tst_test test = {
.test = test_hugeshmat,
.min_mem_avail = 2048,
.setup = setup,
- .cleanup = cleanup,
.hugepages = {1, TST_NEEDS},
+ .save_restore = (const struct tst_path_val[]) {
+ {PATH_SHMMAX, "1073741824", TST_SR_TCONF_MISSING | TST_SR_TBROK_RO},
+ {}
+ },
};
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
index 11cd69050..a68b0da75 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
@@ -53,10 +53,10 @@ static void func_set(void);
static void func_rmid(void);
static void *set_shmat(void);
-struct tcase {
+static struct tcase {
int cmd;
- void (*func_test) (void);
- void (*func_setup) (void);
+ void (*func_test)(void);
+ void (*func_setup)(void);
} tcases[] = {
{IPC_STAT, func_stat, stat_setup_1},
{IPC_STAT, func_stat, stat_setup_2},
@@ -90,7 +90,7 @@ static void test_hugeshmctl(unsigned int i)
/*
* set_shmat() - Attach the shared memory and return the pointer.
*/
-void *set_shmat(void)
+static void *set_shmat(void)
{
void *rval;
@@ -103,8 +103,8 @@ void *set_shmat(void)
/*
* stat_setup_2() - Set up for the IPC_STAT command with shmctl().
- * Attach the shared memory to parent process and
- * some children will inherit the shared memory.
+ * Attach the shared memory to parent process and
+ * some children will inherit the shared memory.
*/
static void stat_setup_2(void)
{
@@ -139,7 +139,7 @@ static void stat_setup_1(void)
/* now we're back - detach the memory and exit */
if (shmdt(test) == -1)
tst_brk(TBROK | TERRNO,
- "shmdt in stat_setup()");
+ "shmdt in this function broke");
exit(0);
default:
@@ -220,7 +220,8 @@ static void stat_cleanup(void)
/* remove the parent's shared memory if we set*/
if (attach_to_parent) {
if (shmdt(attach_to_parent) == -1)
- tst_res(TFAIL | TERRNO, "shmdt in stat_cleanup()");
+ tst_res(TFAIL | TERRNO,
+ "shmdt in this function failed");
attach_to_parent = NULL;
}
}
@@ -244,7 +245,7 @@ static void func_set(void)
{
/* first stat the shared memory to get the new data */
if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
- tst_res(TFAIL | TERRNO, "shmctl in func_set()");
+ tst_res(TFAIL | TERRNO, "shmctl in this function failed");
return;
}
@@ -268,18 +269,18 @@ static void func_rmid(void)
{
/* Do another shmctl() - we should get EINVAL */
if (shmctl(shm_id_1, IPC_STAT, &buf) != -1)
- tst_brk(TBROK, "shmctl in func_rmid() "
+ tst_brk(TBROK, "shmctl in this function "
"succeeded unexpectedly");
if (errno != EINVAL)
- tst_res(TFAIL | TERRNO, "shmctl in func_rmid() failed "
+ tst_res(TFAIL | TERRNO, "shmctl in this function failed "
"unexpectedly - expect errno=EINVAL, got");
else
- tst_res(TPASS, "shmctl in func_rmid() failed as expected, "
+ tst_res(TPASS, "shmctl in this function failed as expected, "
"shared memory appears to be removed");
shm_id_1 = -1;
}
-void setup(void)
+static void setup(void)
{
long hpage_size;
@@ -293,7 +294,7 @@ void setup(void)
shmkey = getipckey();
}
-void cleanup(void)
+static void cleanup(void)
{
rm_shm(shm_id_1);
}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index 0bc9ffd74..d3f711129 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -27,6 +27,7 @@
#include <pwd.h>
#include <limits.h>
#include "hugetlb.h"
+#include "lapi/syscalls.h"
static size_t shm_size;
static int shm_id_1 = -1;
@@ -34,7 +35,7 @@ static int shm_id_2 = -1;
static int shm_id_3 = -1;
static struct shmid_ds buf;
-struct tcase {
+static struct tcase {
int *shmid;
int cmd;
struct shmid_ds *sbuf;
@@ -50,9 +51,37 @@ struct tcase {
{&shm_id_2, -1, &buf, EINVAL},
};
+static int libc_shmctl(int shmid, int cmd, void *buf)
+{
+ return shmctl(shmid, cmd, buf);
+}
+
+static int sys_shmctl(int shmid, int cmd, void *buf)
+{
+ return tst_syscall(__NR_shmctl, shmid, cmd, buf);
+}
+
+static struct test_variants
+{
+ int (*shmctl)(int shmid, int cmd, void *buf);
+ char *desc;
+} variants[] = {
+ { .shmctl = libc_shmctl, .desc = "libc shmctl()"},
+#if (__NR_shmctl != __LTP__NR_INVALID_SYSCALL)
+ { .shmctl = sys_shmctl, .desc = "__NR_shmctl syscall"},
+#endif
+};
+
static void test_hugeshmctl(unsigned int i)
{
- TEST(shmctl(*(tcases[i].shmid), tcases[i].cmd, tcases[i].sbuf));
+ struct test_variants *tv = &variants[tst_variant];
+
+ if (tcases[i].error == EFAULT && tv->shmctl == libc_shmctl) {
+ tst_res(TCONF, "EFAULT is skipped for libc variant");
+ return;
+ }
+
+ TEST(tv->shmctl(*(tcases[i].shmid), tcases[i].cmd, tcases[i].sbuf));
if (TST_RET != -1) {
tst_res(TFAIL, "shmctl succeeded unexpectedly");
return;
@@ -70,8 +99,11 @@ static void test_hugeshmctl(unsigned int i)
static void setup(void)
{
+ struct test_variants *tv = &variants[tst_variant];
long hpage_size;
+ tst_res(TINFO, "Testing variant: %s", tv->desc);
+
if (tst_hugepages == 0)
tst_brk(TCONF, "No enough hugepages for testing.");
@@ -101,6 +133,7 @@ static void cleanup(void)
static struct tst_test test = {
.test = test_hugeshmctl,
+ .test_variants = ARRAY_SIZE(variants),
.tcnt = ARRAY_SIZE(tcases),
.needs_root = 1,
.needs_tmpdir = 1,
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
index 21ec6bf78..ec4640686 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
@@ -41,10 +41,10 @@
static size_t shm_size;
static int shm_id_1 = -1;
static struct shmid_ds buf;
-static uid_t ltp_uid;
-static char *ltp_user = "nobody";
+static uid_t test_uid;
+static char *test_user = "nobody";
-struct tcase {
+static struct tcase {
int *shmid;
int cmd;
struct shmid_ds *sbuf;
@@ -68,7 +68,7 @@ static void test_hugeshmctl(void)
switch (pid = SAFE_FORK()) {
case 0:
/* set the user ID of the child to the non root user */
- SAFE_SETUID(ltp_uid);
+ SAFE_SETUID(test_uid);
do_child();
exit(0);
default:
@@ -97,7 +97,7 @@ static void do_child(void)
}
}
-void setup(void)
+static void setup(void)
{
long hpage_size;
@@ -115,10 +115,10 @@ void setup(void)
tst_brk(TBROK | TERRNO, "shmget");
/* get the userid for a non root user */
- ltp_uid = getuserid(ltp_user);
+ test_uid = getuserid(test_user);
}
-void cleanup(void)
+static void cleanup(void)
{
rm_shm(shm_id_1);
}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index 7e72a19ca..625761f6e 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -84,7 +84,7 @@ static void cleanup(void)
rm_shm(shm_id_arr[i]);
if (orig_shmmni != -1)
- FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
+ SAFE_FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
}
static struct tst_test test = {
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index 241dab708..34fe08c24 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -39,6 +39,12 @@
# endif
#endif
+/* Check if hugetlb page is gigantic */
+static inline int is_hugetlb_gigantic(unsigned long hpage_size)
+{
+ return (hpage_size / getpagesize()) >> 11;
+}
+
/*
* to get the lower nine permission bits
* from shmid_ds.ipc_perm.mode
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 776809113..cdc3ca146 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -42,7 +42,6 @@ static inline void clean_node(unsigned long *array)
#define MLOCK 2
#define KSM 3
-extern long overcommit;
void oom(int testcase, int lite, int retcode, int allow_sigkill);
void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c
index 25f3435b2..1f58c8325 100644
--- a/testcases/kernel/mem/ksm/ksm05.c
+++ b/testcases/kernel/mem/ksm/ksm05.c
@@ -95,6 +95,10 @@ static struct tst_test test = {
"CONFIG_KSM=y",
NULL
},
+ .tags = (const struct tst_tag[]) {
+ {"CVE", "2011-2183"},
+ {}
+ }
};
#else
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 8ddd7adf7..fbfeef026 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -27,8 +27,6 @@
/* OOM */
-long overcommit = -1;
-
static int alloc_mem(long int length, int testcase)
{
char *s;
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 9f7d76587..b13699898 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -49,22 +49,13 @@ static void verify_oom(void)
testoom(0, 0, ENOMEM, 1);
}
-static void setup(void)
-{
- overcommit = get_sys_tune("overcommit_memory");
-}
-
-static void cleanup(void)
-{
- if (overcommit != -1)
- set_sys_tune("overcommit_memory", overcommit, 0);
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
- .setup = setup,
- .cleanup = cleanup,
.test_all = verify_oom,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", NULL, TST_SR_TBROK},
+ {}
+ },
};
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index b3719f723..8d565d12a 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -56,15 +56,6 @@ static void setup(void)
{
if (!is_numa(NULL, NH_MEMS, 2))
tst_brk(TCONF, "The case need a NUMA system.");
-
- overcommit = get_sys_tune("overcommit_memory");
- set_sys_tune("overcommit_memory", 1, 1);
-}
-
-static void cleanup(void)
-{
- if (overcommit != -1)
- set_sys_tune("overcommit_memory", overcommit, 0);
}
static struct tst_test test = {
@@ -72,8 +63,11 @@ static struct tst_test test = {
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
.setup = setup,
- .cleanup = cleanup,
.test_all = verify_oom,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
+ {}
+ },
};
#else
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 0882c9bbe..778055d03 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -79,27 +79,21 @@ static void verify_oom(void)
static void setup(void)
{
- overcommit = get_sys_tune("overcommit_memory");
- set_sys_tune("overcommit_memory", 1, 1);
-
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
}
-static void cleanup(void)
-{
- if (overcommit != -1)
- set_sys_tune("overcommit_memory", overcommit, 0);
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
.setup = setup,
- .cleanup = cleanup,
.test_all = verify_oom,
.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
+ {}
+ },
};
#else
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index ad39f7e77..d27d9d9e7 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -65,9 +65,6 @@ static void setup(void)
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);
-
/*
* Some nodes do not contain memory, so use
* get_allowed_nodes(NH_MEMS) to get a memory
@@ -82,20 +79,17 @@ static void setup(void)
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
}
-static void cleanup(void)
-{
- if (overcommit != -1)
- set_sys_tune("overcommit_memory", overcommit, 0);
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
.setup = setup,
- .cleanup = cleanup,
.test_all = verify_oom,
.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
+ {}
+ },
};
#else
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index e31146e7a..eb1a64267 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -85,9 +85,6 @@ void setup(void)
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);
-
/*
* Some nodes do not contain memory, so use
* get_allowed_nodes(NH_MEMS) to get a memory
@@ -104,22 +101,19 @@ void setup(void)
SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
}
-void cleanup(void)
-{
- if (overcommit != -1)
- set_sys_tune("overcommit_memory", overcommit, 0);
-}
-
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
.setup = setup,
- .cleanup = cleanup,
.test_all = verify_oom,
.needs_cgroup_ctrls = (const char *const []){
"memory", "cpuset", NULL
},
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", "1", TST_SR_TBROK},
+ {}
+ },
};
#else
diff --git a/testcases/kernel/mem/thp/thp03.c b/testcases/kernel/mem/thp/thp03.c
index c6062505f..839efcb0e 100644
--- a/testcases/kernel/mem/thp/thp03.c
+++ b/testcases/kernel/mem/thp/thp03.c
@@ -30,7 +30,6 @@
* corruption and no data corruption (nor userland nor kernel).
*/
-#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
diff --git a/testcases/kernel/mem/thp/thp04.c b/testcases/kernel/mem/thp/thp04.c
index 7cab5d76b..b5f518ac5 100644
--- a/testcases/kernel/mem/thp/thp04.c
+++ b/testcases/kernel/mem/thp/thp04.c
@@ -26,8 +26,6 @@
* commit 8310d48b125d("huge_memory.c: respect FOLL_FORCE/FOLL_COW for thp").
*/
-#include <sys/mman.h>
-
#include "tst_test.h"
#include "lapi/mmap.h"
#include "tst_fuzzy_sync.h"
diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
index caf8972e0..f33095473 100644
--- a/testcases/kernel/mem/tunable/max_map_count.c
+++ b/testcases/kernel/mem/tunable/max_map_count.c
@@ -53,26 +53,6 @@
#define MAP_COUNT_DEFAULT 1024
#define MAX_MAP_COUNT 65536L
-static long old_max_map_count = -1;
-static long old_overcommit = -1;
-
-static void setup(void)
-{
- SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
-
- old_max_map_count = get_sys_tune("max_map_count");
- old_overcommit = get_sys_tune("overcommit_memory");
- set_sys_tune("overcommit_memory", 0, 1);
-}
-
-static void cleanup(void)
-{
- if (old_overcommit != -1)
- set_sys_tune("overcommit_memory", old_overcommit, 0);
- if (old_max_map_count != -1)
- set_sys_tune("max_map_count", old_max_map_count, 0);
-}
-
/* This is a filter to exclude map entries which aren't accounted
* for in the vm_area_struct's map_count.
*/
@@ -210,7 +190,10 @@ static void max_map_count_test(void)
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
- .setup = setup,
- .cleanup = cleanup,
.test_all = max_map_count_test,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", "0", TST_SR_TBROK},
+ {"/proc/sys/vm/max_map_count", NULL, TST_SR_TBROK},
+ {}
+ },
};
diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c
index eab6c8b2e..19da409e8 100644
--- a/testcases/kernel/mem/tunable/min_free_kbytes.c
+++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
@@ -41,7 +41,6 @@
volatile int end;
static long default_tune = -1;
-static long orig_overcommit = -1;
static unsigned long total_mem;
static void test_tune(unsigned long overcommit_policy);
@@ -217,15 +216,6 @@ static void setup(void)
total_mem = SAFE_READ_MEMINFO("MemTotal:") + SAFE_READ_MEMINFO("SwapTotal:");
default_tune = get_sys_tune("min_free_kbytes");
- orig_overcommit = get_sys_tune("overcommit_memory");
-}
-
-static void cleanup(void)
-{
- if (default_tune != -1)
- set_sys_tune("min_free_kbytes", default_tune, 0);
- if (orig_overcommit != -1)
- set_sys_tune("overcommit_memory", orig_overcommit, 0);
}
static struct tst_test test = {
@@ -233,6 +223,10 @@ static struct tst_test test = {
.forks_child = 1,
.max_runtime = TST_UNLIMITED_RUNTIME,
.setup = setup,
- .cleanup = cleanup,
.test_all = min_free_kbytes_test,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", NULL, TST_SR_TBROK},
+ {"/proc/sys/vm/min_free_kbytes", NULL, TST_SR_TBROK},
+ {}
+ },
};
diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
index 7fe8fe14c..ffb7a6d9d 100644
--- a/testcases/kernel/mem/tunable/overcommit_memory.c
+++ b/testcases/kernel/mem/tunable/overcommit_memory.c
@@ -70,7 +70,6 @@
#define EXPECT_FAIL 1
static char *R_opt;
-static long old_overcommit_memory = -1;
static long old_overcommit_ratio = -1;
static long overcommit_ratio;
static long sum_total;
@@ -90,16 +89,11 @@ static void setup(void)
long mem_total, swap_total;
struct rlimit lim;
- if (access(PATH_SYSVM "overcommit_memory", F_OK) == -1 ||
- access(PATH_SYSVM "overcommit_ratio", F_OK) == -1)
- tst_brk(TCONF, "system doesn't support overcommit_memory");
-
if (R_opt)
overcommit_ratio = SAFE_STRTOL(R_opt, 0, LONG_MAX);
else
overcommit_ratio = DEFAULT_OVER_RATIO;
- old_overcommit_memory = get_sys_tune("overcommit_memory");
old_overcommit_ratio = get_sys_tune("overcommit_ratio");
mem_total = SAFE_READ_MEMINFO("MemTotal:");
@@ -128,14 +122,6 @@ static void setup(void)
tst_res(TINFO, "TotalBatchSize is %ld kB", total_batch_size);
}
-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);
-}
-
static void overcommit_memory_test(void)
{
@@ -269,6 +255,10 @@ static struct tst_test test = {
{}
},
.setup = setup,
- .cleanup = cleanup,
.test_all = overcommit_memory_test,
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/overcommit_memory", NULL, TST_SR_TBROK},
+ {"/proc/sys/vm/overcommit_ratio", NULL, TST_SR_TBROK},
+ {}
+ },
};
diff --git a/testcases/kernel/mem/vma/vma05.sh b/testcases/kernel/mem/vma/vma05.sh
index 9ef6f0a23..c9e4becdb 100755
--- a/testcases/kernel/mem/vma/vma05.sh
+++ b/testcases/kernel/mem/vma/vma05.sh
@@ -30,6 +30,7 @@ setup()
{
ulimit -c unlimited
echo "core" > /proc/sys/kernel/core_pattern
+ unset DEBUGINFOD_URLS
}
cleanup()