[LTP] [PATCH v2] cpuset/cpuset_memory_pressure_test: Fix free memory calculate

Li Wang liwang@redhat.com
Mon Mar 6 09:52:01 CET 2023


On Fri, Mar 3, 2023 at 5:25 PM Hao Ge via ltp <ltp@lists.linux.it> wrote:

> Currently, free has two output formats,as follows
>
> free -m
>         total        used        free      shared  buff/cache   available
> Mem:   128135        3857      120633         158        3644      123219
> Swap:    8191          82        8109
>
> free -m
>         total       used       free     shared    buffers     cached
> Mem:   419694       9464     410230        234        435       6005
> -/+ buffers/cache:       3022     416671
> Swap:    2053          0       2053
>
> We need to avoid the error of adding the available item so that py_mem is
> wrong.
>
> Signed-off-by: Hao Ge <gehao@kylinos.cn>
> ---
>  .../cpuset_memory_pressure_testset.sh                  | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git
> a/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
> b/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
> index eddd7f6c5..88db03fd9 100755
> ---
> a/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
> +++
> b/testcases/kernel/controllers/cpuset/cpuset_memory_pressure_test/cpuset_memory_pressure_testset.sh
> @@ -32,8 +32,16 @@ check
>
>  exit_status=0
>
> +#read free cmd print layout is buff/cache or buff cache
> +bc_string=$(free -m | awk '{if(NR==1) print $5}')
> +
>  # usable physical memory
> -py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
> +if [ "$bc_string" == "buff/cache" ]
> +then
> +        py_mem=$(free -m | awk '{if(NR==2) print $4 + $6}')
> +else
> +        py_mem=$(free -m | awk '{if(NR==2) print $4 + $6 + $7}')
> +fi
>
>  # free swap space
>  sw_mem=$(free -m | awk '{if(NR==4) print $4}')
>

Can we extract all the above sizes from '/proc/meminfo' at once?

# cat /proc/meminfo
MemTotal:        7831852 kB
MemFree:         4455888 kB
MemAvailable:    7193660 kB
Buffers:            5264 kB
Cached:          2902516 kB
SwapCached:            0 kB
Active:          1242876 kB
...
SwapTotal:       8228860 kB
SwapFree:        8228860 kB


-- 
Regards,
Li Wang


More information about the ltp mailing list