1#! /bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2009 FUJITSU LIMITED 4# Author: Li Zefan <lizf@cn.fujitsu.com> 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 32swapoff -a 33sleep 1 34echo $pid > "$mount_point/$task_list" 2> /dev/null 35echo $$ > "$mount_point/$task_list" 2> /dev/null 36 37# now remove the cgroup 38rmdir "$test_path" 39