[LTP] [PATCH 5/7] mem/ksm06: Move ksm restoration into the tst_test struct

Li Wang liwang@redhat.com
Fri Mar 4 03:27:35 CET 2022


On Thu, Mar 3, 2022 at 10:49 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/mem/ksm/ksm06.c | 28 +++-------------------------
>  1 file changed, 3 insertions(+), 25 deletions(-)
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c
> b/testcases/kernel/mem/ksm/ksm06.c
> index 61507b2aa..f5f7319d7 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -39,9 +39,6 @@
>  #ifdef HAVE_NUMA_V2
>  #include <numaif.h>
>
> -static int run = -1;
> -static int sleep_millisecs = -1;
> -static int merge_across_nodes = -1;
>  static unsigned long nr_pages = 100;
>
>  static char *n_opt;
> @@ -141,27 +138,6 @@ static void setup(void)
>
>         if (n_opt)
>                 nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
> -
> -       /* save the current value */
> -       SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
> -       SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
> -                       "%d", &merge_across_nodes);
> -       SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
> -                       "%d", &sleep_millisecs);
> -}
> -
> -static void cleanup(void)
> -{
> -       if (merge_across_nodes != -1) {
> -               FILE_PRINTF(PATH_KSM "merge_across_nodes",
> -                           "%d", merge_across_nodes);
> -       }
> -
> -       if (sleep_millisecs != -1)
> -               FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d",
> sleep_millisecs);
> -
> -       if (run != -1)
> -               FILE_PRINTF(PATH_KSM "run", "%d", run);
>  }
>
>  static struct tst_test test = {
> @@ -171,9 +147,11 @@ static struct tst_test test = {
>                 {}
>         },
>         .setup = setup,
> -       .cleanup = cleanup,
>         .save_restore = (const char * const[]) {
>                 "?/sys/kernel/mm/ksm/max_page_sharing",
>

The mem library verifies the max_page_sharing validity before
setting because some old kernels do not have it. Thus it is fine
to use the prefix '?'.

+               "?/sys/kernel/mm/ksm/run",
> +               "?/sys/kernel/mm/ksm/merge_across_nodes",
> +               "?/sys/kernel/mm/ksm/sleep_millisecs",
>


But for the two knobs(run, sleep_millisecs) that should exist unless
the kernel disables KSM. So here we'd better start with prefix '!' and
add .needs_kconfg for ‘CONFIG_KSM=y' check.
(This also fit for other ksm tests)

For 'merge_across_nodes', we don't need any prefix because
ksm06 is actually relying on it, otherwise TCONF is expected.
Thus it's fine to remove the file check from setup() as well.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220304/18e811e1/attachment.htm>


More information about the ltp mailing list