xref: /aosp_15_r20/external/ltp/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2009 FUJITSU LIMITED
4# Copyright (c) 2016 Cyril Hrubis <[email protected]>
5# Copyright (c) 2018 Xiao Yang <[email protected]>
6# Copyright (c) 2021 Joerg Vehlow <[email protected]>
7#
8# Author: Li Zefan <[email protected]>
9# Restructure for LTP: Shi Weihua <[email protected]>
10# Added memcg enable/disable functinality: Rishikesh K Rajak <[email protected]
11
12MEMCG_TESTFUNC=test
13TST_CNT=3
14
15# Test the memory charge won't move to subgroup
16# $1 - memory.limit_in_bytes in sub group
17test_subgroup()
18{
19	local limit_subgroup=$1
20
21	if [ $limit_subgroup -ne 0 ]; then
22		limit_subgroup=$(memcg_adjust_limit_for_kmem $limit_subgroup)
23	fi
24
25	ROD mkdir subgroup
26	EXPECT_PASS echo $limit_subgroup \> subgroup/memory.limit_in_bytes
27
28	start_memcg_process --mmap-anon -s $MEM_TO_ALLOC
29
30	warmup
31	if [ $? -ne 0 ]; then
32		return
33	fi
34
35	echo $MEMCG_PROCESS_PID > tasks
36	signal_memcg_process $MIN_CHARGED
37	check_mem_stat "rss" $MIN_CHARGED $MEM_TO_ALLOC
38
39	cd subgroup
40	echo $MEMCG_PROCESS_PID > tasks
41	check_mem_stat "rss" 0
42
43	# cleanup
44	cd ..
45	stop_memcg_process
46	rmdir subgroup
47}
48
49test1()
50{
51	tst_res TINFO "Test that group and subgroup have no relationship"
52	test_subgroup $((2 * MEM_TO_ALLOC))
53}
54
55test2()
56{
57	test_subgroup $MEM_TO_ALLOC
58}
59
60test3()
61{
62	test_subgroup 0
63}
64
65. memcg_lib.sh
66
67# Allocate memory bigger than per-cpu kernel memory
68MEM_TO_ALLOC=$((PAGESIZES * 2))
69MIN_CHARGED=$((2 * (PAGESIZES - 1)))
70
71tst_run
72