Skip to contentSkip to conversation

memcg: memcg_subgroup_charge.sh: Fix the parent memory limit

PATCH New Masayoshi Mizuma 4 participants 6 messages Mar 5, 2021 – Sep 21, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memcg: memcg_subgroup_charge.sh: Fix the parent memory limit

From: Masayoshi Mizuma <[email protected]>

memcg_subgroup_charge.sh fails on v5.9 and later kernel. That's because memory.limit_in_bytes isn't set the suitable value so mem_process is killed by OOM accidentally.

The memory.limit_in_bytes is now wrong value because commit 3e38e0aaca9e ("mm: memcg: charge memcg percpu memory to the parent cgroup") changed the charging memory usage. The percpu memory, which is needed to create the subgroup, is charged to the parent's usage.

Since we can get the amount of the percpu memory as memory.usage_in_bytes after the subgroup is created, extend the limit to limit_in_bytes + usage_in_bytes.

---
 .../memcg/functional/memcg_subgroup_charge.sh            | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh +8 -1
index 9b23177a4..512a4e3dd 100755
@@ -20,9 +20,16 @@ TST_CNT=3
 test_subgroup()
 {
 	mkdir subgroup
-	echo $1 > memory.limit_in_bytes
 	echo $2 > subgroup/memory.limit_in_bytes
 
+	# v5.9 and later kernel, percpu memory which is needed to create
+	# the subgroup is charged to the parent's usage.
+	# Extend the parent limit so that we can observe the rss of
+	# memcg_process correctly.
+	pre_used=$(cat memory.usage_in_bytes)
+	newlimit=$(( $1 + pre_used ))
+	echo $newlimit > memory.limit_in_bytes
+
 	start_memcg_process --mmap-anon -s $PAGESIZES
 
 	warmup
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/1 memcg: memcg_subgroup_charge.sh: Fix the parent memory limit

Hi,

Quoted 6 lines · Masayoshi Mizuma

From: Masayoshi Mizuma <[email protected]>

memcg_subgroup_charge.sh fails on v5.9 and later kernel. That's because memory.limit_in_bytes isn't set the suitable value so mem_process is killed by OOM accidentally.

Quoted 7 lines

The memory.limit_in_bytes is now wrong value because commit 3e38e0aaca9e ("mm: memcg: charge memcg percpu memory to the parent cgroup") changed the charging memory usage. The percpu memory, which is needed to create the subgroup, is charged to the parent's usage.

Since we can get the amount of the percpu memory as memory.usage_in_bytes after the subgroup is created, extend the limit to limit_in_bytes + usage_in_bytes.

Sounds reasonable, I guess the test always fails on 5.9?
But the problem is, this test also fails on older kernels sometimes. When I looked at this the last time, I thought it was because sometimes the kernel requires new pages for the page table and that is also taken into account for the memory limit.
I still don't know why the test even sets a limit for the parent group and would vote for completely removing the memory setting on the parent.

J?rg

#2 lore raw

PATCH 1/1 memcg_subgroup_charge: Remove limiting of parent

It is not important how much memory is assigned to the parent group. The stated purpose of the test is to check no memory is assigned to the child group.

Also add the usage stats for the memcg_process because it appears the test will fail because the starting memory counter already includes some buffer/cache on linux-next. I'm not sure this is exactly what happens, but displaying the stats might help.

---
 .../controllers/memcg/functional/memcg_lib.sh    |  2 +-
 .../memcg/functional/memcg_subgroup_charge.sh    | 16 +++++-----------
 2 files changed, 6 insertions(+), 12 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1 -1
index ac9ad8268..1b76b6597 100755
@@ -240,7 +240,7 @@ signal_memcg_process()
 
 		loops=$((loops - 1))
 		if [ $loops -le 0 ]; then
-			tst_brk TBROK "timed out on memory.usage_in_bytes"
+			tst_brk TBROK "timed out on memory.usage_in_bytes" $usage $usage_start $size
 		fi
 	done
 }
testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh +5 -11
index 3fa016102..cda624923 100755
@@ -18,22 +18,16 @@ TST_CNT=3
 MEM_TO_ALLOC=$((PAGESIZES * 2))
 
 # Test the memory charge won't move to subgroup
