[LTP] [PATCH V2] memcg_stress_test.sh: Fix reserved mem calculate

Li Wang liwang@redhat.com
Mon Mar 13 06:59:14 CET 2023


Hi Hao,

On Thu, Mar 9, 2023 at 5:17 PM Hao Ge <gehao@kylinos.cn> wrote:

> When running this test case on a machine with large memory,
> and without swap or swap is too small,existing reserved
> memory is too small for a machine with large memory,and
> will cause forking a subprocess to run a command will fail
> due to memory is exhausted,so optimize reserved memory
> calculate to ten percent of free memory.
>
> Here is an example:
>
> free -m
>               total        used        free      shared  buff/cache
>  available
> Mem:         260184        2959      255854          62        1370
> 236346
> Swap:          4095           0        4095
>
> when you run this testcase,console will report
> fork:Cannot allocate memory
>
> Signed-off-by: Hao Ge <gehao@kylinos.cn>
> ---
>  .../kernel/controllers/memcg/stress/memcg_stress_test.sh    | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git
> a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
> b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
> index cb52840d7..f26a9f72a 100755
> --- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
> +++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
> @@ -40,7 +40,7 @@ setup()
>         MEM=$(( $mem_free + $swap_free / 2 ))
>         MEM=$(( $MEM / 1024 ))
>         RUN_TIME=$(( 15 * 60 ))
> -       [ "$pgsize" = "4096" ] && THREAD_SPARE_MB=1 || THREAD_SPARE_MB=8
> +       RESERVED_MEMORY=$(( $MEM * 10/100 ))
>

Thanks for the improvement work.

But IMHO, this does not completely resolve the potential issue which
in eating free_mem for stress testing.

We have to consider many scenarios for the system's available memory
including without swap file, free_mem > avail_mem, and min_free_kbytes
impaction.

For example, your patch may _not_ work on this:

MemTotal:       36044544 kB
MemFree:        29177728 kB
MemAvailable:   26391488 kB
...
SwapTotal:             0 kB
SwapFree:              0 kB

I would suggest you take a look into:

https://github.com/linux-test-project/ltp/blob/master/lib/tst_memutils.c#L19
to see how this function treats this and keeps a safety mem margin.
Hope it gives you some inspiration.




>
>         tst_res TINFO "Calculated available memory $MEM MB"
>  }
> @@ -93,12 +93,12 @@ run_stress()
>
>  test1()
>  {
> -       run_stress 150 $(( ($MEM - 150 * $THREAD_SPARE_MB) / 150 )) 5
> $RUN_TIME
> +       run_stress 150 $(( ($MEM - $RESERVED_MEMORY) / 150 )) 5 $RUN_TIME
>  }
>
>  test2()
>  {
> -       run_stress 1 $(( $MEM - $THREAD_SPARE_MB)) 5 $RUN_TIME
> +       run_stress 1 $(( $MEM - $RESERVED_MEMORY)) 5 $RUN_TIME
>  }
>
>  . cgroup_lib.sh
> --
> 2.25.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang


More information about the ltp mailing list