All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup
@ 2025-03-26  4:11 T.J. Mercier via ltp
  0 siblings, 0 replies; 4+ messages in thread
From: T.J. Mercier via ltp @ 2025-03-26  4:11 UTC (permalink / raw)
  To: ltp

memcg_control_test_1 sets both a memory limit and a memsw/swap limit to
a single page, and then asks mem_process to allocate 2 pages in an
attempt to cause a memcg OOM kill. However, if swapping is enabled the
first page can be swapped before the second is allocated causing neither
limit to be exceeded, and no OOM kill to occur which results in a test
failure. Fix this by disabling swap in the test cgroup if it is enabled,
causing both pages to always be accounted under memory.max (v2) /
memory.limit_in_bytes (v1).

Fixes: c0b815736 ("New testcase added by Naufal.")
Signed-off-by: T.J. Mercier <tjmercier@google.com>
---
 .../kernel/controllers/memcg/control/memcg_control_test.sh   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
index 68287a70c..eb8db3e30 100644
--- a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
+++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
@@ -12,7 +12,6 @@ TST_NEEDS_TMPDIR=1
 
 PAGE_SIZE=$(tst_getconf PAGESIZE)
 
-TOT_MEM_LIMIT=$PAGE_SIZE
 ACTIVE_MEM_LIMIT=$PAGE_SIZE
 PROC_MEM=$((PAGE_SIZE * 2))
 
@@ -50,13 +49,13 @@ test1()
 
 	# If the kernel is built without swap, the $memsw_memory_limit file is missing
 	if [ -e "$test_dir/$memsw_memory_limit" ]; then
-		ROD echo "$TOT_MEM_LIMIT" \> "$test_dir/$memsw_memory_limit"
+		ROD echo 0 \> "$test_dir/$memsw_memory_limit"
 	fi
 
 	KILLED_CNT=0
 	test_proc_kill
 
-	if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
+	if [ $KILLED_CNT -eq 0 ]; then
 		tst_res TFAIL "Test #1: failed"
 	else
 		tst_res TPASS "Test #1: passed"
-- 
2.49.0.395.g12beb8f557-goog


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

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