-# $1 - memory.limit_in_bytes in parent group
-# $2 - memory.limit_in_bytes in sub group
+# $1 - memory.limit_in_bytes in sub group
 test_subgroup()
 {
-	local limit_parent=$1
-	local limit_subgroup=$2
+	local limit_subgroup=$1
 
-	if [ $limit_parent -ne 0 ]; then
-		limit_parent=$(memcg_adjust_limit_for_kmem $limit_parent)
-	fi
 	if [ $limit_subgroup -ne 0 ]; then
 		limit_subgroup=$(memcg_adjust_limit_for_kmem $limit_subgroup)
 	fi
 
 	ROD mkdir subgroup
-	EXPECT_PASS echo $limit_parent \> memory.limit_in_bytes
 	EXPECT_PASS echo $limit_subgroup \> subgroup/memory.limit_in_bytes
 
 	start_memcg_process --mmap-anon -s $MEM_TO_ALLOC
@@ -60,17 +54,17 @@ test_subgroup()
 test1()
 {
 	tst_res TINFO "Test that group and subgroup have no relationship"
-	test_subgroup $MEM_TO_ALLOC $((2 * MEM_TO_ALLOC))
+	test_subgroup $((2 * MEM_TO_ALLOC))
 }
 
 test2()
 {
-	test_subgroup $MEM_TO_ALLOC $MEM_TO_ALLOC
+	test_subgroup $MEM_TO_ALLOC
 }
 
 test3()
 {
-	test_subgroup $MEM_TO_ALLOC 0
+	test_subgroup 0
 }
 
 tst_run
Signature · 1 line
2.31.1
#3 lore raw

PATCH 1/1 memcg_subgroup_charge: Remove limiting of parent

Hi!

Quoted 8 lines

It is not important how much memory is assigned to the parent group. The stated purpose of the test is to check no memory is assigned to the child group.

Also add the usage stats for the memcg_process because it appears the test will fail because the starting memory counter already includes some buffer/cache on linux-next. I'm not sure this is exactly what happens, but displaying the stats might help.

Uff just found that there is a similar patch from Joerg as well:

http://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Either way we should merge one of them to get this finally fixed.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH] memcg_subgroup_charge: Remove limiting of parent

In reply to Richard Palethorpe

Hi

Quoted 3 lines · Richard Palethorpe via ltp

It is not important how much memory is assigned to the parent group. The stated purpose of the test is to check no memory is assigned to the child group.

I still don't know why the test even wants to limit anything, when it is just checking what is charged. So I would still vote for completely removing the limits and simplifying to just one test case.

But removing one limitation for now is a step in the right direction, so I will not argue anymore :)

Quoted 67 lines

Also add the usage stats for the memcg_process because it appears the test will fail because the starting memory counter already includes some buffer/cache on linux-next. I'm not sure this is exactly what happens, but displaying the stats might help.

---
  .../controllers/memcg/functional/memcg_lib.sh    |  2 +-
  .../memcg/functional/memcg_subgroup_charge.sh    | 16 +++++-----------
  2 files changed, 6 insertions(+), 12 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1 -1
index ac9ad8268..1b76b6597 100755
@@ -240,7 +240,7 @@ signal_memcg_process()
 
  		loops=$((loops - 1))
  		if [ $loops -le 0 ]; then
-			tst_brk TBROK "timed out on memory.usage_in_bytes"
+			tst_brk TBROK "timed out on memory.usage_in_bytes" $usage $usage_start $size
  		fi
  	done
  }
testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh +3 -10
index 3fa016102..cda624923 100755
@@ -18,22 +18,16 @@ TST_CNT=3
  MEM_TO_ALLOC=$((PAGESIZES * 2))
 
  # Test the memory charge won't move to subgroup
-# $1 - memory.limit_in_bytes in parent group
-# $2 - memory.limit_in_bytes in sub group
+# $1 - memory.limit_in_bytes in sub group
  test_subgroup()
  {
-	local limit_parent=$1
-	local limit_subgroup=$2
+	local limit_subgroup=$1
 
-	if [ $limit_parent -ne 0 ]; then
-		limit_parent=$(memcg_adjust_limit_for_kmem $limit_parent)
-	fi
  	if [ $limit_subgroup -ne 0 ]; then
  		limit_subgroup=$(memcg_adjust_limit_for_kmem $limit_subgroup)
  	fi
 
  	ROD mkdir subgroup
-	EXPECT_PASS echo $limit_parent \> memory.limit_in_bytes
  	EXPECT_PASS echo $limit_subgroup \> subgroup/memory.limit_in_bytes
 
  	start_memcg_process --mmap-anon -s $MEM_TO_ALLOC
@@ -60,17 +54,17 @@ test_subgroup()
  test1()
  {
  	tst_res TINFO "Test that group and subgroup have no relationship"
-	test_subgroup $MEM_TO_ALLOC $((2 * MEM_TO_ALLOC))
+	test_subgroup $((2 * MEM_TO_ALLOC))
  }
 
  test2()
  {
-	test_subgroup $MEM_TO_ALLOC $MEM_TO_ALLOC

testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh test_subgroup() · line 70

Quoted 10 lines
testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh +2 -1
+	test_subgroup $MEM_TO_ALLOC
  }
 
  test3()
  {
-	test_subgroup $MEM_TO_ALLOC 0
+	test_subgroup 0
  }
 
  tst_run

Joerg

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH] memcg_subgroup_charge: Remove limiting of parent

Hi!

Quoted 7 lines

I still don't know why the test even wants to limit anything, when it is just checking what is charged.
So I would still vote for completely removing the limits and simplifying to just one test case.

But removing one limitation for now is a step in the right direction, so I will not argue anymore :)

I've split the patch from Ritchie into two and pushed it so that we have this fixed for the release. We should review and rethink these tests once the release is finished since this isn't the only problem there.

Signature · 5 lines
Cyril Hrubis
[email protected]

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