Skip to contentSkip to conversation

memcg_control_test: Disable swapping in test cgroup

PATCH New T.J. Mercier via ltp 1 participant 1 message Mar 31, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg_control_test: Disable swapping in test cgroup

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.")
---
 .../kernel/controllers/memcg/control/memcg_control_test.sh   | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
testcases/kernel/controllers/memcg/control/memcg_control_test.sh +2 -3
index 68287a70c..eb8db3e30 100644
@@ -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"
Signature · 5 lines
2.49.0.395.g12beb8f557-goog


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