* [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup
@ 2025-03-26 22:35 T.J. Mercier via ltp
  2025-03-27 11:11 ` Petr Vorel
       [not found] ` <lo4sjpn6uvhyhgi7welsp4dsvi6jxrl4h5gwacuvqmgfvfqcq7@ayoafjktxzyc>
  0 siblings, 2 replies; 4+ messages in thread
From: T.J. Mercier via ltp @ 2025-03-26 22:35 UTC (permalink / raw)
  To: ltp

memcg_control_test_1 sets both a memory limit and a memsw/swap limit to
a single page, and then asks mem_process to allocate 2 pages in an
attempt to cause a memcg OOM kill. However, if swapping is enabled the
first page can be swapped before the second is allocated causing neither
limit to be exceeded, and no OOM kill to occur which results in a test
failure. Fix this by disabling swap in the test cgroup if it is enabled,
causing both pages to always be accounted under the same counter such
that memory.max (v2) / memory.limit_in_bytes (v1) causes an OOM kill.

Fixes: c0b815736 ("New testcase added by Naufal.")
Signed-off-by: T.J. Mercier <tjmercier@google.com>
---
 .../kernel/controllers/memcg/control/memcg_control_test.sh   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
index 68287a70c..eb8db3e30 100644
--- a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
+++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
@@ -12,7 +12,6 @@ TST_NEEDS_TMPDIR=1
 
 PAGE_SIZE=$(tst_getconf PAGESIZE)
 
-TOT_MEM_LIMIT=$PAGE_SIZE
 ACTIVE_MEM_LIMIT=$PAGE_SIZE
 PROC_MEM=$((PAGE_SIZE * 2))
 
@@ -50,13 +49,13 @@ test1()
 
 	# If the kernel is built without swap, the $memsw_memory_limit file is missing
 	if [ -e "$test_dir/$memsw_memory_limit" ]; then
-		ROD echo "$TOT_MEM_LIMIT" \> "$test_dir/$memsw_memory_limit"
+		ROD echo 0 \> "$test_dir/$memsw_memory_limit"
 	fi
 
 	KILLED_CNT=0
 	test_proc_kill
 
-	if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
+	if [ $KILLED_CNT -eq 0 ]; then
 		tst_res TFAIL "Test #1: failed"
 	else
 		tst_res TPASS "Test #1: passed"
-- 
2.49.0.395.g12beb8f557-goog


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

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

* Re: [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup
  2025-03-26 22:35 [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup T.J. Mercier via ltp
@ 2025-03-27 11:11 ` Petr Vorel
       [not found] ` <lo4sjpn6uvhyhgi7welsp4dsvi6jxrl4h5gwacuvqmgfvfqcq7@ayoafjktxzyc>
  1 sibling, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-03-27 11:11 UTC (permalink / raw)
  To: T.J. Mercier; +Cc: Michal Koutny, ltp

Hi,

> memcg_control_test_1 sets both a memory limit and a memsw/swap limit to
> a single page, and then asks mem_process to allocate 2 pages in an
> attempt to cause a memcg OOM kill. However, if swapping is enabled the
> first page can be swapped before the second is allocated causing neither
> limit to be exceeded, and no OOM kill to occur which results in a test
> failure. Fix this by disabling swap in the test cgroup if it is enabled,
> causing both pages to always be accounted under the same counter such
> that memory.max (v2) / memory.limit_in_bytes (v1) causes an OOM kill.

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

I suppose the old shell tests which cgroupv1 memory.memsw.limit_in_bytes are
written to test memory limits, thus only this one is suitable to modify.

The new C based tests (cgroupv2) should not be affected either.

Kind regards,
Petr

> Fixes: c0b815736 ("New testcase added by Naufal.")
> Signed-off-by: T.J. Mercier <tjmercier@google.com>
> ---
>  .../kernel/controllers/memcg/control/memcg_control_test.sh   | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

> diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
> index 68287a70c..eb8db3e30 100644
> --- a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
> +++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
> @@ -12,7 +12,6 @@ TST_NEEDS_TMPDIR=1

>  PAGE_SIZE=$(tst_getconf PAGESIZE)

> -TOT_MEM_LIMIT=$PAGE_SIZE
>  ACTIVE_MEM_LIMIT=$PAGE_SIZE
>  PROC_MEM=$((PAGE_SIZE * 2))

> @@ -50,13 +49,13 @@ test1()

>  	# If the kernel is built without swap, the $memsw_memory_limit file is missing
>  	if [ -e "$test_dir/$memsw_memory_limit" ]; then
> -		ROD echo "$TOT_MEM_LIMIT" \> "$test_dir/$memsw_memory_limit"
> +		ROD echo 0 \> "$test_dir/$memsw_memory_limit"
>  	fi

>  	KILLED_CNT=0
>  	test_proc_kill

> -	if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
> +	if [ $KILLED_CNT -eq 0 ]; then
>  		tst_res TFAIL "Test #1: failed"
>  	else
>  		tst_res TPASS "Test #1: passed"

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

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

* Re: [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup
       [not found] ` <lo4sjpn6uvhyhgi7welsp4dsvi6jxrl4h5gwacuvqmgfvfqcq7@ayoafjktxzyc>
@ 2025-03-27 19:37   ` T.J. Mercier via ltp
  0 siblings, 0 replies; 4+ messages in thread
From: T.J. Mercier via ltp @ 2025-03-27 19:37 UTC (permalink / raw)
  To: Michal Koutný; +Cc: ltp

On Thu, Mar 27, 2025 at 6:36 AM Michal Koutný <mkoutny@suse.com> wrote:
>
> Hello.
>
> On Wed, Mar 26, 2025 at 10:35:32PM +0000, "T.J. Mercier" <tjmercier@google.com> wrote:
> > memcg_control_test_1 sets both a memory limit and a memsw/swap limit to
> > a single page, and then asks mem_process to allocate 2 pages in an
> > attempt to cause a memcg OOM kill. However, if swapping is enabled the
> > first page can be swapped before the second is allocated causing neither
> > limit to be exceeded, and no OOM kill to occur which results in a test
> > failure. Fix this by disabling swap in the test cgroup if it is enabled,
> > causing both pages to always be accounted under the same counter such
> > that memory.max (v2) / memory.limit_in_bytes (v1) causes an OOM kill.
>
> I see how this fixes the test for v2 but for v1 the write would fail
> with -EINVAL because memory.memsw.limit_in_bytes < memory.limit_in_bytes
> and swapout would still be possible (which it wasn't _on v1_ before this
> patch IIUC).
>
> IOW the testcase should not treat memory.swap.max (v2) and
> memory.memsw.limit_in_bytes (v1) as equivalent quantities.

Thanks Michal. I'm about to send a v2 where swap is disabled only in
memcg v2 but the memsw limit is still applied in memcg v1. Tested on
both versions of memcg this time.

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

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

end of thread, other threads:[~2025-03-31 13:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 22:35 [LTP] [PATCH] memcg_control_test: Disable swapping in test cgroup T.J. Mercier via ltp
2025-03-27 11:11 ` Petr Vorel
     [not found] ` <lo4sjpn6uvhyhgi7welsp4dsvi6jxrl4h5gwacuvqmgfvfqcq7@ayoafjktxzyc>
2025-03-27 19:37   ` T.J. Mercier via ltp
  -- strict thread matches above, loose matches on Subject: below --
2025-03-26  4:11 T.J. Mercier via ltp

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.