1#! /bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2012 FUJITSU LIMITED 4# Copyright (c) 2014-2016 Linux Test Project 5# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de> 6# 7# Author: Peng Haitao <penght@cn.fujitsu.com> 8 9MEMCG_TESTFUNC=test 10TST_CNT=4 11 12. memcg_lib.sh 13 14MEM_TO_ALLOC=$((PAGESIZE * 1024)) 15MEM_LIMIT=$((MEM_TO_ALLOC * 2)) 16 17# Run test cases which checks memory.[memsw.]max_usage_in_bytes after make 18# some memory allocation 19test_max_usage_in_bytes() 20{ 21 local item="memory.max_usage_in_bytes" 22 [ $1 -eq 1 ] && item="memory.memsw.max_usage_in_bytes" 23 local check_after_reset=$2 24 start_memcg_process --mmap-anon -s $MEM_TO_ALLOC 25 26 warmup 27 if [ $? -ne 0 ]; then 28 return 29 fi 30 31 echo $MEMCG_PROCESS_PID > tasks 32 signal_memcg_process $MEM_TO_ALLOC 33 signal_memcg_process $MEM_TO_ALLOC 34 35 check_mem_stat $item $MEM_TO_ALLOC 36 37 if [ $check_after_reset -eq 1 ]; then 38 echo 0 > $item 39 check_mem_stat $item 0 40 fi 41 42 stop_memcg_process 43} 44 45test1() 46{ 47 tst_res TINFO "Test memory.max_usage_in_bytes" 48 test_max_usage_in_bytes 0 0 49} 50 51test2() 52{ 53 tst_res TINFO "Test memory.memsw.max_usage_in_bytes" 54 memcg_require_memsw 55 56 echo $MEM_LIMIT > memory.limit_in_bytes 57 echo $MEM_LIMIT > memory.memsw.limit_in_bytes 58 test_max_usage_in_bytes 1 0 59} 60 61test3() 62{ 63 tst_res TINFO "Test reset memory.max_usage_in_bytes" 64 test_max_usage_in_bytes 0 1 65} 66 67test4() 68{ 69 tst_res TINFO "Test reset memory.memsw.max_usage_in_bytes" 70 memcg_require_memsw 71 72 echo $MEM_LIMIT > memory.limit_in_bytes 73 echo $MEM_LIMIT > memory.memsw.limit_in_bytes 74 test_max_usage_in_bytes 1 1 75} 76 77tst_run 78