• 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=8
11
12. memcg_lib.sh
13
14test1()
15{
16	tst_res TINFO "Test cache"
17	test_mem_stat "--shm -k 3" $PAGESIZES $PAGESIZES "cache" $PAGESIZES $PAGESIZES false
18}
19
20test2()
21{
22	tst_res TINFO "Test mapped_file"
23	test_mem_stat "--mmap-file" $PAGESIZES $PAGESIZES \
24		"mapped_file" $PAGESIZES $PAGESIZES false
25}
26
27test3()
28{
29	tst_res TINFO "Test unevictable with MAP_LOCKED"
30	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES \
31		"unevictable" $PAGESIZES $PAGESIZES false
32}
33
34test4()
35{
36	tst_res TINFO "Test unevictable with mlock"
37	test_mem_stat "--mmap-lock2" $PAGESIZES $PAGESIZES \
38		"unevictable" $PAGESIZES $PAGESIZES false
39}
40
41test5()
42{
43	tst_res TINFO "Test hierarchical_memory_limit with enabling hierarchical accounting"
44	echo 1 > memory.use_hierarchy
45
46	local limit=$(memcg_adjust_limit_for_kmem $PAGESIZES)
47
48	ROD mkdir subgroup
49	EXPECT_PASS echo $limit \> memory.limit_in_bytes
50	EXPECT_PASS echo $((limit + PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
51
52	cd subgroup
53	check_mem_stat "hierarchical_memory_limit" $limit
54
55	cd ..
56	rmdir subgroup
57}
58
59test6()
60{
61	tst_res TINFO "Test hierarchical_memory_limit with disabling hierarchical accounting"
62	memcg_require_hierarchy_disabled
63
64	ROD echo 0 \> memory.use_hierarchy
65
66	ROD mkdir subgroup
67	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
68	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
69
70	cd subgroup
71	check_mem_stat "hierarchical_memory_limit" $((PAGESIZES * 2))
72
73	cd ..
74	rmdir subgroup
75}
76
77test7()
78{
79	tst_res TINFO "Test hierarchical_memsw_limit with enabling hierarchical accounting"
80	memcg_require_memsw
81
82	ROD echo 1 \> memory.use_hierarchy
83
84	ROD mkdir subgroup
85	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
86	EXPECT_PASS echo $PAGESIZES \> memory.memsw.limit_in_bytes
87	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
88	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.memsw.limit_in_bytes
89
90	cd subgroup
91	check_mem_stat "hierarchical_memsw_limit" $PAGESIZES
92
93	cd ..
94	rmdir subgroup
95}
96
97test8()
98{
99	tst_res TINFO "Test hierarchical_memsw_limit with disabling hierarchical accounting"
100	memcg_require_memsw
101	memcg_require_hierarchy_disabled
102
103	ROD echo 0 \> memory.use_hierarchy
104
105	ROD mkdir subgroup
106	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
107	EXPECT_PASS echo $PAGESIZES \> memory.memsw.limit_in_bytes
108	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
109	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.memsw.limit_in_bytes
110
111	cd subgroup
112	check_mem_stat "hierarchical_memsw_limit" $((PAGESIZES * 2))
113
114	cd ..
115	rmdir subgroup
116}
117
118tst_run
119