All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1
@ 2021-06-23  6:24 Li Wang
  2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Li Wang @ 2021-06-23  6:24 UTC (permalink / raw)
  To: ltp

oom03 often gets fail while setting 'memory.swap.max = TESTMEM' in CGroup V2,
as in that scenario (lite == 1), child_alloc only start a single process to
dirty 'TESTMEM + MB' anonymous memory for testing:

testoom(, lite == 1, ,)
? oom(, lite == 1, ,)
? ? child_alloc(, lite == 1,)
? ? ? ? alloc_mem(TESTMEM + MB, )

  mem.c:224: TINFO: start normal OOM testing.
  mem.c:146: TINFO: expected victim is 80466.
  mem.c:38: TINFO: thread (7f411c69d740), allocating 1074790400 bytes.
  mem.c:64: TINFO: swapped is 25546752 bytes.     <------- swap occuring -----
  mem.c:164: TFAIL: victim unexpectedly ended with retcode: 0, expected: 12

TBH, this can not really test the 'memory.swap.max' as expected, since in the
kernel side mem_cgroup_out_of_memory split OOM margin into two-part, one for
memory.max limit, another for memory.swap.max, if any of them get overflow,
then invoke out_of_memory to kill victim-process.

Theoretically, alloc_mem(TESTMEM + MB, ) should work while 'memory.max' is equal
to TESTMEM, but Cgroup v2 tracks memory and swap in separate, which splits memory
and swap counter. So with swappiness enable (default value is 60 on RHEL), it
likely has part of memory swapping out during the allocating, upon that the two
limit loss effect@the same time. Unless disable swap completely then memory.max
will take effect in precisely.

To get more opportunities to reach the swap limitation, let's scale down the
value of 'memory.swap.max' to only 1MB for CGroup v2.

But for CGroup v1, the memory.memsw.limit_in_bytes disallow to less than
memory.limit_in_bytes, so we'd better raise the child_alloc to the twofold
of TESTMEM, and reset memory.memsw.limit_in_bytes to 'TESTMEM + MB'.

Signed-off-by: Li Wang <liwang@redhat.com>
---

