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