[LTP] [PATCH] swapon01: swapon01: prevent OOM happening in swap process
Li Wang
liwang@redhat.com
Fri Mar 15 07:24:48 CET 2024
Here we take many ways to prevent the OOM happening with
run the swapon test:
* shrink the pollute memory size
* increase swapfile size
* setting swap max for Cgroup
* setting test oom_score_adj to -1000
Reproted-by: Wei Gao <wegao@suse.com>
Signed-off-by: Li Wang <liwang@redhat.com>
---
Notes:
Hi Wei,
Could you please test this patch and post the output messages?
Thanks!!
testcases/kernel/syscalls/swapon/swapon01.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index d406e4bd9..b4fc02d6e 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -26,7 +26,7 @@ static void verify_swapon(void)
{
TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
- tst_pollute_memory(TESTMEM, 0x41);
+ tst_pollute_memory(TESTMEM * 9/10, 0x41);
tst_res(TINFO, "SwapCached: %ld Kb", SAFE_READ_MEMINFO("SwapCached:"));
if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
@@ -37,11 +37,21 @@ static void verify_swapon(void)
static void setup(void)
{
+ tst_enable_oom_protection(0);
is_swap_supported(SWAP_FILE);
- make_swapfile(SWAP_FILE, 10, 0);
+ make_swapfile(SWAP_FILE, 1024, 0);
SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
+ if (TST_CG_VER_IS_V1(tst_cg, "memory"))
+ SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL);
+ else
+ SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
+}
+
+static void cleanup(void)
+{
+ tst_disable_oom_protection(0);
}
static struct tst_test test = {
@@ -51,5 +61,6 @@ static struct tst_test test = {
.all_filesystems = 1,
.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
.test_all = verify_swapon,
- .setup = setup
+ .setup = setup,
+ .cleanup = cleanup
};
--
2.40.1
More information about the ltp
mailing list