• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2012 FUJITSU LIMITED
4# Copyright (c) 2014-2018 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
14
15# Run test cases which test memory.move_charge_at_immigrate
16test_move_charge()
17{
18	local memtypes="$1"
19	local size=$2
20	local total_size=$3
21	local move_charge_mask=$4
22	local b_rss=$5
23	local b_cache=$6
24	local a_rss=$7
25	local a_cache=$8
26
27	mkdir subgroup_a
28
29	start_memcg_process $memtypes -s $size
30
31	warmup
32	if [ $? -ne 0 ]; then
33		rmdir subgroup_a
34		return
35	fi
36
37	ROD echo $MEMCG_PROCESS_PID \> subgroup_a/tasks
38	signal_memcg_process $total_size "subgroup_a/"
39
40	ROD mkdir subgroup_b
41	echo $move_charge_mask > subgroup_b/memory.move_charge_at_immigrate
42	echo $MEMCG_PROCESS_PID > subgroup_b/tasks
43
44	cd subgroup_b
45	check_mem_stat "rss" $b_rss
46	check_mem_stat "cache" $b_cache
47	cd ../subgroup_a
48	check_mem_stat "rss" $a_rss
49	check_mem_stat "cache" $a_cache
50	cd ..
51	stop_memcg_process
52	rmdir subgroup_a subgroup_b
53}
54
55
56test1()
57{
58	tst_res TINFO "Test disable moving charges"
59	test_move_charge "--mmap-anon" $PAGESIZES $PAGESIZES 0 0 0 $PAGESIZES 0
60}
61
62test2()
63{
64	tst_res TINFO "Test move anon"
65	test_move_charge "--mmap-anon --shm --mmap-file" $PAGESIZES \
66		$((PAGESIZES * 3)) 1 $PAGESIZES 0 0 $((PAGESIZES * 2))
67}
68
69test3()
70{
71	tst_res TINFO "Test move file"
72	test_move_charge "--mmap-anon --shm --mmap-file" $PAGESIZES \
73		$((PAGESIZES * 3)) 2 0 $((PAGESIZES * 2)) $PAGESIZES 0
74}
75
76test4()
77{
78	tst_res TINFO "Test move anon and file"
79	test_move_charge "--mmap-anon --shm" $PAGESIZES \
80		$((PAGESIZES * 2)) 3 $PAGESIZES $PAGESIZES 0 0
81}
82
83tst_run
84