All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Zhao Gongyi <zhaogongyi@huawei.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
Date: Mon, 24 Oct 2022 08:58:36 +0100	[thread overview]
Message-ID: <87zgdlzlz7.fsf@suse.de> (raw)
In-Reply-To: <20221013134728.49609-3-zhaogongyi@huawei.com>

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that madvise(2) MADV_DONTNEED operation applied to Huge
> TLB pages successfully after kernel version 5.18, and will result
> in zero-fill-on-demand pages for anonymous private mappings.
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  runtest/syscalls                              |  1 +
>  testcases/kernel/syscalls/madvise/.gitignore  |  1 +
>  testcases/kernel/syscalls/madvise/madvise04.c | 62 +++++++++++++++++++
>  3 files changed, 64 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/madvise/madvise04.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index c81764df4..eb1910cec 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -941,6 +941,7 @@ mincore04 mincore04
>  madvise01 madvise01
>  madvise02 madvise02
>  madvise03 madvise03
> +madvise04 madvise04
>  madvise05 madvise05
>  madvise06 madvise06
>  madvise07 madvise07
> diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
> index f4bfdfefe..db8ce47c1 100644
> --- a/testcases/kernel/syscalls/madvise/.gitignore
> +++ b/testcases/kernel/syscalls/madvise/.gitignore
> @@ -1,6 +1,7 @@
>  /madvise01
>  /madvise02
>  /madvise03
> +/madvise04
>  /madvise05
>  /madvise06
>  /madvise07
> diff --git a/testcases/kernel/syscalls/madvise/madvise04.c b/testcases/kernel/syscalls/madvise/madvise04.c
> new file mode 100644
> index 000000000..a970fb33e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/madvise/madvise04.c
> @@ -0,0 +1,62 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
> + * Author: Zhao Gongyi <zhaogongyi@huawei.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Check that madvise(2) MADV_DONTNEED operation applied to Huge TLB pages
> + * successfully after kernel version 5.18, and will result in
> + * zero-fill-on-demand pages for anonymous private mappings.
> + */
> +
> +#include "tst_test.h"
> +
> +#define MAP_SIZE (8 * 1024)
> +
> +static char *addr;
> +static int mapsz;
> +
> +static void run(void)
> +{
> +	TST_EXP_PASS(madvise(addr, mapsz, MADV_DONTNEED));
> +	for (int i = 0; i < mapsz; i++) {
> +		if (addr[i]) {
> +			tst_res(TFAIL,
> +				"There are no zero-fill-on-demand pages "
> +				"for anonymous private mappings");
> +			return;
> +		}
> +	}
> +
> +	tst_res(TPASS, "There are zero-fill-on-demand pages "
> +		       "for anonymous private mappings");
> +}
> +
> +static void setup(void)
> +{
> +	mapsz = tst_get_hugepage_size();
> +	addr = SAFE_MMAP(NULL, mapsz,
> +			PROT_READ | PROT_WRITE,
> +			MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
> +			-1, 0);
> +	memset(addr, 1, mapsz);

If we only do memset here then we are only testing the zero-fill feature
on the first iteration.

> +}
> +
> +static void cleanup(void)
> +{
> +	if (addr)
> +		SAFE_MUNMAP(addr, mapsz);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.min_kver = "5.18",

What happens before 5.18? Could we try applying MADV_DONTNEED and return
TCONF instead?

> +	.needs_root = 1,

Why does this need root?

> +	.hugepages = {1, TST_NEEDS},
> +};
> +
> --
> 2.17.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-10-24  8:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-24  7:58   ` Richard Palethorpe [this message]
2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
2022-10-24  9:48   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
2022-10-24 10:47   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
2022-10-24 11:01   ` Richard Palethorpe
  -- strict thread matches above, loose matches on Subject: below --
2022-10-24  9:29 [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) zhaogongyi via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zgdlzlz7.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=ltp@lists.linux.it \
    --cc=zhaogongyi@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.