Notes:
    v2 --> v3
      * set memory.memsw.limit_in_bytes to TESTMEM+MB as suggest by Richard
      * typo fix and some comments embellishment

 testcases/kernel/mem/lib/mem.c   |  2 +-
 testcases/kernel/mem/oom/oom03.c | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 9f946b5c9..ac890491c 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -78,7 +78,7 @@ static void child_alloc(int testcase, int lite, int threads)
 	pthread_t *th;
 
 	if (lite) {
-		int ret = alloc_mem(TESTMEM + MB, testcase);
+		int ret = alloc_mem(TESTMEM * 2 + MB, testcase);
 		exit(ret);
 	}
 
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 939413744..b3770cf8f 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -46,7 +46,21 @@ static void verify_oom(void)
 	testoom(0, 0, ENOMEM, 1);
 
 	if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) {
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM);
+		/*
+		 * Cgroup v2 tracks memory and swap in separate, which splits
+		 * memory and swap counter. So with swappiness enable (default
+		 * value is 60 on RHEL), it likely has part of memory swapping
+		 * out during the allocating.
+		 *
+		 * To get more opportunities to reach the swap limitation,
+		 * let's scale down the value of 'memory.swap.max' to only
+		 * 1MB for CGroup v2.
+		 */
+		if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1)
+			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", MB);
+		else
+			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM + MB);
+
 		testoom(0, 1, ENOMEM, 1);
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing
  2021-06-23  6:24 [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Li Wang
@ 2021-06-23  6:24 ` Li Wang
  2021-06-23  8:35   ` Petr Vorel
  2021-06-23 10:34   ` Richard Palethorpe
  2021-06-23  6:24 ` [LTP] [PATCH v3 3/3] tst_cgroup: make use of alias in safe_cgroup_has Li Wang
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Li Wang @ 2021-06-23  6:24 UTC (permalink / raw)
  To: ltp

oom03: adding print info and restore memory.swap.max after testing
oom05: enable lite == 1 for memory.swap.max testing

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/mem/oom/oom03.c | 6 ++++++
 testcases/kernel/mem/oom/oom05.c | 8 ++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index b3770cf8f..942b77ba1 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -46,6 +46,7 @@ static void verify_oom(void)
 	testoom(0, 0, ENOMEM, 1);
 
 	if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) {
+		tst_res(TINFO, "OOM on MEMCG with special memswap limitation:");
 		/*
 		 * Cgroup v2 tracks memory and swap in separate, which splits
 		 * memory and swap counter. So with swappiness enable (default
@@ -62,6 +63,11 @@ static void verify_oom(void)
 			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM + MB);
 
 		testoom(0, 1, ENOMEM, 1);
+
+		if (TST_CGROUP_VER(cg, "memory") == TST_CGROUP_V1)
+			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL);
+		else
+			SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max");
 	}
 
 	/* OOM for MEMCG with mempolicy */
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index 9c9bba7f6..079cab123 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -63,8 +63,12 @@ static void verify_oom(void)
 	if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) {
 		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
 				"special memswap limitation:");
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM);
-		testoom(0, 0, ENOMEM, 1);
+		if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1)
+			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", MB);
+		else
+			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM + MB);
+
+		testoom(0, 1, ENOMEM, 1);
 
 		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
 				"disabled memswap limitation:");
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 3/3] tst_cgroup: make use of alias in safe_cgroup_has
  2021-06-23  6:24 [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Li Wang
  2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
@ 2021-06-23  6:24 ` Li Wang
  2021-06-23  7:40 ` [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Petr Vorel
  2021-06-23 10:33 ` Richard Palethorpe
  3 siblings, 0 replies; 8+ messages in thread
From: Li Wang @ 2021-06-23  6:24 UTC (permalink / raw)
  To: ltp

This is to fix the check issue of 'memory.swap.max' on CGroup v1.

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
Signed-off-by: Li Wang <liwang@redhat.com>
---
 lib/tst_cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 18e3b6169..61cc02fa7 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -1010,7 +1010,7 @@ int safe_cgroup_has(const char *const file, const int lineno,
 		if (!(alias = cgroup_file_alias(cfile, *dir)))
 		    continue;
 
-		if (!faccessat((*dir)->dir_fd, file_name, F_OK, 0))
+		if (!faccessat((*dir)->dir_fd, alias, F_OK, 0))
 			return 1;
 
 		if (errno == ENOENT)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1
  2021-06-23  6:24 [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Li Wang
  2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
  2021-06-23  6:24 ` [LTP] [PATCH v3 3/3] tst_cgroup: make use of alias in safe_cgroup_has Li Wang
@ 2021-06-23  7:40 ` Petr Vorel
  2021-06-23 10:33 ` Richard Palethorpe
  3 siblings, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2021-06-23  7:40 UTC (permalink / raw)
  To: ltp

Hi,

LGTM
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing
  2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
@ 2021-06-23  8:35   ` Petr Vorel
  2021-06-23 10:34   ` Richard Palethorpe
  1 sibling, 0 replies; 8+ messages in thread
From: Petr Vorel @ 2021-06-23  8:35 UTC (permalink / raw)
  To: ltp

Hi Li,

> oom03: adding print info and restore memory.swap.max after testing
> oom05: enable lite == 1 for memory.swap.max testing
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1
  2021-06-23  6:24 [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Li Wang
                   ` (2 preceding siblings ...)
  2021-06-23  7:40 ` [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Petr Vorel
@ 2021-06-23 10:33 ` Richard Palethorpe
  2021-06-23 12:32   ` Li Wang
  3 siblings, 1 reply; 8+ messages in thread
From: Richard Palethorpe @ 2021-06-23 10:33 UTC (permalink / raw)
  To: ltp


Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing
  2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
  2021-06-23  8:35   ` Petr Vorel
@ 2021-06-23 10:34   ` Richard Palethorpe
  1 sibling, 0 replies; 8+ messages in thread
From: Richard Palethorpe @ 2021-06-23 10:34 UTC (permalink / raw)
  To: ltp


Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

-- 
Thank you,
Richard.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1
  2021-06-23 10:33 ` Richard Palethorpe
@ 2021-06-23 12:32   ` Li Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Li Wang @ 2021-06-23 12:32 UTC (permalink / raw)
  To: ltp

Patchset pushed, thanks!

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210623/c2b50fc7/attachment-0001.htm>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-23 12:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23  6:24 [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Li Wang
2021-06-23  6:24 ` [LTP] [PATCH v3 2/3] oom: enable lite == 1 for memory.swap.max testing Li Wang
2021-06-23  8:35   ` Petr Vorel
2021-06-23 10:34   ` Richard Palethorpe
2021-06-23  6:24 ` [LTP] [PATCH v3 3/3] tst_cgroup: make use of alias in safe_cgroup_has Li Wang
2021-06-23  7:40 ` [LTP] [PATCH v3 1/3] mem: child alloc memory should larger than memory.max + memory.swap.max if lite==1 Petr Vorel
2021-06-23 10:33 ` Richard Palethorpe
2021-06-23 12:32   ` Li Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.