xref: /aosp_15_r20/external/ltp/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#! /bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2009 FUJITSU LIMITED
4# Author: Li Zefan <[email protected]>
5
6cgroup_version="$1"
7mount_point="$2"
8test_path="$3"
9
10if [ "$cgroup_version" = "2" ]; then
11	task_list="cgroup.procs"
12	memory_limit="memory.max"
13else
14	task_list="tasks"
15	memory_limit="memory.limit_in_bytes"
16fi
17
18echo $$ > "$test_path/$task_list"
19
20./memcg_test_4 &
21pid=$!
22sleep 1
23
24# let $pid allocate 100M memory
25/bin/kill -SIGUSR1 $pid
26sleep 1
27
28# shrink memory, and then 80M will be swapped
29echo 40M > "$test_path/$memory_limit"
30
31# turn off swap, and swapoff will be killed
32for s in $(cut -F1 /proc/swaps | tail -n +2); do
33	swapoff $s
34done
35sleep 1
36echo $pid > "$mount_point/$task_list" 2> /dev/null
37echo $$ > "$mount_point/$task_list"  2> /dev/null
38
39# now remove the cgroup
40rmdir "$test_path"
41