Skip to contentSkip to conversation

controllers/cpuacct: skip cpuacct_100_100 on small memory systems

PATCH Superseded Krzysztof Kozlowski 2 participants 6 messages Jun 14, 2021 – Jun 24, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 controllers/cpuacct: skip cpuacct_100_100 on small memory systems

Running cpuacct_100_100 on a system with less than ~4 GB of RAM fails:

cpuacct 1 TINFO: timeout per run is 0h 5m 0s
cpuacct 1 TINFO: cpuacct: /sys/fs/cgroup/cpu,cpuacct cpuacct 1 TINFO: Creating 100 subgroups each with 100 processes testcases/bin/cpuacct.sh: 0: Cannot fork

In dmesg:

LTP: starting cpuacct_100_100 (cpuacct.sh 100 100)
cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-1.scope

The reason is cgroups pid limit set by systemd user.slice. For example on 2 GB RAM machine it is set as:

    /sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207

Add a check for both free memory and maximum number of pids (when using systemd) to skip the test. Systems not using systemd might still fail.

---

Changes since v1:
1. Add checking for pids.
2. Accurately check the memory constraints.

---
 .../kernel/controllers/cpuacct/cpuacct.sh     | 56 +++++++++++++++++++
 1 file changed, 56 insertions(+)
testcases/kernel/controllers/cpuacct/cpuacct.sh +56 -0
index 323aa7513bf4..66a48dde679b 100755
@@ -38,12 +38,68 @@ OPTIONS
 EOF
 }
 
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local realuid="$SUDO_UID"
+	local tasksneeded=$((max * nbprocess + 100))
+
+	if [ "$realuid" = "" ]; then
+		realuid=`id -u`
+		test $? || return 0
+	fi
+
+	local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
+	test $? || return 0
+
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"
+
+	return 0
+}
+
 setup()
 {
 	if ! grep -q -w cpuacct /proc/cgroups; then
 		tst_brk TCONF "cpuacct not supported on this system"
 	fi
 
+	check_limits
+	# Don't bother with memory limit checks on smaller tests
+	if [ $max -ge 100 ] && [ $nbprocess -ge 100 ]; then
+		check_free_memory
+	fi
+
 	mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2`
 	tst_res TINFO "cpuacct: $mount_point"
 	if [ "$mount_point" = "" ]; then
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 2/2 controllers/cpuacct: fix rmdir failures on early test abort

The "testpath" variable is assigned at the end of setup(), so if test exits early, the "rmdir $testpath" is wrong:

cpuacct 1 TCONF: not enough of memory on this system (less than 3840 MB) cpuacct 1 TINFO: removing created directories
rmdir: missing operand
Try 'rmdir --help' for more information.

---

Changes since v1:
1. None.

---
 testcases/kernel/controllers/cpuacct/cpuacct.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
testcases/kernel/controllers/cpuacct/cpuacct.sh +5 -4
index 66a48dde679b..2e9ff5a5286c 100755
@@ -127,12 +127,13 @@ cleanup()
 {
 	tst_res TINFO "removing created directories"
 
-	if [ -d "$testpath/subgroup_1" ]; then
-		rmdir $testpath/subgroup_*
+	if [ "$testpath" ]; then
+		if [ -d "$testpath/subgroup_1" ]; then
+			rmdir $testpath/subgroup_*
+		fi
+		rmdir $testpath
 	fi
 
-	rmdir $testpath
-
 	if [ "$mounted" -ne 1 ]; then
 		tst_res TINFO "Umounting cpuacct"
 		umount $mount_point
Signature · 1 line
2.27.0
#2 lore raw

PATCH v2 1/2 controllers/cpuacct: skip cpuacct_100_100 on small memory systems

In reply to Krzysztof Kozlowski

Hi!

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 53

Quoted 13 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +13 -0
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? || return 0

I do not think that something as basic as awk on /proc/meminfo here will fail...

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 62

Quoted 8 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +8 -0
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then

I would still add some memory margin to the memneeded here. At least add a hundred of megabytes before we do the check.

Quoted 14 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +14 -0
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local realuid="$SUDO_UID"
+	local tasksneeded=$((max * nbprocess + 100))
+
+	if [ "$realuid" = "" ]; then
+		realuid=`id -u`

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 86

Quoted 10 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +10 -0
+		test $? || return 0
+	fi
+
+	local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
+	test $? || return 0
+
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"

Huh, is this really needed? The test is supposed to run under root. The user is supposed to login as a root or at least do 'su -' before executing LTP anyways.

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 99

Quoted 12 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +6 -0
+	return 0
+}
+
 setup()
 {
 	if ! grep -q -w cpuacct /proc/cgroups; then
 		tst_brk TCONF "cpuacct not supported on this system"
 	fi
 
+	check_limits
+	# Don't bother with memory limit checks on smaller tests
+	if [ $max -ge 100 ] && [ $nbprocess -ge 100 ]; then

We should probably check if the $max * $mbprocess -ge 1000 or something like that just in a case someone addds a test with large enough $nbprocess.

Quoted 9 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +3 -0
+		check_free_memory
+	fi
+
 	mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2`
 	tst_res TINFO "cpuacct: $mount_point"
 	if [ "$mount_point" = "" ]; then
Signature · 1 line
2.27.0
Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH v2 1/2 controllers/cpuacct: skip cpuacct_100_100 on small memory systems

Quoted 17 lines · Cyril Hrubis

Hi!

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 53

Quoted 13 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +13 -0
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? || return 0

I do not think that something as basic as awk on /proc/meminfo here will fail...

It's still nice pattern to check for return values but if you insist, I can drop it.

Quoted 12 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 62

Quoted 9 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +8 -0
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then

I would still add some memory margin to the memneeded here. At least add a hundred of megabytes before we do the check.

Sure.

Quoted 21 lines
Quoted 21 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +20 -0
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local realuid="$SUDO_UID"
+	local tasksneeded=$((max * nbprocess + 100))
+
+	if [ "$realuid" = "" ]; then
+		realuid=`id -u`
+		test $? || return 0
+	fi
+
+	local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
+	test $? || return 0
+
Quoted 8 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 86

Quoted 4 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +4 -0
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"

Huh, is this really needed? The test is supposed to run under root. The user is supposed to login as a root or at least do 'su -' before executing LTP anyways.

Yeah, because even root sessions (user-0.slice) have the PID limit set by systemd.

$ ssh root@....
$ grep . /sys/fs/cgroup/pids/user.slice/*/*
/sys/fs/cgroup/pids/user.slice/user-0.slice/cgroup.clone_children:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/notify_on_release:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.current:5
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.events:max 0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207
Quoted 10 lines
Quoted 10 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +3 -0
+	return 0
+}
+
 setup()
 {
 	if ! grep -q -w cpuacct /proc/cgroups; then
 		tst_brk TCONF "cpuacct not supported on this system"
 	fi
Quoted 7 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 99

Quoted 3 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +3 -0
+	check_limits
+	# Don't bother with memory limit checks on smaller tests
+	if [ $max -ge 100 ] && [ $nbprocess -ge 100 ]; then

We should probably check if the $max * $mbprocess -ge 1000 or something like that just in a case someone addds a test with large enough $nbprocess.

Makes sense, optionally the check can be done always.

Thanks for the review!

Best regards,
Krzysztof

#4 lore raw

PATCH v2 1/2 controllers/cpuacct: skip cpuacct_100_100 on small memory systems

Quoted 70 lines · Krzysztof Kozlowski
Quoted 17 lines · Cyril Hrubis

Hi!

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 53

Quoted 13 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +13 -0
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? || return 0

I do not think that something as basic as awk on /proc/meminfo here will fail...

It's still nice pattern to check for return values but if you insist, I can drop it.

Quoted 12 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 62

Quoted 9 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +8 -0
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then

I would still add some memory margin to the memneeded here. At least add a hundred of megabytes before we do the check.

Sure.

Quoted 21 lines
Quoted 21 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +20 -0
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local realuid="$SUDO_UID"
+	local tasksneeded=$((max * nbprocess + 100))
+
+	if [ "$realuid" = "" ]; then
+		realuid=`id -u`
+		test $? || return 0
+	fi
+
+	local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
+	test $? || return 0
+
Quoted 8 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 86

Quoted 4 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +4 -0
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"

Huh, is this really needed? The test is supposed to run under root. The user is supposed to login as a root or at least do 'su -' before executing LTP anyways.

Yeah, because even root sessions (user-0.slice) have the PID limit set by systemd.

Quoted 7 lines
$ ssh root@....
$ grep . /sys/fs/cgroup/pids/user.slice/*/*
/sys/fs/cgroup/pids/user.slice/user-0.slice/cgroup.clone_children:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/notify_on_release:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.current:5
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.events:max 0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207

I forgot to mention: that's a default Ubuntu 20.04 LTS system on 2 GB RAM machine, with systemd 245.4-4ubuntu3.6.

Best regards,
Krzysztof

#5 lore raw

PATCH v2 1/2 controllers/cpuacct: skip cpuacct_100_100 on small memory systems

Quoted 79 lines · Krzysztof Kozlowski
Quoted 70 lines · Krzysztof Kozlowski
Quoted 17 lines · Cyril Hrubis

Hi!

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 53

Quoted 13 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +13 -0
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? || return 0

I do not think that something as basic as awk on /proc/meminfo here will fail...

It's still nice pattern to check for return values but if you insist, I can drop it.

Quoted 12 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 62

Quoted 9 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +8 -0
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then

I would still add some memory margin to the memneeded here. At least add a hundred of megabytes before we do the check.

Sure.

Quoted 21 lines
Quoted 21 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +20 -0
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local realuid="$SUDO_UID"
+	local tasksneeded=$((max * nbprocess + 100))
+
+	if [ "$realuid" = "" ]; then
+		realuid=`id -u`
+		test $? || return 0
+	fi
+
+	local tasksmax=`systemctl show user-${real_uid}.slice | awk -F '=' '/TasksMax/ {print $2}'`
+	test $? || return 0
+
Quoted 8 lines

testcases/kernel/controllers/cpuacct/cpuacct.sh OPTIONS · line 86

Quoted 4 lines
testcases/kernel/controllers/cpuacct/cpuacct.sh +4 -0
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"

Huh, is this really needed? The test is supposed to run under root. The user is supposed to login as a root or at least do 'su -' before executing LTP anyways.

Yeah, because even root sessions (user-0.slice) have the PID limit set by systemd.

Quoted 7 lines
$ ssh root@....
$ grep . /sys/fs/cgroup/pids/user.slice/*/*
/sys/fs/cgroup/pids/user.slice/user-0.slice/cgroup.clone_children:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/notify_on_release:0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.current:5
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.events:max 0
/sys/fs/cgroup/pids/user.slice/user-0.slice/pids.max:5207
Quoted 2 lines

I forgot to mention: that's a default Ubuntu 20.04 LTS system on 2 GB RAM machine, with systemd 245.4-4ubuntu3.6.

Any further comments here or something to fix? I think there were no objections to this patch, right?

Best regards,
Krzysztof