• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2################################################################################
3#
4# Copyright (C) 2022 Huawei Device Co., Ltd.
5# SPDX-License-Identifier: GPL-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10# See the License for the specific language governing permissions and
11# limitations under the License.
12#
13################################################################################
14# File: mem_debug05.sh
15#
16# Description: Dimension measurement information of DR/kswapd/zswapd test
17#
18# Authors:     Wangyuting - wangyuting36@huawei.com
19#
20# History:     Mar 23 2022 - init scripts
21#
22################################################################################
23source tst_oh.sh
24
25do_setup()
26{
27    zcat /proc/config.gz | grep CONFIG_RECLAIM_ACCT=y || tst_res TCONF "CONFIG_RECLAIM_ACCT=y not satisfied!"
28
29    avail_buffers=/dev/memcg/memory.avail_buffers
30
31    local zswapd_s=/dev/memcg/memory.zswapd_pressure_show
32    local buffer_size=$(cat $zswapd_s | grep 'buffer_size' | awk -F ':' '{print$2}')
33
34    avail_buffers_def=$(cat /dev/memcg/memory.avail_buffers | awk '$1=="avail_buffers:"{print $2}')
35    min_avail_buffers_def=$(cat /dev/memcg/memory.avail_buffers | awk '$1=="min_avail_buffers:"{print $2}')
36    high_avail_buffers_def=$(cat /dev/memcg/memory.avail_buffers | awk '$1=="high_avail_buffers:"{print $2}')
37    free_swap_threshold_def=$(cat /dev/memcg/memory.avail_buffers | awk '$1=="free_swap_threshold:"{print $2}')
38
39    echo 0 $(( $buffer_size + 50 )) $(( $buffer_size + 100 )) 0 > $avail_buffers
40    sleep 3
41}
42
43do_test()
44{
45    local ret=0
46
47    reclaim_acct_disable="/sys/module/reclaim_acct/parameters/disable"
48    reclaim_acct_disable_def=$(cat /sys/module/reclaim_acct/parameters/disable)
49    echo 0 > $reclaim_acct_disable
50
51    wukong exec -s 10 -i 1000 -a 0.28 -t 0.72 -c 1000000 &
52    sleep 100
53
54    check_reclaim_efficiency "reclaim"
55    check_reclaim_efficiency "kswapd"
56    check_reclaim_efficiency "zswapd"
57
58}
59
60check_reclaim_efficiency()
61{
62    local mem_type=$1
63
64    cat /proc/reclaim_efficiency > log.txt
65    local total_process_time=$(cat log.txt | grep -A5 $mem_type | grep total_process | awk '{print $2}')
66    local drain_pages_time=$(cat log.txt | grep -A5 $mem_type | grep drain_pages | awk '{print $2}')
67    local shrink_file_time=$(cat log.txt | grep -A5 $mem_type | grep shrink_file | awk '{print $2}')
68    local shrink_anon_time=$(cat log.txt | grep -A5 $mem_type | grep shrink_anon | awk '{print $2}')
69    local shrink_slab_time=$(cat log.txt | grep -A5 $mem_type | grep shrink_slab | awk '{print $2}')
70    local sum_time_a=$(($drain_pages_time + $shrink_file_time))
71    local sum_time_b=$(($shrink_anon_time + $shrink_slab_time))
72    local sum_time=$(($sum_time_a + $sum_time_b))
73
74    if [ $sum_time -le $total_process_time ]; then
75        tst_res TPASS "total_process_time in $mem_type isn't less than sum of subprocess."
76    else
77        tst_res TFAIL "total_process_time in $mem_type is less than sum of subprocess."
78    fi
79
80    local total_process_freed=$(cat log.txt | grep -A5 $mem_type | grep total_process | awk '{print $3}')
81    local shrink_file_freed=$(cat log.txt | grep -A5 $mem_type | grep shrink_file | awk '{print $3}')
82    local shrink_anon_freed=$(cat log.txt | grep -A5 $mem_type | grep shrink_anon | awk '{print $3}')
83    local sum_freed=$(($shrink_file_freed + $shrink_anon_freed))
84
85    if [ $sum_freed -eq $total_process_freed ]; then
86        tst_res TPASS "total_process_freed in $mem_type calculate correctly."
87    else
88        tst_res TFAIL "total_process_freed in $mem_type calculate incorrectly."
89    fi
90}
91
92do_clean()
93{
94    local pid=$(ps -ef | grep wukong | grep -v grep | awk '{print $2}')
95    kill -9 $pid
96    echo $reclaim_acct_disable_def > $reclaim_acct_disable
97    echo $avail_buffers_def $min_avail_buffers_def $high_avail_buffers_def $free_swap_threshold_def > $avail_buffers
98    rm -rf log.txt
99}
100
101do_setup
102do_test
103do_clean
104tst_exit