[LTP] [PATCH] hugetlb: Initialize orig_shmmax and orig_shmmni value

Li Wang liwang@redhat.com
Thu Oct 31 09:17:34 CET 2019


On Thu, Oct 31, 2019 at 2:45 PM Eric Lin <tesheng@andestech.com> wrote:

> When doing save_nr_hugepages() in setup() and there
> is no Huge page support in system, it will call
> cleanup() and write wrong orig_shmmax and orig_shmmni
> value back to file.
>
> To fix it, we initialize the orig_shmmax and
> orig_shmmni to -1 and check it in cleanup().
>
> Signed-off-by: Eric Lin <tesheng@andestech.com>
>
Reviewed-by: Li Wang <liwang@redhat.com>


> ---
>  testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c   | 5 +++--
>  testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> index d375810cb..c76e4167f 100644
> --- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> +++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> @@ -38,7 +38,7 @@
>  static long huge_free;
>  static long huge_free2;
>  static long hugepages;
> -static long orig_shmmax, new_shmmax;
> +static long orig_shmmax = -1, new_shmmax;
>
>  static void shared_hugepage(void);
>
> @@ -106,7 +106,8 @@ static void setup(void)
>  static void cleanup(void)
>  {
>         restore_nr_hugepages();
> -       SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
> +       if (orig_shmmax != -1)
> +               SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", orig_shmmax);
>  }
>
>  static struct tst_test test = {
> diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
> b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
> index d5255228b..f2ecc465d 100644
> --- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
> +++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
> @@ -39,7 +39,7 @@ static int num_shms;
>  static int shm_id_arr[MAXIDS];
>
>  static long hugepages = 128;
> -static long orig_shmmni;
> +static long orig_shmmni = -1;
>  static struct tst_option options[] = {
>         {"s:", &nr_opt, "-s   num  Set the number of the been allocated
> hugepages"},
>         {NULL, NULL, NULL}
> @@ -105,7 +105,8 @@ static void cleanup(void)
>         for (i = 0; i < num_shms; i++)
>                 rm_shm(shm_id_arr[i]);
>
> -       FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
> +       if (orig_shmmni != -1)
> +               FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
>         restore_nr_hugepages();
>  }
>
> --
> 2.17.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191031/8515c390/attachment-0001.htm>


More information about the ltp mailing list