public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/4] swapon01: Improving test with memory limits and swap reporting
Date: Mon, 22 Jan 2024 15:29:47 +0800	[thread overview]
Message-ID: <20240122072948.2568801-3-liwang@redhat.com> (raw)
In-Reply-To: <20240122072948.2568801-1-liwang@redhat.com>

This is target to create a more robust and controlled environment to test
the swapon system call. By introducing memory limits through cgroups and
filling memory with a known pattern, the test can better assess swapon
behavior when the system experiences memory pressure.

Additionally, the reporting of "SwapCached" memory before turning off the
swap file provides a clearer understanding of the swap system's state in
response to the test conditions.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon01.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index e1fe50459..a74a5171e 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -20,11 +20,15 @@
 
 #define MNTPOINT	"mntpoint"
 #define SWAP_FILE	MNTPOINT"/swapfile01"
+#define TESTMEM		(1UL<<30)
 
 static void verify_swapon(void)
 {
 	TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0));
 
+	tst_pollute_memory(TESTMEM, 0x41);
+	tst_res(TINFO, "SwapCached: %ld Kb", SAFE_READ_MEMINFO("SwapCached:"));
+
 	if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) {
 		tst_brk(TBROK | TERRNO,
 				"Failed to turn off swapfile, system reboot recommended");
@@ -35,6 +39,9 @@ static void setup(void)
 {
 	is_swap_supported(SWAP_FILE);
 	make_swapfile(SWAP_FILE, 0);
+
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 }
 
 static struct tst_test test = {
@@ -42,6 +49,7 @@ static struct tst_test test = {
 	.mount_device = 1,
 	.needs_root = 1,
 	.all_filesystems = 1,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
 	.test_all = verify_swapon,
 	.setup = setup
 };
-- 
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2024-01-22  7:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22  7:29 [LTP] [PATCH 1/4] libswap: add known swap supported fs check Li Wang
2024-01-22  7:29 ` [LTP] [PATCH 2/4] swapon01: Test on all filesystems Li Wang
2024-01-22  7:29 ` Li Wang [this message]
2024-01-22  9:08   ` [LTP] [PATCH 3/4] swapon01: Improving test with memory limits and swap reporting Petr Vorel
2024-01-22  7:29 ` [LTP] [PATCH 4/4] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
2024-01-22  8:40   ` Petr Vorel
2024-01-22  8:47     ` Petr Vorel
2024-01-22  9:20       ` Li Wang
2024-01-22  9:04     ` Li Wang
2024-01-22  9:03 ` [LTP] [PATCH 1/4] libswap: add known swap supported fs check Petr Vorel
2024-01-22  9:12   ` Li Wang
2024-01-22 10:57     ` Petr Vorel
2024-01-22  9:41   ` Petr Vorel
2024-01-22 10:22     ` Li Wang
2024-01-22  9:13 ` Petr Vorel
2024-01-22  9:32   ` Li Wang
2024-01-22 11:03     ` Petr Vorel
2024-01-22 14:23       ` Li Wang
2024-01-22 20:23         ` Petr Vorel
2024-01-23  5:55           ` Li Wang
2024-01-23  7:30             ` Li Wang
2024-01-23  7:48               ` Petr Vorel
2024-01-23 12:04                 ` Li Wang
2024-01-23 12:31                   ` Petr Vorel
2024-01-23 13:10                     ` Li Wang
2024-01-23 15:45                       ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240122072948.2568801-3-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox